wok-current annotate slitaz-dev-tools/stuff/tazdev @ rev 4717
slitaz-dev-tools: add tazdev purge
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Jan 05 11:56:30 2010 +0100 (2010-01-05) |
parents | bf3619b6ee2a |
children | 7fd0a3f6eb9c |
rev | line source |
---|---|
pankso@3440 | 1 #!/bin/sh |
pankso@3440 | 2 # Tazdev - SliTaz developers and build host tool. |
pankso@3440 | 3 # System wide config file: /etc/slitaz/tazdev.conf |
pankso@3440 | 4 # |
pankso@3440 | 5 # (c) 2009 SliTaz GNU/Linux - GNU gpl v3 |
pankso@3440 | 6 # |
pankso@3440 | 7 # Authors : Christophe Lincoln (Pankso) <pankso@slitaz.org> |
pankso@3440 | 8 # |
pankso@3440 | 9 |
pankso@3440 | 10 if [ -f /etc/slitaz/tazdev.conf ]; then |
pankso@3440 | 11 . /etc/slitaz/tazdev.conf |
pankso@3444 | 12 if [ -f $PWD/tazdev.conf ]; then |
pankso@3444 | 13 . $PWD/tazdev.conf |
pankso@3444 | 14 fi |
pankso@3440 | 15 else |
pankso@3440 | 16 echo -e "\nNo config file found in /etc/slitaz or the current dir...\n" |
pankso@3440 | 17 exit 0 |
pankso@3440 | 18 fi |
pankso@3440 | 19 |
pankso@3440 | 20 usage() |
pankso@3440 | 21 { |
pankso@3440 | 22 echo -e "\nSliTaz developers and build host tool\n |
pankso@3499 | 23 \033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking|path] |
pankso@3440 | 24 \033[1mCommands: \033[0m\n |
pankso@3500 | 25 usage Print this short usage and command list. |
paul@3526 | 26 projects-stats Display statistics about your projects (-ps). |
pankso@3500 | 27 cmplog Log 'tazwok cmp' result (or use tazbb). |
pankso@3500 | 28 update-wok Update Hg wok and copy it to the chroot wok. |
pankso@3500 | 29 update-www Update SliTaz Website repo from Hg. |
pankso@3500 | 30 chroot Mount virtual fs if needed and chroot into the build env. |
pankso@3500 | 31 gen-chroot Generate a chroot using the last cooking base rootfs. |
paul@3526 | 32 clean-chroot Clean a chroot environment (skip root/ and home/). |
pascal@4717 | 33 purge Remove obsolate packages and obsolate source tarballs. |
pankso@3500 | 34 push Upload new packages to the main mirror (-p). |
pankso@3500 | 35 dry-push Show what will be uploaded to the mirror. Does nothing (-dp). |
pankso@3500 | 36 pull Download new packages from the main mirror. |
pankso@3500 | 37 dry-pull Show what will be downloaded from the mirror. Does nothing.\n" |
pankso@3440 | 38 } |
pankso@3440 | 39 |
pankso@3440 | 40 # Exit if user is not root. |
pankso@3440 | 41 check_root() |
pankso@3440 | 42 { |
pankso@3440 | 43 if test $(id -u) != 0 ; then |
pankso@3440 | 44 echo -e "\nThis program requires being run as root.\n" |
pankso@3440 | 45 exit 0 |
pankso@3440 | 46 fi |
pankso@3440 | 47 } |
pankso@3440 | 48 |
pankso@3499 | 49 status() |
pankso@3499 | 50 { |
pankso@3499 | 51 local CHECK=$? |
pankso@3500 | 52 echo -en "\033[70G" |
pankso@3499 | 53 if [ $CHECK = 0 ]; then |
pankso@3500 | 54 echo "Done" |
pankso@3499 | 55 else |
pankso@3500 | 56 echo "Failed" |
pankso@3499 | 57 fi |
pankso@3499 | 58 return $CHECK |
pankso@3499 | 59 } |
pankso@3499 | 60 |
pankso@3499 | 61 get_version() |
pankso@3499 | 62 { |
pankso@3499 | 63 if [ "$2" = "stable" ]; then |
pankso@3499 | 64 VERSION=stable |
pankso@3522 | 65 SLITAZ=$STABLE |
pankso@3499 | 66 elif [ -n "$2" ]; then |
pankso@3522 | 67 # Undigest - custom ? |
pankso@3522 | 68 VERSION=$2 |
pankso@3522 | 69 SLITAZ=/home/slitaz/$2 |
pankso@3499 | 70 else |
pankso@3499 | 71 VERSION=cooking |
pankso@3522 | 72 SLITAZ=$COOKING |
pankso@3499 | 73 fi |
pankso@3522 | 74 ROOTFS=$SLITAZ/chroot |
pankso@3522 | 75 HG_WOK=$SLITAZ/wok |
pankso@3522 | 76 BUILD_WOK=$SLITAZ/chroot/home/slitaz/wok |
pankso@3499 | 77 } |
pankso@3499 | 78 |
pankso@3440 | 79 check_mirror() |
pankso@3440 | 80 { |
pankso@3440 | 81 # ping -c 1 $MIRROR |
pankso@3440 | 82 if [ -n "$2" ]; then |
pankso@3440 | 83 USER=$2 |
pankso@3440 | 84 else |
pankso@3605 | 85 USER=$USER |
pankso@3440 | 86 fi |
pankso@3605 | 87 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then |
pankso@3440 | 88 REMOTE_DIR=$MIRROR_DIR/stable/ |
pankso@3440 | 89 LOCAL_DIR=$STABLE/packages/ |
pankso@3440 | 90 else |
pankso@3440 | 91 REMOTE_DIR=$MIRROR_DIR/cooking/ |
pankso@3440 | 92 LOCAL_DIR=$COOKING/packages/ |
pankso@3522 | 93 fi |
pankso@3440 | 94 } |
pankso@3440 | 95 |
pankso@3522 | 96 # Mount virtual Kernel file systems and chroot but check that nobody |
pankso@3499 | 97 # else has done mounts |
pankso@3499 | 98 mount_chroot() |
pankso@3499 | 99 { |
pankso@3499 | 100 if [ ! -d $ROOTFS/proc/1 ]; then |
paul@3526 | 101 echo -n "Mounting virtual filesystems..." |
pankso@3499 | 102 mount -t proc proc $ROOTFS/proc |
pankso@3499 | 103 mount -t sysfs sysfs $ROOTFS/sys |
pankso@3499 | 104 mount -t devpts devpts $ROOTFS/dev/pts |
pankso@3499 | 105 mount -t tmpfs shm $ROOTFS/dev/shm |
pankso@3499 | 106 status |
pankso@3499 | 107 fi |
pankso@3499 | 108 } |
pankso@3499 | 109 |
pankso@3522 | 110 # Unmount virtual Kernel file systems on exit and ensure we are the last |
pankso@3499 | 111 # user before unmounting ! |
pankso@3499 | 112 umount_chroot() |
pankso@3499 | 113 { |
pankso@3499 | 114 # Not working. Buggy ps ? |
pankso@3499 | 115 #sleep 6 |
pankso@3499 | 116 ps=$(ps | grep `basename $0` | grep -v grep | wc -l) |
pankso@3499 | 117 if [ "$ps" == "1" ]; then |
paul@3526 | 118 echo -ne "\Unmounting virtual filesystems..." |
pankso@3499 | 119 umount $ROOTFS/dev/shm |
pankso@3499 | 120 umount $ROOTFS/dev/pts |
pankso@3499 | 121 umount $ROOTFS/sys |
pankso@3499 | 122 umount $ROOTFS/proc |
pankso@3499 | 123 status |
pankso@3499 | 124 else |
pankso@3499 | 125 echo -e "\nProcess: $ps\n" |
pankso@3499 | 126 ps | grep `basename $0` | grep -v grep |
paul@3526 | 127 echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n" |
pankso@3499 | 128 fi |
pankso@3499 | 129 } |
pankso@3499 | 130 |
pankso@3499 | 131 # Get the last cooking base rootfs, extract and configure. |
pankso@3499 | 132 gen_new_chroot() |
pankso@3499 | 133 { |
pankso@3499 | 134 echo -e "\nGenerating new chroot in : $ROOTFS" |
pankso@3499 | 135 echo "================================================================================" |
pankso@3499 | 136 mkdir -p $ROOTFS && cd $ROOTFS |
pankso@3499 | 137 wget $DL_URL/boot/cooking/rootfs-base.gz |
pankso@3499 | 138 echo -n "Extracting the rootfs..." |
pankso@3499 | 139 lzma d rootfs-base.gz -so | cpio -id |
pankso@3499 | 140 rm rootfs-base.gz |
pankso@3499 | 141 echo -n "Creating resolv.conf..." |
pankso@3499 | 142 cat /etc/resolv.conf > etc/resolv.conf |
pankso@3499 | 143 status |
pankso@3499 | 144 echo "================================================================================" |
pankso@3499 | 145 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'" |
pankso@3499 | 146 echo -e "Example: tazdev chroot $ROOTFS\n" |
pankso@3499 | 147 } |
pankso@3499 | 148 |
pascal@4717 | 149 # Remove obsolate slitaz packages |
pascal@4717 | 150 purge_packages() |
pascal@4717 | 151 { |
pascal@4717 | 152 TMP_FILE=/tmp/tazdev.$$ |
pascal@4717 | 153 ls $BUILD_WOK | while read pkg; do |
pascal@4717 | 154 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue |
pascal@4717 | 155 EXTRAVERSION="" |
pascal@4717 | 156 . $BUILD_WOK/$pkg/taz/*/receipt |
pascal@4717 | 157 echo $PACKAGE-$VERSION$EXTRAVERSION.tazpkg |
pascal@4717 | 158 done > $TMP_FILE |
pascal@4717 | 159 ls $SLITAZ/chroot/home/slitaz/packages | while read pkg; do |
pascal@4717 | 160 case "$pkg" in |
pascal@4717 | 161 *.tazpkg) |
pascal@4717 | 162 grep -q ^$pkg$ $TMP_FILE && continue |
pascal@4717 | 163 echo Remove $pkg |
pascal@4717 | 164 rm -f $SLITAZ/chroot/home/slitaz/packages/$pkg ;; |
pascal@4717 | 165 esac |
pascal@4717 | 166 done |
pascal@4717 | 167 rm -f $TMP_FILE |
pascal@4717 | 168 } |
pascal@4717 | 169 |
pascal@4717 | 170 # Remove obsolate source tarballs |
pascal@4717 | 171 purge_sources() |
pascal@4717 | 172 { |
pascal@4717 | 173 TMP_FILE=/tmp/tazdev.$$ |
pascal@4717 | 174 ls $BUILD_WOK | while read pkg; do |
pascal@4717 | 175 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue |
pascal@4717 | 176 TARBALL="" |
pascal@4717 | 177 . $BUILD_WOK/$pkg/taz/*/receipt |
pascal@4717 | 178 [ -n "$TARBALL" ] && echo $TARBALL |
pascal@4717 | 179 done > $TMP_FILE |
pascal@4717 | 180 ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do |
pascal@4717 | 181 grep -q ^$pkg$ $TMP_FILE && continue |
pascal@4717 | 182 echo Remove $pkg |
pascal@4717 | 183 rm -f $SLITAZ/chroot/home/slitaz/src/$pkg |
pascal@4717 | 184 done |
pascal@4717 | 185 rm -f $TMP_FILE |
pascal@4717 | 186 } |
pascal@4717 | 187 |
pankso@3440 | 188 case "$1" in |
pankso@3440 | 189 cmplog) |
pankso@3440 | 190 # Log 'tazwok cmp' for the web interface (can be used via a cron job). |
pankso@3440 | 191 check_root |
pankso@3444 | 192 echo -e "Starting 'tazwok cmp' (can be long)...\n" |
pankso@3440 | 193 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG |
pankso@3440 | 194 echo "Date: `date`" >> $CMP_LOG ;; |
pankso@3500 | 195 '-ps'|projects-stats) |
pankso@3500 | 196 echo -e "\nStatistics for: $PROJECTS\n" |
pankso@3500 | 197 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision" |
pankso@3500 | 198 echo -ne "\033[48G Version" && echo -e "\033[64G Files" |
pankso@3500 | 199 echo "================================================================================" |
pankso@3500 | 200 cd $PROJECTS |
pankso@3500 | 201 for proj in * |
pankso@3500 | 202 do |
pankso@3500 | 203 rev="" |
pankso@3500 | 204 echo -n "$proj" |
pankso@3500 | 205 size=`du -sh $proj | awk '{ print $1 }'` |
pankso@3500 | 206 echo -ne "\033[24G $size" |
pankso@3500 | 207 if [ -d $proj/.hg ]; then |
pankso@3500 | 208 cd $proj |
pankso@3500 | 209 rev=`hg head --template '{rev}\n'` |
pankso@3500 | 210 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1` |
pankso@3500 | 211 echo -ne "\033[38G $rev" |
pankso@3500 | 212 echo -ne "\033[48G $vers" && cd .. |
pankso@3500 | 213 fi |
pankso@3500 | 214 files=`find $proj -type f | wc -l` |
pankso@3500 | 215 echo -e "\033[64G $files" |
pankso@3500 | 216 done |
pankso@3500 | 217 echo "================================================================================" |
pankso@3500 | 218 echo "" ;; |
pankso@3440 | 219 update-wok) |
pankso@3499 | 220 # Update the Hg wok and copy it to the chroot env. Hg wok is |
pankso@3440 | 221 # copied to the chroot wok to avoid messing with build result |
paul@3455 | 222 # file and so we can also modify receipt directly without affecting |
pankso@3499 | 223 # the Hg wok. |
pankso@3440 | 224 check_root |
pascal@3731 | 225 get_version $@ |
pankso@3444 | 226 echo "" |
pankso@3447 | 227 echo "Hg wok : $HG_WOK" |
pankso@3447 | 228 echo "Build wok : $BUILD_WOK" |
pankso@3440 | 229 cd $HG_WOK |
pankso@3440 | 230 hg pull && hg update |
pankso@3447 | 231 echo -n "Copying Hg wok to the build wok... " |
pankso@3447 | 232 cp -a $HG_WOK/* $BUILD_WOK |
pankso@3499 | 233 cp -a $HG_WOK/.hg $BUILD_WOK |
pankso@3499 | 234 status && echo "" ;; |
pankso@3441 | 235 update-www) |
pankso@3441 | 236 # Update website from repo. |
pankso@3441 | 237 echo "" |
pankso@3441 | 238 cd $WEBSITE && hg pull && hg update |
pankso@3441 | 239 echo "" ;; |
pankso@3440 | 240 chroot) |
pankso@3522 | 241 # Chroot into a build env. Default to cooking configured in |
pankso@3440 | 242 # tazdev.conf |
pankso@3440 | 243 check_root |
pascal@3731 | 244 get_version $@ |
pankso@3499 | 245 mount_chroot |
pankso@3499 | 246 echo -e "\nChrooting in $ROOTFS...\n" |
pankso@3499 | 247 chroot $ROOTFS /bin/sh --login |
pankso@3499 | 248 umount_chroot |
pankso@3499 | 249 echo -e "Exiting $ROOTFS chroot environment...\n" ;; |
pankso@3499 | 250 gen-chroot) |
pankso@3499 | 251 check_root |
pascal@3731 | 252 get_version $@ |
pankso@3499 | 253 # Dont break another env. |
pankso@3499 | 254 if [ -d $ROOTFS/bin ]; then |
paul@3526 | 255 echo -e "\nA chroot environment already exists in : $ROOTFS\n" |
pankso@3499 | 256 exit 1 |
pankso@3499 | 257 fi |
pankso@3499 | 258 gen_new_chroot ;; |
pankso@3499 | 259 clean-chroot) |
pankso@3499 | 260 # Keep root/ and /home they may have a build wok, custom scripts, etc. |
pankso@3499 | 261 check_root |
pankso@3499 | 262 if [ -z "$2" ]; then |
pankso@3499 | 263 echo -e "\nPlease specify the path to the chroot environment to clean.\n" |
pankso@3499 | 264 exit 0 |
pankso@3440 | 265 else |
pankso@3499 | 266 ROOTFS=$2 |
pankso@3499 | 267 if [ ! -d "$ROOTFS" ]; then |
paul@3526 | 268 echo -e "\nWarning : $ROOTFS doesn't exist!\n" |
pankso@3499 | 269 exit 1 |
pankso@3499 | 270 fi |
pankso@3440 | 271 fi |
pankso@3499 | 272 if [ -d $ROOTFS/proc/1 ]; then |
pankso@3499 | 273 echo -e "\nWarning : $ROOTFS/proc mounted!\n" |
pankso@3499 | 274 exit 1 |
pankso@3440 | 275 fi |
pankso@3499 | 276 cd $ROOTFS || exit 1 |
pankso@3499 | 277 echo -e "\nCleaning chroot in: $ROOTFS" |
pankso@3499 | 278 echo "================================================================================" |
pankso@3499 | 279 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var |
pankso@3499 | 280 do |
pankso@3499 | 281 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... " |
pankso@3499 | 282 rm -rf $i |
pankso@3499 | 283 status |
pankso@3499 | 284 done |
pankso@3499 | 285 echo "================================================================================" |
pankso@3499 | 286 echo "" ;; |
pankso@3500 | 287 '-p'|push) |
pankso@3502 | 288 check_mirror $@ |
pankso@3440 | 289 rsync -r -t -l -v -z --delete \ |
pankso@3499 | 290 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;; |
pankso@3500 | 291 '-dp'|dry-push) |
pankso@3502 | 292 check_mirror $@ |
pankso@3440 | 293 rsync -r -t -l -v -z --delete --dry-run \ |
pankso@3499 | 294 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;; |
pankso@3440 | 295 pull) |
pankso@3502 | 296 check_mirror $@ |
pankso@3440 | 297 rsync -r -t -l -v -z --delete \ |
pankso@3499 | 298 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;; |
pankso@3440 | 299 dry-pull) |
pankso@3502 | 300 check_mirror $@ |
pankso@3440 | 301 rsync -r -t -l -v -z --delete --dry-run \ |
pankso@3499 | 302 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;; |
pascal@4717 | 303 purge) |
pascal@4717 | 304 check_root |
pascal@4717 | 305 get_version $@ |
pascal@4717 | 306 purge_packages |
pascal@4717 | 307 purge_sources |
pascal@4717 | 308 ;; |
pankso@3440 | 309 usage|*) |
pankso@3440 | 310 usage ;; |
pankso@3440 | 311 esac |
pankso@3440 | 312 |
pankso@3440 | 313 exit 0 |