wilde@1139: #-*-sh-*- wilde@1139: ME=`basename "$0"` wilde@1139: DEFAULT_PREFIX="$HOME/TrustBridge" wilde@1139: SYSDEFAULT_PREFIX="/usr/local" wilde@1139: CFGPATH="${XDG_CONFIG_HOME:-$HOME/.config}/BSI" wilde@1139: DATAPATH="${XDG_DATA_HOME:-$HOME/.local/share}/BSI/TrustBridge" wilde@1139: SYSCFGPATH="/etc/TrustBridge" wilde@1139: # FIXME: wilde@1139: # Set the real data path for system wide installation once its known. wilde@1139: SYSDATAPATH="$DATAPATH" wilde@1139: INSTCFGNAME="TrustBridge-inst.cfg" wilde@1139: FORCE=0 wilde@1139: SYSINST=0 wilde@1139: DEINSTALL=0 wilde@1139: UPDATE=0 wilde@1139: BINNAMES="###BINNAMES###" wilde@1139: ICONNAME="###ICONNAME###" wilde@1139: HELPNAMES="###HELPNAMES###" wilde@1139: HELPNAMES_SOURCES="###HELPNAMES_SOURCES###" wilde@1139: HELPNAMES_STATIC="###HELPNAMES_STATIC###" wilde@1139: HELPNAMES_IMG="###HELPNAMES_IMG###" wilde@1139: ARCH="###ARCH###" wilde@1139: wilde@1139: declare -A instcfg oldinstcfg wilde@1139: declare inst_default_prefix instdata_path instcfg_path instcfg_file wilde@1139: instcfg=( wilde@1139: [TIMESTMP]=`date -u +%Y%m%d%H%M%S` wilde@1139: [VERSION]='@PROJECT_VERSION@' wilde@1139: [PREFIX]='' wilde@1139: ) wilde@1139: oldinstcfg=( wilde@1139: [TIMESTMP]='' wilde@1139: [VERSION]='' wilde@1139: [PREFIX]='' wilde@1139: ) wilde@1139: wilde@1139: declare -A L10N_DE wilde@1139: ###INCLUDE:linux-installer.l10n-de wilde@1149: ###INCLUDE:linux-installer-common.l10n-de wilde@1149: ###INCLUDE:linux-installer-uninstall.l10n-de wilde@1139: wilde@1139: getxt() wilde@1139: { wilde@1139: # Poor mans gettext for l10n completely self contained in one shell wilde@1139: # script. wilde@1139: MSGID="$1" wilde@1139: shift wilde@1139: case ${LANGUAGE:-${LC_ALL:-${LC_MESSAGES:-$LANG}}} in wilde@1139: de*) wilde@1139: if [ "${L10N_DE[$MSGID]}" ] ; then wilde@1139: MSG="${L10N_DE[$MSGID]}" wilde@1139: else wilde@1139: MSG="$MSGID" wilde@1139: fi wilde@1139: ;; wilde@1139: *) wilde@1139: MSG="$MSGID" wilde@1139: ;; wilde@1139: esac wilde@1139: wilde@1139: printf "$MSG" "$@" wilde@1139: } wilde@1139: wilde@1139: version() wilde@1139: { wilde@1139: cat <=2) wilde@1139: and comes with ABSOLUTELY NO WARRANTY! wilde@1139: See LICENSE.txt for details. wilde@1139: EOF wilde@1139: exit 0 wilde@1139: } wilde@1139: wilde@1139: fatal() wilde@1139: { wilde@1139: getxt "$1" >&2 wilde@1139: if [ $DEINSTALL -eq 1 ] ; then wilde@1139: getxt "Deinstallation failed.\n" >&2 wilde@1139: else wilde@1139: getxt "Installation failed.\n" >&2 wilde@1139: fi wilde@1139: exit 1 wilde@1139: } wilde@1139: wilde@1139: yorn() wilde@1139: { wilde@1139: local c wilde@1139: while true ; do wilde@1139: read -n 1 c wilde@1139: echo wilde@1139: case "$c" in wilde@1139: y|Y|j|J) wilde@1139: return 0 wilde@1139: ;; wilde@1139: n|N) wilde@1139: return 1 wilde@1139: ;; wilde@1139: *) wilde@1139: getxt >&2 "Answer [Y]es or [N]o:\n" wilde@1139: esac wilde@1139: done wilde@1139: } wilde@1139: wilde@1139: check_priv() wilde@1139: { wilde@1139: if [ $SYSINST -eq 1 -a "$UID" -ne 0 ] ; then wilde@1139: fatal "System wide installation or deinstallation requires root privileges!\n" wilde@1139: fi wilde@1139: } wilde@1139: wilde@1139: init_vars() wilde@1139: { wilde@1139: if [ -n "${SUDO_USER-}" ] ; then wilde@1139: # Default to system wide installation when running with sudo wilde@1139: SYSINST=1 wilde@1139: fi wilde@1139: wilde@1139: if [ $SYSINST -eq 1 ] ; then wilde@1139: inst_default_prefix="$SYSDEFAULT_PREFIX" wilde@1139: instcfg_path="${SYSCFGPATH}" wilde@1139: instdata_path="${SYSDATAPATH}" wilde@1139: autostart_path="$(getent passwd "${SUDO_USER}" | cut -d ':' -f 6)/.config/autostart" wilde@1139: startmenu_path="/usr/share/applications" wilde@1139: else wilde@1139: inst_default_prefix="$DEFAULT_PREFIX" wilde@1139: instcfg_path="${CFGPATH}" wilde@1139: instdata_path="${DATAPATH}" wilde@1139: autostart_path=${XDG_CONFIG_HOME:-~/.config/autostart} wilde@1139: startmenu_path=${XDG_DATA_HOME:-~/.local/share/applications} wilde@1139: if [ $DEINSTALL -eq 1 ] ; then wilde@1139: if [ ! -r ${instcfg_path}/${INSTCFGNAME} ]; then wilde@1139: if [ -r ${SYSCFGPATH}/${INSTCFGNAME} ]; then wilde@1139: # Fall back to system uninstallation if no user config found wilde@1139: SYSINST=1 wilde@1139: init_vars wilde@1139: check_priv wilde@1139: fi wilde@1139: fi wilde@1139: else wilde@1139: # extra bin path not needed on deinstall: wilde@1139: extra_bin_path=`mktemp --tmpdir -d tmpbin.XXXXXXXXXX` wilde@1139: fi wilde@1139: fi wilde@1139: instcfg_file="${instcfg_path}/${INSTCFGNAME}" wilde@1139: HOST_ARCH=$(uname -m) wilde@1139: } wilde@1139: wilde@1139: read_oldinstcfg() wilde@1139: { wilde@1139: if [ -r "$instcfg_file" ] ; then wilde@1139: getxt "Reading '%s' ...\n" "$instcfg_file" wilde@1139: for key in "${!oldinstcfg[@]}" ; do wilde@1139: oldinstcfg[$key]=`sed -n "/$key/s/[^=]*=\(.*\)/\1/p" "$instcfg_file"` wilde@1139: done wilde@1139: fi wilde@1139: } wilde@1139: wilde@1139: wilde@1139: setup_cronjob() wilde@1139: { wilde@1139: local tmpcrontab=`mktemp` wilde@1139: wilde@1139: if [ $SYSINST -eq 1 -a "${SUDO_USER+X}" ] ; then wilde@1139: local crontabopt="-u $SUDO_USER" wilde@1139: else wilde@1139: local crontabopt='' wilde@1139: fi wilde@1139: wilde@1139: if [ "$1" != "deinstall" ] ; then wilde@1139: local trustbridge_tray_starter="${instcfg[PREFIX]}/bin/trustbridge-tray-starter.sh" wilde@1139: else wilde@1139: local trustbridge_tray_starter="${oldinstcfg[PREFIX]}/bin/trustbridge-tray-starter.sh" wilde@1139: fi wilde@1139: wilde@1139: crontab $crontabopt -l | \ wilde@1139: grep -vF "$trustbridge_tray_starter" \ wilde@1139: >"$tmpcrontab" wilde@1139: if [ "$1" != "deinstall" ] ; then wilde@1139: echo "$(( $RANDOM / 555 )) 12 * * * \"$trustbridge_tray_starter\"" \ wilde@1139: >>"$tmpcrontab" wilde@1139: fi wilde@1139: crontab $crontabopt "$tmpcrontab" wilde@1139: rm "$tmpcrontab" wilde@1139: }