wok rev 3499

tazdev: Add command gen-chroot and clean-chroot + tiny fix
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jun 19 02:43:44 2009 +0200 (2009-06-19)
parents 07633a539a9d
children e4b53fbe493e
files slitaz-dev-tools/receipt slitaz-dev-tools/stuff/tazdev slitaz-dev-tools/stuff/tazdev.conf
line diff
     1.1 --- a/slitaz-dev-tools/receipt	Thu Jun 18 21:10:59 2009 +0200
     1.2 +++ b/slitaz-dev-tools/receipt	Fri Jun 19 02:43:44 2009 +0200
     1.3 @@ -1,7 +1,7 @@
     1.4  # SliTaz package receipt
     1.5  
     1.6  PACKAGE="slitaz-dev-tools"
     1.7 -VERSION="1.0"
     1.8 +VERSION="1.1"
     1.9  CATEGORY="development"
    1.10  SHORT_DESC="SliTaz developers and build host tools."
    1.11  MAINTAINER="pankso@slitaz.org"
     2.1 --- a/slitaz-dev-tools/stuff/tazdev	Thu Jun 18 21:10:59 2009 +0200
     2.2 +++ b/slitaz-dev-tools/stuff/tazdev	Fri Jun 19 02:43:44 2009 +0200
     2.3 @@ -20,17 +20,19 @@
     2.4  usage()
     2.5  {
     2.6  	echo -e "\nSliTaz developers and build host tool\n
     2.7 -\033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking]
     2.8 +\033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking|path]
     2.9  \033[1mCommands: \033[0m\n
    2.10 -  usage        Print this short usage and command list.
    2.11 -  cmplog       Log 'tazwok cmp' result.
    2.12 -  update-wok   Update Hg wok and copy it to the chroot wok.
    2.13 -  update-www   Update SliTaz Website repo.
    2.14 -  chroot       Mount virtual fs if needed and chroot into the build env.
    2.15 -  push         Upload new packages to the mirror.
    2.16 -  dry-push     Show what will be uploaded to the mirror. Does nothing.
    2.17 -  pull         Download new packages from the mirror.
    2.18 -  dry-pull     Show what will be downloaded from the mirror. Does nothing.\n"
    2.19 +  usage         Print this short usage and command list.
    2.20 +  cmplog        Log 'tazwok cmp' result (or use tazbb).
    2.21 +  update-wok    Update Hg wok and copy it to the chroot wok.
    2.22 +  update-www    Update SliTaz Website repo from Hg.
    2.23 +  chroot        Mount virtual fs if needed and chroot into the build env.
    2.24 +  gen-chroot    Generate a chroot environment using the last cooking base rootf.
    2.25 +  clean-chroot  Clean a chroot environment (skip root/ and home/)
    2.26 +  push          Upload new packages to the main mirror.
    2.27 +  dry-push      Show what will be uploaded to the mirror. Does nothing.
    2.28 +  pull          Download new packages from the main mirror.
    2.29 +  dry-pull      Show what will be downloaded from the mirror. Does nothing.\n"
    2.30  }
    2.31  
    2.32  # Exit if user is not root.
    2.33 @@ -42,6 +44,30 @@
    2.34  	fi
    2.35  }
    2.36  
    2.37 +status()
    2.38 +{
    2.39 +	local CHECK=$?
    2.40 +	if [ $CHECK = 0 ]; then
    2.41 +		echo " Done"
    2.42 +	else
    2.43 +		echo " Failed"
    2.44 +	fi
    2.45 +	return $CHECK
    2.46 +}
    2.47 +
    2.48 +get_version()
    2.49 +{
    2.50 +	if [ "$2" = "stable" ]; then
    2.51 +		VERSION=stable
    2.52 +		ROOTFS=$STABLE/chroot
    2.53 +	elif [ -n "$2" ]; then
    2.54 +		ROOTFS=$2
    2.55 +	else
    2.56 +		VERSION=cooking
    2.57 +		ROOTFS=$COOKING/chroot
    2.58 +	fi
    2.59 +}
    2.60 +
    2.61  check_mirror()
    2.62  {
    2.63  	# ping -c 1 $MIRROR
    2.64 @@ -59,6 +85,59 @@
    2.65  	fi	
    2.66  }
    2.67  
    2.68 +# Mount virtual Kernel file systems and chroot but check that nobody 
    2.69 +# else has done mounts
    2.70 +mount_chroot()
    2.71 +{
    2.72 +	if [ ! -d $ROOTFS/proc/1 ]; then
    2.73 +		echo -n "Mounting virtual filesystem..."
    2.74 +		mount -t proc proc $ROOTFS/proc
    2.75 +		mount -t sysfs sysfs $ROOTFS/sys
    2.76 +		mount -t devpts devpts $ROOTFS/dev/pts
    2.77 +		mount -t tmpfs shm $ROOTFS/dev/shm
    2.78 +		status
    2.79 +	fi
    2.80 +}
    2.81 +
    2.82 +# Unmount virtual Kernel file systems on exit and ensure we are the last 
    2.83 +# user before unmounting !
    2.84 +umount_chroot()
    2.85 +{
    2.86 +	# Not working. Buggy ps ?
    2.87 +	#sleep 6
    2.88 +	ps=$(ps | grep `basename $0` | grep -v grep | wc -l)
    2.89 +	if [ "$ps" == "1" ]; then
    2.90 +		echo -ne "\Unmounting virtual filesystem..."
    2.91 +		umount $ROOTFS/dev/shm
    2.92 +		umount $ROOTFS/dev/pts
    2.93 +		umount $ROOTFS/sys
    2.94 +		umount $ROOTFS/proc
    2.95 +		status
    2.96 +	else
    2.97 +		echo -e "\nProcess: $ps\n"
    2.98 +		ps | grep `basename $0` | grep -v grep
    2.99 +		echo -e "\nLeaving virtual filesystem unmounted (`pidof tazdev`)...\n"
   2.100 +	fi
   2.101 +}
   2.102 +
   2.103 +# Get the last cooking base rootfs, extract and configure.
   2.104 +gen_new_chroot()
   2.105 +{
   2.106 +	echo -e "\nGenerating new chroot in : $ROOTFS"
   2.107 +	echo "================================================================================"
   2.108 +	mkdir -p $ROOTFS && cd $ROOTFS
   2.109 +	wget $DL_URL/boot/cooking/rootfs-base.gz
   2.110 +	echo -n "Extracting the rootfs..."
   2.111 +	lzma d rootfs-base.gz -so | cpio -id
   2.112 +	rm rootfs-base.gz
   2.113 +	echo -n "Creating resolv.conf..."
   2.114 +	cat /etc/resolv.conf > etc/resolv.conf
   2.115 +	status
   2.116 +	echo "================================================================================"
   2.117 +	echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
   2.118 +	echo -e "Example: tazdev chroot $ROOTFS\n"
   2.119 +}
   2.120 +
   2.121  case "$1" in
   2.122  	cmplog)
   2.123  		# Log 'tazwok cmp' for the web interface (can be used via a cron job).
   2.124 @@ -67,10 +146,10 @@
   2.125  		tazwok cmp | grep ^[A-Z] | tee $CMP_LOG
   2.126  		echo "Date: `date`" >> $CMP_LOG ;;
   2.127  	update-wok)
   2.128 -		# Update the Hg wok and copy it to the chroot env. Hg wok id 
   2.129 +		# Update the Hg wok and copy it to the chroot env. Hg wok is
   2.130  		# copied to the chroot wok to avoid messing with build result
   2.131  		# file and so we can also modify receipt directly without affecting
   2.132 -		# the main Hg.
   2.133 +		# the Hg wok.
   2.134  		check_root
   2.135  		if [ "$2" = "stable" ]; then
   2.136  			HG_WOK=$STABLE/wok
   2.137 @@ -86,7 +165,8 @@
   2.138  		hg pull && hg update
   2.139  		echo -n "Copying Hg wok to the build wok... "
   2.140  		cp -a $HG_WOK/* $BUILD_WOK
   2.141 -		echo -e "Done\n" ;;
   2.142 +		cp -a $HG_WOK/.hg $BUILD_WOK
   2.143 +		status && echo "" ;;
   2.144  	update-www)
   2.145  		# Update website from repo.
   2.146  		echo ""
   2.147 @@ -96,47 +176,65 @@
   2.148  		# Chroot into a build env. Default to cooking configured in 
   2.149  		# tazdev.conf
   2.150  		check_root
   2.151 -		if [ "$1" = "stable" ]; then
   2.152 -			ROOTFS=$STABLE/chroot
   2.153 +		get_version
   2.154 +		mount_chroot
   2.155 +		echo -e "\nChrooting in $ROOTFS...\n"
   2.156 +		chroot $ROOTFS /bin/sh --login
   2.157 +		umount_chroot
   2.158 +		echo -e "Exiting $ROOTFS chroot environment...\n" ;;
   2.159 +	gen-chroot)
   2.160 +		check_root
   2.161 +		get_version
   2.162 +		# Dont break another env.
   2.163 +		if [ -d $ROOTFS/bin ]; then
   2.164 +			echo -e "\nA chroot environment already exist in : $ROOTFS\n"
   2.165 +			exit 1
   2.166 +		fi
   2.167 +		gen_new_chroot ;;
   2.168 +	clean-chroot)
   2.169 +		# Keep root/ and /home they may have a build wok, custom scripts, etc.
   2.170 +		check_root
   2.171 +		if [ -z "$2" ]; then
   2.172 +			echo -e "\nPlease specify the path to the chroot environment to clean.\n"
   2.173 +			exit 0
   2.174  		else
   2.175 -			ROOTFS=$COOKING/chroot
   2.176 -			[ -n "$1" ] && ROOTFS=$1
   2.177 +			ROOTFS=$2
   2.178 +			if [ ! -d "$ROOTFS" ]; then
   2.179 +				echo -e "\nWarning : $ROOTFS dont exit!\n"
   2.180 +				exit 1
   2.181 +			fi
   2.182  		fi
   2.183 -		# Mount virtual Kernel file systems and chroot but check that 
   2.184 -		# nobody else has done mounts
   2.185 -		if [ ! -d $ROOTFS/proc/1 ]; then
   2.186 -			mount -t proc proc $ROOTFS/proc
   2.187 -			mount -t sysfs sysfs $ROOTFS/sys
   2.188 -			mount -t devpts devpts $ROOTFS/dev/pts
   2.189 -			mount -t tmpfs shm $ROOTFS/dev/shm
   2.190 +		if [ -d $ROOTFS/proc/1 ]; then
   2.191 +			echo -e "\nWarning : $ROOTFS/proc mounted!\n"
   2.192 +			exit 1
   2.193  		fi
   2.194 -		echo "Chrooting in $ROOTFS... "
   2.195 -		chroot $ROOTFS /bin/sh --login
   2.196 -		# Unmount virtual Kernel file systems on exit and ensure we are the 
   2.197 -		# last user before unmounting !
   2.198 -		if [ "$(ps | grep $(basename $0) | grep -v grep | wc -l)" == "1" ]; then
   2.199 -			umount $ROOTFS/dev/shm
   2.200 -			umount $ROOTFS/dev/pts
   2.201 -			umount $ROOTFS/sys
   2.202 -			umount $ROOTFS/proc
   2.203 -		fi
   2.204 -		echo "Exiting $ROOTFS chroot environment... " ;;
   2.205 +		cd $ROOTFS || exit 1
   2.206 +		echo -e "\nCleaning chroot in: $ROOTFS"
   2.207 +		echo "================================================================================"
   2.208 +		for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
   2.209 +		do
   2.210 +			echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
   2.211 +			rm -rf $i
   2.212 +			status
   2.213 +		done
   2.214 +		echo "================================================================================"
   2.215 +		echo "" ;;
   2.216  	push)
   2.217  		check_mirror
   2.218  		rsync -r -t -l -v -z --delete \
   2.219 -			$LOCAL_DIR -e ssh $USER@$HOST:$REMOTE_DIR ;;
   2.220 +			$LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
   2.221  	dry-push)
   2.222  		check_mirror
   2.223  		rsync -r -t -l -v -z --delete --dry-run \
   2.224 -			$LOCAL_DIR -e ssh $USER@$HOST:$REMOTE_DIR ;;
   2.225 +			$LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
   2.226  	pull)
   2.227  		check_mirror
   2.228  		rsync -r -t -l -v -z --delete \
   2.229 -			-e ssh $USER@$HOST:$REMOTE_DIR $LOCAL_DIR ;;
   2.230 +			-e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
   2.231  	dry-pull)
   2.232  		check_mirror
   2.233  		rsync -r -t -l -v -z --delete --dry-run \
   2.234 -			-e ssh $USER@$HOST:$REMOTE_DIR $LOCAL_DIR ;;
   2.235 +			-e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
   2.236  	usage|*)
   2.237  		usage ;;
   2.238  esac
     3.1 --- a/slitaz-dev-tools/stuff/tazdev.conf	Thu Jun 18 21:10:59 2009 +0200
     3.2 +++ b/slitaz-dev-tools/stuff/tazdev.conf	Fri Jun 19 02:43:44 2009 +0200
     3.3 @@ -11,6 +11,7 @@
     3.4  # Path to the Website repo.
     3.5  WEBSITE="/home/slitaz/www/website"
     3.6  
     3.7 -# Main mirror settings.
     3.8 +# Main mirror to push and download (ISO, rootfs. etc).
     3.9  MIRROR="mirror.slitaz.org"
    3.10 +DL_URL="http://mirror.switch.ch/ftp/mirror/slitaz"
    3.11  MIRROR_DIR="/var/www/slitaz/mirror/packages"