view packaging/linux-installer.inc.in @ 710:86c9ff4cfb02

(Issue30) Actually set the text as data also for removal
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 02 Jul 2014 14:26:29 +0200
parents 37899f717fa5
children acbe75423283
line wrap: on
line source
#!/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

declare -A instcfg oldinstcfg
declare inst_default_prefix instcfg_file
instcfg=(
  [TIMESTMP]=`date -u +%Y%m%d%H%M%S`
  [VERSION]='@PROJECT_VERSION@'
  [PREFIX]=''
)
oldinstcfg=(
  [TIMESTMP]=''
  [VERSION]=''
  [PREFIX]=''
)

version()
{
  cat <<EOF
TrustBridge ${instcfg[VERSION]} Installer

Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH

This is free software.  You may redistribute copies of it under the terms of
the GNU GPL (v>=2).   See LICENSE.txt for details.
There is NO WARRANTY, to the extent permitted by law.
EOF
  exit 0
}

fatal()
{
  echo "$1" >&2
  echo "Installation failed." >&2
  exit 1
}

usage()
{
  cat <<EOF
Usage: $ME [OPTION]...
Install TrustBridge.

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.
      --help         display this help and exit
      --version      output version information and exit
EOF
  exit $1
}

parse_args()
{
  OPTS=`getopt \
      -l force,help,prefix:,system,version \
      -o f,p:,s -n "$ME" -- "$@"`
  [ $? -eq 0 ] || usage 23

  eval set -- "$OPTS"

  while true ; do
    case "$1" in
      --prefix|-p)
        instcfg[PREFIX]="$2"
        shift 2
        ;;
      --system|-s)
        SYSINST=1
        shift 1
        ;;
      --force|-f)
        FORCE=1
        shift 1
        ;;
      --help)
        usage 0
        ;;
      --version)
        version
        ;;
      --)
        shift
        break
        ;;
    esac
  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"`
  echo "# Created by TrustBridge-Installer, don't touch!" >"$instcfg_file"
  for key in "${!instcfg[@]}" ; do
    echo "${key}=${instcfg[$key]}" >>"$instcfg_file"
  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
}

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
------------------------------------------------------------------------

   TrustBridge - Installer
   Version ${instcfg[VERSION]}

------------------------------------------------------------------------
EOF

if [ -z "${instcfg[PREFIX]}" ] ; then

    if [ "${oldinstcfg[PREFIX]}" ] ; then
        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 [${inst_default_prefix}]: "
    read -e instcfg[PREFIX]

    [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${inst_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]}':"

if [ ! -d "${instcfg[PREFIX]}" ] ; then
    echo "creating installation directory ..."
    install -d "${instcfg[PREFIX]}" || fatal "Could not create '${instcfg[PREFIX]}'!"
fi

echo "unpacking files ..."
cd "${instcfg[PREFIX]}"

# ----------------------------------------------------------------------
# regular shar archive inserted here:
###SHAR###
# ----------------------------------------------------------------------

echo "Writing installation configuration to: $instcfg_file ..."
write_instcfg
exit 0

http://wald.intevation.org/projects/trustbridge/