From d2223b6d9806427c50d5fab4ee7bf919c98d0fd1 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 15:17:45 +0100 Subject: ask_option now supports optional (skippable) and required menus. labels and exit codes are applied differently --- src/core/libs/lib-ui-interactive.sh | 30 +++++++++++++++--------------- src/core/libs/lib-ui.sh | 32 ++++++++++++++++++++------------ src/core/procedures/base | 2 +- src/core/procedures/interactive | 8 ++++---- 4 files changed, 40 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index f015082..1e6d42f 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -28,7 +28,7 @@ interactive_configure_system() [ -n "$FILE" ] && DEFAULT="$FILE" helptext= grep -q '^/dev/mapper' $TMP_FSTAB && helptext="Don't forget to add the appropriate modules for your /dev/mapper devices to mkinitcpio.conf" #TODO: we can improve this a bit - ask_option $DEFAULT "Configuration" "$helptext" \ + ask_option $DEFAULT "Configuration" "$helptext" required \ "/etc/rc.conf" "System Config" \ "/etc/fstab" "Filesystem Mountpoints" \ "/etc/mkinitcpio.conf" "Initramfs Config" \ @@ -69,7 +69,7 @@ interactive_timezone () { interactive_time () { # utc or localtime? - ask_option no "Clock configuration" "Is your hardware clock in UTC or local time?" "UTC" " " "localtime" " " || return 1 + ask_option no "Clock configuration" "Is your hardware clock in UTC or local time?" required "UTC" " " "localtime" " " || return 1 HARDWARECLOCK=$ANSWER_OPTION dohwclock @@ -109,7 +109,7 @@ interactive_autoprepare() if [ $(echo $DISCS | wc -w) -gt 1 ] then notify "Available Disks:\n\n$(_getavaildisks)\n" - ask_option no 'Harddrive selection' "Select the hard drive to use" $(finddisks 1 _) || return 1 + ask_option no 'Harddrive selection' "Select the hard drive to use" required $(finddisks 1 _) || return 1 DISC=$ANSWER_OPTION else DISC=$DISCS @@ -148,7 +148,7 @@ interactive_autoprepare() CHOSEN_FS="" while [ "$CHOSEN_FS" = "" ] do - ask_option no 'Filesystem selection' "Select a filesystem for / and /home:" $FSOPTS || return 1 + ask_option no 'Filesystem selection' "Select a filesystem for / and /home:" required $FSOPTS || return 1 FSTYPE=$ANSWER_OPTION ask_yesno "$FSTYPE will be used for / and /home. Is this OK?" yes && CHOSEN_FS=1 done @@ -195,7 +195,7 @@ interactive_partition() { DISC="" while true; do # Prompt the user with a list of known disks - ask_option no 'Disc selection' "Select the disk you want to partition (select DONE when finished)" $DISCS || return 1 + ask_option no 'Disc selection' "Select the disk you want to partition (select DONE when finished)" required $DISCS || return 1 DISC=$ANSWER_OPTION if [ "$DISC" = "OTHER" ]; then ask_string "Enter the full path to the device you wish to partition" "/dev/sda" || return 1 @@ -253,7 +253,7 @@ interactive_filesystem () local old_fs_params=$fs_params ask_option edit "Alter this $fs_type filesystem on $part ?" \ - "Alter $fs_type filesystem (label:$fs_label, mountpoint:$fs_mountpoint) on $part (type:$part_type, label:$part_label) ?" \ + "Alter $fs_type filesystem (label:$fs_label, mountpoint:$fs_mountpoint) on $part (type:$part_type, label:$part_label) ?" required \ edit EDIT delete DELETE #TODO: nicer display if label is empty etc # Don't alter, and return if user cancels @@ -306,7 +306,7 @@ interactive_filesystem () else default= [ -n "$fs_type" ] && default="--default-item $fs_type" - ask_option no "Select filesystem" "Select a filesystem for $part:" $FSOPTS || return 1 + ask_option no "Select filesystem" "Select a filesystem for $part:" required $FSOPTS || return 1 fs_type=$ANSWER_OPTION fi @@ -463,7 +463,7 @@ interactive_filesystems() { menu_list="$menu_list $part $infostring" #don't add extra spaces, dialog doesn't like that. done < $TMP_BLOCKDEVICES - ask_option no "Manage filesystems" "Here you can manage your filesystems, block devices and virtual devices (device mapper). Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." $menu_list DONE _ + ask_option no "Manage filesystems" "Here you can manage your filesystems, block devices and virtual devices (device mapper). Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." required $menu_list DONE _ [ $? -gt 0 ] && USERHAPPY=1 && break [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break @@ -492,7 +492,7 @@ interactive_filesystems() { list="XXX no-LV's-defined-yet-make-a-new-one" fi list="$list empty NEW" - ask_option empty "Manage LV's on this VG" "Edit/create new LV's on this VG:" $list + ask_option empty "Manage LV's on this VG" "Edit/create new LV's on this VG:" required $list EDIT_VG=$ANSWER_OPTION if [ "$ANSWER_OPTION" = XXX -o "$ANSWER_OPTION" = empty ] then @@ -631,7 +631,7 @@ interactive_runtime_network() { return 1 fi - ask_option no "Interface selection" "Select a network interface" $ifaces || return 1 #TODO: code used originaly --nocancel here. what's the use? + make ok button 'select' + ask_option no "Interface selection" "Select a network interface" required $ifaces || return 1 #TODO: code used originaly --nocancel here. what's the use? + make ok button 'select' INTERFACE=$ANSWER_OPTION @@ -763,7 +763,7 @@ EOF notify "No hard drives were found" return 1 fi - ask_option no "Boot device selection" "Select the boot device where the GRUB bootloader will be installed (usually the MBR and not a partition)." $DEVS || return 1 + ask_option no "Boot device selection" "Select the boot device where the GRUB bootloader will be installed (usually the MBR and not a partition)." required $DEVS || return 1 ROOTDEV=$ANSWER_OPTION infofy "Installing the GRUB bootloader..." cp -a $var_TARGET_DIR/usr/lib/grub/i386-pc/* $var_TARGET_DIR/boot/grub/ @@ -785,7 +785,7 @@ EOF fi ask_yesno "Do you have your system installed on software raid?\nAnswer 'YES' to install grub to another hard disk." no if [ $? -eq 0 ]; then - ask_option no "Boot partition device selection" "Please select the boot partition device, this cannot be autodetected!\nPlease redo grub installation for all partitions you need it!" $DEVS || return 1 + ask_option no "Boot partition device selection" "Please select the boot partition device, this cannot be autodetected!\nPlease redo grub installation for all partitions you need it!" required $DEVS || return 1 bootpart=$ANSWER_OPTION fi bootpart=$(mapdev $bootpart) @@ -832,7 +832,7 @@ interactive_select_source() var_FILE_URL="file:///src/core/pkg" var_SYNC_URL= - ask_option no "Source selection" "Please select an installation source" \ + ask_option no "Source selection" "Please select an installation source" required \ "1" "CD-ROM or OTHER SOURCE" \ "2" "FTP/HTTP" || return 1 @@ -866,7 +866,7 @@ interactive_select_mirror() { notify "Keep in mind ftp.archlinux.org is throttled.\nPlease select another mirror to get full download speed." # FIXME: this regex doesn't honor commenting MIRRORS=$(egrep -o '((ftp)|(http))://[^/]*' "${var_MIRRORLIST}" | sed 's|$| _|g') - ask_option no "Mirror selection" "Select an FTP/HTTP mirror" $MIRRORS "Custom" "_" || return 1 + ask_option no "Mirror selection" "Select an FTP/HTTP mirror" required $MIRRORS "Custom" "_" || return 1 local _server=$ANSWER_OPTION if [ "${_server}" = "Custom" ]; then ask_string "Enter the full URL to core repo." "ftp://ftp.archlinux.org/core/os/$var_ARCH" || return 1 @@ -889,7 +889,7 @@ interactive_get_editor() { which nano &>/dev/null && EDITOR_OPTS+=("nano" "nano (easier)") which joe &>/dev/null && EDITOR_OPTS+=("joe" "joe's editor") which vi &>/dev/null && EDITOR_OPTS+=("vi" "vi (advanced)") - ask_option no "Text editor selection" "Select a Text Editor to Use" "${EDITOR_OPTS[@]}" + ask_option no "Text editor selection" "Select a Text Editor to Use" required "${EDITOR_OPTS[@]}" #TODO: this code could be a little bit cleaner. case $ANSWER_OPTION in "nano") EDITOR="nano" ;; diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 9e75cef..e81cbb3 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -190,7 +190,8 @@ ask_number () # $1 default item (set to 'no' for none) # $2 title # $3 additional explanation (default: '') -# shift;shift; $@ list of options. first tag. then name. (eg tagA itemA "tag B" 'item B' ) +# $4 type (required or optional). '' means required. cancel labels will be 'Cancel' and 'Skip' respectively. if (canceled), required will return >0, optional not. +# shift 4 ; $@ list of options. first tag. then name. (eg tagA itemA "tag B" 'item B' ) # the response will be echoed to stdout. but also $ANSWER_OPTION will be set. take that because the former method seems to not work. # $? if user cancelled. 0 otherwise ask_option () @@ -352,16 +353,20 @@ _dia_ask_option () [ "$1" != 'no' ] && DEFAULT="--default-item $1" [ -z "$2" ] && die_error "ask_option \$2 must be the title" # $3 is optional more info - [ -z "$5" ] && debug 'UI' "_dia_ask_option args: $@" && die_error "ask_option makes only sense if you specify at least one option (with tag and name)" #nothing wrong with only 1 option. it still shows useful info to the user + TYPE=${4:-required} + [ -z "$6" ] && debug 'UI' "_dia_ask_option args: $@" && die_error "ask_option makes only sense if you specify at least one option (with tag and name)" #nothing wrong with only 1 option. it still shows useful info to the user DIA_MENU_TITLE=$2 EXTRA_INFO=$3 - shift 3 - _dia_DIALOG $DEFAULT --colors --title " $DIA_MENU_TITLE " --menu "$DIA_MENU_TEXT $EXTRA_INFO" 20 80 16 "$@" 2>$ANSWER + shift 4 + CANCEL_LABEL= + [ $TYPE == optional ] && CANCEL_LABEL='--cancel-label "Skip"' + _dia_DIALOG $DEFAULT $CANCEL_LABEL --colors --title " $DIA_MENU_TITLE " --menu "$DIA_MENU_TEXT $EXTRA_INFO" 20 80 16 "$@" 2>$ANSWER ret=$? ANSWER_OPTION=`cat $ANSWER` debug 'UI' "dia_ask_option: User choose $ANSWER_OPTION ($DIA_MENU_TITLE)" - return $ret + [ $type == required ] && return $ret + return 0 # TODO: check if dialog returned >0 because of an other reason then the user hitting 'cancel/skip' } @@ -407,14 +412,14 @@ _dia_ask_timezone () done while [ "$SET_ZONE" != "1" ]; do SET_REGION="" - ask_option no "Please select a region" '' $REGIONS + ask_option no "Please select a region" '' required $REGIONS region=ANSWER_OPTION if [ $? -eq 0 ]; then ZONES="" for i in $(grep ^[A-Z] /usr/share/zoneinfo/zone.tab | grep $region/ | cut -f 3 | sed -e "s#$region/##g"| sort -u); do ZONES="$ZONES $i -" done - ask_option no "Please select a timezone" '' $ZONES + ask_option no "Please select a timezone" '' required $ZONES zone=$ANSWER_OPTION [ $? -gt 0 ] && ANSWER_TIMEZONE="$region/$zone" && return fi @@ -516,11 +521,12 @@ _cli_ask_option () [ "$1" != 'no' ] && DEFAULT=$1 #TODO: if user forgot to specify a default (eg all args are 1 pos to the left, we can end up in an endless loop :s) [ -z "$2" ] && die_error "ask_option \$2 must be the title" # $3 is optional more info - [ -z "$5" ] && debug 'UI' "_dia_ask_option args: $@" && die_error "ask_option makes only sense if you specify at least one option (with tag and name)" #nothing wrong with only 1 option. it still shows useful info to the user + TYPE=${4:-required} + [ -z "$6" ] && debug 'UI' "_dia_ask_option args: $@" && die_error "ask_option makes only sense if you specify at least one option (with tag and name)" #nothing wrong with only 1 option. it still shows useful info to the user MENU_TITLE=$2 EXTRA_INFO=$3 - shift 3 + shift 4 echo "$MENU_TITLE" [ -n "$EXTRA_INFO" ] && echo "$EXTRA_INFO" @@ -529,7 +535,9 @@ _cli_ask_option () echo "$1 ] $2" shift 2 done - echo "CANCEL ] CANCEL" + CANCEL_LABEL=CANCEL + [ $TYPE == optional ] && CANCEL_LABEL=SKIP + echo "$CANCEL_LABEL ] $CANCEL_LABEL" [ -n "$DEFAULT" ] && echo -n " > [ $DEFAULT ] " [ -z "$DEFAULT" ] && echo -n " > " read ANSWER_OPTION @@ -624,7 +632,7 @@ set_keymap () for i in $(find $KBDDIR/keymaps -name "*.gz" | sort); do KEYMAPS="$KEYMAPS ${i##$KBDDIR/keymaps/} -" done - ask_option "$var_KEYMAP" "Select A Keymap" '' $KEYMAPS && { + ask_option "$var_KEYMAP" "Select A Keymap" '' $KEYMAPS optional && { loadkeys -q $KBDDIR/keymaps/$ANSWER_OPTION var_KEYMAP=$ANSWER_OPTION } @@ -634,7 +642,7 @@ set_keymap () for i in $(find $KBDDIR/consolefonts -maxdepth 1 ! -name '*.cp.gz' -name "*.gz" | sed 's|^.*/||g' | sort); do FONTS="$FONTS $i -" done - ask_option "$var_CONSOLEFONT" "Select A Console Font" '' $FONTS && { + ask_option "$var_CONSOLEFONT" "Select A Console Font" '' optional $FONTS && { var_CONSOLEFONT=$ANSWER_OPTION for i in 1 2 3 4 do diff --git a/src/core/procedures/base b/src/core/procedures/base index 845ce2d..88bd9c3 100644 --- a/src/core/procedures/base +++ b/src/core/procedures/base @@ -104,7 +104,7 @@ worker_set_clock () while true; do default=no [ -n "$NEXTITEM" ] && default="$NEXTITEM" - ask_option $default "Date/time configuration" '' \ + ask_option $default "Date/time configuration" '' required \ "1" "Select region and timezone" \ "2" "Set time and date" \ "3" "Return to Main Menu" diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index 46bd6d7..ec9185a 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -53,7 +53,7 @@ mainmenu() [ -n "$NEXTITEM" ] && default="$NEXTITEM" #TODO: why does a '2' appear instead of '' ?? - ask_option $default "MAIN MENU" '' \ + ask_option $default "MAIN MENU" '' required \ "1" "$worker_select_source_title" \ "2" "$worker_set_clock_title" \ "3" "$worker_prepare_disks_title" \ @@ -96,7 +96,7 @@ mainmenu() select_source_extras_menu () { while true; do - ask_option no "FTP Installation" 'Make sure the network is ok before continuing the installer' \ + ask_option no "FTP Installation" 'Make sure the network is ok before continuing the installer' required \ "1" "$worker_runtime_network_title" \ "2" "$worker_select_mirror_title" \ "3" "Return to Main Menu" @@ -147,7 +147,7 @@ worker_prepare_disks() default=no [ -n "$NEXTITEM" ] && default="$NEXTITEM" - ask_option $default "Prepare Hard Drive" '' \ + ask_option $default "Prepare Hard Drive" '' required \ "1" "Auto-Prepare (erases the ENTIRE hard drive and sets up partitions and filesystems)" \ "2" "Partition Hard Drives" \ "3" "Configure block devices, filesystems and mountpoints" \ @@ -246,7 +246,7 @@ worker_select_mirror () worker_install_bootloader () { - ask_option Grub "Choose bootloader" "Which bootloader would you like to use? Grub is the Arch default." \ + ask_option Grub "Choose bootloader" "Which bootloader would you like to use? Grub is the Arch default." required \ "Grub" "Use the GRUB bootloader (default)" \ "None" "\Zb\Z1Warning\Z0\ZB: you must install your own bootloader!" -- cgit v1.2.3-54-g00ecf