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