#!/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 <&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=" " set -x ;; off) set +x PS4="+" ;; esac } # Synopsis: get_root ["X"] # # This function makes sure the user has root-privileges. # Argument X means it won't use "sudo" to gain root-privileges, because sudo doesn't support X-applications function get_root() { if ((UID)); then p="$PWD/$(basename "$0")" if [ -x /usr/bin/sudo -a "$1" != "X" ]; then if /usr/bin/sudo -n -l "$p" &>/dev/null; then /usr/bin/sudo "$p" "${O_ARGS[@]}" exit $? fi fi if [ -x /usr/lib/kde4/libexec/kdesu ]; then /usr/lib/kde4/libexec/kdesu --noignorebutton -d -- "$p" --pid $$ "${O_ARGS[@]}" &>/dev/null exit $? fi if [ -z "$as_root" ]; then for as_root in kdesu gksu exec do which $as_root &>/dev/null && break done fi $as_root -- "$p" --pid $$ "${O_ARGS[@]}" &>/dev/null exit $? fi } O_ARGS=( "${@}" ) 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 get_root EOT="$(echo -e '\004')" while true do if ((INSTALLER_OUTPUT)); then echo "" 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