slitaz-arm rev 27

Handle flavor.conf and rm old libtaz.sh from ARM rootfs
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 03 14:39:11 2014 +0100 (2014-03-03)
parents 490947b1da1a
children 15f4a6497b20
files flavors/base/flavor.conf rootfs/lib/libtaz.sh sat
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/flavors/base/flavor.conf	Mon Mar 03 14:39:11 2014 +0100
     1.3 @@ -0,0 +1,8 @@
     1.4 +# SliTaz ARM Flavor configuration file.
     1.5 +#
     1.6 +
     1.7 +FLAVOR="base"
     1.8 +VERSION="20140303"
     1.9 +MAINTAINER="pankso@slitaz.org"
    1.10 +SHORT_DESC="SliTaz ARM text mode base system"
    1.11 +WEB_SITE="http://arm.slitaz.org"
     2.1 --- a/rootfs/lib/libtaz.sh	Mon Mar 03 13:44:20 2014 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,172 +0,0 @@
     2.4 -#!/bin/sh
     2.5 -#
     2.6 -# SliTaz Base functions used from boot scripts to end user tools. Use
     2.7 -# gettext and not echo for messages. Keep output suitable for GTK boxes
     2.8 -# and Ncurses dialog. LibTaz should not depend on any configuration file.
     2.9 -# No bloated code here, functions must be used by at least 3-4 tools.
    2.10 -#
    2.11 -# Documentation: man libtaz or /usr/share/doc/slitaz/libtaz.txt
    2.12 -#
    2.13 -# Copyright (C) 2012 SliTaz GNU/Linux - BSD License
    2.14 -#
    2.15 -
    2.16 -# Internationalization. We can't export TEXTDOMAIN because this script
    2.17 -# includes to other scripts with other TEXTDOMAIN exported
    2.18 -. /usr/bin/gettext.sh
    2.19 -
    2.20 -# xgettext (from Makefile) can't extract strings from above example:
    2.21 -# gettext -d 'slitaz-base' 'Done'
    2.22 -# so, I defined own function (and added it as option to xgettext in Makefile)
    2.23 -lgettext() {
    2.24 -	gettext -d 'slitaz-base' $1
    2.25 -}
    2.26 -
    2.27 -# Internal variables.
    2.28 -okmsg="$(lgettext 'Done')"
    2.29 -ermsg="$(lgettext 'Failed')"
    2.30 -: ${okcolor=32}
    2.31 -: ${ercolor=31}
    2.32 -: ${decolor=36}
    2.33 -
    2.34 -# Parse cmdline options and store values in a variable.
    2.35 -for opt in "$@"
    2.36 -do
    2.37 -	case "$opt" in
    2.38 -		--*=*) export ${opt#--} ;;
    2.39 -		--*) export ${opt#--}="yes" ;;
    2.40 -	esac
    2.41 -done
    2.42 -[ "$HTTP_REFERER" ] && output="html"
    2.43 -
    2.44 -# Get terminal columns
    2.45 -get_cols() {
    2.46 -	stty -a 2>/dev/null | head -n 1 | cut -d ";" -f 3 | awk '{print $2}'
    2.47 -}
    2.48 -
    2.49 -# Return command status. Default to colored console output.
    2.50 -status() {
    2.51 -	local check=$?
    2.52 -	case $output in
    2.53 -		raw|gtk)
    2.54 -			done=" $okmsg"
    2.55 -			error=" $ermsg" ;;
    2.56 -		html)
    2.57 -			done=" <span style='color: $okcolor;'>$okmsg</span>"
    2.58 -			error=" <span style='color: $ercolor;'>$ermsg</span>" ;;
    2.59 -		*)
    2.60 -			local cols=$(get_cols)
    2.61 -			[ "$cols" ] || cols=80
    2.62 -			local scol=$(($cols - 10))
    2.63 -			done="\\033[${scol}G[ \\033[1;${okcolor}m${okmsg}\\033[0;39m ]"
    2.64 -			error="\\033[${scol}G[ \\033[1;${ercolor}m${ermsg}\\033[0;39m ]" ;;
    2.65 -	esac
    2.66 -	if [ $check = 0 ]; then
    2.67 -		echo -e "$done"
    2.68 -	else
    2.69 -		echo -e "$error"
    2.70 -	fi
    2.71 -}
    2.72 -
    2.73 -# Line separator.
    2.74 -separator() {
    2.75 -	local sepchar="="
    2.76 -	[ "$HTTP_REFERER" ] && local sepchar="<hr />"
    2.77 -	case $output in
    2.78 -		raw|gtk) local sepchar="-" && local cols="8" ;;
    2.79 -		html) local sepchar="<hr />" ;;
    2.80 -		*)
    2.81 -			local cols=$(get_cols)
    2.82 -			[ "$cols" ] || cols=80 ;;
    2.83 -	esac
    2.84 -	for c in $(seq 1 $cols); do
    2.85 -		echo -n "$sepchar"
    2.86 -	done && echo ""
    2.87 -}
    2.88 -
    2.89 -# New line for echo -n or gettext.
    2.90 -newline() {
    2.91 -	echo ""
    2.92 -}
    2.93 -
    2.94 -# Display a bold message. GTK Yad: Works only in --text=""
    2.95 -boldify() {
    2.96 -	case $output in
    2.97 -		raw) echo "$@" ;;
    2.98 -		gtk) echo "<b>$@</b>" ;;
    2.99 -		html) echo "<strong>$@</strong>" ;;
   2.100 -		*) echo -e "\\033[1m$@\\033[0m" ;;
   2.101 -	esac
   2.102 -}
   2.103 -
   2.104 -# Better to keep messages unsplitted
   2.105 -# Example: unboldify "My <b>pretty</b> function ;)"
   2.106 -unboldify() {
   2.107 -	case $output in
   2.108 -		raw)	echo "$@" | sed -e 's|<b>||g;s|</b>||g' ;;
   2.109 -		gtk)	echo "$@" ;;
   2.110 -		html)	echo "$@" | sed -e 's|<b>|<strong>|g;s|</b>|</strong>|g' ;;
   2.111 -		*)		echo -e "$(echo "$@" | sed -e 's|<b>|\\033[1m|g;s|</b>|\\033[0m|g')" ;;
   2.112 -	esac
   2.113 -}
   2.114 -
   2.115 -# Usage: colorize "Message" colorNB or use --color=NB option
   2.116 -# when running a tool. Default to white/38 and no html or gtk.
   2.117 -colorize() {
   2.118 -	: ${color=$1}
   2.119 -	shift
   2.120 -	local content="$@"
   2.121 -	case $output in
   2.122 -		raw|gtk|html) echo "$content" ;;
   2.123 -		*)
   2.124 -			[ "$color" ] || color=38
   2.125 -			echo -e "\\033[1;${color}m${content}\\033[0;39m" ;;
   2.126 -	esac
   2.127 -	unset color
   2.128 -}
   2.129 -
   2.130 -# Indent text $1 spaces.
   2.131 -indent() {
   2.132 -	local in="$1"
   2.133 -	shift
   2.134 -	echo -e "\033["$in"G $@";
   2.135 -}
   2.136 -
   2.137 -# Check if user is logged as root.
   2.138 -check_root() {
   2.139 -	if [ $(id -u) != 0 ]; then
   2.140 -		lgettext "You must be root to execute:" && echo " $(basename $0) $@"
   2.141 -		exit 1
   2.142 -	fi
   2.143 -}
   2.144 -
   2.145 -# Display debug info when --debug is used.
   2.146 -debug() {
   2.147 -	[ "$debug" ] && echo "$(colorize $decolor "DEBUG:") $1"
   2.148 -}
   2.149 -
   2.150 -# Gettextize yes/no.
   2.151 -translate_query() {
   2.152 -	case $1 in
   2.153 -		y) lgettext "y" ;;
   2.154 -		Y) lgettext "Y" ;;
   2.155 -		n) lgettext "n" ;;
   2.156 -		N) lgettext "N" ;;
   2.157 -		# Support other cases but keep them untranslated.
   2.158 -		*) echo "$1" ;;
   2.159 -	esac
   2.160 -}
   2.161 -
   2.162 -# Usage: echo -n "The question" && confirm
   2.163 -confirm() {
   2.164 -	[ "$yes" ] && true
   2.165 -	echo -n " ($(translate_query y)/$(translate_query N)) ? "
   2.166 -	read answer
   2.167 -	[ "$answer" == "$(translate_query y)" ]
   2.168 -}
   2.169 -
   2.170 -# Log activities. $activity should be set by the script. The log format
   2.171 -# is suitable for web interfaces like cook. Usage: log "String"
   2.172 -log() {
   2.173 -	[ "$activity" ] || activity=/var/log/slitaz/libtaz.log
   2.174 -	echo "$(date '+%Y-%m-%d %H:%M') : $@" >> $activity
   2.175 -}
     3.1 --- a/sat	Mon Mar 03 13:44:20 2014 +0100
     3.2 +++ b/sat	Mon Mar 03 14:39:11 2014 +0100
     3.3 @@ -17,6 +17,7 @@
     3.4  distro="$work/distro"
     3.5  flavors="$work/flavors"
     3.6  rootfs="$distro/rootfs"
     3.7 +data="$distro/data"
     3.8  
     3.9  # http://mirror.slitaz.org/packages/cooking/arm/
    3.10  mirror="http://cook.slitaz.org/cross/arm/packages/"
    3.11 @@ -37,7 +38,7 @@
    3.12    mirror     Download or sync the SliTaz ARM mirror
    3.13  
    3.14  $(boldify "Options:")
    3.15 -  --spk      Include Spk package manager in the distro
    3.16 +  --spk      Clean or include Spk package manager in the distro
    3.17    --kmap     Include the system keymap config in the distro
    3.18    --work=    Path to work dir with packages and rootfs
    3.19    --size=    Specify optional vdisk size (default 20Mb)
    3.20 @@ -75,25 +76,26 @@
    3.21  		check_root
    3.22  		newline && boldify "Generating SliTaz ARM distro"
    3.23  		separator
    3.24 -		rm -rf $distro && mkdir -p ${rootfs}
    3.25 +		rm -rf $distro && mkdir -p ${rootfs} ${data}
    3.26  		
    3.27  		# Get --flavor= packages lists
    3.28  		if [ "$flavor" ]; then
    3.29  			echo -n "Getting $flavor packages.list..."
    3.30 -			cp -f $flavors/$flavor/packages.list $distro 2>/dev/null
    3.31 +			cp $flavors/$flavor/packages.list ${data} 2>/dev/null &&
    3.32 +			cp $flavors/$flavor/flavor.conf ${data} 2>/dev/null
    3.33  			status
    3.34  		fi
    3.35  
    3.36  		# Packages
    3.37 -		rm -f $distro/packages.full
    3.38 -		if [ -f "$distro/packages.list" ]; then
    3.39 -			for pkg in $(cat $distro/packages.list)
    3.40 +		rm -f ${data}/packages.full
    3.41 +		if [ -f "${data}/packages.list" ]; then
    3.42 +			for pkg in $(cat ${data}/packages.list)
    3.43  			do
    3.44  				IFS="|"
    3.45  				grep "^$pkg |" $work/mirror/packages.desc | while read pkg version desc
    3.46  				do
    3.47  					echo ${pkg}-${version}-arm.tazpkg | sed s'/ //'g \
    3.48 -						>> $distro/packages.full
    3.49 +						>> ${data}/packages.full
    3.50  				done
    3.51  				unset IFS
    3.52  			done
    3.53 @@ -104,13 +106,13 @@
    3.54  				echo "" && exit 1
    3.55  			fi
    3.56  			echo -n "Using packages directory..."
    3.57 -			cd $packages && ls -1 > $distro/packages.full
    3.58 +			cd $packages && ls -1 >${data}/packages.full
    3.59  			status
    3.60  		fi
    3.61  		
    3.62  		# Deps install is not well handled by tazpkg/spk actually.
    3.63  		# So simply install all packages and don't resolve deps.
    3.64 -		for pkg in $(cat $distro/packages.full)
    3.65 +		for pkg in $(cat ${data}/packages.full)
    3.66  		do
    3.67  			pkgdir=$(basename $pkg .tazpkg)
    3.68  			db=${rootfs}/var/lib/tazpkg
    3.69 @@ -138,19 +140,24 @@
    3.70  		fi
    3.71  
    3.72  		# Move kernel outside the distro
    3.73 -		if [ -d "$distro/rootfs/boot" ]; then
    3.74 +		if [ -d "$rootfs/boot" ]; then
    3.75  			mv -f ${rootfs}/boot/linux-* ${distro}/linux-arm
    3.76  			chmod -x ${distro}/linux-arm
    3.77  		else
    3.78 -			echo -n "Missing: ${rootfs}/boot"; false
    3.79 -			status && exit 1
    3.80 +			echo -n "Missing Kernel directory: rootfs/boot/"; false
    3.81 +			status
    3.82  		fi
    3.83  
    3.84  		# SLITAZ_ARCH
    3.85 -		echo -n "Setting SliTaz arch to: arm"
    3.86 -		sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \
    3.87 -			${rootfs}/etc/slitaz/slitaz.conf
    3.88 -		status
    3.89 +		if [ -f "${rootfs}/etc/slitaz/slitaz.conf" ]; then
    3.90 +			echo -n "Setting SliTaz arch to: arm"
    3.91 +			sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \
    3.92 +				${rootfs}/etc/slitaz/slitaz.conf
    3.93 +			status
    3.94 +		else
    3.95 +			echo -n "Missing distro: /etc/slitaz/slitaz.conf"; false
    3.96 +			status && exit 1
    3.97 +		fi
    3.98  
    3.99  		# Mirror
   3.100  		echo "$mirror" > ${rootfs}/var/lib/tazpkg/mirror
   3.101 @@ -161,12 +168,15 @@
   3.102  		mkdir -p run
   3.103  
   3.104  		# Update modules.dep
   3.105 -		. var/lib/tazpkg/installed/linux/receipt
   3.106 -		depmod -b . ${VERSION}-slitaz
   3.107 +		if [ -f "var/lib/tazpkg/installed/linux/receipt" ]; then
   3.108 +			. var/lib/tazpkg/installed/linux/receipt
   3.109 +			depmod -b . ${VERSION}-slitaz
   3.110 +		fi
   3.111  
   3.112  		# Custom rootfs: make sure all files belong to root
   3.113  		if [ -d "$work/rootfs" ]; then
   3.114 -			echo -n "Copying custom ARM: rootfs"
   3.115 +			size=$(du -sh $work/rootfs | awk '{print $1}')
   3.116 +			echo -n "Copying custom ARM rootfs: $size"
   3.117  			tmp=$distro/tmp-$$
   3.118  			mkdir -p $tmp
   3.119  			cp -r $work/rootfs/* $tmp
   3.120 @@ -176,11 +186,15 @@
   3.121  		fi
   3.122  		
   3.123  		# Custom flavor rootfs
   3.124 -		if [ -d "$flavors/$flavor/rootfs" ]; then
   3.125 -			echo -n "Copying $flavor ARM: rootfs"
   3.126 +		if [ -f "${data}/flavor.conf" ]; then
   3.127 +			. ${data}/flavor.conf
   3.128 +		fi
   3.129 +		if [ -d "$flavors/${FLAVOR}/rootfs" ]; then
   3.130 +			size=$(du -sh $flavors/${FLAVOR}/rootfs | awk '{print $1}')
   3.131 +			echo -n "Copying ${FLAVOR} ARM rootfs: $size"
   3.132  			tmp=$distro/tmp-$$
   3.133  			mkdir -p $tmp
   3.134 -			cp -r $flavors/$flavor/rootfs/* $tmp
   3.135 +			cp -r $flavors/${FLAVOR}/rootfs/* $tmp
   3.136  			chown -R root.root $tmp
   3.137  			cp -a $tmp/* ${rootfs} && rm -rf $tmp
   3.138  			status
   3.139 @@ -207,20 +221,30 @@
   3.140  		boldify "SliTaz ARM distro summary"
   3.141  		separator
   3.142  		time=$(($(date +%s) - $time))
   3.143 -		echo -n "Build time     : " && echo "${time}s"
   3.144 -		echo -n "Initramfs size : " && du -sh $distro/$initramfs | awk '{print $1}'
   3.145 -		echo -n "Rootfs size    : " && du -sh ${rootfs} | awk '{print $1}'
   3.146 -		echo -n "Packages       : " && ls $db/installed | wc -l
   3.147 +		initramfs_size="$(du -sh $distro/$initramfs | awk '{print $1}')"
   3.148 +		rootfs_size="$(du -sh ${rootfs} | awk '{print $1}')"
   3.149 +		pkgs_count="$(ls $db/installed | wc -l)"
   3.150 +		[ "$FLAVOR" ] && echo "Flavor name    : $FLAVOR"
   3.151 +		echo "Build time     : ${time}s"
   3.152 +		echo "Initramfs      : $initramfs"
   3.153 +		echo "Initramfs size : $initramfs_size"
   3.154 +		echo "Rootfs size    : $rootfs_size" 
   3.155 +		echo "Packages       : $pkgs_count"
   3.156  		separator && newline ;;
   3.157  		
   3.158  	flavors)
   3.159  		newline
   3.160 -		echo -n "$(boldify 'Flavor')" && indent 14 "$(boldify 'Packages')"
   3.161 +		echo -n "$(boldify 'Flavor')" && 
   3.162 +		echo -n "$(indent 12 $(boldify 'Packages'))"
   3.163 +		indent 24 $(boldify 'Description')
   3.164  		separator
   3.165  		for flavor in $(ls $flavors)
   3.166  		do
   3.167 +			. $flavors/$flavor/flavor.conf
   3.168  			pkgs=$(cat $flavors/$flavor/packages.list | wc -l)
   3.169 -			echo -n "$flavor" && indent 14 "$pkgs"
   3.170 +			echo -n "$flavor" && 
   3.171 +			echo -n "$(indent 12 $pkgs)" && indent 24 "$SHORT_DESC"
   3.172 +			unset SHORT_DESC
   3.173  		done
   3.174  		newline ;;
   3.175