Mercurial > trustbridge
diff packaging/linux-installer.inc.in @ 711:acbe75423283
Added deinstallation functionality.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Wed, 02 Jul 2014 15:12:25 +0200 |
parents | 37899f717fa5 |
children | e71c59b16eee |
line wrap: on
line diff
--- a/packaging/linux-installer.inc.in Wed Jul 02 14:26:29 2014 +0200 +++ b/packaging/linux-installer.inc.in Wed Jul 02 15:12:25 2014 +0200 @@ -9,6 +9,8 @@ INSTCFGNAME="installation.cfg" FORCE=0 SYSINST=0 +DEINSTALL=0 +BINNAMES="###BINNAMES###" declare -A instcfg oldinstcfg declare inst_default_prefix instcfg_file @@ -41,7 +43,11 @@ fatal() { echo "$1" >&2 - echo "Installation failed." >&2 + if [ $DEINSTALL -eq 1 ] ; then + echo "Deinstallation failed." >&2 + else + echo "Installation failed." >&2 + fi exit 1 } @@ -53,20 +59,40 @@ Options: -p, --prefix=PATH install files in PATH - -s, --system=PATH make an system wide installation -f, --force install to given prefix, even when a current installation with different prefix exists. + -d, --deinstall deinstall files from current installation + -s, --system=PATH make an system wide (de)installation --help display this help and exit --version output version information and exit EOF exit $1 } +yorn() +{ + local c + while true ; do + read -n 1 c + echo + case "$c" in + y|Y|j|J) + return 0 + ;; + n|N) + return 1 + ;; + *) + echo >&2 "Answer [Y]es or [N]o: " + esac + done +} + parse_args() { OPTS=`getopt \ - -l force,help,prefix:,system,version \ - -o f,p:,s -n "$ME" -- "$@"` + -l deinstall,force,help,prefix:,system,version \ + -o d,f,p:,s -n "$ME" -- "$@"` [ $? -eq 0 ] || usage 23 eval set -- "$OPTS" @@ -85,6 +111,10 @@ FORCE=1 shift 1 ;; + --deinstall|-d) + DEINSTALL=1 + shift 1 + ;; --help) usage 0 ;; @@ -136,6 +166,31 @@ fi } +deinstall() +{ + if [ "${oldinstcfg[PREFIX]}" ] ; then + echo "Really deinstall TrustBridge from '${oldinstcfg[PREFIX]}'?" + yorn || exit 0 + local deinstdir="${oldinstcfg[PREFIX]}/bin" + echo "Deinstalling from '${oldinstcfg[PREFIX]}'." + for file in $BINNAMES ; do + local path="${deinstdir}/$file" + echo "Deleting '$path' ..." + rm "$path" || echo >&2 "WARNING: Could not delete: '$path'!" + done + while [ "$deinstdir" -a -z "$(ls -A "$deinstdir")" ] ; do + echo "Deleting empty directory '$deinstdir' ..." + rmdir "$deinstdir" + deinstdir=`dirname "$deinstdir"` + done + echo "Removing installation configuration from: $instcfg_file ..." + rm "$instcfg_file" + echo "Deinstallation finished." + else + echo "No current installation found! No harm done." + fi +} + #====================================================================== # main() @@ -154,6 +209,12 @@ ------------------------------------------------------------------------ EOF +if [ $DEINSTALL -eq 1 ] ; then + deinstall + # Stop after deinstallation: + exit 0 +fi + if [ -z "${instcfg[PREFIX]}" ] ; then if [ "${oldinstcfg[PREFIX]}" ] ; then @@ -186,6 +247,7 @@ echo "unpacking files ..." cd "${instcfg[PREFIX]}" +set +u # ---------------------------------------------------------------------- # regular shar archive inserted here: ###SHAR###