slitaz-dev-tools rev 274

tazdev: cosmetic changes, raise maintainability of the code, fix few typos, fix using `tazpkg --root=` here...
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Feb 28 17:16:47 2017 +0200 (2017-02-28)
parents 32887197a722
children 0b423b5392bc
files tazdev/tazdev tazdev/tazdev.conf
line diff
     1.1 --- a/tazdev/tazdev	Mon Feb 27 22:08:17 2017 +0100
     1.2 +++ b/tazdev/tazdev	Tue Feb 28 17:16:47 2017 +0200
     1.3 @@ -1,11 +1,11 @@
     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. Keep the code clear and
     1.8 -# well commented please, also: configuration variables are $UPPERCASE
     1.9 -# and variables initialized by tazdev itself are $lowerspace
    1.10 +# Tazdev - SliTaz developers and build host tool. System-wide config file
    1.11 +# is located at /etc/slitaz/tazdev.conf. Please, keep the code clear and
    1.12 +# well commented. Also keep in mind: configuration variables are $UPPERCASE
    1.13 +# and variables initialized by tazdev itself are $lowercase.
    1.14  #
    1.15 -# (c) 2014-2017 SliTaz GNU/Linux - GNU gpl v3
    1.16 +# (c) 2014-2017 SliTaz GNU/Linux - GNU GPL v3
    1.17  #
    1.18  # AUTHORS
    1.19  #     Christophe Lincoln <pankso@slitaz.org>
    1.20 @@ -21,39 +21,47 @@
    1.21  [ -f ~/.config/slitaz/tazdev.conf ] && . ~/.config/slitaz/tazdev.conf
    1.22  [ -f tazdev.conf ] && . ./tazdev.conf
    1.23  
    1.24 -if [ ! "$SLITAZ_HOME" ]; then
    1.25 -	echo -e "\nNo config file found\n" && exit 1
    1.26 -fi
    1.27 +[ -n "$SLITAZ_HOME" ] || die "No config file found"
    1.28 +
    1.29 +
    1.30 +# Remove all --parameters from cmdline
    1.31 +IFS=$'\n'
    1.32 +set -- $(echo "$*" | sed '/^--/d')
    1.33 +unset IFS
    1.34 +
    1.35  
    1.36  usage() {
    1.37 -	cat << EOT
    1.38 +	cat <<EOT
    1.39  
    1.40 -$(boldify "Usage:") $(basename $0) [command] [vers|user|tool] [vers|--opts]
    1.41 +$(boldify "Usage:") $(basename $0) <command> [<options>] [--options]
    1.42  
    1.43  SliTaz developers and build host tool v$VERSION
    1.44  
    1.45  $(boldify "Commands:")
    1.46 -       usage          Print this short usage and command list
    1.47 -       help           Give help on a SliTaz tool or library.
    1.48 -  -s   stats          Display statistics about your projects
    1.49 -  -c   chroot         Mount virtual fs and chroot into the build env
    1.50 -  -gc  gen-chroot     Generate a chroot using packages from config file
    1.51 -  -uc  unchroot       Unmount chroot specified on cmdline
    1.52 -  -cc  clean-chroot   Clean a chroot environment (skip root/ and home/)
    1.53 -  -p   push           Upload new packages to the main mirror
    1.54 -  -dp  dry-push       Show what will be uploaded to the mirror.
    1.55 -       pull           Download new packages from the main mirror
    1.56 -       dry-pull       Show what will be downloaded from the mirror.
    1.57 -  -ur  up-repos       Update all your SliTaz projects repos in one command.
    1.58 -  -rp  relpkg         Archive and upload new package/project version
    1.59 -  -sc  setup-cgi      Setup your CGI environment
    1.60 +       usage                     Print this short usage and command list
    1.61 +       help <tool>               Give help on a SliTaz tool or library
    1.62 +  -s   stats                     Display statistics for your projects
    1.63 +  -c   chroot [<ver>|<rootfs>]   Mount virtual FS and chroot into the build env
    1.64 +  -gc  gen-chroot [<ver>]        Generate a chroot using packages from config
    1.65 +                                 file
    1.66 +  -uc  umchroot [<rootfs>]       Unmount chroot specified on cmdline
    1.67 +  -cc  clean-chroot [<ver>]      Clean a chroot environment (skip root/ and
    1.68 +                                 home/)
    1.69 +  -p   push     [<user> [<ver>]] Upload new packages to the main mirror
    1.70 +  -dp  dry-push [<user> [<ver>]] Show what will be uploaded to the mirror
    1.71 +       pull     [<user> [<ver>]] Download new packages from the main mirror
    1.72 +       dry-pull [<user> [<ver>]] Show what will be downloaded from the mirror
    1.73 +  -ur  up-repos                  Update all your SliTaz projects repos in one
    1.74 +                                 command
    1.75 +  -rp  relpkg <pkg> [<version>]  Archive and upload new package/project version
    1.76 +  -sc  setup-cgi                 Setup your CGI environment
    1.77  
    1.78  $(boldify "Options:")
    1.79 -  --rootfs=           Path to the chroot to generate or clean
    1.80 -  --arch=             Specify the architecture type for cross-chroot, push/pull
    1.81 -  --clean             Clean chroot before generation a new one
    1.82 +  --rootfs=            Path to the chroot to generate or clean
    1.83 +  --arch=              Specify the architecture type for cross-chroot, push/pull
    1.84 +  --clean or --forced  Clean chroot before generation a new one
    1.85  
    1.86 -$(boldify "Options:")
    1.87 +$(boldify "Examples:")
    1.88    $(basename $0) gen-chroot undigest --clean
    1.89    $(basename $0) -c --arch=arm
    1.90  
    1.91 @@ -62,46 +70,36 @@
    1.92  
    1.93  get_version() {
    1.94  	# Stable, undigest or custom.
    1.95 -	if [ "$2" ] && [ ! $(echo $2 | grep "\--*") ]; then
    1.96 -		version=$2
    1.97 -		slitaz=$SLITAZ_HOME/$2
    1.98 +	version=${2:-cooking}
    1.99 +	slitaz="$SLITAZ_HOME/$version"
   1.100 +	if [ -n "$arch" ]; then
   1.101 +		rootfs="$slitaz/$arch/chroot"
   1.102  	else
   1.103 -		version=cooking
   1.104 -		slitaz=$SLITAZ_HOME/cooking
   1.105 -	fi
   1.106 -	if [ "$arch" ]; then
   1.107 -		rootfs=$slitaz/$arch/chroot
   1.108 -	else
   1.109 -		rootfs=$slitaz/chroot
   1.110 +		rootfs="$slitaz/chroot"
   1.111  	fi
   1.112  }
   1.113  
   1.114  check_mirror() {
   1.115 -	# ping -c 1 $MIRROR
   1.116 -	if [ -n "$2" ]; then
   1.117 -		user=$2
   1.118 -	else
   1.119 -		user=$user
   1.120 -	fi
   1.121 -	if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
   1.122 -		remote=$MIRROR_PKGS/stable/
   1.123 -		local=$SLITAZ_HOME/stable/packages/
   1.124 -	elif [ "$2" = "backports" ] || [ "$3" = "backports" ]; then
   1.125 -		remote=$MIRROR_PKGS/backports/
   1.126 -		local=$SLITAZ_HOME/backports/packages/
   1.127 -	elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
   1.128 -		remote=$MIRROR_PKGS/undigest/
   1.129 -		local=$SLITAZ_HOME/undigest/packages/
   1.130 -	elif [ "$2" = "rpi" ] || [ "$3" = "rpi" ]; then
   1.131 -		remote=$MIRROR_PKGS/cross/rpi/
   1.132 -		local=$SLITAZ_HOME/cooking/arm/packages/
   1.133 -	else
   1.134 -		remote=$MIRROR_PKGS/cooking/
   1.135 -		local=$SLITAZ_HOME/cooking/packages/
   1.136 -	fi
   1.137 -	if [ "$arch" ]; then
   1.138 -		remote=${remote}$arch/
   1.139 -		local=${local}$arch/
   1.140 +	[ -n "$2" ] && user="$2"
   1.141 +	local repo="$3"
   1.142 +	case $repo in
   1.143 +		stable|backports|undigest)
   1.144 +			remote="$MIRROR_PKGS/$repo/"
   1.145 +			local="$SLITAZ_HOME/$repo/packages/"
   1.146 +			;;
   1.147 +		rpi)
   1.148 +			remote="$MIRROR_PKGS/cross/rpi/"
   1.149 +			local="$SLITAZ_HOME/cooking/arm/packages/"
   1.150 +			;;
   1.151 +		*)
   1.152 +			remote="$MIRROR_PKGS/cooking/"
   1.153 +			local="$SLITAZ_HOME/cooking/packages/"
   1.154 +			;;
   1.155 +	esac
   1.156 +
   1.157 +	if [ -n "$arch" ]; then
   1.158 +		remote="$remote$arch/"
   1.159 +		local="$local$arch/"
   1.160  	fi
   1.161  }
   1.162  
   1.163 @@ -112,40 +110,39 @@
   1.164  	mount -o bind $1 $2
   1.165  }
   1.166  
   1.167 -# Mount virtual Kernel file systems and chroot but check that nobody
   1.168 +# Mount virtual Kernel file systems and chroot, but check that nobody
   1.169  # else has done mounts
   1.170  mount_chroot()
   1.171  {
   1.172 -	if [ ! -d $rootfs/proc/1 ]; then
   1.173 -		echo -ne "\nMounting virtual filesystems..."
   1.174 -		mount -t proc proc $rootfs/proc
   1.175 -		mount -t sysfs sysfs $rootfs/sys
   1.176 +	if [ ! -d "$rootfs/proc/1" ]; then
   1.177 +		newline
   1.178 +		action 'Mounting virtual filesystems...'
   1.179 +		mount -t proc   proc   $rootfs/proc
   1.180 +		mount -t sysfs  sysfs  $rootfs/sys
   1.181  		mount -t devpts devpts $rootfs/dev/pts
   1.182 -		mount -t tmpfs shm $rootfs/dev/shm
   1.183 +		mount -t tmpfs  shm    $rootfs/dev/shm
   1.184  		status
   1.185  	fi
   1.186 -	# Mount source so they can be shared between cooking/stable/undigest.
   1.187 -	# But do it only if it's a slitaz development chroot.
   1.188 -	fs=$rootfs/home/slitaz
   1.189 +	# Mount source, so they can be shared between cooking/stable/undigest.
   1.190 +	# But do it only if it's a SliTaz development chroot.
   1.191 +	fs="$rootfs/home/slitaz"
   1.192  	if [ -d "$slitaz" ]; then
   1.193  		bind_chroot_dir $SLITAZ_HOME/src $fs/src
   1.194 -		# Now mount package dir so they are in /home/slitaz/$version
   1.195 -		# We may not mount cache wok or others it has no point and if
   1.196 -		# one wants to use a shared wok he can bind it manually.
   1.197 -		if [ "$arch" ]; then
   1.198 -			slitaz=$slitaz/$arch
   1.199 -		fi
   1.200 -		[ -d "$fs/packages" ] || mkdir -p $fs/packages
   1.201 -		[ -d "$slitaz/packages" ] || mkdir -p $fs/packages
   1.202 -		bind_chroot_dir $slitaz/packages $fs/packages
   1.203 +		# Now mount package dir, so they are in /home/slitaz/$version
   1.204 +		# We may not mount cache wok or others: it has no point and if
   1.205 +		# one wants to use a shared wok, he can bind it manually.
   1.206 +		[ -n "$arch" ] && slitaz="$slitaz/$arch"
   1.207 +		mkdir -p "$fs/packages" "$slitaz/packages"
   1.208 +		bind_chroot_dir "$slitaz/packages" "$fs/packages"
   1.209  	fi
   1.210  }
   1.211  
   1.212  # Unmount virtual Kernel file systems.
   1.213  umount_chroot() {
   1.214 -	[ "$1" ] && rootfs=$1
   1.215 -	fs=$rootfs/home/slitaz
   1.216 -	echo -ne "\nUnmounting virtual filesystems..."
   1.217 +	[ -n "$1" ] && rootfs="$1"
   1.218 +	fs="$rootfs/home/slitaz"
   1.219 +	newline
   1.220 +	action 'Unmounting virtual filesystems...'
   1.221  	umount $rootfs/dev/shm
   1.222  	umount $rootfs/dev/pts
   1.223  	umount $rootfs/sys
   1.224 @@ -154,52 +151,52 @@
   1.225  		umount $fs/src
   1.226  		umount $fs/packages
   1.227  	fi
   1.228 -	status && echo ""
   1.229 +	status
   1.230 +	newline
   1.231  }
   1.232  
   1.233  # Get the last cooking base rootfs, extract and configure.
   1.234  gen_chroot() {
   1.235 -	echo -e "\nGenerating new chroot in: $rootfs"
   1.236 -	separator
   1.237 +	title "Generating new chroot in $rootfs"
   1.238 +
   1.239  	mkdir -p $rootfs
   1.240 -	# We my gen cooking chroot from a stable version or invers
   1.241 +	# We may gen cooking chroot from a stable version or vice versa
   1.242  	case "$version" in
   1.243 -		cooking|undigest) url="http://$MIRROR/packages/cooking/" ;;
   1.244 -		stable*|4.0*|backports) url="http://$MIRROR/packages/stable/" ;;
   1.245 +		stable*|4.0*|backports)
   1.246 +			url="http://$MIRROR/packages/stable/" ;;
   1.247 +		*)
   1.248 +			url="http://$MIRROR/packages/cooking/" ;;
   1.249  	esac
   1.250 +
   1.251  	# --mirror=
   1.252 -	[ "$mirror" ] && url="$mirror"
   1.253 -	mpath=/var/lib/tazpkg/mirror
   1.254 -	cp $mpath ${mpath}.tazdev
   1.255 -	echo "$url" > $mpath
   1.256 +	[ -n "$mirror" ] && url="$mirror"
   1.257 +	mpath="/var/lib/tazpkg/mirror"
   1.258  	mkdir -p $(dirname $rootfs$mpath)
   1.259  	echo "$url" > $rootfs$mpath
   1.260 -	echo -n "Mirror URL: ${url#http://}"
   1.261 -	tazpkg recharge 2>/dev/null 1>/dev/null
   1.262 +
   1.263 +	action "Mirror URL: ${url#http://}"
   1.264 +	tazpkg recharge --root="$rootfs" --quiet >/dev/null
   1.265  	status
   1.266 -	for pkg in $CHROOT_PKGS
   1.267 -	do
   1.268 -		echo -n "Installing: $pkg $vers"
   1.269 -		tazpkg -gi $pkg --root=$rootfs 2>/dev/null 1>/dev/null
   1.270 +
   1.271 +	for pkg in $CHROOT_PKGS; do
   1.272 +		action "Installing: $pkg $vers"
   1.273 +		tazpkg -gi $pkg --root="$rootfs" --quiet
   1.274  		status
   1.275  	done
   1.276 -	echo -n "Creating resolv.conf..."
   1.277 +
   1.278 +	action "Creating resolv.conf..."
   1.279  	cat /etc/resolv.conf > $rootfs/etc/resolv.conf
   1.280  	status
   1.281 -	echo -n "Creating TZ..."
   1.282 +
   1.283 +	action "Creating TZ..."
   1.284  	cat /etc/TZ > $rootfs/etc/TZ
   1.285  	status
   1.286 -	echo -n "Restoring host packages list..."
   1.287 -	mv -f ${mpath}.tazdev $mpath
   1.288 -	tazpkg recharge 2>/dev/null 1>/dev/null >/dev/null
   1.289 -	status
   1.290 -	separator
   1.291 +
   1.292  	case "$version" in
   1.293  		cooking) version="" ;;
   1.294  	esac
   1.295  	[ "$arch" ] && version="$version --arch=$arch"
   1.296 -	echo -n "Ready to chroot with:"; colorize 34 " tazdev -c $version"
   1.297 -	newline
   1.298 +	footer "Ready to chroot with: $(colorize 34 "tazdev -c $version")"
   1.299  }
   1.300  
   1.301  #
   1.302 @@ -208,198 +205,197 @@
   1.303  
   1.304  case "$1" in
   1.305  	stats|-s)
   1.306 -		newline
   1.307 -		echo "Statistics for: $PROJECTS"
   1.308 -		newline
   1.309 -		echo "Project $(indent 24 Revision) $(indent 38 Version) $(indent 54 Files)"
   1.310 -		separator
   1.311 -		cd ${PROJECTS}
   1.312 -		for proj in *
   1.313 -		do
   1.314 +		title "Statistics for $PROJECTS"
   1.315 +		printf "%-23s %-13s %-15s %s\n" 'Project' 'Revision' 'Version' 'Files'
   1.316 +		separator '-'
   1.317 +		cd $PROJECTS
   1.318 +		for proj in *; do
   1.319  			rev=""
   1.320 -			if [ -d "${PROJECTS}/${proj}/.hg" ]; then
   1.321 -				cd ${PROJECTS}/${proj}
   1.322 -				rev=$(hg head --template '{rev}\n')
   1.323 -				vers=$(hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1)
   1.324 +			if [ -d "$PROJECTS/$proj/.hg" ]; then
   1.325 +				cd $PROJECTS/$proj
   1.326 +				rev=$(hg head --template '{rev};' | sed 's|;$||')	# we have multiple heads in some projects
   1.327 +				vers=$(hg tags | grep -v tip | head -n1 | cut -d" " -f1)	# some projects don't have any version tags
   1.328  				files=$(find . -type f | wc -l)
   1.329 -				echo "$proj $(indent 24 $rev) $(indent 38 $vers) $(indent 54 $files)"
   1.330 +				printf "%-23s %-13s %-15s %s\n" "$proj" "$rev" "${vers:--}" "$files"
   1.331  			fi
   1.332  		done
   1.333 -		separator
   1.334 -		echo "" ;;
   1.335 +		footer
   1.336 +		;;
   1.337 +
   1.338  	chroot|-c)
   1.339  		# Chroot into a build env. Default to cooking configured in tazdev.conf
   1.340 -		check_root
   1.341 +		check_root $1
   1.342  		get_version $@
   1.343 -		[ -d "$2" ] && rootfs=$2
   1.344 +		[ -d "$2" ] && rootfs="$2"
   1.345  		mount_chroot
   1.346  		echo -e "Chrooting to: $rootfs\n"
   1.347  		chroot $rootfs /bin/sh --login
   1.348 -		umount_chroot ;;
   1.349 +		umount_chroot
   1.350 +		;;
   1.351 +
   1.352  	umchroot|-uc)
   1.353 -		check_root
   1.354 +		check_root $1
   1.355  		get_version $@
   1.356 -		[ -d "$2" ] && rootfs=$2
   1.357 -		umount_chroot $rootfs ;;
   1.358 +		[ -d "$2" ] && rootfs="$2"
   1.359 +		umount_chroot $rootfs
   1.360 +		;;
   1.361 +
   1.362  	gen-chroot|-gc)
   1.363 -		check_root
   1.364 +		check_root $1
   1.365  		# We can use: --rootfs=/path/to/chroot
   1.366 -		if [ ! "$rootfs" ]; then
   1.367 -			get_version $@
   1.368 -		fi
   1.369 -		if [ "$clean" ] || [ "$forced" ]; then
   1.370 -			$0 -cc --rootfs=$rootfs --noline
   1.371 -		fi
   1.372 -		# Dont break another env.
   1.373 -		if [ -d $rootfs/bin ]; then
   1.374 -			echo -e "\nA chroot environment already exists in : $rootfs\n"
   1.375 -			exit 1
   1.376 -		fi
   1.377 -		gen_chroot ;;
   1.378 +		[ -n "$rootfs" ] || get_version $@
   1.379 +
   1.380 +		# If --clean or --forced option given
   1.381 +		[ -n "$clean$forced" ] && $0 -cc --rootfs=$rootfs
   1.382 +
   1.383 +		# Don't break another env.
   1.384 +		[ -d "$rootfs/bin" ] &&
   1.385 +			die "A chroot environment already exists in $rootfs.\nUse --clean or --forced to clean this chroot."
   1.386 +
   1.387 +		gen_chroot
   1.388 +		;;
   1.389 +
   1.390  	clean-chroot|-cc)
   1.391 -		check_root
   1.392 +		check_root $1
   1.393  		# We can use: --rootfs=/path/to/chroot
   1.394 -		if [ ! "$rootfs" ]; then
   1.395 -			get_version $@
   1.396 -		fi
   1.397 -		if [ ! -d "$rootfs" ]; then
   1.398 -			echo -e "\nChroot doesn't exist: $rootfs\n"
   1.399 -			exit 1
   1.400 -		fi
   1.401 -		if [ -d $rootfs/proc/1 ]; then
   1.402 -			echo -e "\nWARNING: $rootfs/proc mounted!\n"
   1.403 -			exit 1
   1.404 -		fi
   1.405 +		[ -n "$rootfs" ] || get_version $@
   1.406 +
   1.407 +		[ ! -d "$rootfs" ] && die "Chroot '$rootfs' doesn't exist"
   1.408 +
   1.409 +		[ -d "$rootfs/proc/1" ] && die "WARNING: $rootfs/proc mounted!"
   1.410 +
   1.411  		cd $rootfs || exit 1
   1.412 -		echo ""
   1.413 -		boldify "Cleaning chroot: $rootfs"
   1.414 -		separator
   1.415 +
   1.416 +		title "Cleaning chroot $rootfs"
   1.417  		# Keep root/ and /home they may have a build wok, custom scripts, etc.
   1.418 -		for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run
   1.419 -		do
   1.420 +		for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run; do
   1.421  			if [ -d "$i" ]; then
   1.422 -				echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
   1.423 -				rm -rf $i && status
   1.424 +				action "Removing: $i ($(du -sh $i | awk '{ print $1 }'))..."
   1.425 +				rm -rf $i
   1.426 +				status
   1.427  			fi
   1.428  		done
   1.429  		rm -f init
   1.430 -		separator
   1.431 -		[ "$noline" ] || newline ;;
   1.432 +		footer
   1.433 +		;;
   1.434 +
   1.435  	push|-p)
   1.436  		check_mirror $@
   1.437  		rsync -r -t -O -l -v -z --delete \
   1.438 -			$local -e ssh $user@$MIRROR:$remote ;;
   1.439 +			$local -e ssh $user@$MIRROR:$remote
   1.440 +		;;
   1.441 +
   1.442  	dry-push|-dp)
   1.443  		check_mirror $@
   1.444  		rsync -r -t -O -l -v -z --delete --dry-run \
   1.445 -			$local -e ssh $user@$MIRROR:$remote ;;
   1.446 +			$local -e ssh $user@$MIRROR:$remote
   1.447 +		;;
   1.448 +
   1.449  	pull)
   1.450  		check_mirror $@
   1.451  		rsync -r -t -l -v -z --delete \
   1.452 -			-e ssh $user@$MIRROR:$remote $local ;;
   1.453 +			-e ssh $user@$MIRROR:$remote $local
   1.454 +		;;
   1.455 +
   1.456  	dry-pull)
   1.457  		check_mirror $@
   1.458  		rsync -r -t -l -v -z --delete --dry-run \
   1.459 -			-e ssh $user@$MIRROR:$remote $local ;;
   1.460 +			-e ssh $user@$MIRROR:$remote $local
   1.461 +		;;
   1.462 +
   1.463  	up-repos|-ur)
   1.464  		# Update all at once.
   1.465 -		newline
   1.466 -		boldify "Update all SliTaz Hg repos"
   1.467 -		separator
   1.468 -		for p in $(ls $PROJECTS)
   1.469 -		do
   1.470 -			echo -n $(boldify Project:) && colorize 36 " $p"
   1.471 -			cd ${PROJECTS}/${p}
   1.472 +		title "Update all SliTaz Hg repos"
   1.473 +		for p in $(ls $PROJECTS); do
   1.474 +			title "Project $p"
   1.475 +			cd $PROJECTS/$p
   1.476  			hg pull -u
   1.477  		done
   1.478 -		separator
   1.479 -		newline ;;
   1.480 +		footer
   1.481 +		;;
   1.482 +
   1.483  	relpkg|-rp)
   1.484  		# Release a slitaz sub-project and upload tarball to mirror
   1.485  		[ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
   1.486 -		if [ -z $2 ]; then
   1.487 -			echo -e "\nUsage: $0 relpkg package [version]\n"
   1.488 -			exit 0
   1.489 -		fi
   1.490 +		[ -z "$2" ] && die "Usage: $0 relpkg package [version]"
   1.491 +
   1.492  		pkg=$2
   1.493 -		
   1.494 +		version="$3"
   1.495 +
   1.496  		# We can get the last found version in .hgtags
   1.497 -		if [ -z $3 ]; then
   1.498 -			version=$(tail -n 1 $PROJECTS/$pkg/.hgtags | awk '{print $2'})
   1.499 -		else
   1.500 -			version=$3
   1.501 -		fi
   1.502 +		[ -n "$version" ] ||
   1.503 +			version=$(awk 'END{print $2}' $PROJECTS/$pkg/.hgtags)
   1.504  
   1.505 -		echo "" && cd $PROJECTS/$pkg
   1.506 +		newline
   1.507 +		cd $PROJECTS/$pkg
   1.508  
   1.509  		# Sanity check
   1.510 -		if ! grep -q $version$ .hgtags; then
   1.511 -			echo "Missing Hg tag for version: $version"
   1.512 -			echo -e "You may want to: hg tag $version && hg push\n"
   1.513 -			exit 0
   1.514 -		fi
   1.515 +		grep -q $version$ .hgtags ||
   1.516 +			die "Missing Hg tag for version $version\nYou may want to: hg tag $version; hg push\n"
   1.517  
   1.518  		# Archive
   1.519 -		echo -n "Creating tarball and md5sum for: $pkg-$version... "
   1.520 +		action "Creating tarball and md5sum for $pkg-$version..."
   1.521  		hg archive -t tgz $SOURCE/$pkg-$version.tar.gz
   1.522  		( cd $SOURCE; md5sum $pkg-$version.tar.gz > $pkg-$version.md5 )
   1.523 -		echo "Done"
   1.524 +		status
   1.525  
   1.526  		# Upload
   1.527 -		echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
   1.528 -		read upload
   1.529 -		if [ "$upload" = "y" ]; then
   1.530 -			cd ${SOURCE}
   1.531 -			echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
   1.532 -			scp $pkg-$version.tar.gz $pkg-$version.md5 \
   1.533 +		confirm 'Do you wish to upload tarball to the mirror?' 'n' &&
   1.534 +		{
   1.535 +			cd $SOURCE
   1.536 +			echo "Uploading to $MIRROR/sources/${pkg#slitaz-}"
   1.537 +			scp "$pkg-$version.tar.gz" "$pkg-$version.md5" \
   1.538  				$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
   1.539 -		fi
   1.540 +		}
   1.541  
   1.542  		# Update pkg in wok
   1.543 -		echo -n "Do you wish to update $pkg in wok [N/y] ? "
   1.544 -		read update
   1.545 -		if [ "$update" = "y" ]; then
   1.546 -			echo -n "Updating $pkg: $version"
   1.547 +		confirm "Do you wish to update $pkg in wok?" 'n' &&
   1.548 +		{
   1.549 +			action "Updating $pkg: $version"
   1.550  			cd $PROJECTS/wok
   1.551  			sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
   1.552  			status
   1.553 -		fi ;;
   1.554 -	
   1.555 +		}
   1.556 +		;;
   1.557 +
   1.558  	setup-cgi|-sc)
   1.559  		. /etc/slitaz/slitaz.conf
   1.560 -		echo "$(boldify 'Public :') $PUBLIC" 
   1.561 -		mkdir -p ${PUBLIC}/cgi-bin
   1.562 -		cd ${PUBLIC}/cgi-bin
   1.563 +		echo "$(boldify 'Public:') $PUBLIC"
   1.564 +		mkdir -p $PUBLIC/cgi-bin
   1.565 +		cd $PUBLIC/cgi-bin
   1.566  		for proj in tazbug tinycm mediabox; do
   1.567 -			if [ ! -d "$proj" ]; then
   1.568 -				hg clone ttp://hg.slitaz.org/${proj}
   1.569 -			fi
   1.570 +			[ -d "$proj" ] || hg clone http://hg.slitaz.org/$proj
   1.571  		done
   1.572 -		if [ ! -d "$INSTALLED/lighttpd" ]; then
   1.573 -			sudo tazpkg -gi lighttpd
   1.574 -		fi
   1.575 +		[ -d "$INSTALLED/lighttpd" ] || sudo tazpkg -gi lighttpd
   1.576 +
   1.577  		echo
   1.578  		echo "TODO: setup SCN (tinycm install + plugins from slitaz-forge"
   1.579  		echo
   1.580 -		echo "$(boldify 'URL    :') http://localhost/~${USER}/cgi-bin/" ;;
   1.581 -	
   1.582 +		echo "$(boldify 'URL    :') http://localhost/~$USER/cgi-bin/"
   1.583 +		;;
   1.584 +
   1.585  	help)
   1.586 -		if [ ! "$2" ]; then
   1.587 -			echo "Missing tool/library name"
   1.588 -			echo "Example: tazdev help httphelper"; exit 0
   1.589 +		doc='/usr/share/doc/slitaz/'
   1.590 +		topics="Available help topics: $(cd $doc; ls *.txt | sed 's|.txt$||' | tr '\n' ' ')"
   1.591 +		[ -n "$2" ] ||
   1.592 +		die "Missing tool/library name\nExample: tazdev help httphelper\n\n$topics"
   1.593 +
   1.594 +		if [ -f "$doc$2.txt" ]; then
   1.595 +			{
   1.596 +				output='raw' title "Help for $2"
   1.597 +				cat $doc$2.txt
   1.598 +				footer
   1.599 +			} | less -M
   1.600 +		else
   1.601 +			echo "No help found for '$2'"
   1.602 +			longline "$topics"
   1.603  		fi
   1.604 -		newline
   1.605 -		boldify "Help for: $2"
   1.606 -		separator
   1.607 -		if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
   1.608 -			less -M /usr/share/doc/slitaz/$2.txt
   1.609 -		else
   1.610 -			echo "No help found"
   1.611 -		fi
   1.612 -		separator && newline ;;
   1.613 -	
   1.614 -	usage|*) usage ;;
   1.615 -	
   1.616 +		;;
   1.617 +
   1.618 +	usage|*)
   1.619 +		usage
   1.620 +		;;
   1.621 +
   1.622  esac
   1.623  
   1.624  exit 0
     2.1 --- a/tazdev/tazdev.conf	Mon Feb 27 22:08:17 2017 +0100
     2.2 +++ b/tazdev/tazdev.conf	Tue Feb 28 17:16:47 2017 +0200
     2.3 @@ -7,12 +7,12 @@
     2.4  # Path to all own and copy projects.
     2.5  PROJECTS="$HOME/Projects"
     2.6  
     2.7 -# Path to all web and CGI/SHell projects developped localy.
     2.8 +# Path to all web and CGI/Shell projects developed localy.
     2.9  # URL: http://localhost/~$USER/
    2.10  PUBLIC="$HOME/Public"
    2.11  
    2.12  # Path to archive
    2.13 -SOURCE=$SLITAZ_HOME/src
    2.14 +SOURCE="$SLITAZ_HOME/src"
    2.15  
    2.16  # Packages to generate a minimal chroot.
    2.17  CHROOT_PKGS="slitaz-base-files busybox cookutils tazpkg lzma"