diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/easydialog.in | 152 | ||||
-rw-r--r-- | lib/tools.in | 38 | ||||
-rw-r--r-- | lib/vserver.in | 56 |
3 files changed, 123 insertions, 123 deletions
diff --git a/lib/easydialog.in b/lib/easydialog.in index 056c76c..a0495a7 100644 --- a/lib/easydialog.in +++ b/lib/easydialog.in @@ -20,43 +20,43 @@ DIALOG=dialog HELP= setApplicationTitle() { - BACKTITLE=$* + BACKTITLE=$* } setHelp() { - HELP="$@" + HELP="$@" } setDimension() { - WIDTH=$1 - HEIGHT=$2 + WIDTH=$1 + HEIGHT=$2 } booleanBox() { - $DIALOG --backtitle "$BACKTITLE" --title "$1" \ - `[ "$3" == no ] && echo '--defaultno'` --yesno "$2" $HEIGHT $WIDTH + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + `[ "$3" == no ] && echo '--defaultno'` --yesno "$2" $HEIGHT $WIDTH } msgBox() { - $DIALOG --backtitle "$BACKTITLE" --title "$1" \ - --msgbox "$2" $HEIGHT $WIDTH + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + --msgbox "$2" $HEIGHT $WIDTH } gaugeBox() { - $DIALOG --backtitle "$BACKTITLE" --title "$1" \ - --gauge "$2" $HEIGHT $WIDTH 0 + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + --gauge "$2" $HEIGHT $WIDTH 0 } inputBox() { - local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 - trap "rm -f $temp" 0 - REPLY= - $DIALOG --backtitle "$BACKTITLE" --title "$1" \ - --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp - local status=$? - [ $status = 0 ] && REPLY=$(cat $temp) - rm -f $temp - return $status + local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 + trap "rm -f $temp" 0 + REPLY= + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp + local status=$? + [ $status = 0 ] && REPLY=$(cat $temp) + rm -f $temp + return $status } # Xdialog and {dialog,whiptail} use different mechanism to "qoute" the @@ -67,7 +67,7 @@ inputBox() { # mechanism to the standard double-quoting one. it receives two # arguements, the file that has the data and the box type. _listReplyHook() { - cat $1 + cat $1 } # this is the base implementation of all the list based boxes, it works @@ -75,79 +75,79 @@ _listReplyHook() { # this function with an extra argument specifying the actual box that # needs to be rendered. _genericListBox() { - local box=$1 - shift 1 - local title=$1 - local text=$2 - shift 2 - local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 - trap "rm -f $temp" 0 - REPLY= - $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \ - $box "$text" $HEIGHT $WIDTH 10 \ - "$@" 2> $temp - local status=$? - [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box) - rm -f $temp - _DEFAULT= - return $status + local box=$1 + shift 1 + local title=$1 + local text=$2 + shift 2 + local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 + trap "rm -f $temp" 0 + REPLY= + $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \ + $box "$text" $HEIGHT $WIDTH 10 \ + "$@" 2> $temp + local status=$? + [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box) + rm -f $temp + _DEFAULT= + return $status } setDefault() { - _DEFAULT="--default-item $1" + _DEFAULT="--default-item $1" } menuBox() { - _genericListBox --menu "$@" + _genericListBox --menu "$@" } ## a menu box with additional help info displayed ## at the bottom of the window when an item is selected menuBoxHelp() { - HELP="--item-help" - _genericListBox --menu "$@" - status=$? - HELP= - return $status + HELP="--item-help" + _genericListBox --menu "$@" + status=$? + HELP= + return $status } ## a menu box with an addition button 'help' menuBoxHelpFile() { - HELP="--help-button" - _genericListBox --menu "$@" - status=$? - HELP= - return $status + HELP="--help-button" + _genericListBox --menu "$@" + status=$? + HELP= + return $status } checkBox() { - _genericListBox --checklist "$@" + _genericListBox --checklist "$@" } radioBox() { - _genericListBox --radiolist "$@" + _genericListBox --radiolist "$@" } textBox() { - $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH + $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH } passwordBox() { - local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 - trap "rm -f $temp" 0 - REPLY= - $DIALOG --backtitle "$BACKTITLE" --title "$1" \ - --passwordbox "$2" $HEIGHT $WIDTH 2> $temp - local status=$? - [ $status = 0 ] && REPLY=$(cat $temp) - rm -f $temp - return $status + local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 + trap "rm -f $temp" 0 + REPLY= + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + --passwordbox "$2" $HEIGHT $WIDTH 2> $temp + local status=$? + [ $status = 0 ] && REPLY=$(cat $temp) + rm -f $temp + return $status } ######################################################### ## begin-item-display style lists -## +## ## these lists are built by calling fuctions multiple times. ## this can make it easier to build your list in a loop ## @@ -177,7 +177,7 @@ listDisplay() { boxtype=$1 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 trap "rm -f $temp" 0 - + local label local text local status @@ -188,13 +188,13 @@ listDisplay() { echo -ne " --$boxtype '$_menu_msg' " echo -ne " $HEIGHT $WIDTH 10 " for ((i=0; i < $_menu_items ; i++)); do - label=${_menu_labels[$i]} - text=${_menu_text[$i]} - status=${_menu_status[$i]} - echo -ne " $label '$text' $status " + label=${_menu_labels[$i]} + text=${_menu_text[$i]} + status=${_menu_status[$i]} + echo -ne " $label '$text' $status " done ) | xargs $DIALOG 2> $temp - + local status=$? REPLY="" [ $status = 0 ] && REPLY=`cat $temp` @@ -219,10 +219,10 @@ formItem() { _form_text[$_form_items]=$2 let "_form_items += 1" } - + formDisplay() { local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 - + max_length=0 for ((i=0; i < ${#_form_labels[@]} ; i++)); do label=${_form_labels[$i]} @@ -232,19 +232,19 @@ formDisplay() { fi done let "max_length += 2" - + local xpos=1 ( echo -n -e "--form '$_form_title' 0 0 20" for ((i=0; i < $_form_items ; i++)); do - label=${_form_labels[$i]} - text=${_form_text[$i]} - echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30" - let "xpos += _form_gap" + label=${_form_labels[$i]} + text=${_form_text[$i]} + echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30" + let "xpos += _form_gap" done ) | xargs $DIALOG 2> $temp local status=$? - + ## ## the exit status is meaningless, it is always 0. ## i can't figure out how to get the exit status of dialog @@ -254,7 +254,7 @@ formDisplay() { ## swallowed by xargs. xargs should return different exit status ## depending on the exit status of the command run, but i have ## never been able to get that to work. - ## + ## REPLY= if [ $status = 0 ]; then diff --git a/lib/tools.in b/lib/tools.in index 0005be9..0d368b8 100644 --- a/lib/tools.in +++ b/lib/tools.in @@ -10,39 +10,39 @@ # create a temporary file in a secure way. # function maketemp() { - local tempfile=`mktemp /tmp/$1.XXXXXXXX` - echo $tempfile + local tempfile=`mktemp /tmp/$1.XXXXXXXX` + echo $tempfile } ##################################################### ## CONFIG-FILE RELATED FUNCTIONS function setfile() { - CURRENT_CONF_FILE=$1 + CURRENT_CONF_FILE=$1 } function setsection() { - CURRENT_SECTION=$1 + CURRENT_SECTION=$1 } # # sets a global var with name equal to $1 # to the value of the configuration parameter $1 # $2 is the default. -# +# function getconf() { - CURRENT_PARAM=$1 - ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE` - # if nothing is returned, set the default - if [ "$ret" == "" -a "$2" != "" ]; then - ret="$2" - fi - - # replace * with %, so that it is not globbed. - ret="${ret//\\*/__star__}" - - # this is weird, but single quotes are needed to - # allow for returned values with spaces. $ret is still expanded - # because it is in an 'eval' statement. - eval $1='$ret' + CURRENT_PARAM=$1 + ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE` + # if nothing is returned, set the default + if [ "$ret" == "" -a "$2" != "" ]; then + ret="$2" + fi + + # replace * with %, so that it is not globbed. + ret="${ret//\\*/__star__}" + + # this is weird, but single quotes are needed to + # allow for returned values with spaces. $ret is still expanded + # because it is in an 'eval' statement. + eval $1='$ret' } diff --git a/lib/vserver.in b/lib/vserver.in index 153a9b0..cc96a71 100644 --- a/lib/vserver.in +++ b/lib/vserver.in @@ -66,7 +66,7 @@ init_vservers() { found_vservers=`ls $VROOTDIR | grep -E -v "lost\+found|ARCHIVES" | tr "\n" " "` if [ -z "$found_vservers" ]; then `if [ "$arg" = nodialog ]; then echo warning; else echo "msgBox warning"; fi` \ - "vservers enabled in $conffile, but no vserver was found in $VROOTDIR."; + "vservers enabled in $conffile, but no vserver was found in $VROOTDIR."; return fi vservers_are_available=yes @@ -142,9 +142,9 @@ choose_one_vserver() { while [ -z "$REPLY" ]; do [ -n "$selected_vservers" ] && setDefault $selected_vservers listBegin "$title" "Choose at least one Linux-Vserver to backup:" - for vserver in $found_vservers; do - listItem "$vserver" "Backup $vserver vserver" - done + for vserver in $found_vservers; do + listItem "$vserver" "Backup $vserver vserver" + done listDisplay menu [ $? = 0 ] || return 1 done @@ -152,17 +152,17 @@ choose_one_vserver() { } ## -## If Vservers are not enabled, set host_or_vservers='host' and then return +## If Vservers are not enabled, set host_or_vservers='host' and then return ## Else, have the user choose if he/she wants to perform the backup on the host ## system or on one Vserver. ## Set, respectively, $host_or_vservers to 'host' or 'vservers'. ## Returns 1 if cancelled. ## choose_host_or_one_vserver() { - if [ "$vservers_are_available" != "yes" ] + if [ "$vservers_are_available" != "yes" ] then - host_or_vservers='host' - return + host_or_vservers='host' + return fi local title=$1 # if there is one, set the previously chosen item as the default @@ -173,11 +173,11 @@ choose_host_or_one_vserver() { [ $? = 0 ] || return 1 case $REPLY in "host") - host_or_vservers='host' - ;; + host_or_vservers='host' + ;; "vserver") - host_or_vservers='vservers' - ;; + host_or_vservers='vservers' + ;; esac } @@ -191,10 +191,10 @@ choose_host_or_one_vserver() { ## Returns 1 if cancelled. ## choose_host_or_vservers_or_both() { - if [ "$vservers_are_available" != "yes" ] + if [ "$vservers_are_available" != "yes" ] then - host_or_vservers='host' - return + host_or_vservers='host' + return fi local title=$1 # if there is one, set the previously chosen item as the default @@ -206,14 +206,14 @@ choose_host_or_vservers_or_both() { [ $? = 0 ] || return 1 case $REPLY in "host") - host_or_vservers='host' - ;; + host_or_vservers='host' + ;; "vservers") - host_or_vservers='vservers' - ;; + host_or_vservers='vservers' + ;; "both") - host_or_vservers='both' - ;; + host_or_vservers='both' + ;; esac } @@ -236,13 +236,13 @@ choose_one_or_more_vservers() { local vserver_was_selected= REPLY= while [ -z "$REPLY" ]; do - listBegin "$title" "Choose at least one Linux-Vserver to backup:" - # list existing vservers, preselecting the previously selected ones - for vserver in $found_vservers; do - listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver` - done - listDisplay checklist - [ $? = 0 ] || return 1 + listBegin "$title" "Choose at least one Linux-Vserver to backup:" + # list existing vservers, preselecting the previously selected ones + for vserver in $found_vservers; do + listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver` + done + listDisplay checklist + [ $? = 0 ] || return 1 done # remove quotes around each vserver name selected_vservers=`echo $REPLY | tr -d '"'` |