#!/bin/sh
#
# slitaz-arm - The complemented ARM version of /usr/bin/slitaz
#
. /lib/libtaz.sh

# Handle commands
case "$1" in

	info)
		/usr/bin/slitaz
		# To remove on next slitaz-base-file release
		echo -n "Machine type : " && uname -m
		echo -n "System date  : " && date
		newline ;;
	
	flavor)
		newline
		boldify "SliTaz ARM flavor"
		separator
		if [ -f "/etc/slitaz/flavor.conf" ]; then
			. /etc/slitaz/flavor.conf
			echo "Flavor     : $FLAVOR"
			echo "Build date : $BUILD_DATE"
			echo "Maintainer : $MAINTAINER"
			echo "Short desc : $SHORT_DESC"
			echo "Web site   : $WEB_SITE"
		else
			echo "Missing: /etc/slitaz/flavor.conf"
		fi 
		separator && newline ;;
	
	up-flavor)
		hgurl="http://hg.slitaz.org/slitaz-arm"
		cache="/var/cache/$1"
		if [ ! -f "/etc/slitaz/flavor.conf" ]; then
			echo "Missing: /etc/slitaz/flavor.conf" && exit 1
		fi
		if ! busybox wget -q -s ${hgurl}; then
			echo "Hg repo is unreachable..." && exit 1
		fi
		. /etc/slitaz/flavor.conf
		newline
		colorize 35 "Updating SliTaz ARM"
		separator
		echo "Flavor template: $FLAVOR"
		mkdir -p ${cache} && cd ${cache}
		wget ${hgurl}/archive/tip.tar.bz2
		tar xjf tip.tar.bz2
		cd slitaz-arm-*
		if [ -d "flavors/$FLAVOR/rootfs" ]; then
			echo "Installing custom flavor files..."
			cp -rf flavors/$FLAVOR/rootfs/* /
		else
			echo "No custom flavor files to install..."
		fi
		rm -rf ${cache}
		separator
		newline ;;
	
	*) echo "Usage: $(basename $0) [info|flavor|up-flavor]" ;;
	
esac && exit 0
