wok annotate slitaz-dev-tools/stuff/tazdev @ rev 3731
tazdev: fix get_version
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Jul 22 21:54:45 2009 +0200 (2009-07-22) |
parents | baa5f0488bc8 |
children | 031f6e973842 |
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/). |
pankso@3500 | 33 push Upload new packages to the main mirror (-p). |
pankso@3500 | 34 dry-push Show what will be uploaded to the mirror. Does nothing (-dp). |
pankso@3500 | 35 pull Download new packages from the main mirror. |
pankso@3500 | 36 dry-pull Show what will be downloaded from the mirror. Does nothing.\n" |
pankso@3440 | 37 } |
pankso@3440 | 38 |
pankso@3440 | 39 # Exit if user is not root. |
pankso@3440 | 40 check_root() |
pankso@3440 | 41 { |
pankso@3440 | 42 if test $(id -u) != 0 ; then |
pankso@3440 | 43 echo -e "\nThis program requires being run as root.\n" |
pankso@3440 | 44 exit 0 |
pankso@3440 | 45 fi |
pankso@3440 | 46 } |
pankso@3440 | 47 |
pankso@3499 | 48 status() |
pankso@3499 | 49 { |
pankso@3499 | 50 local CHECK=$? |
pankso@3500 | 51 echo -en "\033[70G" |
pankso@3499 | 52 if [ $CHECK = 0 ]; then |
pankso@3500 | 53 echo "Done" |
pankso@3499 | 54 else |
pankso@3500 | 55 echo "Failed" |
pankso@3499 | 56 fi |
pankso@3499 | 57 return $CHECK |
pankso@3499 | 58 } |
pankso@3499 | 59 |
pankso@3499 | 60 get_version() |
pankso@3499 | 61 { |
pankso@3499 | 62 if [ "$2" = "stable" ]; then |
pankso@3499 | 63 VERSION=stable |
pankso@3522 | 64 SLITAZ=$STABLE |
pankso@3499 | 65 elif [ -n "$2" ]; then |
pankso@3522 | 66 # Undigest - custom ? |
pankso@3522 | 67 VERSION=$2 |
pankso@3522 | 68 SLITAZ=/home/slitaz/$2 |
pankso@3499 | 69 else |
pankso@3499 | 70 VERSION=cooking |
pankso@3522 | 71 SLITAZ=$COOKING |
pankso@3499 | 72 fi |
pankso@3522 | 73 ROOTFS=$SLITAZ/chroot |
pankso@3522 | 74 HG_WOK=$SLITAZ/wok |
pankso@3522 | 75 BUILD_WOK=$SLITAZ/chroot/home/slitaz/wok |
pankso@3499 | 76 } |
pankso@3499 | 77 |
pankso@3440 | 78 check_mirror() |
pankso@3440 | 79 { |
pankso@3440 | 80 # ping -c 1 $MIRROR |
pankso@3440 | 81 if [ -n "$2" ]; then |
pankso@3440 | 82 USER=$2 |
pankso@3440 | 83 else |
pankso@3605 | 84 USER=$USER |
pankso@3440 | 85 fi |
pankso@3605 | 86 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then |
pankso@3440 | 87 REMOTE_DIR=$MIRROR_DIR/stable/ |
pankso@3440 | 88 LOCAL_DIR=$STABLE/packages/ |
pankso@3440 | 89 else |
pankso@3440 | 90 REMOTE_DIR=$MIRROR_DIR/cooking/ |
pankso@3440 | 91 LOCAL_DIR=$COOKING/packages/ |
pankso@3522 | 92 fi |
pankso@3440 | 93 } |
pankso@3440 | 94 |
pankso@3522 | 95 # Mount virtual Kernel file systems and chroot but check that nobody |
pankso@3499 | 96 # else has done mounts |
pankso@3499 | 97 mount_chroot() |
pankso@3499 | 98 { |
pankso@3499 | 99 if [ ! -d $ROOTFS/proc/1 ]; then |
paul@3526 | 100 echo -n "Mounting virtual filesystems..." |
pankso@3499 | 101 mount -t proc proc $ROOTFS/proc |
pankso@3499 | 102 mount -t sysfs sysfs $ROOTFS/sys |
pankso@3499 | 103 mount -t devpts devpts $ROOTFS/dev/pts |
pankso@3499 | 104 mount -t tmpfs shm $ROOTFS/dev/shm |
pankso@3499 | 105 status |
pankso@3499 | 106 fi |
pankso@3499 | 107 } |
pankso@3499 | 108 |
pankso@3522 | 109 # Unmount virtual Kernel file systems on exit and ensure we are the last |
pankso@3499 | 110 # user before unmounting ! |
pankso@3499 | 111 umount_chroot() |
pankso@3499 | 112 { |
pankso@3499 | 113 # Not working. Buggy ps ? |
pankso@3499 | 114 #sleep 6 |
pankso@3499 | 115 ps=$(ps | grep `basename $0` | grep -v grep | wc -l) |
pankso@3499 | 116 if [ "$ps" == "1" ]; then |
paul@3526 | 117 echo -ne "\Unmounting virtual filesystems..." |
pankso@3499 | 118 umount $ROOTFS/dev/shm |
pankso@3499 | 119 umount $ROOTFS/dev/pts |
pankso@3499 | 120 umount $ROOTFS/sys |
pankso@3499 | 121 umount $ROOTFS/proc |
pankso@3499 | 122 status |
pankso@3499 | 123 else |
pankso@3499 | 124 echo -e "\nProcess: $ps\n" |
pankso@3499 | 125 ps | grep `basename $0` | grep -v grep |
paul@3526 | 126 echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n" |
pankso@3499 | 127 fi |
pankso@3499 | 128 } |
pankso@3499 | 129 |
pankso@3499 | 130 # Get the last cooking base rootfs, extract and configure. |
pankso@3499 | 131 gen_new_chroot() |
pankso@3499 | 132 { |
pankso@3499 | 133 echo -e "\nGenerating new chroot in : $ROOTFS" |
pankso@3499 | 134 echo "================================================================================" |
pankso@3499 | 135 mkdir -p $ROOTFS && cd $ROOTFS |
pankso@3499 | 136 wget $DL_URL/boot/cooking/rootfs-base.gz |
pankso@3499 | 137 echo -n "Extracting the rootfs..." |
pankso@3499 | 138 lzma d rootfs-base.gz -so | cpio -id |
pankso@3499 | 139 rm rootfs-base.gz |
pankso@3499 | 140 echo -n "Creating resolv.conf..." |
pankso@3499 | 141 cat /etc/resolv.conf > etc/resolv.conf |
pankso@3499 | 142 status |
pankso@3499 | 143 echo "================================================================================" |
pankso@3499 | 144 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'" |
pankso@3499 | 145 echo -e "Example: tazdev chroot $ROOTFS\n" |
pankso@3499 | 146 } |
pankso@3499 | 147 |
pankso@3440 | 148 case "$1" in |
pankso@3440 | 149 cmplog) |
pankso@3440 | 150 # Log 'tazwok cmp' for the web interface (can be used via a cron job). |
pankso@3440 | 151 check_root |
pankso@3444 | 152 echo -e "Starting 'tazwok cmp' (can be long)...\n" |
pankso@3440 | 153 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG |
pankso@3440 | 154 echo "Date: `date`" >> $CMP_LOG ;; |
pankso@3500 | 155 '-ps'|projects-stats) |
pankso@3500 | 156 echo -e "\nStatistics for: $PROJECTS\n" |
pankso@3500 | 157 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision" |
pankso@3500 | 158 echo -ne "\033[48G Version" && echo -e "\033[64G Files" |
pankso@3500 | 159 echo "================================================================================" |
pankso@3500 | 160 cd $PROJECTS |
pankso@3500 | 161 for proj in * |
pankso@3500 | 162 do |
pankso@3500 | 163 rev="" |
pankso@3500 | 164 echo -n "$proj" |
pankso@3500 | 165 size=`du -sh $proj | awk '{ print $1 }'` |
pankso@3500 | 166 echo -ne "\033[24G $size" |
pankso@3500 | 167 if [ -d $proj/.hg ]; then |
pankso@3500 | 168 cd $proj |
pankso@3500 | 169 rev=`hg head --template '{rev}\n'` |
pankso@3500 | 170 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1` |
pankso@3500 | 171 echo -ne "\033[38G $rev" |
pankso@3500 | 172 echo -ne "\033[48G $vers" && cd .. |
pankso@3500 | 173 fi |
pankso@3500 | 174 files=`find $proj -type f | wc -l` |
pankso@3500 | 175 echo -e "\033[64G $files" |
pankso@3500 | 176 done |
pankso@3500 | 177 echo "================================================================================" |
pankso@3500 | 178 echo "" ;; |
pankso@3440 | 179 update-wok) |
pankso@3499 | 180 # Update the Hg wok and copy it to the chroot env. Hg wok is |
pankso@3440 | 181 # copied to the chroot wok to avoid messing with build result |
paul@3455 | 182 # file and so we can also modify receipt directly without affecting |
pankso@3499 | 183 # the Hg wok. |
pankso@3440 | 184 check_root |
pascal@3731 | 185 get_version $@ |
pankso@3444 | 186 echo "" |
pankso@3447 | 187 echo "Hg wok : $HG_WOK" |
pankso@3447 | 188 echo "Build wok : $BUILD_WOK" |
pankso@3440 | 189 cd $HG_WOK |
pankso@3440 | 190 hg pull && hg update |
pankso@3447 | 191 echo -n "Copying Hg wok to the build wok... " |
pankso@3447 | 192 cp -a $HG_WOK/* $BUILD_WOK |
pankso@3499 | 193 cp -a $HG_WOK/.hg $BUILD_WOK |
pankso@3499 | 194 status && echo "" ;; |
pankso@3441 | 195 update-www) |
pankso@3441 | 196 # Update website from repo. |
pankso@3441 | 197 echo "" |
pankso@3441 | 198 cd $WEBSITE && hg pull && hg update |
pankso@3441 | 199 echo "" ;; |
pankso@3440 | 200 chroot) |
pankso@3522 | 201 # Chroot into a build env. Default to cooking configured in |
pankso@3440 | 202 # tazdev.conf |
pankso@3440 | 203 check_root |
pascal@3731 | 204 get_version $@ |
pankso@3499 | 205 mount_chroot |
pankso@3499 | 206 echo -e "\nChrooting in $ROOTFS...\n" |
pankso@3499 | 207 chroot $ROOTFS /bin/sh --login |
pankso@3499 | 208 umount_chroot |
pankso@3499 | 209 echo -e "Exiting $ROOTFS chroot environment...\n" ;; |
pankso@3499 | 210 gen-chroot) |
pankso@3499 | 211 check_root |
pascal@3731 | 212 get_version $@ |
pankso@3499 | 213 # Dont break another env. |
pankso@3499 | 214 if [ -d $ROOTFS/bin ]; then |
paul@3526 | 215 echo -e "\nA chroot environment already exists in : $ROOTFS\n" |
pankso@3499 | 216 exit 1 |
pankso@3499 | 217 fi |
pankso@3499 | 218 gen_new_chroot ;; |
pankso@3499 | 219 clean-chroot) |
pankso@3499 | 220 # Keep root/ and /home they may have a build wok, custom scripts, etc. |
pankso@3499 | 221 check_root |
pankso@3499 | 222 if [ -z "$2" ]; then |
pankso@3499 | 223 echo -e "\nPlease specify the path to the chroot environment to clean.\n" |
pankso@3499 | 224 exit 0 |
pankso@3440 | 225 else |
pankso@3499 | 226 ROOTFS=$2 |
pankso@3499 | 227 if [ ! -d "$ROOTFS" ]; then |
paul@3526 | 228 echo -e "\nWarning : $ROOTFS doesn't exist!\n" |
pankso@3499 | 229 exit 1 |
pankso@3499 | 230 fi |
pankso@3440 | 231 fi |
pankso@3499 | 232 if [ -d $ROOTFS/proc/1 ]; then |
pankso@3499 | 233 echo -e "\nWarning : $ROOTFS/proc mounted!\n" |
pankso@3499 | 234 exit 1 |
pankso@3440 | 235 fi |
pankso@3499 | 236 cd $ROOTFS || exit 1 |
pankso@3499 | 237 echo -e "\nCleaning chroot in: $ROOTFS" |
pankso@3499 | 238 echo "================================================================================" |
pankso@3499 | 239 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var |
pankso@3499 | 240 do |
pankso@3499 | 241 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... " |
pankso@3499 | 242 rm -rf $i |
pankso@3499 | 243 status |
pankso@3499 | 244 done |
pankso@3499 | 245 echo "================================================================================" |
pankso@3499 | 246 echo "" ;; |
pankso@3500 | 247 '-p'|push) |
pankso@3502 | 248 check_mirror $@ |
pankso@3440 | 249 rsync -r -t -l -v -z --delete \ |
pankso@3499 | 250 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;; |
pankso@3500 | 251 '-dp'|dry-push) |
pankso@3502 | 252 check_mirror $@ |
pankso@3440 | 253 rsync -r -t -l -v -z --delete --dry-run \ |
pankso@3499 | 254 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;; |
pankso@3440 | 255 pull) |
pankso@3502 | 256 check_mirror $@ |
pankso@3440 | 257 rsync -r -t -l -v -z --delete \ |
pankso@3499 | 258 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;; |
pankso@3440 | 259 dry-pull) |
pankso@3502 | 260 check_mirror $@ |
pankso@3440 | 261 rsync -r -t -l -v -z --delete --dry-run \ |
pankso@3499 | 262 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;; |
pankso@3440 | 263 usage|*) |
pankso@3440 | 264 usage ;; |
pankso@3440 | 265 esac |
pankso@3440 | 266 |
pankso@3440 | 267 exit 0 |