[PATCH 2 of 3] Use config from old installation for sensible default prefix
Wald Commits
scm-commit at wald.intevation.org
Wed Jul 2 11:57:52 CEST 2014
# HG changeset patch
# User Sascha Wilde <wilde at intevation.de>
# Date 1404295016 -7200
# Node ID ff2efc1cb8fa489f4ebe30a06e7bd595255e2eaf
# Parent 480bc550d2ad3544f8c4a019fa67dbedaf59d0b0
Use config from old installation for sensible default prefix.
diff -r 480bc550d2ad -r ff2efc1cb8fa packaging/linux-installer.inc.in
--- a/packaging/linux-installer.inc.in Wed Jul 02 10:59:31 2014 +0200
+++ b/packaging/linux-installer.inc.in Wed Jul 02 11:56:56 2014 +0200
@@ -5,14 +5,20 @@
CFGPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge"
SYSCFGPATH="/etc/TrustBridge"
INSTCFGNAME="installation.cfg"
+FORCE=0
instcfg_file="${CFGPATH}/${INSTCFGNAME}"
-declare -A instcfg
+declare -A instcfg oldinstcfg
instcfg=(
[TIMESTMP]=`date -u +%Y%m%d%H%M%S`
[VERSION]='@PROJECT_VERSION@'
[PREFIX]=''
)
+oldinstcfg=(
+ [TIMESTMP]=''
+ [VERSION]=''
+ [PREFIX]=''
+)
version()
{
@@ -44,6 +50,8 @@
Options:
-p, --prefix=PATH install files in PATH
+ -f, --force install to given prefix, even when a current
+ installation with different prefix exists.
--help display this help and exit
--version output version information and exit
EOF
@@ -53,8 +61,8 @@
parse_args()
{
OPTS=`getopt \
- -l help,prefix:,version \
- -o p: -n "$ME" -- "$@"`
+ -l force,help,prefix:,version \
+ -o f,p: -n "$ME" -- "$@"`
[ $? -eq 0 ] || usage 23
eval set -- "$OPTS"
@@ -65,6 +73,10 @@
instcfg[PREFIX]="$2"
shift 2
;;
+ --force|-f)
+ FORCE=1
+ shift 1
+ ;;
--help)
usage 0
;;
@@ -88,10 +100,21 @@
done
}
+read_oldinstcfg()
+{
+ if [ -r "$instcfg_file" ] ; then
+ echo "Reading '$instcfg_file' ..."
+ for key in "${!oldinstcfg[@]}" ; do
+ oldinstcfg[$key]=`sed -n "/$key/s/[^=]*=\(.*\)/\1/p" "$instcfg_file"`
+ done
+ fi
+}
+
#======================================================================
# main()
parse_args "$@"
+read_oldinstcfg
cat <<EOF
------------------------------------------------------------------------
@@ -103,10 +126,25 @@
EOF
if [ -z "${instcfg[PREFIX]}" ] ; then
+
+ if [ "${oldinstcfg[PREFIX]}" ] ; then
+ DEFAULT_PREFIX="${oldinstcfg[PREFIX]}"
+ echo "An existing installation (v${oldinstcfg[VERSION]}) was detected!"
+ echo "It is HIGHLY RECOMMENDED to accept the default prefix"
+ echo "to update the current installation."
+ echo "For a new prefix you should deinstall first!"
+ fi
echo -n "Select installation prefix for TrustBridge [${DEFAULT_PREFIX}]: "
read -e instcfg[PREFIX]
[ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${DEFAULT_PREFIX}"
+else
+ # Prefix was given on invocation:
+ if [ "${oldinstcfg[PREFIX]}" -a \
+ "${instcfg[PREFIX]}" != "${oldinstcfg[PREFIX]}" -a \
+ $FORCE -ne 1 ] ; then
+ fatal "Prefix differs from current installation (${oldinstcfg[PREFIX]}). Aborting!"
+ fi
fi
echo "Installing to '${instcfg[PREFIX]}':"
More information about the Trustbridge-commits
mailing list