diff options
author | Andreas Loibl <andreas@andreas-loibl.de> | 2011-03-17 05:07:10 +0100 |
---|---|---|
committer | Andreas Loibl <andreas@andreas-loibl.de> | 2011-03-17 05:07:10 +0100 |
commit | 00286a5db286e21a766b6af057052dc5d17561ad (patch) | |
tree | 7232dadf6dc3570705c3104fe0c000f480c7a0ee /backend/backend.sh.in | |
download | acritoxinstaller-00286a5db286e21a766b6af057052dc5d17561ad.zip acritoxinstaller-00286a5db286e21a766b6af057052dc5d17561ad.tar.gz |
Initial commit
Diffstat (limited to 'backend/backend.sh.in')
-rwxr-xr-x | backend/backend.sh.in | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/backend/backend.sh.in b/backend/backend.sh.in new file mode 100755 index 0000000..4c0c161 --- /dev/null +++ b/backend/backend.sh.in @@ -0,0 +1,96 @@ +#!/bin/bash + +cd "$(dirname "$0")" +SEARCHPATH="@DATA_INSTALL_DIR@" +[ ! -e "$SEARCHPATH" -a -e ./modules ] && SEARCHPATH="." + +for i in $(find $SEARCHPATH/modules/ -type f | sort); do + source $i +done + +function print_usage() +{ +cat <<EOF >&2 +$(basename $0): + + -ni + NonInteractive mode, no prompt is shown and INSTALLER_OUTPUT is set to 1 + -e command + Run "command" + +EOF +exit 0 +} + +function set_debug() +{ + case $1 in + on) + PS4="<acritoxinstaller debug> " + set -x + ;; + off) + set +x + PS4="+" + ;; + esac +} + +if ((UID)); then + p="$PWD/$(basename "$0")" + if [ -x /usr/bin/sudo ]; then + if /usr/bin/sudo -n -l "$p" &>/dev/null; then + /usr/bin/sudo "$p" "$@" + exit $? + fi + fi + if [ -x /usr/lib/kde4/libexec/kdesu ]; then + /usr/lib/kde4/libexec/kdesu --noignorebutton -d -- "$p" --pid $$ "$@" &>/dev/null + exit $? + fi + if [ -z "$as_root" ]; then + for as_root in /usr/bin/kdesu /usr/bin/gksu exec + do + [ -x $as_root ] && break + done + fi + $as_root "$p" --pid $$ "$@" &>/dev/null + exit $? +fi + +while [ "$1" ] +do + case $1 in + "-ni") + export INSTALLER_OUTPUT=1 + ;; + "-e") + shift + eval "$@" + exit $? + ;; + "--pid") + exec 0<"/proc/$2/fd/0" 1>"/proc/$2/fd/1" 2>"/proc/$2/fd/2" + shift + ;; + "-h") + print_usage + ;; + esac + shift +done + +EOT="$(echo -e '\004')" +while true +do + if ((INSTALLER_OUTPUT)); then + echo "<acritoxinstaller prompt>" + IFS=" " read -d "$EOT" -r command params + else + IFS=" " read -er -p "installer> " command params + fi + declare -F ${command}_pre &>/dev/null && eval "${command}_pre" + eval "$command $params" + declare -F ${command}_post &>/dev/null && eval "${command}_post" +done + |