[PATCH] Added deinstallation functionality
Wald Commits
scm-commit at wald.intevation.org
Wed Jul 2 15:12:38 CEST 2014
# HG changeset patch
# User Sascha Wilde <wilde at intevation.de>
# Date 1404306745 -7200
# Node ID acbe7542328333a7b09362c25a34d97a466a79b0
# Parent 86c9ff4cfb024a5e761b7e03f49015b526a1335c
Added deinstallation functionality.
diff -r 86c9ff4cfb02 -r acbe75423283 packaging/linux-createpackage.sh.in
--- a/packaging/linux-createpackage.sh.in Wed Jul 02 14:26:29 2014 +0200
+++ b/packaging/linux-createpackage.sh.in Wed Jul 02 15:12:25 2014 +0200
@@ -19,12 +19,19 @@
# shar-archive.
echo "Using $TMPDIR for temporary installation to build installer..."
install -d "$TMPDIR/bin"
-install "${EXEFILES[@]}" "$TMPDIR/bin"
+install "${EXEFILES[@]}" "$TMPDIR/bin"
+
+echo "Creating shar archive ..."
+cd "$TMPDIR"
+shar -z -B bin/* | sed 's/^exit 0//' >>"$TMPSHAR"
echo "Building $INSTALLER..."
cp "@CMAKE_BINARY_DIR@/packaging/linux-installer.inc" "$INSTALLER"
-cd "$TMPDIR"
-shar -z -B bin/* | sed 's/^exit 0//' >>"$TMPSHAR"
+binnames=""
+for file in "${EXEFILES[@]}" ; do
+ binnames="`basename $file` $binnames"
+done
+sed -i "s/###BINNAMES###/${binnames}/" "$INSTALLER"
sed -i "/###SHAR###/r $TMPSHAR" "$INSTALLER"
chmod +x "$INSTALLER"
diff -r 86c9ff4cfb02 -r acbe75423283 packaging/linux-installer.inc.in
--- 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###
More information about the Trustbridge-commits
mailing list