sup rev 20

Add remove command nd improve install
author Christophe Lincoln <pankso@slitaz.org>
date Sun Feb 26 21:05:33 2017 +0100 (2017-02-26)
parents 85b9905011cb
children a5e4d133589a
files libsup.sh sup
line diff
     1.1 --- a/libsup.sh	Sun Feb 26 19:20:31 2017 +0100
     1.2 +++ b/libsup.sh	Sun Feb 26 21:05:33 2017 +0100
     1.3 @@ -30,6 +30,13 @@
     1.4  # Functions
     1.5  #
     1.6  
     1.7 +# Set ttysize= # stty will not work if called from GTK box or CGI script
     1.8 +tty_size() {
     1.9 +	local size=$(stty size | cut -d " " -f 2)
    1.10 +	[ "$size" ] && local size=80
    1.11 +	echo ${size}
    1.12 +}
    1.13 +
    1.14  # Extract a sup package: extract_sup "/path/to/pkg.sup"
    1.15  extract_sup() {
    1.16  	pkg="$(basename ${1%.sup})"
    1.17 @@ -76,7 +83,7 @@
    1.18  	
    1.19  	newline
    1.20  	gettext "Installing package:"; colorize 36 " $PACKAGE $VERSION"
    1.21 -	log "$(gettext 'Installing package:') $pkg"
    1.22 +	log "$(gettext 'Installing package:') $PACKAGE $VERSION"
    1.23  	separator
    1.24  	
    1.25  	# Extract and source receip first to check deps
    1.26 @@ -86,9 +93,8 @@
    1.27  	# have to dl and move files where they were in $HOME
    1.28  	cd files
    1.29  	if grep -q "^sup_install" ../receip; then
    1.30 -		local in=$(($(stty size | cut -d " " -f 2) - 15))
    1.31  		gettext "Executing install function:"
    1.32 -		indent ${in} $(colorize 33 " sup_install")
    1.33 +		indent $(($(tty_size) - 18)) "[ $(colorize 33 sup_install) ]"
    1.34  		sup_install
    1.35  	fi
    1.36  	
    1.37 @@ -106,7 +112,9 @@
    1.38  	echo "sup_size=\"$(du -sh files | cut -d "	" -f 1)\"" >> receip
    1.39  	
    1.40  	# Now we need a place to store package data and set $sup_size
    1.41 -	gettext "Installing files to $HOME..."
    1.42 +	
    1.43 +	gettext "Installing files:"
    1.44 +	echo -n "$(colorize 35 " $(wc -l files.list | cut -d " " -f 1)")"
    1.45  	data="${installed}/${PACKAGE}"
    1.46  	mkdir -p ${data}
    1.47  	for file in receip README files.list; do
    1.48 @@ -115,7 +123,46 @@
    1.49  	for file in $(ls -A files); do
    1.50  		cp -rf files/${file} ${HOME}
    1.51  	done && status
    1.52 -	separator
    1.53 -	gettext "Installed files:"; colorize 35 " $(cat files.list | wc -l)"
    1.54  	newline && rm -rf ${cache}
    1.55  }
    1.56 +
    1.57 +# Remove a sup package
    1.58 +remove_sup() {
    1.59 +	pkg="$1"
    1.60 +	files_list="$installed/$pkg/files.list"
    1.61 +	. ${installed}/${pkg}/receip
    1.62 +	
    1.63 +	newline
    1.64 +	gettext "Removing package:"; colorize 36 " $PACKAGE $VERSION"
    1.65 +	log "$(gettext 'Removing package:') $PACKAGE $VERSION"
    1.66 +	separator
    1.67 +	
    1.68 +	gettext "Files to remove :"
    1.69 +	indent $(($(tty_size) - 8)) \
    1.70 +		"[ $(colorize 33 $(wc -l ${files_list} | cut -d ' ' -f 1)) ]"
    1.71 +	
    1.72 +	# Remove all files
    1.73 +	for file in $(cat $files_list)
    1.74 +	do
    1.75 +		# --verbose
    1.76 +		if [ "$verbose" ]; then
    1.77 +			gettext "Removing file   :"; echo -n " ${file#/}"
    1.78 +			rm -f "${HOME}${file}"; status
    1.79 +			# Empty folder ?
    1.80 +			if [ ! "$(ls -A ${HOME}$(dirname $file))" ]; then
    1.81 +				path="$(dirname $file)"
    1.82 +				gettext "Removing folder :"; echo -n " ${path#/}"
    1.83 +				rmdir "${HOME}$(dirname $file)"; status
    1.84 +			fi
    1.85 +		else
    1.86 +			rm -f "${HOME}${file}"
    1.87 +			# Empty folder ?
    1.88 +			if [ ! "$(ls -A ${HOME}$(dirname $file))" ]; then
    1.89 +				rmdir "${HOME}$(dirname $file)"
    1.90 +			fi
    1.91 +		fi
    1.92 +	done
    1.93 +	gettext "Removing packages from local database..."
    1.94 +	rm -rf ${installed}/${pkg}; status
    1.95 +	newline
    1.96 +}
     2.1 --- a/sup	Sun Feb 26 19:20:31 2017 +0100
     2.2 +++ b/sup	Sun Feb 26 21:05:33 2017 +0100
     2.3 @@ -32,6 +32,7 @@
     2.4    -c  cook           $(gettext "Cook a package from the wok")
     2.5    -e  extract        $(gettext "Extract a package to current dir")
     2.6    -i  install        $(gettext "Install a sup package")
     2.7 +  -r  remove         $(gettext "Install a sup package")
     2.8    -l  list           $(gettext "List installed packages and your wok")
     2.9  
    2.10  $(boldify $(gettext "Options:"))
    2.11 @@ -96,7 +97,7 @@
    2.12  		# Sanity check
    2.13  		if [ ! "$pkg" ]; then
    2.14  			gettext "You must specify a package to cook:"
    2.15 -			boldify " sup cook [package]" && exit 1
    2.16 +			boldify " sup $1 [package]" && exit 1
    2.17  		fi
    2.18  		if [ ! -f "$receip" ]; then
    2.19  			gettext "Can't find receip in wok for:"
    2.20 @@ -161,8 +162,8 @@
    2.21  		
    2.22  		# Sanity check
    2.23  		if [ ! "$pkg" ]; then
    2.24 -			gettext "Missing package in argument:"
    2.25 -			colorize 35 " sup extract [package.sup]" && exit 1
    2.26 +			gettext "Missing package file in argument:"
    2.27 +			colorize 35 " sup $1 [package.sup]" && exit 1
    2.28  		fi
    2.29  		if [ ! -f "$pkg" ]; then
    2.30  			gettext "Can't find package file:"; colorize 35 " $pkg" && exit 1
    2.31 @@ -182,8 +183,8 @@
    2.32  		pkg="$2"
    2.33  		
    2.34  		if [ ! "$pkg" ]; then
    2.35 -			gettext "Missing package in argument:"
    2.36 -			boldify " sup install [name|pkg.sup]" && exit 1
    2.37 +			gettext "Missing package name or file in argument:"
    2.38 +			boldify " sup $1 [package] or [file.sup]" && exit 1
    2.39  		fi
    2.40  		
    2.41  		# Sup pkg in current dir
    2.42 @@ -204,6 +205,22 @@
    2.43  		
    2.44  		gettext "Can't find sup package:"; colorize 31 " $pkg" ;;
    2.45  	
    2.46 +	-r|remove)
    2.47 +		# Remove a package
    2.48 +		pkg="$2"
    2.49 +		
    2.50 +		if [ ! "$pkg" ]; then
    2.51 +			gettext "Missing package name in argument:"
    2.52 +			boldify " sup $1 [package]" && exit 1
    2.53 +		fi
    2.54 +		
    2.55 +		if [ -d "$installed/$pkg" ]; then
    2.56 +			remove_sup "$pkg"
    2.57 +		else
    2.58 +			gettext "Can't find installed package:"; colorize 31 " $pkg"
    2.59 +			exit 1
    2.60 +		fi ;;
    2.61 +	
    2.62  	-l|list)
    2.63  		installed_nb=$(ls ${installed} | wc -l)
    2.64  		newline
    2.65 @@ -241,8 +258,7 @@
    2.66  			separator
    2.67  			echo "Short desc: $SHORT_DESC"
    2.68  			echo ""
    2.69 -			boldify "Installed files size: $sup_size"
    2.70 -			#
    2.71 +			boldify "$(gettext 'Installed files:') ($sup_size)"
    2.72  			cat ${installed}/${pkg}/files.list
    2.73  			newline
    2.74  		else