Mercurial > trustbridge
diff packaging/linux-installer.inc.in @ 707:37899f717fa5
Added system wide installation.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Wed, 02 Jul 2014 12:39:28 +0200 |
parents | ff2efc1cb8fa |
children | acbe75423283 |
line wrap: on
line diff
--- a/packaging/linux-installer.inc.in Wed Jul 02 11:57:32 2014 +0200 +++ b/packaging/linux-installer.inc.in Wed Jul 02 12:39:28 2014 +0200 @@ -1,14 +1,17 @@ #!/bin/bash +set -u ME=`basename "$0"` DEFAULT_PREFIX="$HOME/TrustBridge" +SYSDEFAULT_PREFIX="/usr/local" CFGPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge" SYSCFGPATH="/etc/TrustBridge" INSTCFGNAME="installation.cfg" FORCE=0 +SYSINST=0 -instcfg_file="${CFGPATH}/${INSTCFGNAME}" declare -A instcfg oldinstcfg +declare inst_default_prefix instcfg_file instcfg=( [TIMESTMP]=`date -u +%Y%m%d%H%M%S` [VERSION]='@PROJECT_VERSION@' @@ -50,7 +53,8 @@ Options: -p, --prefix=PATH install files in PATH - -f, --force install to given prefix, even when a current + -s, --system=PATH make an system wide installation + -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 @@ -61,8 +65,8 @@ parse_args() { OPTS=`getopt \ - -l force,help,prefix:,version \ - -o f,p: -n "$ME" -- "$@"` + -l force,help,prefix:,system,version \ + -o f,p:,s -n "$ME" -- "$@"` [ $? -eq 0 ] || usage 23 eval set -- "$OPTS" @@ -73,6 +77,10 @@ instcfg[PREFIX]="$2" shift 2 ;; + --system|-s) + SYSINST=1 + shift 1 + ;; --force|-f) FORCE=1 shift 1 @@ -91,6 +99,17 @@ done } +init_vars() +{ + if [ $SYSINST -eq 1 ] ; then + inst_default_prefix="$SYSDEFAULT_PREFIX" + instcfg_file="${SYSCFGPATH}/${INSTCFGNAME}" + else + inst_default_prefix="$DEFAULT_PREFIX" + instcfg_file="${CFGPATH}/${INSTCFGNAME}" + fi +} + write_instcfg() { install -d `dirname "$instcfg_file"` @@ -107,13 +126,23 @@ for key in "${!oldinstcfg[@]}" ; do oldinstcfg[$key]=`sed -n "/$key/s/[^=]*=\(.*\)/\1/p" "$instcfg_file"` done - fi + fi } +check_priv() +{ + if [ $SYSINST -eq 1 -a "$UID" -ne 0 ] ; then + fatal "System wide installation requires root privileges!" + fi +} + + #====================================================================== # main() parse_args "$@" +init_vars +check_priv read_oldinstcfg cat <<EOF @@ -128,16 +157,16 @@ if [ -z "${instcfg[PREFIX]}" ] ; then if [ "${oldinstcfg[PREFIX]}" ] ; then - DEFAULT_PREFIX="${oldinstcfg[PREFIX]}" + inst_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}]: " + echo -n "Select installation prefix for TrustBridge [${inst_default_prefix}]: " read -e instcfg[PREFIX] - [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${DEFAULT_PREFIX}" + [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${inst_default_prefix}" else # Prefix was given on invocation: if [ "${oldinstcfg[PREFIX]}" -a \