# HG changeset patch # User Christophe Lincoln # Date 1488139533 -3600 # Node ID c0a780b534c244b6b2062782d83139b85cef6c18 # Parent 85b9905011cb470f4a105000d0653602598eaf7f Add remove command nd improve install diff -r 85b9905011cb -r c0a780b534c2 libsup.sh --- a/libsup.sh Sun Feb 26 19:20:31 2017 +0100 +++ b/libsup.sh Sun Feb 26 21:05:33 2017 +0100 @@ -30,6 +30,13 @@ # Functions # +# Set ttysize= # stty will not work if called from GTK box or CGI script +tty_size() { + local size=$(stty size | cut -d " " -f 2) + [ "$size" ] && local size=80 + echo ${size} +} + # Extract a sup package: extract_sup "/path/to/pkg.sup" extract_sup() { pkg="$(basename ${1%.sup})" @@ -76,7 +83,7 @@ newline gettext "Installing package:"; colorize 36 " $PACKAGE $VERSION" - log "$(gettext 'Installing package:') $pkg" + log "$(gettext 'Installing package:') $PACKAGE $VERSION" separator # Extract and source receip first to check deps @@ -86,9 +93,8 @@ # have to dl and move files where they were in $HOME cd files if grep -q "^sup_install" ../receip; then - local in=$(($(stty size | cut -d " " -f 2) - 15)) gettext "Executing install function:" - indent ${in} $(colorize 33 " sup_install") + indent $(($(tty_size) - 18)) "[ $(colorize 33 sup_install) ]" sup_install fi @@ -106,7 +112,9 @@ echo "sup_size=\"$(du -sh files | cut -d " " -f 1)\"" >> receip # Now we need a place to store package data and set $sup_size - gettext "Installing files to $HOME..." + + gettext "Installing files:" + echo -n "$(colorize 35 " $(wc -l files.list | cut -d " " -f 1)")" data="${installed}/${PACKAGE}" mkdir -p ${data} for file in receip README files.list; do @@ -115,7 +123,46 @@ for file in $(ls -A files); do cp -rf files/${file} ${HOME} done && status - separator - gettext "Installed files:"; colorize 35 " $(cat files.list | wc -l)" newline && rm -rf ${cache} } + +# Remove a sup package +remove_sup() { + pkg="$1" + files_list="$installed/$pkg/files.list" + . ${installed}/${pkg}/receip + + newline + gettext "Removing package:"; colorize 36 " $PACKAGE $VERSION" + log "$(gettext 'Removing package:') $PACKAGE $VERSION" + separator + + gettext "Files to remove :" + indent $(($(tty_size) - 8)) \ + "[ $(colorize 33 $(wc -l ${files_list} | cut -d ' ' -f 1)) ]" + + # Remove all files + for file in $(cat $files_list) + do + # --verbose + if [ "$verbose" ]; then + gettext "Removing file :"; echo -n " ${file#/}" + rm -f "${HOME}${file}"; status + # Empty folder ? + if [ ! "$(ls -A ${HOME}$(dirname $file))" ]; then + path="$(dirname $file)" + gettext "Removing folder :"; echo -n " ${path#/}" + rmdir "${HOME}$(dirname $file)"; status + fi + else + rm -f "${HOME}${file}" + # Empty folder ? + if [ ! "$(ls -A ${HOME}$(dirname $file))" ]; then + rmdir "${HOME}$(dirname $file)" + fi + fi + done + gettext "Removing packages from local database..." + rm -rf ${installed}/${pkg}; status + newline +} diff -r 85b9905011cb -r c0a780b534c2 sup --- a/sup Sun Feb 26 19:20:31 2017 +0100 +++ b/sup Sun Feb 26 21:05:33 2017 +0100 @@ -32,6 +32,7 @@ -c cook $(gettext "Cook a package from the wok") -e extract $(gettext "Extract a package to current dir") -i install $(gettext "Install a sup package") + -r remove $(gettext "Install a sup package") -l list $(gettext "List installed packages and your wok") $(boldify $(gettext "Options:")) @@ -96,7 +97,7 @@ # Sanity check if [ ! "$pkg" ]; then gettext "You must specify a package to cook:" - boldify " sup cook [package]" && exit 1 + boldify " sup $1 [package]" && exit 1 fi if [ ! -f "$receip" ]; then gettext "Can't find receip in wok for:" @@ -161,8 +162,8 @@ # Sanity check if [ ! "$pkg" ]; then - gettext "Missing package in argument:" - colorize 35 " sup extract [package.sup]" && exit 1 + gettext "Missing package file in argument:" + colorize 35 " sup $1 [package.sup]" && exit 1 fi if [ ! -f "$pkg" ]; then gettext "Can't find package file:"; colorize 35 " $pkg" && exit 1 @@ -182,8 +183,8 @@ pkg="$2" if [ ! "$pkg" ]; then - gettext "Missing package in argument:" - boldify " sup install [name|pkg.sup]" && exit 1 + gettext "Missing package name or file in argument:" + boldify " sup $1 [package] or [file.sup]" && exit 1 fi # Sup pkg in current dir @@ -204,6 +205,22 @@ gettext "Can't find sup package:"; colorize 31 " $pkg" ;; + -r|remove) + # Remove a package + pkg="$2" + + if [ ! "$pkg" ]; then + gettext "Missing package name in argument:" + boldify " sup $1 [package]" && exit 1 + fi + + if [ -d "$installed/$pkg" ]; then + remove_sup "$pkg" + else + gettext "Can't find installed package:"; colorize 31 " $pkg" + exit 1 + fi ;; + -l|list) installed_nb=$(ls ${installed} | wc -l) newline @@ -241,8 +258,7 @@ separator echo "Short desc: $SHORT_DESC" echo "" - boldify "Installed files size: $sup_size" - # + boldify "$(gettext 'Installed files:') ($sup_size)" cat ${installed}/${pkg}/files.list newline else