slitaz-dev-tools diff tazdev/tazdev @ rev 1
Import tazdev from wok
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Feb 24 04:02:55 2011 +0100 (2011-02-24) |
parents | |
children | 2f52d47889b0 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tazdev/tazdev Thu Feb 24 04:02:55 2011 +0100 1.3 @@ -0,0 +1,356 @@ 1.4 +#!/bin/sh 1.5 +# Tazdev - SliTaz developers and build host tool. 1.6 +# System wide config file: /etc/slitaz/tazdev.conf 1.7 +# 1.8 +# (c) 2009 SliTaz GNU/Linux - GNU gpl v3 1.9 +# 1.10 +# Authors : Christophe Lincoln (Pankso) <pankso@slitaz.org> 1.11 +# 1.12 + 1.13 +if [ -f /etc/slitaz/tazdev.conf ]; then 1.14 + . /etc/slitaz/tazdev.conf 1.15 + if [ -f $PWD/tazdev.conf ]; then 1.16 + . $PWD/tazdev.conf 1.17 + fi 1.18 +else 1.19 + echo -e "\nNo config file found in /etc/slitaz or the current dir...\n" 1.20 + exit 0 1.21 +fi 1.22 + 1.23 +usage() 1.24 +{ 1.25 + echo -e "\nSliTaz developers and build host tool\n 1.26 +\033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking|experimental|path] 1.27 +\033[1mCommands: \033[0m\n 1.28 + usage Print this short usage and command list. 1.29 + projects-stats Display statistics about your projects (-ps). 1.30 + cmplog Log 'tazwok cmp' result (or use tazbb). 1.31 + update-wok Update Hg wok and copy it to the chroot wok. 1.32 + update-www Update SliTaz Website repo from Hg. 1.33 + chroot Mount virtual fs if needed and chroot into the build env. 1.34 + gen-chroot Generate a chroot using the last cooking base rootfs. 1.35 + clean-chroot Clean a chroot environment (skip root/ and home/). 1.36 + purge Remove obsolete packages and obsolete source tarballs. 1.37 + dry-purge Show obsolete packages and obsolete source tarballs. 1.38 + push Upload new packages to the main mirror (-p). 1.39 + dry-push Show what will be uploaded to the mirror. Does nothing (-dp). 1.40 + pull Download new packages from the main mirror. 1.41 + dry-pull Show what will be downloaded from the mirror. Does nothing. 1.42 + relpkg Archive and upload new package/project version.\n" 1.43 +} 1.44 + 1.45 +# Exit if user is not root. 1.46 +check_root() 1.47 +{ 1.48 + if test $(id -u) != 0 ; then 1.49 + echo -e "\nThis program requires being run as root.\n" 1.50 + exit 0 1.51 + fi 1.52 +} 1.53 + 1.54 +status() 1.55 +{ 1.56 + local CHECK=$? 1.57 + echo -en "\033[70G" 1.58 + if [ $CHECK = 0 ]; then 1.59 + echo "Done" 1.60 + else 1.61 + echo "Failed" 1.62 + fi 1.63 + return $CHECK 1.64 +} 1.65 + 1.66 +get_version() 1.67 +{ 1.68 + if [ "$2" = "stable" ]; then 1.69 + VERSION=stable 1.70 + SLITAZ=$STABLE 1.71 + elif [ -n "$2" ]; then 1.72 + # Undigest - custom ? 1.73 + VERSION=$2 1.74 + SLITAZ=/home/slitaz/$2 1.75 + else 1.76 + VERSION=cooking 1.77 + SLITAZ=$COOKING 1.78 + fi 1.79 + ROOTFS=$SLITAZ/chroot 1.80 + HG_WOK=$SLITAZ/wok 1.81 + BUILD_WOK=$SLITAZ/chroot/home/slitaz/wok 1.82 +} 1.83 + 1.84 +check_mirror() 1.85 +{ 1.86 + # ping -c 1 $MIRROR 1.87 + if [ -n "$2" ]; then 1.88 + USER=$2 1.89 + else 1.90 + USER=$USER 1.91 + fi 1.92 + if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then 1.93 + REMOTE_DIR=$MIRROR_PKGS/stable/ 1.94 + LOCAL_DIR=$STABLE/packages/ 1.95 + elif [ "$2" = "experimental" ] || [ "$3" = "experimental" ]; then 1.96 + REMOTE_DIR=$MIRROR_PKGS/experimental/ 1.97 + LOCAL_DIR=$EXPERIMENTAL/packages/ 1.98 + else 1.99 + REMOTE_DIR=$MIRROR_PKGS/cooking/ 1.100 + LOCAL_DIR=$COOKING/packages/ 1.101 + fi 1.102 +} 1.103 + 1.104 +# Mount virtual Kernel file systems and chroot but check that nobody 1.105 +# else has done mounts 1.106 +mount_chroot() 1.107 +{ 1.108 + if [ ! -d $ROOTFS/proc/1 ]; then 1.109 + echo -n "Mounting virtual filesystems..." 1.110 + mount -t proc proc $ROOTFS/proc 1.111 + mount -t sysfs sysfs $ROOTFS/sys 1.112 + mount -t devpts devpts $ROOTFS/dev/pts 1.113 + mount -t tmpfs shm $ROOTFS/dev/shm 1.114 + status 1.115 + fi 1.116 +} 1.117 + 1.118 +# Unmount virtual Kernel file systems on exit and ensure we are the last 1.119 +# user before unmounting ! 1.120 +umount_chroot() 1.121 +{ 1.122 + # Not working. Buggy ps ? 1.123 + #sleep 6 1.124 + ps=$(ps | grep `basename $0` | grep -v grep | wc -l) 1.125 + if [ "$ps" == "1" ]; then 1.126 + echo -ne "\Unmounting virtual filesystems..." 1.127 + umount $ROOTFS/dev/shm 1.128 + umount $ROOTFS/dev/pts 1.129 + umount $ROOTFS/sys 1.130 + umount $ROOTFS/proc 1.131 + status 1.132 + else 1.133 + echo -e "\nProcess: $ps\n" 1.134 + ps | grep `basename $0` | grep -v grep 1.135 + echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n" 1.136 + fi 1.137 +} 1.138 + 1.139 +# Get the last cooking base rootfs, extract and configure. 1.140 +gen_new_chroot() 1.141 +{ 1.142 + echo -e "\nGenerating new chroot in : $ROOTFS" 1.143 + echo "================================================================================" 1.144 + mkdir -p $ROOTFS && cd $ROOTFS 1.145 + wget $DL_URL/boot/cooking/rootfs-base.gz 1.146 + echo -n "Extracting the rootfs..." 1.147 + lzma d rootfs-base.gz -so | cpio -id 1.148 + rm rootfs-base.gz 1.149 + echo -n "Creating resolv.conf..." 1.150 + cat /etc/resolv.conf > etc/resolv.conf 1.151 + status 1.152 + echo "================================================================================" 1.153 + echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'" 1.154 + echo -e "Example: tazdev chroot $ROOTFS\n" 1.155 +} 1.156 + 1.157 +# Remove obsolate slitaz packages 1.158 +purge_packages() 1.159 +{ 1.160 + arg=$1 1.161 + TMP_FILE=/tmp/tazdev.$$ 1.162 + ls $BUILD_WOK | while read pkg; do 1.163 + [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue 1.164 + EXTRAVERSION="" 1.165 + . $BUILD_WOK/$pkg/taz/*/receipt 1.166 + echo $PACKAGE-$VERSION$EXTRAVERSION.tazpkg 1.167 + done > $TMP_FILE 1.168 + ls $SLITAZ/chroot/home/slitaz/packages | while read pkg; do 1.169 + case "$pkg" in 1.170 + *.tazpkg) 1.171 + grep -q ^$pkg$ $TMP_FILE && continue 1.172 + echo Remove $pkg 1.173 + [ "$arg" == "purge" ] && 1.174 + rm -f $SLITAZ/chroot/home/slitaz/packages/$pkg ;; 1.175 + esac 1.176 + done 1.177 + rm -f $TMP_FILE 1.178 +} 1.179 + 1.180 +# Remove obsolate source tarballs 1.181 +purge_sources() 1.182 +{ 1.183 + arg=$1 1.184 + TMP_FILE=/tmp/tazdev.$$ 1.185 + ls $BUILD_WOK | while read pkg; do 1.186 + [ -f $BUILD_WOK/$pkg/receipt ] || continue 1.187 + TARBALL="" 1.188 + . $BUILD_WOK/$pkg/receipt 1.189 + [ -n "$TARBALL" ] && echo $TARBALL 1.190 + grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \ 1.191 + -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \ 1.192 + -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \ 1.193 + sed "s|['\"/]||g" | while read file ; do 1.194 + eval echo $file 2> /dev/null 1.195 + done 1.196 + done > $TMP_FILE 1.197 + ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do 1.198 + grep -q ^$pkg$ $TMP_FILE && continue 1.199 + echo Remove $pkg 1.200 + [ "$arg" == "purge" ] && 1.201 + rm -f $SLITAZ/chroot/home/slitaz/src/$pkg 1.202 + done 1.203 + rm -f $TMP_FILE 1.204 +} 1.205 + 1.206 +case "$1" in 1.207 + cmplog) 1.208 + # Log 'tazwok cmp' for the web interface (can be used via a cron job). 1.209 + check_root 1.210 + echo -e "Starting 'tazwok cmp' (can be long)...\n" 1.211 + tazwok cmp | grep ^[A-Z] | tee $CMP_LOG 1.212 + echo "Date: `date`" >> $CMP_LOG ;; 1.213 + '-ps'|projects-stats) 1.214 + echo -e "\nStatistics for: $PROJECTS\n" 1.215 + echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision" 1.216 + echo -ne "\033[48G Version" && echo -e "\033[64G Files" 1.217 + echo "================================================================================" 1.218 + cd $PROJECTS 1.219 + for proj in * 1.220 + do 1.221 + rev="" 1.222 + echo -n "$proj" 1.223 + size=`du -sh $proj | awk '{ print $1 }'` 1.224 + echo -ne "\033[24G $size" 1.225 + if [ -d $proj/.hg ]; then 1.226 + cd $proj 1.227 + rev=`hg head --template '{rev}\n'` 1.228 + vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1` 1.229 + echo -ne "\033[38G $rev" 1.230 + echo -ne "\033[48G $vers" && cd .. 1.231 + fi 1.232 + files=`find $proj -type f | wc -l` 1.233 + echo -e "\033[64G $files" 1.234 + done 1.235 + echo "================================================================================" 1.236 + echo "" ;; 1.237 + update-wok) 1.238 + # Update the Hg wok and copy it to the chroot env. Hg wok is 1.239 + # copied to the chroot wok to avoid messing with build result 1.240 + # file and so we can also modify receipt directly without affecting 1.241 + # the Hg wok. 1.242 + check_root 1.243 + get_version $@ 1.244 + echo "" 1.245 + echo "Hg wok : $HG_WOK" 1.246 + echo "Build wok : $BUILD_WOK" 1.247 + cd $HG_WOK 1.248 + hg pull && hg update 1.249 + echo -n "Copying Hg wok to the build wok... " 1.250 + cp -a $HG_WOK/* $BUILD_WOK 1.251 + cp -a $HG_WOK/.hg $BUILD_WOK 1.252 + status && echo "" ;; 1.253 + update-www) 1.254 + # Update website from repo. 1.255 + echo "" 1.256 + cd $WEBSITE && hg pull && hg update 1.257 + echo "" ;; 1.258 + chroot) 1.259 + # Chroot into a build env. Default to cooking configured in 1.260 + # tazdev.conf 1.261 + check_root 1.262 + get_version $@ 1.263 + mount_chroot 1.264 + echo -e "\nChrooting in $ROOTFS...\n" 1.265 + chroot $ROOTFS /bin/sh --login 1.266 + umount_chroot 1.267 + echo -e "Exiting $ROOTFS chroot environment...\n" ;; 1.268 + gen-chroot) 1.269 + check_root 1.270 + get_version $@ 1.271 + # Dont break another env. 1.272 + if [ -d $ROOTFS/bin ]; then 1.273 + echo -e "\nA chroot environment already exists in : $ROOTFS\n" 1.274 + exit 1 1.275 + fi 1.276 + gen_new_chroot ;; 1.277 + clean-chroot) 1.278 + # Keep root/ and /home they may have a build wok, custom scripts, etc. 1.279 + check_root 1.280 + if [ -z "$2" ]; then 1.281 + echo -e "\nPlease specify the path to the chroot environment to clean.\n" 1.282 + exit 0 1.283 + else 1.284 + ROOTFS=$2 1.285 + if [ ! -d "$ROOTFS" ]; then 1.286 + echo -e "\nWarning : $ROOTFS doesn't exist!\n" 1.287 + exit 1 1.288 + fi 1.289 + fi 1.290 + if [ -d $ROOTFS/proc/1 ]; then 1.291 + echo -e "\nWarning : $ROOTFS/proc mounted!\n" 1.292 + exit 1 1.293 + fi 1.294 + cd $ROOTFS || exit 1 1.295 + echo -e "\nCleaning chroot in: $ROOTFS" 1.296 + echo "================================================================================" 1.297 + for i in bin dev etc init lib media mnt proc sbin sys tmp usr var 1.298 + do 1.299 + echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... " 1.300 + rm -rf $i 1.301 + status 1.302 + done 1.303 + echo "================================================================================" 1.304 + echo "" ;; 1.305 + '-p'|push) 1.306 + check_mirror $@ 1.307 + rsync -r -t -l -v -z --delete \ 1.308 + $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;; 1.309 + '-dp'|dry-push) 1.310 + check_mirror $@ 1.311 + rsync -r -t -l -v -z --delete --dry-run \ 1.312 + $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;; 1.313 + pull) 1.314 + check_mirror $@ 1.315 + rsync -r -t -l -v -z --delete \ 1.316 + -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;; 1.317 + dry-pull) 1.318 + check_mirror $@ 1.319 + rsync -r -t -l -v -z --delete --dry-run \ 1.320 + -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;; 1.321 + purge|dry-purge) 1.322 + check_root 1.323 + get_version $@ 1.324 + purge_packages $1 1.325 + purge_sources $1 ;; 1.326 + relpkg) 1.327 + [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources" 1.328 + if [ -z $2 ] || [ -z $3 ]; then 1.329 + echo -e "\nUsage: $0 relpkg package version\n" 1.330 + exit 0 1.331 + fi 1.332 + PACKAGE=$2 1.333 + VERSION=$3 1.334 + echo "" 1.335 + cd $PROJECTS/$PACKAGE 1.336 + # Sanity check 1.337 + if ! grep -q $VERSION$ .hgtags; then 1.338 + echo "Missing Hg tag for version: $VERSION" 1.339 + echo -e "You may want to: hg tag $VERSION && hg push\n" 1.340 + exit 0 1.341 + fi 1.342 + # Archive 1.343 + echo -n "Creating tarball and md5sum for: $PACKAGE-$VERSION... " 1.344 + hg archive -t tgz $PACKAGE-$VERSION.tar.gz 1.345 + md5sum $PACKAGE-$VERSION.tar.gz > $PACKAGE-$VERSION.md5 1.346 + echo "Done" 1.347 + # Upload 1.348 + echo -n "Do you wish to upload tarball to the mirror [N/y] ? " 1.349 + read upload 1.350 + if [ "$upload" = "y" ]; then 1.351 + echo "Uploading to: $MIRROR/sources/${PACKAGE#slitaz-}" 1.352 + scp $PACKAGE-$VERSION.tar.gz $PACKAGE-$VERSION.md5 \ 1.353 + $USER@$MIRROR:$MIRROR_SOURCES/${PACKAGE#slitaz-} 1.354 + fi ;; 1.355 + usage|*) 1.356 + usage ;; 1.357 +esac 1.358 + 1.359 +exit 0