wok-6.x annotate slitaz-dev-tools/stuff/tazdev @ rev 3500

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