wok-6.x annotate slitaz-dev-tools/stuff/tazdev @ rev 7254
Up: xorg-xprop to 1.2.0.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Sun Nov 14 15:46:44 2010 +0000 (2010-11-14) |
parents | d26b0b60ce2e |
children | 4249e7ca9034 |
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@5926 | 180 [ -f $BUILD_WOK/$pkg/receipt ] || continue |
pascal@4717 | 181 TARBALL="" |
pascal@5926 | 182 . $BUILD_WOK/$pkg/receipt |
pascal@4717 | 183 [ -n "$TARBALL" ] && echo $TARBALL |
pascal@5926 | 184 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \ |
pascal@5926 | 185 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \ |
pascal@5926 | 186 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \ |
pascal@5926 | 187 sed "s|['\"/]||g" | while read file ; do |
pascal@5926 | 188 eval echo $file 2> /dev/null |
pascal@5926 | 189 done |
pascal@4717 | 190 done > $TMP_FILE |
pascal@4717 | 191 ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do |
pascal@4717 | 192 grep -q ^$pkg$ $TMP_FILE && continue |
pascal@4717 | 193 echo Remove $pkg |
pascal@4719 | 194 [ "$arg" == "purge" ] && |
pascal@4717 | 195 rm -f $SLITAZ/chroot/home/slitaz/src/$pkg |
pascal@4717 | 196 done |
pascal@4717 | 197 rm -f $TMP_FILE |
pascal@4717 | 198 } |
pascal@4717 | 199 |
pankso@3440 | 200 case "$1" in |
pankso@3440 | 201 cmplog) |
pankso@3440 | 202 # Log 'tazwok cmp' for the web interface (can be used via a cron job). |
pankso@3440 | 203 check_root |
pankso@3444 | 204 echo -e "Starting 'tazwok cmp' (can be long)...\n" |
pankso@3440 | 205 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG |
pankso@3440 | 206 echo "Date: `date`" >> $CMP_LOG ;; |
pankso@3500 | 207 '-ps'|projects-stats) |
pankso@3500 | 208 echo -e "\nStatistics for: $PROJECTS\n" |
pankso@3500 | 209 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision" |
pankso@3500 | 210 echo -ne "\033[48G Version" && echo -e "\033[64G Files" |
pankso@3500 | 211 echo "================================================================================" |
pankso@3500 | 212 cd $PROJECTS |
pankso@3500 | 213 for proj in * |
pankso@3500 | 214 do |
pankso@3500 | 215 rev="" |
pankso@3500 | 216 echo -n "$proj" |
pankso@3500 | 217 size=`du -sh $proj | awk '{ print $1 }'` |
pankso@3500 | 218 echo -ne "\033[24G $size" |
pankso@3500 | 219 if [ -d $proj/.hg ]; then |
pankso@3500 | 220 cd $proj |
pankso@3500 | 221 rev=`hg head --template '{rev}\n'` |
pankso@3500 | 222 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1` |
pankso@3500 | 223 echo -ne "\033[38G $rev" |
pankso@3500 | 224 echo -ne "\033[48G $vers" && cd .. |
pankso@3500 | 225 fi |
pankso@3500 | 226 files=`find $proj -type f | wc -l` |
pankso@3500 | 227 echo -e "\033[64G $files" |
pankso@3500 | 228 done |
pankso@3500 | 229 echo "================================================================================" |
pankso@3500 | 230 echo "" ;; |
pankso@3440 | 231 update-wok) |
pankso@3499 | 232 # Update the Hg wok and copy it to the chroot env. Hg wok is |
pankso@3440 | 233 # copied to the chroot wok to avoid messing with build result |
paul@3455 | 234 # file and so we can also modify receipt directly without affecting |
pankso@3499 | 235 # the Hg wok. |
pankso@3440 | 236 check_root |
pascal@3731 | 237 get_version $@ |
pankso@3444 | 238 echo "" |
pankso@3447 | 239 echo "Hg wok : $HG_WOK" |
pankso@3447 | 240 echo "Build wok : $BUILD_WOK" |
pankso@3440 | 241 cd $HG_WOK |
pankso@3440 | 242 hg pull && hg update |
pankso@3447 | 243 echo -n "Copying Hg wok to the build wok... " |
pankso@3447 | 244 cp -a $HG_WOK/* $BUILD_WOK |
pankso@3499 | 245 cp -a $HG_WOK/.hg $BUILD_WOK |
pankso@3499 | 246 status && echo "" ;; |
pankso@3441 | 247 update-www) |
pankso@3441 | 248 # Update website from repo. |
pankso@3441 | 249 echo "" |
pankso@3441 | 250 cd $WEBSITE && hg pull && hg update |
pankso@3441 | 251 echo "" ;; |
pankso@3440 | 252 chroot) |
pankso@3522 | 253 # Chroot into a build env. Default to cooking configured in |
pankso@3440 | 254 # tazdev.conf |
pankso@3440 | 255 check_root |
pascal@3731 | 256 get_version $@ |
pankso@3499 | 257 mount_chroot |
pankso@3499 | 258 echo -e "\nChrooting in $ROOTFS...\n" |
pankso@3499 | 259 chroot $ROOTFS /bin/sh --login |
pankso@3499 | 260 umount_chroot |
pankso@3499 | 261 echo -e "Exiting $ROOTFS chroot environment...\n" ;; |
pankso@3499 | 262 gen-chroot) |
pankso@3499 | 263 check_root |
pascal@3731 | 264 get_version $@ |
pankso@3499 | 265 # Dont break another env. |
pankso@3499 | 266 if [ -d $ROOTFS/bin ]; then |
paul@3526 | 267 echo -e "\nA chroot environment already exists in : $ROOTFS\n" |
pankso@3499 | 268 exit 1 |
pankso@3499 | 269 fi |
pankso@3499 | 270 gen_new_chroot ;; |
pankso@3499 | 271 clean-chroot) |
pankso@3499 | 272 # Keep root/ and /home they may have a build wok, custom scripts, etc. |
pankso@3499 | 273 check_root |
pankso@3499 | 274 if [ -z "$2" ]; then |
pankso@3499 | 275 echo -e "\nPlease specify the path to the chroot environment to clean.\n" |
pankso@3499 | 276 exit 0 |
pankso@3440 | 277 else |
pankso@3499 | 278 ROOTFS=$2 |
pankso@3499 | 279 if [ ! -d "$ROOTFS" ]; then |
paul@3526 | 280 echo -e "\nWarning : $ROOTFS doesn't exist!\n" |
pankso@3499 | 281 exit 1 |
pankso@3499 | 282 fi |
pankso@3440 | 283 fi |
pankso@3499 | 284 if [ -d $ROOTFS/proc/1 ]; then |
pankso@3499 | 285 echo -e "\nWarning : $ROOTFS/proc mounted!\n" |
pankso@3499 | 286 exit 1 |
pankso@3440 | 287 fi |
pankso@3499 | 288 cd $ROOTFS || exit 1 |
pankso@3499 | 289 echo -e "\nCleaning chroot in: $ROOTFS" |
pankso@3499 | 290 echo "================================================================================" |
pankso@3499 | 291 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var |
pankso@3499 | 292 do |
pankso@3499 | 293 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... " |
pankso@3499 | 294 rm -rf $i |
pankso@3499 | 295 status |
pankso@3499 | 296 done |
pankso@3499 | 297 echo "================================================================================" |
pankso@3499 | 298 echo "" ;; |
pankso@3500 | 299 '-p'|push) |
pankso@3502 | 300 check_mirror $@ |
pankso@3440 | 301 rsync -r -t -l -v -z --delete \ |
pankso@3499 | 302 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;; |
pankso@3500 | 303 '-dp'|dry-push) |
pankso@3502 | 304 check_mirror $@ |
pankso@3440 | 305 rsync -r -t -l -v -z --delete --dry-run \ |
pankso@3499 | 306 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;; |
pankso@3440 | 307 pull) |
pankso@3502 | 308 check_mirror $@ |
pankso@3440 | 309 rsync -r -t -l -v -z --delete \ |
pankso@3499 | 310 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;; |
pankso@3440 | 311 dry-pull) |
pankso@3502 | 312 check_mirror $@ |
pankso@3440 | 313 rsync -r -t -l -v -z --delete --dry-run \ |
pankso@3499 | 314 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;; |
pascal@4719 | 315 purge|dry-purge) |
pascal@4717 | 316 check_root |
pascal@4717 | 317 get_version $@ |
pascal@4719 | 318 purge_packages $1 |
pankso@5158 | 319 purge_sources $1 ;; |
pankso@5158 | 320 relpkg) |
pankso@5158 | 321 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources" |
pankso@5158 | 322 if [ -z $2 ] || [ -z $3 ]; then |
pankso@5158 | 323 echo -e "\nUsage: $0 relpkg package version\n" |
pankso@5158 | 324 exit 0 |
pankso@5158 | 325 fi |
pankso@5158 | 326 PACKAGE=$2 |
pankso@5158 | 327 VERSION=$3 |
pankso@5158 | 328 echo "" |
pankso@5158 | 329 cd $PROJECTS/$PACKAGE |
pankso@5158 | 330 # Sanity check |
pankso@5158 | 331 if ! grep -q $VERSION$ .hgtags; then |
pankso@5158 | 332 echo "Missing Hg tag for version: $VERSION" |
pankso@5158 | 333 echo -e "You may want to: hg tag $VERSION && hg push\n" |
pankso@5158 | 334 exit 0 |
pankso@5158 | 335 fi |
pankso@5158 | 336 # Archive |
pankso@5158 | 337 echo -n "Creating tarball and md5sum for: $PACKAGE-$VERSION... " |
pankso@5158 | 338 hg archive -t tgz $PACKAGE-$VERSION.tar.gz |
pankso@5158 | 339 md5sum $PACKAGE-$VERSION.tar.gz > $PACKAGE-$VERSION.md5 |
pankso@5158 | 340 echo "Done" |
pankso@5158 | 341 # Upload |
pankso@5158 | 342 echo -n "Do you wish to upload tarball to the mirror [N/y] ? " |
pankso@5158 | 343 read upload |
pankso@5158 | 344 if [ "$upload" = "y" ]; then |
pankso@5158 | 345 echo "Uploading to: $MIRROR/sources/${PACKAGE#slitaz-}" |
pankso@5158 | 346 scp $PACKAGE-$VERSION.tar.gz $PACKAGE-$VERSION.md5 \ |
pankso@5158 | 347 $USER@$MIRROR:$MIRROR_SOURCES/${PACKAGE#slitaz-} |
pankso@5158 | 348 fi ;; |
pankso@3440 | 349 usage|*) |
pankso@3440 | 350 usage ;; |
pankso@3440 | 351 esac |
pankso@3440 | 352 |
pankso@3440 | 353 exit 0 |