tazpkg rev 805

tazpkg: tiny improvements (-l, -lm, -lf, -a, -sf).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat May 16 17:37:27 2015 +0300 (2015-05-16)
parents e5c261e450c7
children 6ac7d1bf450b
files tazpkg
line diff
     1.1 --- a/tazpkg	Fri May 15 04:33:46 2015 +0300
     1.2 +++ b/tazpkg	Sat May 16 17:37:27 2015 +0300
     1.3 @@ -261,7 +261,7 @@
     1.4  # If not and user is root we create them.
     1.5  
     1.6  check_base_dir() {
     1.7 -	if [ "$(id -u)" == "0" ]; then
     1.8 +	if [ "$(id -u)" == '0' ]; then
     1.9  		check_dir $1$CACHE_DIR
    1.10  		check_dir $1$INSTALLED
    1.11  		check_dir $1$SLITAZ_LOGS
    1.12 @@ -394,15 +394,17 @@
    1.13  check_for_installed_info() {
    1.14  	info_path="$ROOT$PKGS_DB/installed.info"
    1.15  	if [ ! -f "$info_path" ]; then
    1.16 -		if [ "$(id -u)" == "0" ]; then
    1.17 +		if [ "$(id -u)" == '0' ]; then
    1.18  			_ 'File "%s" generated. Please wait...' installed.info
    1.19  			for pkg in $ROOT$PKGS_DB/installed/*/receipt; do
    1.20  				unset_receipt
    1.21  				. $pkg
    1.22  				SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
    1.23  				DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
    1.24 +				MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" \
    1.25 +					$ROOT$PKGS_DB/installed.md5 | awk '{print $1}')"
    1.26  				cat >> $info_path << EOT
    1.27 -$PACKAGE	$VERSION$EXTRAVERSION	$CATEGORY	$SHORT_DESC	$WEB_SITE	$TAGS	$SIZES	$DEPENDS
    1.28 +$PACKAGE	$VERSION$EXTRAVERSION	$CATEGORY	$SHORT_DESC	$WEB_SITE	$TAGS	$SIZES	$DEPENDS	$MD5
    1.29  EOT
    1.30  			done
    1.31  		else
    1.32 @@ -411,6 +413,9 @@
    1.33  			exit 1
    1.34  		fi
    1.35  	fi
    1.36 +
    1.37 +	# Check for md5 field in the installed.info
    1.38 +
    1.39  }
    1.40  
    1.41  
    1.42 @@ -1064,7 +1069,7 @@
    1.43  					for i in $pkg-*.tazpkg; do
    1.44  						[ -f $i ] || continue
    1.45  						{ cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
    1.46 -						[ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
    1.47 +						[ "$(. $TMP_DIR/receipt; echo $PACKAGE)" == "$pkg" ] || continue
    1.48  						if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
    1.49  						then
    1.50  							found=1
    1.51 @@ -1185,9 +1190,9 @@
    1.52  				[ -f $pkg/receipt ] || continue
    1.53  				EXTRAVERSION=""
    1.54  				. $pkg/receipt
    1.55 -				[ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
    1.56 +				[ "$PACKAGE-$VERSION$EXTRAVERSION" == "$file" ] && break
    1.57  			done
    1.58 -			[ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
    1.59 +			[ "$PACKAGE-$VERSION$EXTRAVERSION" == "$file" ] && continue
    1.60  			cd $CACHE_DIR
    1.61  			download $file.tazpkg
    1.62  			cd $TMP_DIR
    1.63 @@ -1236,7 +1241,7 @@
    1.64  	else
    1.65  		read NEW_MIRROR_URL
    1.66  	fi
    1.67 -	if [ "$NEW_MIRROR_URL" = "" ]; then
    1.68 +	if [ -z "$NEW_MIRROR_URL" ]; then
    1.69  		_ 'Nothing has been changed.'
    1.70  	else
    1.71  		_ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
    1.72 @@ -1375,10 +1380,13 @@
    1.73  				title 'Blocked packages'
    1.74  				if [ -s "$BLOCKED" ];then
    1.75  					cat $BLOCKED
    1.76 +					num=$(wc -l < $BLOCKED)
    1.77 +					footer "$(_p '%s package' '%s packages' "$num" \
    1.78 +						"$(colorize 31 $num)")"
    1.79  				else
    1.80  					_ 'No blocked packages found.'
    1.81  				fi
    1.82 -				newline; exit 0
    1.83 +				newline
    1.84  				;;
    1.85  
    1.86  			c|cat|categories)
    1.87 @@ -1387,28 +1395,22 @@
    1.88  
    1.89  				echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
    1.90  				sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
    1.91 -				if ($1==$2) print $1; else print $1"\033[15G "$2}'
    1.92 +				if ($1==$2) print $1; else printf "%-14s %s\n", $1, $2}'
    1.93  
    1.94  				num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
    1.95 -				footer "$(_p \
    1.96 -					'%s category' \
    1.97 -					'%s categories' $num \
    1.98 -					$num)"
    1.99 -				exit 0
   1.100 +				footer "$(_p '%s category' '%s categories' "$num" \
   1.101 +					"$(colorize 33 $num)")"
   1.102  				;;
   1.103  
   1.104  			'')
   1.105  				# By default list all packages and versions.
   1.106  				title 'List of all installed packages'
   1.107 -				TMPLIST=$(mktemp)
   1.108 -				awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
   1.109 -					$PKGS_DB/installed.info | tee $TMPLIST | translate_category
   1.110 -
   1.111 -				packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
   1.112 -				footer "$(emsg $(_p \
   1.113 -					'%s package installed.' \
   1.114 -					'%s packages installed.' $packages \
   1.115 -					"<c 32>$packages</c>"))"
   1.116 +				awk -F$'\t' '{printf "%-34s %-17s %s\n", $1, $2, $3}' \
   1.117 +					$PKGS_DB/installed.info | translate_category
   1.118 +
   1.119 +				num=$(wc -l < $PKGS_DB/installed.info)
   1.120 +				footer "$(_p '%s package installed.' '%s packages installed.' "$num" \
   1.121 +					"$(colorize 32 $num)")"
   1.122  				;;
   1.123  
   1.124  			*)
   1.125 @@ -1417,18 +1419,15 @@
   1.126  				ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
   1.127  				title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
   1.128  				TMPLIST=$(mktemp)
   1.129 -				awk -F$'\t' '
   1.130 -				{
   1.131 -					if ($3 == "'$ASKED_CATEGORY'")
   1.132 -						print $1"\033[35G "$2
   1.133 -				}' \
   1.134 +				awk -F$'\t' -vcat="$ASKED_CATEGORY" \
   1.135 +					'{ if ($3 == cat) printf "%-34s %s\n", $1, $2; }' \
   1.136  					$PKGS_DB/installed.info | tee $TMPLIST | translate_category
   1.137  
   1.138 -				packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
   1.139 +				num=$(wc -l < $TMPLIST); rm $TMPLIST
   1.140  				footer "$(emsg $(_p \
   1.141  					'%s package installed of category "%s".' \
   1.142 -					'%s packages installed of category "%s".' $packages \
   1.143 -					"<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
   1.144 +					'%s packages installed of category "%s".' $num \
   1.145 +					"<c 32>$num</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
   1.146  				;;
   1.147  		esac ;;
   1.148  
   1.149 @@ -1445,36 +1444,54 @@
   1.150  					num=$(wc -l < $PKGS_DB/packages.diff)
   1.151  					footer "$(_p \
   1.152  						'%s new package listed on the mirror.' \
   1.153 -						'%s new packages listed on the mirror.' $num \
   1.154 -						$num)"
   1.155 +						'%s new packages listed on the mirror.' "$num" \
   1.156 +						"$(colorize 32 $num)")"
   1.157  				else
   1.158  					newline
   1.159  					_ 'Unable to list anything, no packages.diff found.'
   1.160  					_ 'Recharge your current list to create a first diff.'
   1.161  					newline
   1.162 -				fi; exit 0 ;;
   1.163 -			--text|--txt|--raw|*)
   1.164 +				fi
   1.165 +				;;
   1.166 +			*)
   1.167  				title 'List of available packages on the mirror'
   1.168 -				cat $PKGS_DB/packages.txt ;;
   1.169 +				awk -F$'\t' '{
   1.170 +					split($7, s, " ");
   1.171 +					printf "%s\n%s\n%s\n%s (%s installed)\n\n", $1, $2, $4, s[1], s[2];
   1.172 +					}' $PKGS_DB/packages.info
   1.173 +				num=$(wc -l < $PKGS_DB/packages.info)
   1.174 +				footer "$(_p \
   1.175 +					'%s package in the last recharged list.' \
   1.176 +					'%s packages in the last recharged list.' "$num" \
   1.177 +					"$(colorize 32 $num)")"
   1.178 +				;;
   1.179  		esac
   1.180 -		pkgs=$(wc -l < $PKGS_DB/packages.list)
   1.181 -		footer "$(emsg "$(_p \
   1.182 -			'%s package in the last recharged list.' \
   1.183 -			'%s packages in the last recharged list.' $pkgs \
   1.184 -			"<c 32>$pkgs</c>")")"
   1.185  		;;
   1.186  
   1.187  
   1.188  	list-files|-lf)
   1.189  		# List files installed with the package.
   1.190  		check_for_package_on_cmdline
   1.191 -		check_for_receipt
   1.192 -		title 'Installed files by "%s"' $PACKAGE
   1.193 -		sort < $INSTALLED/$PACKAGE/files.list
   1.194 -		files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
   1.195 -		footer "$(emsg "$(_p \
   1.196 -			'%s file' '%s files' $files \
   1.197 -			"<c 32>$files</c>")")"
   1.198 +		if [ -d "$INSTALLED/$PACKAGE" ]; then
   1.199 +			# installed package
   1.200 +			title 'Installed files by "%s"' $PACKAGE
   1.201 +			sort < $INSTALLED/$PACKAGE/files.list
   1.202 +			num=$(wc -l < $INSTALLED/$PACKAGE/files.list)
   1.203 +			footer "$(_p '%s file' '%s files' $num \
   1.204 +				"$(colorize 32 $num)")"
   1.205 +		elif [ -n "$(grep "^$PACKAGE"$'\t' $PKGS_DB/packages.info)" ]; then
   1.206 +			# available package
   1.207 +			title 'Installed files by "%s"' $PACKAGE
   1.208 +			TMPLIST=$(mktemp)
   1.209 +			lzcat $PKGS_DB/files.list.lzma | sed -n "/^$PACKAGE: / s|^[^:]*: ||p" | tee $TMPLIST
   1.210 +			num=$(wc -l < $TMPLIST); rm $TMPLIST
   1.211 +			footer "$(_p '%s file' '%s files' $num \
   1.212 +				"$(colorize 32 $num)")"
   1.213 +		else
   1.214 +			newline
   1.215 +			_ 'Package "%s" not available.' "$PACKAGE"
   1.216 +			newline
   1.217 +		fi
   1.218  		;;
   1.219  
   1.220  
   1.221 @@ -1482,13 +1499,13 @@
   1.222  		# Information about package.
   1.223  		check_for_package_on_cmdline
   1.224  		check_for_receipt
   1.225 -		EXTRAVERSION=""
   1.226 +		EXTRAVERSION=''
   1.227  		. $INSTALLED/$PACKAGE/receipt
   1.228  		im && title 'TazPKG information'
   1.229  		# Display localized short description
   1.230  		for LC in $LANG ${LANG%_*}; do
   1.231  			if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
   1.232 -				LOCDESC=$(grep -e "^$PACKAGE	" $PKGS_DB/packages-desc.$LC | cut -d'	' -f2)
   1.233 +				LOCDESC=$(grep -e "^$PACKAGE"$'\t' $PKGS_DB/packages-desc.$LC | cut -d$'\t' -f2)
   1.234  				[ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
   1.235  			fi
   1.236  		done
   1.237 @@ -1516,12 +1533,13 @@
   1.238  
   1.239  	desc)
   1.240  		# Display package description
   1.241 -		if [ -n "$(grep -e "^$PACKAGE	" $PKGS_DB/installed.info)" ]; then
   1.242 +		if [ -n "$(grep -e "^$PACKAGE"$'\t' $PKGS_DB/installed.info)" ]; then
   1.243  			im && title 'Description of package "%s"' $PACKAGE
   1.244 -			if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
   1.245 +			if [ -s "$INSTALLED/$PACKAGE/description.txt" ]; then
   1.246  				cat $INSTALLED/$PACKAGE/description.txt
   1.247  			else
   1.248 -				im && awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
   1.249 +				im && awk -F$'\t' -vp="$PACKAGE" '{
   1.250 +					if ($1 == p) print $4 }' $PKGS_DB/installed.info
   1.251  			fi
   1.252  			im && footer
   1.253  		else
   1.254 @@ -1532,10 +1550,10 @@
   1.255  
   1.256  	activity|log|-a)
   1.257  		# Show activity log
   1.258 -		[ "$nb" ] || nb=18
   1.259 +		[ -n "$nb" ] || nb='18'
   1.260  		title 'TazPKG Activity'
   1.261 -		IFS=" "
   1.262 -		tail -n ${nb} ${LOG} | \
   1.263 +		IFS=' '
   1.264 +		tail -n $nb $LOG | tac | \
   1.265  		while read date hour none action none pkg vers none; do
   1.266  			case $action in
   1.267  				Installed)
   1.268 @@ -1545,7 +1563,8 @@
   1.269  				*)
   1.270  					action=$(boldify $action) ;;
   1.271  			esac
   1.272 -			echo "$date $hour : $action $pkg $vers"
   1.273 +			date_locale="$(date -d "$date $hour" '+%x %X')"
   1.274 +			echo "$date_locale : $action $pkg $vers"
   1.275  		done
   1.276  		unset IFS
   1.277  		footer ;;
   1.278 @@ -1583,27 +1602,30 @@
   1.279  			exit 0
   1.280  		fi
   1.281  		title 'Search result for file "%s"' $2
   1.282 -
   1.283  		TMPLIST=$(mktemp)
   1.284 -		if [ "$3" == "--mirror" ]; then
   1.285 -
   1.286 +
   1.287 +		if [ -n "$mirror" ]; then
   1.288 +			TMPDIR=$(mktemp -d)
   1.289  			for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
   1.290  				[ -f $i ] || continue
   1.291 -				lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
   1.292 -					BEGIN { last = "" }
   1.293 -					$2 ~ /'$2'/ {
   1.294 -						if (last != $1) {
   1.295 -							last = $1;
   1.296 -							PP = P;
   1.297 -							sub(/%s/, $1, PP);
   1.298 -							printf("\n\e[1;33m%s\e[0;39m\n", PP);
   1.299 -						}
   1.300 -						gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
   1.301 -						print $2;
   1.302 -						printf "%s" 1 >> T;
   1.303 +				lzcat $i | awk -F: -vtmp="$TMPLIST" -vdir="$TMPDIR" \
   1.304 +					-vfile="$2" -vcfile="$(colorize 32 $2)" '
   1.305 +					BEGIN { efile = gensub("\+", "\\\+", "g", file); }
   1.306 +					index($2, file) {
   1.307 +						gsub(efile, cfile, $2);
   1.308 +						print $2 >> dir"/"$1;
   1.309 +						printf "1" >> tmp;
   1.310  					}'
   1.311  			done
   1.312  
   1.313 +			for pkg in $(cd $TMPDIR; ls); do
   1.314 +				newline
   1.315 +				emsg "<c 33>$(_ 'Package %s:' $pkg)</c>"
   1.316 +				cat $TMPDIR/$pkg
   1.317 +			done
   1.318 +
   1.319 +			rm -r $TMPDIR
   1.320 +
   1.321  		else
   1.322  
   1.323  			# Check all pkg files.list in search match which specify the package
   1.324 @@ -1613,11 +1635,12 @@
   1.325  					. $pkg/receipt
   1.326  					newline
   1.327  					emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
   1.328 -					awk -vT=$TMPLIST '
   1.329 -						/'$2'/ {
   1.330 -							gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
   1.331 +					awk -vtmp="$TMPLIST" -vfile="$2" -vcfile="$(colorize 32 $2)" '
   1.332 +						BEGIN { efile = gensub("\+", "\\\+", "g", file); }
   1.333 +						index($0, file) {
   1.334 +							gsub(efile, cfile);
   1.335  							print " "$0;
   1.336 -							printf "%s" 1 >> T;
   1.337 +							printf "1" >> tmp;
   1.338  						}
   1.339  					' $pkg/files.list
   1.340  				fi
   1.341 @@ -1625,12 +1648,9 @@
   1.342  
   1.343  		fi
   1.344  
   1.345 -		match=$(wc -m < $TMPLIST)
   1.346 -		rm $TMPLIST
   1.347 -
   1.348 -		footer "$(emsg "$(_p \
   1.349 -			'%s file' '%s files' $match \
   1.350 -			"<c 32>$match</c>")")"
   1.351 +		num=$(wc -m < $TMPLIST); rm $TMPLIST
   1.352 +		footer "$(_p '%s file' '%s files' "$num" \
   1.353 +			"$(colorize 32 $num)")"
   1.354  		;;
   1.355  
   1.356  
   1.357 @@ -1648,7 +1668,7 @@
   1.358  		# Search for a file on mirror and output only the package name
   1.359  		TMPLIST=$(mktemp)
   1.360  		for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
   1.361 -				[ -f $i ] || continue
   1.362 +				[ -f "$i" ] || continue
   1.363  				lzcat $i | awk -F: -vT=$TMPLIST '
   1.364  					BEGIN { P = "" }
   1.365  					$2 ~ /'$2'/ {
   1.366 @@ -1891,7 +1911,7 @@
   1.367  				confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
   1.368  				answer=$?
   1.369  			fi
   1.370 -			if [ $answer = 0 ]; then
   1.371 +			if [ "$answer" == '0' ]; then
   1.372  				for i in $ALTERED; do
   1.373  					if [ -d "$ROOT$INSTALLED/$i" ]; then
   1.374  						echo "tazpkg remove $i $ROOTOPTS"
   1.375 @@ -1908,7 +1928,7 @@
   1.376  				confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
   1.377  				answer=$?
   1.378  			fi
   1.379 -			if [ $answer = 0 ]; then
   1.380 +			if [ "$answer" == '0' ]; then
   1.381  				for i in $REFRESH; do
   1.382  					if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
   1.383  						_ 'Check %s for reinstallation' "$INSTALLED/$i"
   1.384 @@ -2710,15 +2730,15 @@
   1.385  		check_for_package_on_cmdline
   1.386  		check_for_packages_list
   1.387  
   1.388 -		DO_CHECK=""
   1.389 -		[ "$forced" ] && DO_CHECK=no
   1.390 -		[ "$root" ] && ROOT="$root" && check_base_dir "$root"
   1.391 -		[ "$list" ] && INSTALL_LIST="$list"
   1.392 -		if [ "$rootconfig" ]; then
   1.393 -			if [ "$root" ]; then
   1.394 -				CACHE_DIR=$root/$CACHE_DIR
   1.395 -				SAVE_CACHE_DIR=$CACHE_DIR
   1.396 -				PKGS_DB=$root/$PKGS_DB
   1.397 +		DO_CHECK=''
   1.398 +		[ -n "$forced" ] && DO_CHECK=no
   1.399 +		[ -n "$root" ] && ROOT="$root" && check_base_dir "$root"
   1.400 +		[ -n "$list" ] && INSTALL_LIST="$list"
   1.401 +		if [ -n "$rootconfig" ]; then
   1.402 +			if [ -n "$root" ]; then
   1.403 +				CACHE_DIR="$root/$CACHE_DIR"
   1.404 +				SAVE_CACHE_DIR="$CACHE_DIR"
   1.405 +				PKGS_DB="$root/$PKGS_DB"
   1.406  			else
   1.407  				_ 'rootconfig needs --root= option used.' >&2
   1.408  				exit 1
   1.409 @@ -2728,7 +2748,7 @@
   1.410  		# Get repositories priority list.
   1.411  		look_for_priority
   1.412  
   1.413 -		AUTOEXEC="no"
   1.414 +		AUTOEXEC='no'
   1.415  		if ! check_for_package_in_list check; then
   1.416  			CACHE_DIR="${CACHE_DIR%/*}/get"
   1.417  			[ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
   1.418 @@ -2736,8 +2756,8 @@
   1.419  				install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
   1.420  				exit 0
   1.421  			else
   1.422 -				PACKAGE=get-$PACKAGE
   1.423 -				AUTOEXEC=$PACKAGE
   1.424 +				PACKAGE="get-$PACKAGE"
   1.425 +				AUTOEXEC="$PACKAGE"
   1.426  				check_for_package_in_list
   1.427  				if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
   1.428  					$AUTOEXEC $ROOT
   1.429 @@ -2745,8 +2765,8 @@
   1.430  				fi
   1.431  			fi
   1.432  		fi
   1.433 -		# Check if forced install.
   1.434 -		if ! [ "$forced" ]; then
   1.435 +		# Check if no forced install.
   1.436 +		if [ -z "$forced" ]; then
   1.437  			check_for_installed_package $ROOT
   1.438  		fi
   1.439  		cd $CACHE_DIR
   1.440 @@ -2765,21 +2785,22 @@
   1.441  			newline
   1.442  			download $PACKAGE.tazpkg
   1.443  		fi
   1.444 -		PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
   1.445 -		[ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
   1.446 -		install_package $ROOT
   1.447 +		PACKAGE_FILE="$CACHE_DIR/$PACKAGE.tazpkg"
   1.448 +		[ -n "$rootconfig" ] && PKGS_DB="${PKGS_DB#$root}"
   1.449 +		install_package "$ROOT"
   1.450  		[ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
   1.451  		update_desktop_database $ROOT
   1.452 -		update_mime_database $ROOT ;;
   1.453 +		update_mime_database    $ROOT ;;
   1.454  
   1.455  
   1.456  	clean-cache|-cc)
   1.457  		# Remove all downloaded packages.
   1.458  		check_root $@
   1.459  		files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
   1.460 -		size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
   1.461 -		title 'Path: %s' $CACHE_DIR
   1.462 -		action "Cleaning cache directory..."
   1.463 +		size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ "$files" == '0' ] && size="0K"
   1.464 +
   1.465 +		title "Cleaning cache directory..."
   1.466 +		action 'Path: %s' $CACHE_DIR
   1.467  		rm -rf $CACHE_DIR/*
   1.468  		status
   1.469  
   1.470 @@ -2792,15 +2813,15 @@
   1.471  
   1.472  	list-undigest)
   1.473  		# list undigest URLs.
   1.474 -		if [ "$2" = "--box" ]; then
   1.475 +		if [ -n "$box" ]; then
   1.476  			for i in $PKGS_DB/undigest/*/mirror; do
   1.477 -				[ -f $i ] || continue
   1.478 +				[ -f "$i" ] || continue
   1.479  				echo "$(basename $(dirname $i))|$(cat $i)"
   1.480  			done
   1.481  		else
   1.482  			title 'Current undigest(s)'
   1.483  			for i in $PKGS_DB/undigest/*/mirror; do
   1.484 -				if [ ! -f $i ]; then
   1.485 +				if [ ! -f "$i" ]; then
   1.486  					_ 'No undigest mirror found.'
   1.487  					exit 1
   1.488  				fi
   1.489 @@ -2814,13 +2835,13 @@
   1.490  		# remove undigest URL.
   1.491  		check_root $@
   1.492  		undigest="$2"
   1.493 -		if [ -d $PKGS_DB/undigest/$2 ]; then
   1.494 +		if [ -d "$PKGS_DB/undigest/$2" ]; then
   1.495  			confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
   1.496 -			if [ $? = 0 ]; then
   1.497 +			if [ $? == 0 ]; then
   1.498  				action 'Removing "%s" undigest...' $undigest
   1.499  				rm -rf $PKGS_DB/undigest/$2
   1.500  				status
   1.501 -				rmdir $PKGS_DB/undigest 2> /dev/null
   1.502 +				rmdir $PKGS_DB/undigest 2>/dev/null
   1.503  			fi
   1.504  		else
   1.505  			_ 'Undigest "%s" not found' $undigest
   1.506 @@ -2834,12 +2855,12 @@
   1.507  		[ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
   1.508  		if [ -z "$undigest" ]; then
   1.509  			i=1
   1.510 -			while [ -d $PKGS_DB/undigest/$i ]; do
   1.511 +			while [ -d "$PKGS_DB/undigest/$i" ]; do
   1.512  				i=$(($i+1))
   1.513  			done
   1.514  			undigest=$i
   1.515  		fi
   1.516 -		if [ ! -d $PKGS_DB/undigest/$undigest ]; then
   1.517 +		if [ ! -d "$PKGS_DB/undigest/$undigest" ]; then
   1.518  			_ 'Creating new undigest "%s".' $undigest
   1.519  			mkdir $PKGS_DB/undigest/$undigest
   1.520  		fi
   1.521 @@ -2856,7 +2877,7 @@
   1.522  		# Replay post_install from receipt
   1.523  		check_for_package_on_cmdline
   1.524  		check_root $@
   1.525 -		ROOT=""
   1.526 +		ROOT=''
   1.527  		while [ -n "$3" ]; do
   1.528  			case "$3" in
   1.529  				--root=*)
   1.530 @@ -2892,12 +2913,12 @@
   1.531  
   1.532  	shell)
   1.533  		# TazPKG SHell
   1.534 -		if test $(id -u) = 0 ; then
   1.535 +		if [ "$(id -u)" == '0' ]; then
   1.536  			PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
   1.537  		else
   1.538  			PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
   1.539  		fi
   1.540 -		if [ ! "$2" = "--noheader" ]; then
   1.541 +		if [ "$2" != "--noheader" ]; then
   1.542  			clear
   1.543  			title 'TazPKG SHell.'
   1.544  			_ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
   1.545 @@ -2923,17 +2944,17 @@
   1.546  	depends)
   1.547  		# Display dependencies tree
   1.548  		cd $INSTALLED
   1.549 -		ALL_DEPS=""
   1.550 -		if [ -f $2/receipt ]; then
   1.551 -			dep_scan $2 ""
   1.552 +		ALL_DEPS=''
   1.553 +		if [ -f "$2/receipt" ]; then
   1.554 +			dep_scan $2 ''
   1.555  		fi ;;
   1.556  
   1.557  
   1.558  	rdepends)
   1.559  		# Display reverse dependencies tree
   1.560  		cd $INSTALLED
   1.561 -		ALL_DEPS=""
   1.562 -		if [ -f $2/receipt ]; then
   1.563 +		ALL_DEPS=''
   1.564 +		if [ -f "$2/receipt" ]; then
   1.565  			rdep_scan $2
   1.566  		fi ;;
   1.567  
   1.568 @@ -2941,18 +2962,18 @@
   1.569  	list-suggested)
   1.570  		for i in $(ls -d $INSTALLED/*); do
   1.571  			. $i/receipt
   1.572 -			if [ "$SUGGESTED" ]; then
   1.573 +			if [ -n "$SUGGESTED" ]; then
   1.574  				if [ -z "$all" ]; then
   1.575  				for s in $SUGGESTED; do
   1.576 -					[ -d $INSTALLED/$s ] && \
   1.577 -					SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
   1.578 +					[ -d "$INSTALLED/$s" ] && \
   1.579 +						SUGGESTED="$(echo -n $SUGGESTED | sed "s/$s//")"
   1.580  				done
   1.581  				fi
   1.582  				cat <<EOT
   1.583  $(boldify $(echo $PACKAGE):) $SUGGESTED
   1.584  EOT
   1.585  			fi
   1.586 -		SUGGESTED=""
   1.587 +		SUGGESTED=''
   1.588  		done ;;
   1.589  
   1.590  
   1.591 @@ -2983,7 +3004,7 @@
   1.592  		fi
   1.593  		ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
   1.594  		DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
   1.595 -		MISSING=""
   1.596 +		MISSING=''
   1.597  		for i in $DEPENDS; do
   1.598  			[ -e $INSTALLED/$i ] && continue
   1.599  			MISSING="$MISSING$i "
   1.600 @@ -2994,7 +3015,7 @@
   1.601  			confirm "$(_ 'Link all missing dependencies? (y/N)')"
   1.602  			answer=$?
   1.603  			newline
   1.604 -			if [ $answer = 0 ]; then
   1.605 +			if [ "$answer" == 0 ]; then
   1.606  				for i in $MISSING; do
   1.607  					tazpkg link $i $TARGET_DIR
   1.608  				done
   1.609 @@ -3010,13 +3031,13 @@
   1.610  			pre_install
   1.611  		fi
   1.612  		while read path; do
   1.613 -			[ -e $path ] && continue
   1.614 +			[ -e "$path" ] && continue
   1.615  			while true; do
   1.616 -				dir=$(dirname $path)
   1.617 -				[ -e $dir ] && break
   1.618 -				path=$dir
   1.619 +				dir="$(dirname $path)"
   1.620 +				[ -e "$dir" ] && break
   1.621 +				path="$dir"
   1.622  			done
   1.623 -			ln -s $TARGET_DIR$path $dir
   1.624 +			ln -s "$TARGET_DIR$path" "$dir"
   1.625  		done < $INSTALLED/$PACKAGE/files.list
   1.626  		if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
   1.627  			post_install