slitaz-dev-tools rev 81

tazdev: huge clean-up and use $lowercase var in script
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 07 00:10:02 2011 +0200 (2011-05-07)
parents 2940ea5fe229
children c6a685a113c0
files tazdev/tazdev
line diff
     1.1 --- a/tazdev/tazdev	Fri May 06 23:58:23 2011 +0200
     1.2 +++ b/tazdev/tazdev	Sat May 07 00:10:02 2011 +0200
     1.3 @@ -1,7 +1,9 @@
     1.4  #!/bin/sh
     1.5  #
     1.6  # Tazdev - SliTaz developers and build host tool. System wide config
     1.7 -# file is located at: /etc/slitaz/tazdev.conf
     1.8 +# file is located at: /etc/slitaz/tazdev.conf. Keep the code clear and
     1.9 +# well commented please, also: configuration variablea are $UPERCASE
    1.10 +# and variables initialized by tazdev itself are $lowersace
    1.11  #
    1.12  # (c) 2011 SliTaz GNU/Linux - GNU gpl v3
    1.13  #
    1.14 @@ -11,7 +13,7 @@
    1.15  #
    1.16  
    1.17  [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
    1.18 -[ -f $PWD/tazdev.conf ] && . $PWD/tazdev.conf
    1.19 +[ -f tazdev.conf ] && . ./tazdev.conf
    1.20  
    1.21  if [ -z "$SLITAZ" ]; then
    1.22  	echo -e "\nNo config file found\n" && exit 1
    1.23 @@ -24,7 +26,6 @@
    1.24  \033[1mCommands: \033[0m\n
    1.25   usage               Print this short usage and command list
    1.26   projects-stats|-ps  Display statistics about your projects
    1.27 - update-wok          Update Hg wok and copy it to the chroot wok
    1.28   chroot              Mount virtual fs if needed and chroot into the build env
    1.29   gen-chroot|-gs      Generate a chroot using the last cooking base rootfs
    1.30   umount-chroot|-uc   Unmount chroot specified on cmdline (--forced to force)
    1.31 @@ -50,39 +51,39 @@
    1.32  
    1.33  status()
    1.34  {
    1.35 -	local CHECK=$?
    1.36 +	local check=$?
    1.37  	echo -en "\033[70G"
    1.38 -	if [ $CHECK = 0 ]; then
    1.39 +	if [ $check = 0 ]; then
    1.40  		echo "Done"
    1.41  	else
    1.42  		echo "Failed"
    1.43  	fi
    1.44 -	return $CHECK
    1.45 +	return $check
    1.46  }
    1.47  
    1.48  get_version()
    1.49  {
    1.50  	if [ "$2" = "stable" ]; then
    1.51 -		VERSION=stable
    1.52 -		SLITAZ=$STABLE
    1.53 +		version=stable
    1.54 +		slitaz=$STABLE
    1.55  	elif [ -n "$2" ]; then
    1.56  		# Undigest - custom ?
    1.57 -		VERSION=$2
    1.58 -		SLITAZ=/home/slitaz/$2
    1.59 +		version=$2
    1.60 +		slitaz=/home/slitaz/$2
    1.61  	else
    1.62 -		VERSION=cooking
    1.63 -		SLITAZ=$COOKING
    1.64 +		version=cooking
    1.65 +		slitaz=$COOKING
    1.66  	fi
    1.67 -	ROOTFS=$SLITAZ/chroot
    1.68 +	rootfs=$slitaz/chroot
    1.69  }
    1.70  
    1.71  check_mirror()
    1.72  {
    1.73  	# ping -c 1 $MIRROR
    1.74  	if [ -n "$2" ]; then
    1.75 -		USER=$2
    1.76 +		user=$2
    1.77  	else
    1.78 -		USER=$USER
    1.79 +		user=$user
    1.80  	fi
    1.81  	if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
    1.82  		REMOTE_DIR=$MIRROR_PKGS/stable/
    1.83 @@ -100,25 +101,25 @@
    1.84  # else has done mounts
    1.85  mount_chroot()
    1.86  {
    1.87 -	if [ ! -d $ROOTFS/proc/1 ]; then
    1.88 +	if [ ! -d $rootfs/proc/1 ]; then
    1.89  		echo -en "\nMounting virtual filesystems..."
    1.90 -		mount -t proc proc $ROOTFS/proc
    1.91 -		mount -t sysfs sysfs $ROOTFS/sys
    1.92 -		mount -t devpts devpts $ROOTFS/dev/pts
    1.93 -		mount -t tmpfs shm $ROOTFS/dev/shm
    1.94 +		mount -t proc proc $rootfs/proc
    1.95 +		mount -t sysfs sysfs $rootfs/sys
    1.96 +		mount -t devpts devpts $rootfs/dev/pts
    1.97 +		mount -t tmpfs shm $rootfs/dev/shm
    1.98  		status
    1.99  	fi
   1.100  	# Mount source so they can be shared between cooking/stable/undigest.
   1.101  	# But do it only if it's a slitaz developement chroot.
   1.102 -	fs=$ROOTFS/home/slitaz
   1.103 -	if [ -d "$SLITAZ" ]; then
   1.104 -		mkdir -p $SLITAZ/src $fs/src
   1.105 -		mount -o bind $SLITAZ/src $fs/src
   1.106 -		# Now mount package dir so they are in /home/slitaz/$VERSION
   1.107 +	fs=$rootfs/home/slitaz
   1.108 +	if [ -d "$slitaz" ]; then
   1.109 +		mkdir -p $slitaz/src $fs/src
   1.110 +		mount -o bind $slitaz/src $fs/src
   1.111 +		# Now mount package dir so they are in /home/slitaz/$version
   1.112  		# We may not mount cache wok or others it has no point and if
   1.113  		# one want to use a shared wok he can bind it manually.
   1.114 -		mkdir -p $SLITAZ/$VERSION/packages $fs/packages
   1.115 -		mount -o bind $SLITAZ/$VERSION/packages $fs/packages
   1.116 +		mkdir -p $slitaz/$version/packages $fs/packages
   1.117 +		mount -o bind $slitaz/$version/packages $fs/packages
   1.118  	fi
   1.119  }
   1.120  
   1.121 @@ -127,13 +128,13 @@
   1.122  umount_chroot()
   1.123  {
   1.124  	[ "$1" ] && ROOTF=$1
   1.125 -	fs=$ROOTFS/home/slitaz
   1.126 -	echo -e "\nChroot: $ROOTFS"
   1.127 +	fs=$rootfs/home/slitaz
   1.128 +	echo -e "\nChroot: $rootfs"
   1.129  	echo -n "Unmounting virtual filesystems..."
   1.130 -	umount $ROOTFS/dev/shm
   1.131 -	umount $ROOTFS/dev/pts
   1.132 -	umount $ROOTFS/sys
   1.133 -	umount $ROOTFS/proc
   1.134 +	umount $rootfs/dev/shm
   1.135 +	umount $rootfs/dev/pts
   1.136 +	umount $rootfs/sys
   1.137 +	umount $rootfs/proc
   1.138  	umount $fs/src
   1.139  	umount $fs/packages
   1.140  	echo -e "Done\n"
   1.141 @@ -145,50 +146,50 @@
   1.142  # Get the last cooking base rootfs, extract and configure.
   1.143  gen_new_chroot()
   1.144  {
   1.145 -	echo -e "\nGenerating new chroot in : $ROOTFS"
   1.146 +	echo -e "\nGenerating new chroot in : $rootfs"
   1.147  	echo "================================================================================"
   1.148 -	mkdir -p $ROOTFS 
   1.149 +	mkdir -p $rootfs 
   1.150  	for pkg in busybox libtaz tazwok tazchroot \
   1.151  		tazpkg slitaz-base-files
   1.152  	do
   1.153 -		tazpkg get-install $pkg --root=$ROOTFS
   1.154 +		tazpkg get-install $pkg --root=$rootfs
   1.155  	done
   1.156  	echo -n "Creating resolv.conf..."
   1.157 -	cat /etc/resolv.conf > $ROOTFS/etc/resolv.conf
   1.158 +	cat /etc/resolv.conf > $rootfs/etc/resolv.conf
   1.159  	status
   1.160  	echo "================================================================================"
   1.161  	echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
   1.162 -	echo -e "Example: tazdev chroot $ROOTFS\n"
   1.163 +	echo -e "Example: tazdev chroot $rootfs\n"
   1.164  }
   1.165  
   1.166  # Remove obsolate slitaz packages
   1.167  purge_packages()
   1.168  {
   1.169  	arg=$1
   1.170 -	TMP_FILE=/tmp/tazdev.$$
   1.171 +	tmp=/tmp/tazdev.$$
   1.172  	ls $BUILD_WOK | while read pkg; do
   1.173  		[ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
   1.174 -		EXTRAVERSION=""
   1.175 +		EXTRAversion=""
   1.176  		. $BUILD_WOK/$pkg/taz/*/receipt
   1.177 -		echo $PACKAGE-$VERSION$EXTRAVERSION.tazpkg
   1.178 -	done > $TMP_FILE
   1.179 -	ls $SLITAZ/chroot/home/slitaz/packages | while read pkg; do
   1.180 +		echo $pkg-$version$EXTRAversion.tazpkg
   1.181 +	done > $tmp
   1.182 +	ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
   1.183  		case "$pkg" in
   1.184  		*.tazpkg)
   1.185 -			grep -q ^$pkg$ $TMP_FILE && continue
   1.186 +			grep -q ^$pkg$ $tmp && continue
   1.187  			echo Remove $pkg
   1.188  			[ "$arg" == "purge" ] &&
   1.189 -			rm -f $SLITAZ/chroot/home/slitaz/packages/$pkg ;;
   1.190 +			rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
   1.191  		esac
   1.192  	done
   1.193 -	rm -f $TMP_FILE
   1.194 +	rm -f $tmp
   1.195  }
   1.196  
   1.197  # Remove obsolate source tarballs
   1.198  purge_sources()
   1.199  {
   1.200  	arg=$1
   1.201 -	TMP_FILE=/tmp/tazdev.$$
   1.202 +	tmp=/tmp/tazdev.$$
   1.203  	ls $BUILD_WOK | while read pkg; do
   1.204  		[ -f $BUILD_WOK/$pkg/receipt ] || continue
   1.205  		TARBALL=""
   1.206 @@ -200,14 +201,14 @@
   1.207  		sed "s|['\"/]||g" | while read file ; do
   1.208  			eval echo $file 2> /dev/null
   1.209  		done
   1.210 -	done > $TMP_FILE
   1.211 -	ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do
   1.212 -		grep -q ^$pkg$ $TMP_FILE && continue
   1.213 +	done > $tmp
   1.214 +	ls $slitaz/chroot/home/slitaz/src | while read pkg; do
   1.215 +		grep -q ^$pkg$ $tmp && continue
   1.216  		echo Remove $pkg
   1.217  		[ "$arg" == "purge" ] &&
   1.218 -		rm -f $SLITAZ/chroot/home/slitaz/src/$pkg
   1.219 +		rm -f $slitaz/chroot/home/slitaz/src/$pkg
   1.220  	done
   1.221 -	rm -f $TMP_FILE
   1.222 +	rm -f $tmp
   1.223  }
   1.224  
   1.225  case "$1" in
   1.226 @@ -240,23 +241,23 @@
   1.227  		# tazdev.conf
   1.228  		check_root
   1.229  		get_version $@
   1.230 -		[ -d "$2" ] && ROOTFS=$2
   1.231 +		[ -d "$2" ] && rootfs=$2
   1.232  		mount_chroot
   1.233 -		echo -e "Chrooting in $ROOTFS...\n"
   1.234 -		chroot $ROOTFS /bin/sh --login
   1.235 +		echo -e "Chrooting in $rootfs...\n"
   1.236 +		chroot $rootfs /bin/sh --login
   1.237  		umount_chroot ;;
   1.238  	umount-chroot|-uc)
   1.239  		check_root
   1.240  		get_version $@
   1.241 -		[ "$2" ] && ROOTFS=$2
   1.242 -		umount_chroot $ROOTFS ;;
   1.243 +		[ "$2" ] && rootfs=$2
   1.244 +		umount_chroot $rootfs ;;
   1.245  	gen-chroot|-gc)
   1.246  		check_root
   1.247  		get_version $@
   1.248 -		[ -d "$2" ] && ROOTFS=$2
   1.249 +		[ -d "$2" ] && rootfs=$2
   1.250  		# Dont break another env.
   1.251 -		if [ -d $ROOTFS/bin ]; then
   1.252 -			echo -e "\nA chroot environment already exists in : $ROOTFS\n"
   1.253 +		if [ -d $rootfs/bin ]; then
   1.254 +			echo -e "\nA chroot environment already exists in : $rootfs\n"
   1.255  			exit 1
   1.256  		fi
   1.257  		gen_new_chroot ;;
   1.258 @@ -267,18 +268,18 @@
   1.259  			echo -e "\nPlease specify the path to the chroot environment to clean.\n"
   1.260  			exit 0
   1.261  		else
   1.262 -			ROOTFS=$2
   1.263 -			if [ ! -d "$ROOTFS" ]; then
   1.264 -				echo -e "\nWarning : $ROOTFS doesn't exist!\n"
   1.265 +			rootfs=$2
   1.266 +			if [ ! -d "$rootfs" ]; then
   1.267 +				echo -e "\nWarning : $rootfs doesn't exist!\n"
   1.268  				exit 1
   1.269  			fi
   1.270  		fi
   1.271 -		if [ -d $ROOTFS/proc/1 ]; then
   1.272 -			echo -e "\nWarning : $ROOTFS/proc mounted!\n"
   1.273 +		if [ -d $rootfs/proc/1 ]; then
   1.274 +			echo -e "\nWarning : $rootfs/proc mounted!\n"
   1.275  			exit 1
   1.276  		fi
   1.277 -		cd $ROOTFS || exit 1
   1.278 -		echo -e "\nCleaning chroot in: $ROOTFS"
   1.279 +		cd $rootfs || exit 1
   1.280 +		echo -e "\nCleaning chroot in: $rootfs"
   1.281  		echo "================================================================================"
   1.282  		for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
   1.283  		do
   1.284 @@ -291,19 +292,19 @@
   1.285  	push|-p)
   1.286  		check_mirror $@
   1.287  		rsync -r -t -l -v -z --delete \
   1.288 -			$LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
   1.289 +			$LOCAL_DIR -e ssh $user@$MIRROR:$REMOTE_DIR ;;
   1.290  	dry-push|-dp)
   1.291  		check_mirror $@
   1.292  		rsync -r -t -l -v -z --delete --dry-run \
   1.293 -			$LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
   1.294 +			$LOCAL_DIR -e ssh $user@$MIRROR:$REMOTE_DIR ;;
   1.295  	pull)
   1.296  		check_mirror $@
   1.297  		rsync -r -t -l -v -z --delete \
   1.298 -			-e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
   1.299 +			-e ssh $user@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
   1.300  	dry-pull)
   1.301  		check_mirror $@
   1.302  		rsync -r -t -l -v -z --delete --dry-run \
   1.303 -			-e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
   1.304 +			-e ssh $user@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
   1.305  	purge|dry-purge)
   1.306  		check_root
   1.307  		get_version $@
   1.308 @@ -315,28 +316,30 @@
   1.309  			echo -e "\nUsage: $0 relpkg package version\n"
   1.310  			exit 0
   1.311  		fi
   1.312 -		PACKAGE=$2
   1.313 -		VERSION=$3
   1.314 -		echo ""
   1.315 -		cd $PROJECTS/$PACKAGE
   1.316 +		pkg=$2
   1.317 +		version=$3
   1.318 +		echo "" && cd $PROJECTS/$pkg
   1.319 +		
   1.320  		# Sanity check
   1.321 -		if ! grep -q $VERSION$ .hgtags; then
   1.322 -			echo "Missing Hg tag for version: $VERSION"
   1.323 -			echo -e "You may want to: hg tag $VERSION && hg push\n"
   1.324 +		if ! grep -q $version$ .hgtags; then
   1.325 +			echo "Missing Hg tag for version: $version"
   1.326 +			echo -e "You may want to: hg tag $version && hg push\n"
   1.327  			exit 0
   1.328  		fi
   1.329 +		
   1.330  		# Archive
   1.331 -		echo -n "Creating tarball and md5sum for: $PACKAGE-$VERSION... "
   1.332 -		hg archive -t tgz $PACKAGE-$VERSION.tar.gz
   1.333 -		md5sum $PACKAGE-$VERSION.tar.gz > $PACKAGE-$VERSION.md5
   1.334 +		echo -n "Creating tarball and md5sum for: $pkg-$version... "
   1.335 +		hg archive -t tgz $pkg-$version.tar.gz
   1.336 +		md5sum $pkg-$version.tar.gz > $pkg-$version.md5
   1.337  		echo "Done"
   1.338 +		
   1.339  		# Upload
   1.340  		echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
   1.341  		read upload
   1.342  		if [ "$upload" = "y" ]; then
   1.343 -			echo "Uploading to: $MIRROR/sources/${PACKAGE#slitaz-}"
   1.344 -			scp $PACKAGE-$VERSION.tar.gz $PACKAGE-$VERSION.md5 \
   1.345 -				$USER@$MIRROR:$MIRROR_SOURCES/${PACKAGE#slitaz-}
   1.346 +			echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
   1.347 +			scp $pkg-$version.tar.gz $pkg-$version.md5 \
   1.348 +				$user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
   1.349  		fi ;;
   1.350  	reliso|-ri)
   1.351  		# Generate all official images iso at once.