From fb96730dbfd801c45bc2009c1960d30403ecabc1 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 22 Feb 2009 17:48:13 +0100 Subject: since we use /tmp now, no more need to hide files. some categorizing (tagging) of files is useful though --- src/core/libs/lib-ui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 2315394..0664817 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -6,9 +6,9 @@ # Taken from setup. we store dialog output in a file. TODO: can't we do this with variables? ASKDEV -ANSWER=$RUNTIME_DIR/.dialog-answer +ANSWER=$RUNTIME_DIR/aif-dialog-answer DIA_MENU_TEXT="Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." -DIA_SUCCESSIVE_ITEMS=$RUNTIME_DIR/.dia-successive-items +DIA_SUCCESSIVE_ITEMS=$RUNTIME_DIR/aif-dia-successive-items ### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ### -- cgit v1.2.3-54-g00ecf From 0fb2a618b05a4cc69a8036ba93e07943289fd5dd Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 22 Feb 2009 19:43:58 +0100 Subject: cleanup in blockdevice size stuff. correct usage of units etc. inspired by FS#12949 - "hdparm -I" fails in VMware 0001-Using-fdisk-instead-of-hdparm-to-get-disc-capacity.patch --- src/core/libs/lib-blockdevices-filesystems.sh | 35 ++++++++++++++++----------- src/core/libs/lib-ui-interactive.sh | 6 ++--- src/core/libs/lib-ui.sh | 15 +++++++----- 3 files changed, 33 insertions(+), 23 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 1cbfcbe..28fb51c 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -736,24 +736,31 @@ get_filesystem_program () # $1 blockdevice -# $2 standard SI for 1000*n, IEC for 1024*n (optional. defaults to SI) -# --> Note that if you do SI on a partition, you get the size of the entire disk, so for now you need IEC for single partitions -# output will be in $BLOCKDEVICE_SIZE in MB/MiB +# $2 unit: B, KiB, kB, MiB, MB, GiB or GB. defaults to B (we follow IEEE 1541-2002 ) +# output will be in $BLOCKDEVICE_SIZE # WARNING: hdparm works - by design - only for ide/sata. not scsi et al -# TODO: clean up all disk size related stuff. see http://bugs.archlinux.org/task/12949 get_blockdevice_size () { [ -b "$1" ] || die_error "get_blockdevice_size needs a blockdevice as \$1 ($1 given)" - standard=${2:-SI} - - if [ "$standard" = SI ] - then - BLOCKDEVICE_SIZE=$(hdparm -I $1 | grep -F '1000*1000' | sed "s/^.*:[ \t]*\([0-9]*\) MBytes.*$/\1/") - elif [ "$standard" = IEC ] + unit=${2:-B} + allowed_units=(B KiB kB MiB MB GiB GB) + if ! is_in $unit "${allowed_units[@]}" then - #NOTE: unreliable method: on some interwebs they say 1 block = 512B, on other internets they say 1 block = 1kiB. 1kiB seems to work for me. don't sue me if it doesn't for you - #blocks=`fdisk -s $1` || show_warning "Fdisk problem" "Something failed when trying to do fdisk -s $1" - #BLOCKDEVICE_SIZE=$(($blocks/1024)) - BLOCKDEVICE_SIZE=$((`fdisk -l $1 | sed -n '2p' | cut -d' ' -f5`/1024)) + die_error "Unrecognized unit $unit!" fi + + # NOTES about older, deprecated methods: + # - BLOCKDEVICE_SIZE=$(hdparm -I $1 | grep -F '1000*1000' | sed "s/^.*:[ \t]*\([0-9]*\) MBytes.*$/\1/") # if you do this on a partition, you get the size of the entire disk ! + hdparm only supports sata and ide. not scsi. + # - unreliable method: on some interwebs they say 1 block = 512B, on other internets they say 1 block = 1kiB. 1kiB seemed to work for me. + # blocks=`fdisk -s $1` || show_warning "Fdisk problem" "Something failed when trying to do fdisk -s $1" + # BLOCKDEVICE_SIZE=$(($blocks/1024)) + # + bytes=$((`fdisk -l $1 2>/dev/null | sed -n '2p' | cut -d' ' -f5`)) + [ $unit = B ] && BLOCKDEVICE_SIZE=$bytes + [ $unit = KiB ] && BLOCKDEVICE_SIZE=$(($bytes/2*10)) # /1024 + [ $unit = kB ] && BLOCKDEVICE_SIZE=$(($bytes/10**3)) # /1000 + [ $unit = MiB ] && BLOCKDEVICE_SIZE=$(($bytes/2*20)) # ... + [ $unit = MB ] && BLOCKDEVICE_SIZE=$(($bytes/10**6)) + [ $unit = GiB ] && BLOCKDEVICE_SIZE=$(($bytes/2*30)) + [ $unit = GB ] && BLOCKDEVICE_SIZE=$(($bytes/10**9)) } diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 8fdc5dc..8076a0e 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -113,7 +113,7 @@ interactive_autoprepare() DISC=${DISC// /} # strip all whitespace. we need this for some reason.TODO: find out why - get_blockdevice_size $DISC SI + get_blockdevice_size $DISC MB FSOPTS= which `get_filesystem_program ext2` &>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" which `get_filesystem_program ext3` &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" @@ -449,9 +449,9 @@ interactive_filesystems() { fs_display=${fs//;target/} [ "$label" != no_label ] && label_display="($label)" [ "$label" = no_label ] && label_display= - if [ -b "${part/+/}" ] && get_blockdevice_size ${part/+/} IEC # test -b <-- exit's 0, test -b '' exits >0. + if [ -b "${part/+/}" ] && get_blockdevice_size ${part/+/} MB # test -b <-- exit's 0, test -b '' exits >0. then - infostring="${type},${BLOCKDEVICE_SIZE}MB${label_display}->$fs_display" # add size in MB for existing blockdevices (eg not for mapper devices that are not yet created yet) #TODO: ${BLOCKDEVICE_SIZE} is empty sometimes? + infostring="${type},${BLOCKDEVICE_SIZE}MB${label_display}->$fs_display" # add size in MB for existing blockdevices (eg not for mapper devices that are not yet created yet) else infostring="${type}${label_display}->$fs_display" fi diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 0664817..3a40eb2 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -129,14 +129,17 @@ printk() # TODO: pass disks as argument to decouple backend logic -# Get a list of available disks for use in the "Available disks" dialogs. This -# will print the disks as follows, getting size info from hdparm: -# /dev/sda: 640133 MBytes (640 GB) -# /dev/sdb: 640135 MBytes (640 GB) +# Get a list of available disks for use in the "Available disks" dialogs. +# Something like: +# /dev/sda: 640133 MB (640 GB) +# /dev/sdb: 640135 MB (640 GB) _getavaildisks() { - # NOTE: to test as non-root, stick in a 'sudo' before the hdparm call - for i in $(finddisks); do echo -n "$i: "; hdparm -I $i | grep -F '1000*1000' | sed "s/.*1000:[ \t]*\(.*\)/\1/"; echo "\n"; done + for i in $(finddisks) + do + get_blockdevice_size $i MB + echo "$i: $BLOCKDEVICE_SIZE MB ($(($BLOCKDEVICE_SIZE/1000)) GB)\n" + done } -- cgit v1.2.3-54-g00ecf From 857ede360d7877576fb146b3db5f7cccf2f7658a Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 22 Feb 2009 20:21:56 +0100 Subject: various fixes/features for ask_number --- src/core/libs/lib-ui.sh | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 3a40eb2..70cf9e3 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -131,14 +131,14 @@ printk() # TODO: pass disks as argument to decouple backend logic # Get a list of available disks for use in the "Available disks" dialogs. # Something like: -# /dev/sda: 640133 MB (640 GB) -# /dev/sdb: 640135 MB (640 GB) +# /dev/sda: 640133 MiB (640 GiB) +# /dev/sdb: 640135 MiB (640 GiB) _getavaildisks() { for i in $(finddisks) do - get_blockdevice_size $i MB - echo "$i: $BLOCKDEVICE_SIZE MB ($(($BLOCKDEVICE_SIZE/1000)) GB)\n" + get_blockdevice_size $i MiB + echo "$i: $BLOCKDEVICE_SIZE MiB ($(($BLOCKDEVICE_SIZE/2**10)) GiB)\n" done } @@ -166,17 +166,18 @@ ask_datetime () # ask for a number. # $1 question # $2 lower limit (optional) -# $3 upper limit (optional) -# $4 default : TODO implement in cli -# echo's the number the user said +# $3 upper limit (optional. set 0 for none) +# $4 default (optional) +# sets $ANSWER_NUMBER to the number the user specified # returns 1 if the user cancelled or did not enter a numeric, 0 otherwise ask_number () { [ -z "$1" ] && die_error "ask_number needs a question!" - [ -n "$2" ] && [[ $2 = *[^0-9]* ]] && die_error "ask_number \$2 must be a number! not $2" - [ -n "$3" ] && [[ $3 = *[^0-9]* ]] && die_error "ask_number \$3 must be a number! not $3" - [ "$var_UI_TYPE" = dia ] && { _dia_ask_number "$1" "$2" "$3" ; return $? ; } - [ "$var_UI_TYPE" = cli ] && { _cli_ask_number "$1" "$2" "$3" ; return $? ; } + [ -n "$2" ] && [[ "$2" = *[^0-9]* ]] && die_error "ask_number \$2 must be a number! not $2" + [ -n "$3" ] && [[ "$3" = *[^0-9]* ]] && die_error "ask_number \$3 must be a number! not $3" + [ -n "$4" ] && [[ "$4" = *[^0-9]* ]] && die_error "ask_number \$4 must be a number! not $4" + [ "$var_UI_TYPE" = dia ] && { _dia_ask_number "$1" $2 $3 $4; return $? ; } + [ "$var_UI_TYPE" = cli ] && { _cli_ask_number "$1" $2 $3 $4; return $? ; } } @@ -313,17 +314,17 @@ _dia_ask_number () while true do str="$1" - [ -n "$2" ] && str2="min $2" - [ -n "$3" ] && str2="$str2 max $3" + [ -n $2 ] && str2="min $2" + [ -n $3 -a $3 != '0' ] && str2="$str2 max $3" [ -n "$str2" ] && str="$str ( $str2 )" - _dia_DIALOG --inputbox "$str" 8 65 "$4" 2>$ANSWER + _dia_DIALOG --inputbox "$str" 8 65 $4 2>$ANSWER ret=$? ANSWER_NUMBER=`cat $ANSWER` if [[ $ANSWER_NUMBER = *[^0-9]* ]] #TODO: handle exit state then show_warning "$ANSWER_NUMBER is not a number! try again." else - if [ -n "$3" -a $ANSWER_NUMBER -gt $3 ] + if [ -n "$3" -a $3 != '0' -a $ANSWER_NUMBER -gt $3 ] then show_warning "$ANSWER_NUMBER is bigger then the maximum,$3! try again." elif [ -n "$2" -a $ANSWER_NUMBER -lt $2 ] @@ -457,8 +458,9 @@ _cli_ask_number () while true do str="$1" - [ -n "$2" ] && str2="min $2" - [ -n "$3" ] && str2="$str2 max $3" + [ -n $2 ] && str2="min $2" + [ -n $3 -a $3 != '0' ] && str2="$str2 max $3" + [ -n $4 ] && str2=" default $4" [ -n "$str2" ] && str="$str ( $str2 )" echo "$str" read ANSWER_NUMBER @@ -466,7 +468,15 @@ _cli_ask_number () then show_warning "$ANSWER_NUMBER is not a number! try again." else - break + if [ -n "$3" -a $3 != '0' -a $ANSWER_NUMBER -gt $3 ] + then + show_warning "$ANSWER_NUMBER is bigger then the maximum,$3! try again." + elif [ -n "$2" -a $ANSWER_NUMBER -lt $2 ] + then + show_warning "$ANSWER_NUMBER is smaller then the minimum,$2! try again." + else + break + fi fi done debug "cli_ask_number: user entered: $ANSWER_NUMBER" -- cgit v1.2.3-54-g00ecf From 5cd407fbb9b44b476ae7c9d460594322f465c24f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 25 Feb 2009 22:09:05 +0100 Subject: adding refactored/reordered date/time setting logic into aif. based on tpowa's tz script. this also means an ncurses implementation of timezone selection --- src/core/libs/lib-misc.sh | 17 +++++++++++ src/core/libs/lib-ui-interactive.sh | 60 ++++++++++++++++++++----------------- src/core/libs/lib-ui.sh | 20 ++++++++++++- src/core/procedures/base | 24 ++++++++++++++- 4 files changed, 91 insertions(+), 30 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-misc.sh b/src/core/libs/lib-misc.sh index c7a5d2f..ac66bd1 100644 --- a/src/core/libs/lib-misc.sh +++ b/src/core/libs/lib-misc.sh @@ -68,3 +68,20 @@ cleanup_runtime () mkdir -p $RUNTIME_DIR || die_error "Cannot create $RUNTIME_DIR" rm -rf $RUNTIME_DIR/aif-dia* &>/dev/null } + + +dohwclock() { + infofy "Syncing hardwareclock to systemclock ..." + if [ "$HARDWARECLOCK" = "UTC" ]; then + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" + else + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" + fi + + [ ! -d /var/lib/hwclock ] && mkdir -p /var/lib/hwclock + if [ ! -f /var/lib/hwclock/adjtime ]; then + echo "0.0 0 0.0" > /var/lib/hwclock/adjtime # what the hell is this for??? + fi + hwclock $HWCLOCK_PARAMS #tpowa does it without, but i would add --noadjtime here +} + diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 804d3c3..f99518e 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -57,48 +57,52 @@ interactive_configure_system() } -# set_clock() -# prompts user to set hardware clock and timezone -# -# params: none -# returns: 1 on failure -interactive_set_clock() -{ - # utc or localtime? - ask_option no "Clock configuration" "Is your hardware clock in UTC or local time?" "UTC" " " "localtime" " " || return 1 - HARDWARECLOCK=$ANSWER_OPTION - - # timezone? +interactive_timezone () { ask_timezone || return 1 - TIMEZONE=$ANSWER_TIMEZONE + TIMEZONE=$ANSWER_TIMEZONE + infofy "Setting Timezone to $TIMEZONE" + [ -e /etc/localtime ] && rm -f /etc/localtime #why do we do this?? tpowa? + dohwclock +} + + + +interactive_time () { + # utc or localtime? + ask_option no "Clock configuration" "Is your hardware clock in UTC or local time?" "UTC" " " "localtime" " " || return 1 + HARDWARECLOCK=$ANSWER_OPTION + + dohwclock + + which ntpdate >/dev/null && ask_option yes "'ntpdate' was detected on your system.\n\nDo you want to use 'ntpdate' for syncing your clock,\nby using the internet clock pool?" "(You need a working internet connection for doing this!)" #TODO: only propose if network ok. + if [ $? -eq 0 ]; then + if ntpdate pool.ntp.org >/dev/null + then + notify "Synced clock with internet pool successfully.\n\nYour current time is now:\n$(date)" + else + show_warning 'Ntp failure' "An error has occured, time was not changed!" + fi + else + + # display and ask to set date/time + ask_datetime - # set system clock from hwclock - stolen from rc.sysinit - local HWCLOCK_PARAMS="" - if [ "$HARDWARECLOCK" = "UTC" ] - then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" - else - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" - fi if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ] then /bin/rm -f /etc/localtime /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi - /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile - - # display and ask to set date/time - ask_datetime # save the time date -s "$ANSWER_DATETIME" || show_warning "Date/time setting failed" "Something went wrong when doing date -s $ANSWER_DATETIME" - /sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile - - return 0 + dohwclock } + + + interactive_autoprepare() { DISCS=$(finddisks) diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 70cf9e3..aa1171c 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -395,7 +395,25 @@ _dia_ask_string () _dia_ask_timezone () { - ANSWER_TIMEZONE=`tzselect` #TODO: implement nicer then this + REGIONS="" + SET_ZONE="" + for i in $(grep ^[A-Z] /usr/share/zoneinfo/zone.tab | cut -f 3 | sed -e 's#/.*##g'| sort -u); do + REGIONS="$REGIONS $i -" + done + while ! [ "$SET_ZONE" = "1" ]; do + SET_REGION="" + ask_option no "Please select a region" '' $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 + zone=$ANSWER_OPTION + [ $? -gt 0 ] && ANSWER_TIMEZONE="$region/$zone" && return + fi + done } diff --git a/src/core/procedures/base b/src/core/procedures/base index cf4e7e2..845ce2d 100644 --- a/src/core/procedures/base +++ b/src/core/procedures/base @@ -101,7 +101,29 @@ worker_runtime_packages () worker_set_clock () { - interactive_set_clock + while true; do + default=no + [ -n "$NEXTITEM" ] && default="$NEXTITEM" + ask_option $default "Date/time configuration" '' \ + "1" "Select region and timezone" \ + "2" "Set time and date" \ + "3" "Return to Main Menu" + [ "$ANSWER_OPTION" = 1 ] && execute worker interactive_timezone && NEXTITEM=2 + [ "$ANSWER_OPTION" = 2 ] && check_depend worker interactive_timezone && execute worker interactive_time && NEXTITEM=3 + [ "$ANSWER_OPTION" = 3 ] && break + done +} + + +worker_interactive_timezone () +{ + interactive_timezone +} + + +worker_interactive_time () +{ + interactive_time } -- cgit v1.2.3-54-g00ecf From a44e96a7df3e117b544e26e30df21a26d61ff17a Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Thu, 26 Feb 2009 21:28:23 +0100 Subject: ui function to set keymap and font + partial procedure for it --- TODO | 1 + src/core/libs/lib-ui.sh | 35 ++++++++++++++++++++++++++++++++++- src/core/procedures/partial-keymap | 6 ++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/core/procedures/partial-keymap (limited to 'src/core/libs/lib-ui.sh') diff --git a/TODO b/TODO index c7b04ef..b196487 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,7 @@ See also the FIXME's and TODO's in the code. CURRENT ISSUES: * grub sedding sometimes does, and sometimes doesn't work. default config remains (eg /dev/hda3) +* select timezone -> it hangs :? * when invoking /arch/aif -p interactive on a "normal" pc, it always wants to abort * check everywhere that if users cancels something, we return 1, empty string behavior etc * core/interactive: fix workaround needed for installpkg exitcode diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index aa1171c..53ff8ea 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -9,6 +9,8 @@ ANSWER=$RUNTIME_DIR/aif-dialog-answer DIA_MENU_TEXT="Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." DIA_SUCCESSIVE_ITEMS=$RUNTIME_DIR/aif-dia-successive-items +var_KEYMAP=`sed -n '/^KEYMAP/p' /etc/rc.conf | sed 's/KEYMAP=//' | sed 's/"//g'` #default keymap as configured on install CD. can be overridden +var_CONSOLEFONT=`sed -n '/^CONSOLEFONT/p' /etc/rc.conf | sed 's/KEYMAP=//' | sed 's/"//g'` #default consolefont as configured on install CD. can be overridden ### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ### @@ -400,7 +402,7 @@ _dia_ask_timezone () for i in $(grep ^[A-Z] /usr/share/zoneinfo/zone.tab | cut -f 3 | sed -e 's#/.*##g'| sort -u); do REGIONS="$REGIONS $i -" done - while ! [ "$SET_ZONE" = "1" ]; do + while [ "$SET_ZONE" != "1" ]; do SET_REGION="" ask_option no "Please select a region" '' $REGIONS region=ANSWER_OPTION @@ -610,3 +612,34 @@ _cli_follow_progress () tail -f $2 #TODO: don't block anymore when it's done } + +set_keymap () +{ + KBDDIR="/usr/share/kbd" + + KEYMAPS= + for i in $(find $KBDDIR/keymaps -name "*.gz" | sort); do + KEYMAPS="$KEYMAPS ${i##$KBDDIR/keymaps/} -" + done + ask_option "$var_KEYMAP" "Select A Keymap" '' $KEYMAPS && { + loadkeys -q $KBDDIR/keymaps/$ANSWER_OPTION + var_KEYMAP=$ANSWER_OPTION + } + + FONTS= + # skip .cp.gz and partialfonts files for now see bug #6112, #6111 + 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 && { + var_CONSOLEFONT=$ANSWER_OPTION + for i in 1 2 3 4 + do + if [ -d /dev/vc ]; then + setfont $KBDDIR/consolefonts/$var_CONSOLEFONT -C /dev/vc/$i + else + setfont $KBDDIR/consolefonts/$var_CONSOLEFONT -C /dev/tty$i + fi + done + } +} diff --git a/src/core/procedures/partial-keymap b/src/core/procedures/partial-keymap new file mode 100644 index 0000000..9bb8581 --- /dev/null +++ b/src/core/procedures/partial-keymap @@ -0,0 +1,6 @@ +#!/bin/bash + +start_process () +{ + set_keymap +} -- cgit v1.2.3-54-g00ecf From 8be65c346aa8ca9c7650f935ad608a82250d9a0d Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 13:22:21 +0100 Subject: support for debug categories --- src/aif.sh | 25 +++++++++------- src/core/libs/lib-blockdevices-filesystems.sh | 38 ++++++++++++------------ src/core/libs/lib-misc.sh | 8 ++--- src/core/libs/lib-ui-interactive.sh | 2 +- src/core/libs/lib-ui.sh | 42 +++++++++++++-------------- src/core/procedures/interactive | 2 +- 6 files changed, 61 insertions(+), 56 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/aif.sh b/src/aif.sh index 2e3eac9..618519d 100755 --- a/src/aif.sh +++ b/src/aif.sh @@ -40,6 +40,7 @@ Available procedures: notify () { + debug 'UI' "notify: $@" echo -e "$@" } @@ -52,13 +53,17 @@ log () [ "$LOG_TO_FILE" = 1 ] && echo -e "$str" >> $LOGFILE } - +# $1 = category. one of MAIN, PROCEDURE, UI, UI-INTERACTIVE, FS, MISC, NETWORK, PACMAN, SOFTWARE +# $2 = string to log debug () { + [ "$1" == 'MAIN' -o "$1" == 'PROCEDURE' -o "$1" == 'UI' -o "$1" == 'UI-INTERACTIVE' -o "$1" == 'FS' -o "$1" == 'MISC' -o "$1" == 'NETWORK' -o "$1" == 'PACMAN' -o "$1" == 'SOFTWARE' ] || die_error "debug \$1 ($1) is not a valid debug category" + [ -n "$2" ] || die_error "debug \$2 cannot be empty" + mkdir -p $LOG_DIR || die_error "Cannot create log directory" - str="[DEBUG] $@" if [ "$DEBUG" = "1" ] then + str="[DEBUG $1 ] $2" echo -e "$str" > $LOG [ "$LOG_TO_FILE" = 1 ] && echo -e "$str" >> $LOGFILE fi @@ -132,8 +137,8 @@ load_lib () # $3... extra args for phase/worker (optional) execute () { - [ -z "$1" -o -z "$2" ] && debug "execute $@" && die_error "Use the execute function like this: execute with type=phase/worker" - [ "$1" != phase -a "$1" != worker ] && debug "execute $@" && die_error "execute's first argument must be a valid type (phase/worker)" + [ -z "$1" -o -z "$2" ] && debug 'MAIN' "execute $@" && die_error "Use the execute function like this: execute with type=phase/worker" + [ "$1" != phase -a "$1" != worker ] && debug 'MAIN' "execute $@" && die_error "execute's first argument must be a valid type (phase/worker)" PWD_BACKUP=`pwd` object=$1_$2 @@ -156,11 +161,11 @@ execute () exit_var=exit_$object read $exit_var <<< 0 # TODO: for some reason the hack below does not work (tested in virtualbox), even though it really should. Someday I must get indirect array variables working and clean this up... - # debug "\$1: $1, \$2: $2, \$object: $object, \$exit_$object: $exit_object" - # debug "declare: `declare | grep -e "^${object}=" | cut -d"=" -f 2-`" + # debug 'MAIN' "\$1: $1, \$2: $2, \$object: $object, \$exit_$object: $exit_object" + # debug 'MAIN' "declare: `declare | grep -e "^${object}=" | cut -d"=" -f 2-`" # props to jedinerd at #bash for this hack. # eval phase=$(declare | grep -e "^${object}=" | cut -d"=" -f 2-) - #debug "\$phase: $phase - ${phase[@]}" + #debug 'MAIN' "\$phase: $phase - ${phase[@]}" unset phase [ "$2" = preparation ] && phase=( "${phase_preparation[@]}" ) [ "$2" = basics ] && phase=( "${phase_basics[@]}" ) @@ -169,13 +174,13 @@ execute () # worker_str contains the name of the worker and optionally any arguments for worker_str in "${phase[@]}" do - debug "Loop iteration. \$worker_str: $worker_str" + debug 'MAIN' "Loop iteration. \$worker_str: $worker_str" execute worker $worker_str || read $exit_var <<< $? # assign last failing exit code to exit_phase_, if any. done ret=${!exit_var} fi - debug "Execute(): $object exit state was $ret" + debug 'MAIN' "Execute(): $object exit state was $ret" cd $PWD_BACKUP return $ret } @@ -191,7 +196,7 @@ ended_ok () [ "$1" != phase -a "$1" != worker ] && die_error "ended_ok's first argument must be a valid type (phase/worker)" object=$1_$2 exit_var=exit_$object - debug "Ended_ok? -> Exit state of $object was: ${!exit_var} (if empty. it's not executed yet)" + debug 'MAIN' "Ended_ok? -> Exit state of $object was: ${!exit_var} (if empty. it's not executed yet)" [ "${!exit_var}" = '0' ] && return 0 [ "${!exit_var}" = '' ] && return 1 return ${!exit_var} diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 7369ec4..ae4f5d0 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -278,7 +278,7 @@ target_configure_fstab() # $2 a string of the form: :[:+] (the + is bootable flag) partition() { - debug "Partition called like: partition '$1' '$2'" + debug 'FS' "Partition called like: partition '$1' '$2'" [ -z "$1" ] && die_error "partition() requires a device file and a partition string" [ -z "$2" ] && die_error "partition() requires a partition string" @@ -317,7 +317,7 @@ partition() sfdisk_input=$(printf "$sfdisk_input") # convert \n to newlines # invoke sfdisk - debug "Partition calls: sfdisk $DEVICE -uM >$LOG 2>&1 <<< $sfdisk_input" + debug 'FS' "Partition calls: sfdisk $DEVICE -uM >$LOG 2>&1 <<< $sfdisk_input" printk off sfdisk $DEVICE -uM >$LOG 2>&1 <Already done" + debug 'FS' "$fs_id ->Already done" else # We can't always do -b on the lvm VG. because the devicefile sometimes doesn't exist for a VG. vgdisplay to the rescue! if [ "$part_type" = lvm-vg ] && vgdisplay $part | grep -q 'VG Name' # $part is a lvm VG and it exists. note that vgdisplay exists 0 when the requested vg doesn't exist. then - debug "$fs_id ->Still need to do it: Making the filesystem on a vg volume" + debug 'FS' "$fs_id ->Still need to do it: Making the filesystem on a vg volume" infofy "Making $fs_type filesystem on $part" disks process_filesystem $part $fs_type $fs_create $fs_mountpoint no_mount $fs_opts $fs_label $fs_params && done_filesystems+=("$fs_id") || returncode=1 elif [ "$part_type" != lvm-pv -a -b "$part" ] # $part is not a lvm PV and it exists then - debug "$fs_id ->Still need to do it: Making the filesystem on a non-pv volume" + debug 'FS' "$fs_id ->Still need to do it: Making the filesystem on a non-pv volume" infofy "Making $fs_type filesystem on $part" disks process_filesystem $part $fs_type $fs_create $fs_mountpoint no_mount $fs_opts $fs_label $fs_params && done_filesystems+=("$fs_id") || returncode=1 elif [ "$part_type" = lvm-pv ] && pvdisplay ${fs_params//:/ } >/dev/null # $part is a lvm PV. all needed lvm pv's exist. note that pvdisplay exits 5 as long as one of the args doesn't exist then - debug "$fs_id ->Still need to do it: Making the filesystem on a pv volume" + debug 'FS' "$fs_id ->Still need to do it: Making the filesystem on a pv volume" infofy "Making $fs_type filesystem on $part" disks process_filesystem ${part/+/} $fs_type $fs_create $fs_mountpoint no_mount $fs_opts $fs_label $fs_params && done_filesystems+=("$fs_id") || returncode=1 else - debug "$fs_id ->Cannot do right now..." + debug 'FS' "$fs_id ->Cannot do right now..." open_items=1 fi fi @@ -512,7 +512,7 @@ rollback_filesystems () then if pvdisplay $real_part &>/dev/null then - debug "$part ->Cannot do right now..." + debug 'FS' "$part ->Cannot do right now..." open_items=1 else infofy "Attempting destruction of device $part (type $part_type)" disks @@ -523,7 +523,7 @@ rollback_filesystems () fi fi else - debug "Skipping destruction of device $part (type $part_type) because it doesn't exist" + debug 'FS' "Skipping destruction of device $part (type $part_type) because it doesn't exist" fi elif [ "$part_type" = lvm-pv ] # Can be in use for: lvm-vg then @@ -531,7 +531,7 @@ rollback_filesystems () then if vgdisplay -v 2>/dev/null | grep -q $real_part # check if it's in use then - debug "$part ->Cannot do right now..." + debug 'FS' "$part ->Cannot do right now..." open_items=1 else infofy "Attempting destruction of device $part (type $part_type)" disks @@ -542,7 +542,7 @@ rollback_filesystems () fi fi else - debug "Skipping destruction of device $part (type $part_type) because it doesn't exist" + debug 'FS' "Skipping destruction of device $part (type $part_type) because it doesn't exist" fi elif [ "$part_type" = lvm-vg ] #Can be in use for: lvm-lv then @@ -551,7 +551,7 @@ rollback_filesystems () open_lv=`vgdisplay -c $part 2>/dev/null | cut -d ':' -f6` if [ $open_lv -gt 0 ] then - debug "$part ->Cannot do right now..." + debug 'FS' "$part ->Cannot do right now..." open_items=1 else infofy "Attempting destruction of device $part (type $part_type)" disks @@ -562,7 +562,7 @@ rollback_filesystems () fi fi else - debug "Skipping destruction of device $part (type $part_type) because it doesn't exist" + debug 'FS' "Skipping destruction of device $part (type $part_type) because it doesn't exist" fi elif [ "$part_type" = lvm-lv ] #Can be in use for: dm_crypt or raw. we don't need to care about raw (it will be unmounted so it can be destroyed) then @@ -570,7 +570,7 @@ rollback_filesystems () then if cryptsetup isLuks $part &>/dev/null then - debug "$part ->Cannot do right now..." + debug 'FS' "$part ->Cannot do right now..." open_items=1 else infofy "Attempting destruction of device $part (type $part_type)" disks @@ -581,7 +581,7 @@ rollback_filesystems () fi fi else - debug "Skipping destruction of device $part (type $part_type) because it doesn't exist" + debug 'FS' "Skipping destruction of device $part (type $part_type) because it doesn't exist" fi else die_error "Unrecognised partition type $part_type for partition $part. This should never happen. please report this" @@ -616,7 +616,7 @@ process_filesystem () { [ "$2" != lvm-lv ] && [ -z "$1" -o ! -b "$1" ] && die_error "process_filesystem needs a partition as \$1" # Don't do this for lv's. It's a hack to workaround non-existence of VG device files. [ -z "$2" ] && die_error "process_filesystem needs a filesystem type as \$2" - debug "process_filesystem $@" + debug 'FS' "process_filesystem $@" part=$1 fs_type=$2 fs_create=${3:-yes} @@ -674,12 +674,12 @@ process_filesystem () BLOCK_ROLLBACK_USELESS=0 if [ "$fs_type" = swap ] then - debug "swaponning $part" + debug 'FS' "swaponning $part" swapon $part >$LOG 2>&1 || ( show_warning 'Swapon' "Error activating swap: swapon $part" ; return 1 ) else [ "$fs_mount" = runtime ] && dst=$fs_mountpoint [ "$fs_mount" = target ] && dst=$var_TARGET_DIR$fs_mountpoint - debug "mounting $part on $dst" + debug 'FS' "mounting $part on $dst" mkdir -p $dst &>/dev/null # directories may or may not already exist mount -t $fs_type $part $dst >$LOG 2>&1 || ( show_warning 'Mount' "Error mounting $part on $dst" ; return 1 ) if [ "$fs_mount" = target -a $fs_mountpoint = '/' ] diff --git a/src/core/libs/lib-misc.sh b/src/core/libs/lib-misc.sh index ac66bd1..97252b9 100644 --- a/src/core/libs/lib-misc.sh +++ b/src/core/libs/lib-misc.sh @@ -12,16 +12,16 @@ run_background () [ -z "$2" ] && die_error "run_background needs a command to execute!" [ -z "$3" ] && die_error "run_background needs a logfile to redirect output to!" - debug "run_background called. identifier: $1, command: $2, logfile: $3" + debug 'MISC' "run_background called. identifier: $1, command: $2, logfile: $3" ( \ touch $RUNTIME_DIR/aif-$1-running - debug "run_background starting $1: $2 >>$3 2>&1" + debug 'MISC' "run_background starting $1: $2 >>$3 2>&1" [ -f $3 ] && echo -e "\n\n\n" >>$3 echo "STARTING $1 . Executing $2 >>$3 2>&1\n" >> $3; var_exit=${1}_exitcode eval "$2" >>$3 2>&1 read $var_exit <<< $? #TODO: bash complains about 'not a valid identifier' - debug "run_background done with $1: exitcode (\$$1_exitcode): "${!var_exit}" .Logfile $3" #TODO ${!var_exit} doesn't show anything --> maybe fixed now + debug 'MISC' "run_background done with $1: exitcode (\$$1_exitcode): ${!var_exit} .Logfile $3" #TODO ${!var_exit} doesn't show anything --> maybe fixed now echo >> $3 rm -f $RUNTIME_DIR/aif-$1-running ) & @@ -50,7 +50,7 @@ wait_for () # $2 needle check_is_in () { - [ -z "$1" ] && debug "check_is_in $1 $2" && die_error "check_is_in needs a non-empty needle as \$2 and a haystack as \$1!" # haystack can be empty though + [ -z "$1" ] && debug 'MISC' "check_is_in $1 $2" && die_error "check_is_in needs a non-empty needle as \$2 and a haystack as \$1!" # haystack can be empty though local pattern="$1" element shift diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index ccb912f..f015082 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -417,7 +417,7 @@ remove_blockdevice () declare target_escaped=${target//\//\\/} # note: apparently no need to escape the '+' sign for sed. declare target_escawk=${target_escaped/+/\\+} # ...but that doesn't count for awk fs_string=`awk "/^$target_escawk / { print \$4}" $TMP_BLOCKDEVICES` #TODO: fs_string is the entire line, incl part? - debug "Cleaning up partition $part (type $part_type, label $part_label). It has the following FS's on it: $fs_string" + debug 'UI-INTERACTIVE' "Cleaning up partition $part (type $part_type, label $part_label). It has the following FS's on it: $fs_string" sed -i "/$target_escaped/d" $TMP_BLOCKDEVICES || show_warning "blockdevice removal" "Could not remove partition $part (type $part_type, label $part_label). This is a bug. please report it" for fs in `sed 's/|/ /g' <<< $fs_string` do diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 53ff8ea..bfe49dc 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -18,7 +18,7 @@ var_CONSOLEFONT=`sed -n '/^CONSOLEFONT/p' /etc/rc.conf | sed 's/KEYMAP=//' | sed # display error message and die die_error () { - debug "die_error: ERROR: $@" + debug 'UI' "die_error: ERROR: $@" notify "ERROR: $@" exit 2 } @@ -35,7 +35,7 @@ show_warning () [ -n "$3" -a "$3" != msg -a "$3" != text ] && die_error "show_warning \$3 must be text or msg" type=msg [ -n "$3" ] && type=$3 - debug "show_warning '$1': $2 ($type)" + debug 'UI' "show_warning '$1': $2 ($type)" if [ "$var_UI_TYPE" = dia ] then _dia_DIALOG --title "$1" --exit-label "Continue" --${type}box "$2" 18 70 || die_error "dialog could not show --${type}box $2. often this means a file does not exist" @@ -52,7 +52,7 @@ show_warning () #notify user notify () { - debug "notify: $@" + debug 'UI' "notify: $@" if [ "$var_UI_TYPE" = dia ] then _dia_DIALOG --msgbox "$@" 20 50 @@ -72,7 +72,7 @@ infofy () #TODO: when using successive things, the screen can become full and yo { successive=${2:-0} succ_last=${3:-0} - debug "infofy: $1" + debug 'UI' "infofy: $1" if [ "$var_UI_TYPE" = dia ] then str="$1" @@ -152,7 +152,7 @@ _getavaildisks() ask_checklist () { [ -z "$1" ] && die_error "ask_checklist needs a question!" - [ -z "$4" ] && debug "ask_checklist args: $@" && die_error "ask_checklist makes only sense if you specify at least 1 thing (tag,item and ON/OFF switch)" + [ -z "$4" ] && debug 'UI' "ask_checklist args: $@" && die_error "ask_checklist makes only sense if you specify at least 1 thing (tag,item and ON/OFF switch)" [ "$var_UI_TYPE" = dia ] && { _dia_ask_checklist "$@" ; return $? ; } [ "$var_UI_TYPE" = cli ] && { _cli_ask_checklist "$@" ; return $? ; } } @@ -289,7 +289,7 @@ _dia_ask_checklist () _dia_DIALOG --checklist "$str" 30 60 20 $list 2>$ANSWER ret=$? ANSWER_CHECKLIST=`cat $ANSWER` - debug "_dia_ask_checklist: user checked ON: $ANSWER_CHECKLIST" + debug 'UI' "_dia_ask_checklist: user checked ON: $ANSWER_CHECKLIST" return $ret } @@ -301,7 +301,7 @@ _dia_ask_datetime () local _date="$(cat $ANSWER)" # form like: 07/12/2008 dialog --timebox "Set the time.\nUse to navigate and up/down to change values." 0 0 2> $ANSWER || return 1 local _time="$(cat $ANSWER)" # form like: 15:26:46 - debug "Date as specified by user $_date time: $_time" + debug 'UI' "Date as specified by user $_date time: $_time" # DD/MM/YYYY hh:mm:ss -> MMDDhhmmYYYY.ss (date default format, set like date $ANSWER_DATETIME) Not enabled because there is no use for it i think. # ANSWER_DATETIME=$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\2\1\4\5\3\6#g') @@ -337,7 +337,7 @@ _dia_ask_number () fi fi done - debug "_dia_ask_number: user entered: $ANSWER_NUMBER" + debug 'UI' "_dia_ask_number: user entered: $ANSWER_NUMBER" [ -z "$ANSWER_NUMBER" ] && return 1 return $ret } @@ -349,7 +349,7 @@ _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 "_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 + [ -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 DIA_MENU_TITLE=$2 EXTRA_INFO=$3 @@ -357,7 +357,7 @@ _dia_ask_option () _dia_DIALOG $DEFAULT --colors --title " $DIA_MENU_TITLE " --menu "$DIA_MENU_TEXT $EXTRA_INFO" 20 80 16 "$@" 2>$ANSWER ret=$? ANSWER_OPTION=`cat $ANSWER` - debug "dia_ask_option: User choose $ANSWER_OPTION ($DIA_MENU_TITLE)" + debug 'UI' "dia_ask_option: User choose $ANSWER_OPTION ($DIA_MENU_TITLE)" return $ret } @@ -378,7 +378,7 @@ _dia_ask_password () [ -n "$type_u" ] && read ${type_u}_PASSWORD < $ANSWER [ -z "$type_u" ] && read PASSWORD < $ANSWER cat $ANSWER - debug "_dia_ask_password: user entered <>" + debug 'UI' "_dia_ask_password: user entered <>" return $ret } @@ -389,7 +389,7 @@ _dia_ask_string () _dia_DIALOG --inputbox "$1" 8 65 "$2" 2>$ANSWER ret=$? ANSWER_STRING=`cat $ANSWER` - debug "_dia_ask_string: user entered $ANSWER_STRING" + debug 'UI' "_dia_ask_string: user entered $ANSWER_STRING" [ -z "$ANSWER_STRING" ] && return $exitcode return $ret } @@ -427,8 +427,8 @@ _dia_ask_yesno () [ -n "$2" ] && str="$str (default: $2)" dialog --yesno "$str" $height 55 # returns 0 for yes, 1 for no ret=$? - [ $ret -eq 0 ] && debug "dia_ask_yesno: User picked YES" - [ $ret -gt 0 ] && debug "dia_ask_yesno: User picked NO" + [ $ret -eq 0 ] && debug 'UI' "dia_ask_yesno: User picked YES" + [ $ret -gt 0 ] && debug 'UI' "dia_ask_yesno: User picked NO" return $ret } @@ -468,7 +468,7 @@ _cli_ask_datetime () { ask_string "Enter date [YYYY-MM-DD hh:mm:ss]" ANSWER_DATETIME=$ANSWER_STRING - debug "Date as picked by user: $ANSWER_STRING" + debug 'UI' "Date as picked by user: $ANSWER_STRING" } @@ -499,7 +499,7 @@ _cli_ask_number () fi fi done - debug "cli_ask_number: user entered: $ANSWER_NUMBER" + debug 'UI' "cli_ask_number: user entered: $ANSWER_NUMBER" [ -z "$ANSWER_NUMBER" ] && return 1 return 0 } @@ -513,7 +513,7 @@ _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 "_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 + [ -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 MENU_TITLE=$2 EXTRA_INFO=$3 @@ -531,7 +531,7 @@ _cli_ask_option () [ -z "$DEFAULT" ] && echo -n " > " read ANSWER_OPTION [ -z "$ANSWER_OPTION" -a -n "$DEFAULT" ] && ANSWER_OPTION="$DEFAULT" - debug "cli_ask_option: User choose $ANSWER_OPTION ($MENU_TITLE)" + debug 'UI' "cli_ask_option: User choose $ANSWER_OPTION ($MENU_TITLE)" [ "$ANSWER_OPTION" = CANCEL ] && return 1 return 0 } @@ -565,7 +565,7 @@ _cli_ask_string () [ -n "$2" ] && echo "(Press enter for default. Default: $2)" echo -n ">" read ANSWER_STRING - debug "cli_ask_string: User entered: $ANSWER_STRING" + debug 'UI' "cli_ask_string: User entered: $ANSWER_STRING" if [ -z "$ANSWER_STRING" ] then if [ -n "$2" ] @@ -595,10 +595,10 @@ _cli_ask_yesno () answer=`tr '[:upper:]' '[:lower:]' <<< $answer` if [ "$answer" = y -o "$answer" = yes ] || [ -z "$answer" -a "$2" = yes ] then - debug "cli_ask_yesno: User picked YES" + debug 'UI' "cli_ask_yesno: User picked YES" return 0 else - debug "cli_ask_yesno: User picked NO" + debug 'UI' "cli_ask_yesno: User picked NO" return 1 fi } diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index 051d187..46bd6d7 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -114,7 +114,7 @@ worker_configure_system() # /etc/pacman.d/mirrorlist # add installer-selected mirror to the top of the mirrorlist if [ "$var_PKG_SOURCE_TYPE" = "ftp" -a "${var_SYNC_URL}" != "" ]; then - debug "Adding choosen mirror (${var_SYNC_URL}) to ${var_TARGET_DIR}/$var_MIRRORLIST" + debug 'PROCEDURE' "Adding choosen mirror (${var_SYNC_URL}) to ${var_TARGET_DIR}/$var_MIRRORLIST" mirrorlist=`awk "BEGIN { printf(\"# Mirror used during installation\nServer = "${var_SYNC_URL}"\n\n\") } 1 " "${var_TARGET_DIR}/$var_MIRRORLIST"` echo "$mirrorlist" > "${var_TARGET_DIR}/$var_MIRRORLIST" #TODO: test this, this may not work fi -- cgit v1.2.3-54-g00ecf From 228da8e66ed4b9b1e88d81b5817ffcad9b7dfdac Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 14:45:59 +0100 Subject: cleaner way + fix for correct consolefont and keymap --- src/core/libs/lib-ui.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index bfe49dc..9e75cef 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -9,8 +9,11 @@ ANSWER=$RUNTIME_DIR/aif-dialog-answer DIA_MENU_TEXT="Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." DIA_SUCCESSIVE_ITEMS=$RUNTIME_DIR/aif-dia-successive-items -var_KEYMAP=`sed -n '/^KEYMAP/p' /etc/rc.conf | sed 's/KEYMAP=//' | sed 's/"//g'` #default keymap as configured on install CD. can be overridden -var_CONSOLEFONT=`sed -n '/^CONSOLEFONT/p' /etc/rc.conf | sed 's/KEYMAP=//' | sed 's/"//g'` #default consolefont as configured on install CD. can be overridden + +#default keymap and consolefont configured on install CD. can be overridden +source /etc/rc.conf +var_KEYMAP=$KEYMAP +var_CONSOLEFONT=$CONSOLEFONT ### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ### -- cgit v1.2.3-54-g00ecf 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 ++++---- tests/test-menus.sh | 12 +++++++++--- 5 files changed, 49 insertions(+), 35 deletions(-) (limited to 'src/core/libs/lib-ui.sh') 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!" diff --git a/tests/test-menus.sh b/tests/test-menus.sh index 9288ff6..4d0bd25 100644 --- a/tests/test-menus.sh +++ b/tests/test-menus.sh @@ -4,9 +4,15 @@ ANSWER="/tmp/.dialog-answer" var_UI_TYPE=dia -ask_option no 'menu title is this yes yes' 'extra explanation is here mkay' tagA itemA "tag B" 'item B' tag-c item\ C +ask_option no 'menu title is this yes yes' 'extra explanation is here mkay OPTIONAL' optional tagA itemA "tag B" 'item B' tag-c item\ C +echo "return code was $?" + +ask_option no 'menu title is this yes yes' 'extra explanation is here mkay REQUIRED' required tagA itemA "tag B" 'item B' tag-c item\ C echo "return code was $?" var_UI_TYPE=cli -ask_option tag-c 'menu title is this yes yes' 'extra explanation is here mkay' tagA itemA "tag B" 'item B' tag-c item\ C -echo "return code was $?" \ No newline at end of file +ask_option tag-c 'menu title is this yes yes' 'extra explanation is here mkay OPTIONAL' optional tagA itemA "tag B" 'item B' tag-c item\ C +echo "return code was $?" + +ask_option tag-c 'menu title is this yes yes' 'extra explanation is here mkay REQUIRED' required tagA itemA "tag B" 'item B' tag-c item\ C +echo "return code was $?" -- cgit v1.2.3-54-g00ecf From 9f9c8d5450da681c6920bea816cbf9a0db170879 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 15:29:17 +0100 Subject: set_keymap option dialog fix --- src/core/libs/lib-ui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index e81cbb3..1724ed1 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -632,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 optional && { + ask_option "$var_KEYMAP" "Select A Keymap" '' optional $KEYMAPS && { loadkeys -q $KBDDIR/keymaps/$ANSWER_OPTION var_KEYMAP=$ANSWER_OPTION } -- cgit v1.2.3-54-g00ecf From 7cc05b89cbe71455d5ea3859341908b3af451baa Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 15:35:15 +0100 Subject: ask_option fixes --- src/core/libs/lib-ui.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 1724ed1..5955334 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -359,13 +359,13 @@ _dia_ask_option () DIA_MENU_TITLE=$2 EXTRA_INFO=$3 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 + CANCEL_LABEL=Cancel + [ $TYPE == optional ] && CANCEL_LABEL='Skip' + _dia_DIALOG $DEFAULT --cancel-label $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)" - [ $type == required ] && 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' } -- cgit v1.2.3-54-g00ecf From 0fc9ade9bbd89355acef54733378066aeaf265cb Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 16:02:20 +0100 Subject: ask_option fixes --- src/core/libs/lib-ui.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 5955334..d7481e4 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -190,10 +190,11 @@ ask_number () # $1 default item (set to 'no' for none) # $2 title # $3 additional explanation (default: '') -# $4 type (required or optional). '' means required. cancel labels will be 'Cancel' and 'Skip' respectively. if (canceled), required will return >0, optional not. +# $4 type (required or optional). '' means required. cancel labels will be 'Cancel' and 'Skip' respectively. # 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 + +# $ANSWER_OPTION : selected answer (if none selected: default (if available), or empty string otherwise). if user hits cancel or skip, this is an empty string. +# $? : 0 if the user selected anything or skipped (when optional), when user cancelled: 1 ask_option () { [ "$var_UI_TYPE" = dia ] && { _dia_ask_option "$@" ; return $? ; } @@ -517,7 +518,7 @@ _cli_ask_option () { #TODO: strip out color codes #TODO: if user entered incorrect choice, ask him again - DEFAULT="" + DEFAULT= [ "$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 @@ -544,6 +545,7 @@ _cli_ask_option () [ -z "$ANSWER_OPTION" -a -n "$DEFAULT" ] && ANSWER_OPTION="$DEFAULT" debug 'UI' "cli_ask_option: User choose $ANSWER_OPTION ($MENU_TITLE)" [ "$ANSWER_OPTION" = CANCEL ] && return 1 + [ -z "$ANSWER_OPTION" -a type == required ] && return 1 return 0 } -- cgit v1.2.3-54-g00ecf From 4d7dbff90b8333deb2c2c3c0dbd1aa3e9aafa3d5 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 16:09:46 +0100 Subject: fixes in set_keymap --- src/core/libs/lib-ui.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index d7481e4..b7f24f9 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -634,17 +634,21 @@ 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" '' optional $KEYMAPS && { + ask_option "$var_KEYMAP" "Select A Keymap" '' optional $KEYMAPS + if [ -n "$ANSWER_OPTION" ] + then loadkeys -q $KBDDIR/keymaps/$ANSWER_OPTION var_KEYMAP=$ANSWER_OPTION - } + fi FONTS= # skip .cp.gz and partialfonts files for now see bug #6112, #6111 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" '' optional $FONTS && { + ask_option "$var_CONSOLEFONT" "Select A Console Font" '' optional $FONTS + if [ -n "$ANSWER_OPTION" ] + then var_CONSOLEFONT=$ANSWER_OPTION for i in 1 2 3 4 do @@ -654,5 +658,5 @@ set_keymap () setfont $KBDDIR/consolefonts/$var_CONSOLEFONT -C /dev/tty$i fi done - } + fi } -- cgit v1.2.3-54-g00ecf From a22294e811ffc7b5765aa0b7190b438588222e1b Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 16:29:49 +0100 Subject: error checking on $TYPE in ask_option --- src/core/libs/lib-ui.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index b7f24f9..336a3e7 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -355,6 +355,7 @@ _dia_ask_option () [ -z "$2" ] && die_error "ask_option \$2 must be the title" # $3 is optional more info TYPE=${4:-required} + [ "$TYPE" != required -a "$TYPE" != optional ] && debug 'UI' "_dia_ask_option args: $@" && die_error "ask option \$4 must be required or optional or ''. not $TYPE" [ -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 @@ -523,6 +524,7 @@ _cli_ask_option () [ -z "$2" ] && die_error "ask_option \$2 must be the title" # $3 is optional more info TYPE=${4:-required} + [ "$TYPE" != required -a "$TYPE" != optional ] && debug 'UI' "_dia_ask_option args: $@" && die_error "ask option \$4 must be required or optional or ''. not $TYPE" [ -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 -- cgit v1.2.3-54-g00ecf From 008773ad691bfa59bc3e0a1ef89b798cea5107bf Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 28 Feb 2009 17:07:01 +0100 Subject: clearer debugging in ask_option functions + fixes in cli_ask_option + font fix in set_keymap --- src/core/libs/lib-ui.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 336a3e7..90afeba 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -366,7 +366,7 @@ _dia_ask_option () _dia_DIALOG $DEFAULT --cancel-label $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)" + debug 'UI' "dia_ask_option: ANSWER_OPTION: $ANSWER_OPTION, returncode (skip/cancel): $ret ($DIA_MENU_TITLE)" [ $TYPE == required ] && return $ret return 0 # TODO: check if dialog returned >0 because of an other reason then the user hitting 'cancel/skip' } @@ -544,11 +544,14 @@ _cli_ask_option () [ -n "$DEFAULT" ] && echo -n " > [ $DEFAULT ] " [ -z "$DEFAULT" ] && echo -n " > " read ANSWER_OPTION + ret=0 [ -z "$ANSWER_OPTION" -a -n "$DEFAULT" ] && ANSWER_OPTION="$DEFAULT" - debug 'UI' "cli_ask_option: User choose $ANSWER_OPTION ($MENU_TITLE)" - [ "$ANSWER_OPTION" = CANCEL ] && return 1 - [ -z "$ANSWER_OPTION" -a type == required ] && return 1 - return 0 + [ "$ANSWER_OPTION" == CANCEL ] && ret=1 && ANSWER_OPTION= + [ "$ANSWER_OPTION" == SKIP ] && ret=0 && ANSWER_OPTION= + [ -z "$ANSWER_OPTION" -a "$TYPE" == required ] && ret=1 + + debug 'UI' "cli_ask_option: ANSWER_OPTION: $ANSWER_OPTION, returncode (skip/cancel): $ret ($MENU_TITLE)" + return $ret } @@ -648,7 +651,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" '' optional $FONTS + ask_option "${var_CONSOLEFONT:-no}" "Select A Console Font" '' optional $FONTS if [ -n "$ANSWER_OPTION" ] then var_CONSOLEFONT=$ANSWER_OPTION -- cgit v1.2.3-54-g00ecf From 931ab8f34899cabe293df900d19f470c50537ce6 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 1 Mar 2009 17:59:07 +0100 Subject: fix for undefined die_error + avoid loops --- src/aif.sh | 10 +++++++++- src/core/libs/lib-ui.sh | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/aif.sh b/src/aif.sh index 92467d9..54ed0a7 100755 --- a/src/aif.sh +++ b/src/aif.sh @@ -35,7 +35,15 @@ Available procedures: } -##### TMP functions that we need during early bootstrap but will be overidden with decent functions by libraries ###### +##### TMP functions that we need during early bootstrap but will be overidden with decent functions from libraries ###### + + +# Do not call other functions like debug, notify, .. here because that might cause loops! +die_error () +{ + echo "ERROR: $@" >&2 + exit 2 +} notify () diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 90afeba..76aeecf 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -19,10 +19,10 @@ var_CONSOLEFONT=$CONSOLEFONT # display error message and die +# Do not call other functions like debug, notify, .. here because that might cause loops! die_error () { - debug 'UI' "die_error: ERROR: $@" - notify "ERROR: $@" + echo "ERROR: $@" >&2 exit 2 } -- cgit v1.2.3-54-g00ecf From 08c0adf9142dffb6a001466d5d4772e11c20c2e1 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 1 Mar 2009 18:32:30 +0100 Subject: port my previous fixes to lib-ui --- src/core/libs/lib-ui.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 76aeecf..cb40c9e 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -98,12 +98,12 @@ log () str="[LOG] `date +"%Y-%m-%d %H:%M:%S"` $@" if [ "$var_UI_TYPE" = dia ] then - echo -e "$str" >$LOG + echo -e "$str" >$LOG || die_error "Cannot log $str to $LOG" else - echo -e "$str" >$LOG + echo -e "$str" >$LOG || die_error "Cannot log $str to $LOG" fi - [ "$LOG_TO_FILE" = 1 ] && echo -e "$str" >> $LOGFILE + [ "$LOG_TO_FILE" = 1 ] && ( echo -e "$str" >> $LOGFILE || die_error "Cannot log $str to $LOGFILE" ) } @@ -114,11 +114,11 @@ debug () then if [ "$var_UI_TYPE" = dia ] then - echo -e "$str" > $LOG + echo -e "$str" > $LOG || die_error "Cannot debug $str to $LOG" else - echo -e "$str" > $LOG + echo -e "$str" > $LOG || die_error "Cannot debug $str to $LOG" fi - [ "$LOG_TO_FILE" = 1 ] && echo -e "$str" >> $LOGFILE + [ "$LOG_TO_FILE" = 1 ] && ( echo -e "$str" >> $LOGFILE || die_error "Cannot debug $str to $LOGFILE" ) fi } -- cgit v1.2.3-54-g00ecf From 178f56fa2a83511ad56b10f2848ebea4bc8ed656 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 6 Mar 2009 19:07:31 +0100 Subject: load lib-ui in early bootstrap so we dont need to define some functions redundantly in aif.sh --- src/aif.sh | 49 ++++-------------------------------- src/core/libs/lib-ui.sh | 66 ++++++++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 77 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/aif.sh b/src/aif.sh index 78275de..09c1f8b 100755 --- a/src/aif.sh +++ b/src/aif.sh @@ -11,11 +11,15 @@ LOG_DIR=/var/log/aif LOGFILE=$LOG_DIR/aif.log +###### Early bootstrap ###### + +# load the lib-ui, it is one we need everywhere so we must load it early. +source $LIB_CORE/libs/lib-ui.sh || ( echo "Something went wrong while sourcing library $LIB_CORE/libs/lib-ui.sh" >&2 && exit 2) + ###### Miscalleaneous functions ###### usage () { - #NOTE: you can't use dia mode here yet because lib-ui isn't sourced yet. But cli is ok for this anyway. msg="aif -p Select a procedure # If given, this *must* be the first option -i Override interface type (optional) -d Explicitly enable debugging (optional) @@ -32,49 +36,6 @@ Available procedures: [ -n "$procedure" ] && msg="$msg\nProcedure ($procedure) specific options:\n$var_ARGS_USAGE" echo -e "$msg" - -} - -##### TMP functions that we need during early bootstrap but will be overidden with decent functions from libraries ###### - - -# Do not call other functions like debug, notify, .. here because that might cause loops! -die_error () -{ - echo "ERROR: $@" >&2 - exit 2 -} - - -notify () -{ - debug 'UI' "notify: $@" - echo -e "$@" -} - - -log () -{ - mkdir -p $LOG_DIR || die_error "Cannot create log directory" - str="[LOG] `date +"%Y-%m-%d %H:%M:%S"` $@" - echo -e "$str" > $LOG || die_error "Cannot log $str to $LOG" - [ "$LOG_TO_FILE" = 1 ] && ( echo -e "$str" >> $LOGFILE || die_error "Cannot log $str to $LOGFILE" ) -} - -# $1 = category. one of MAIN, PROCEDURE, UI, UI-INTERACTIVE, FS, MISC, NETWORK, PACMAN, SOFTWARE -# $2 = string to log -debug () -{ - [ "$1" == 'MAIN' -o "$1" == 'PROCEDURE' -o "$1" == 'UI' -o "$1" == 'UI-INTERACTIVE' -o "$1" == 'FS' -o "$1" == 'MISC' -o "$1" == 'NETWORK' -o "$1" == 'PACMAN' -o "$1" == 'SOFTWARE' ] || die_error "debug \$1 ($1) is not a valid debug category" - [ -n "$2" ] || die_error "debug \$2 cannot be empty" - - mkdir -p $LOG_DIR || die_error "Cannot create log directory" - if [ "$DEBUG" = "1" ] - then - str="[DEBUG $1 ] $2" - echo -e "$str" > $LOG || die_error "Cannot debug $str to $LOG" - [ "$LOG_TO_FILE" = 1 ] && ( echo -e "$str" >> $LOGFILE || die_error "Cannot debug $str to $LOGFILE" ) - fi } diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index cb40c9e..a67388a 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Note that $var_UI_TYPE may not be set here. especially if being loaded in the "early bootstrap" phase + # TODO: implement 'retry until user does it correctly' everywhere # TODO: at some places we should check if $1 etc is only 1 word because we often depend on that # TODO: standardize. eg everything $1= question/title, $2=default @@ -18,12 +20,13 @@ var_CONSOLEFONT=$CONSOLEFONT ### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ### + # display error message and die # Do not call other functions like debug, notify, .. here because that might cause loops! die_error () { echo "ERROR: $@" >&2 - exit 2 + exit 2 } @@ -33,25 +36,25 @@ die_error () # $3 type of item. msg or text if it's a file. (optional. defaults to msg) show_warning () { - [ -z "$1" ] && die_error "show_warning needs a title" - [ -z "$2" ] && die_error "show_warning needs an item to show" - [ -n "$3" -a "$3" != msg -a "$3" != text ] && die_error "show_warning \$3 must be text or msg" - type=msg - [ -n "$3" ] && type=$3 - debug 'UI' "show_warning '$1': $2 ($type)" - if [ "$var_UI_TYPE" = dia ] - then - _dia_DIALOG --title "$1" --exit-label "Continue" --${type}box "$2" 18 70 || die_error "dialog could not show --${type}box $2. often this means a file does not exist" - else - echo "WARNING: $1" - [ "${type}" = msg ] && echo -e "$2" - [ "${type}" = text ] && (cat $2 || die_error "Could not cat $2") - fi + [ -z "$1" ] && die_error "show_warning needs a title" + [ -z "$2" ] && die_error "show_warning needs an item to show" + [ -n "$3" -a "$3" != msg -a "$3" != text ] && die_error "show_warning \$3 must be text or msg" + type=msg + [ -n "$3" ] && type=$3 + debug 'UI' "show_warning '$1': $2 ($type)" + if [ "$var_UI_TYPE" = dia ] + then + _dia_DIALOG --title "$1" --exit-label "Continue" --${type}box "$2" 18 70 || die_error "dialog could not show --${type}box $2. often this means a file does not exist" + else + echo "WARNING: $1" + [ "${type}" = msg ] && echo -e "$2" + [ "${type}" = text ] && (cat $2 || die_error "Could not cat $2") + fi return 0 } - - + + #notify user notify () { @@ -91,38 +94,35 @@ infofy () #TODO: when using successive things, the screen can become full and yo fi } - # logging of stuff log () { + mkdir -p $LOG_DIR || die_error "Cannot create log directory" str="[LOG] `date +"%Y-%m-%d %H:%M:%S"` $@" - if [ "$var_UI_TYPE" = dia ] - then - echo -e "$str" >$LOG || die_error "Cannot log $str to $LOG" - else - echo -e "$str" >$LOG || die_error "Cannot log $str to $LOG" - fi + echo -e "$str" > $LOG || die_error "Cannot log $str to $LOG" [ "$LOG_TO_FILE" = 1 ] && ( echo -e "$str" >> $LOGFILE || die_error "Cannot log $str to $LOGFILE" ) } +# $1 = category. one of MAIN, PROCEDURE, UI, UI-INTERACTIVE, FS, MISC, NETWORK, PACMAN, SOFTWARE +# $2 = string to log debug () { - str="[DEBUG] $@" + [ "$1" == 'MAIN' -o "$1" == 'PROCEDURE' -o "$1" == 'UI' -o "$1" == 'UI-INTERACTIVE' -o "$1" == 'FS' -o "$1" == 'MISC' -o "$1" == 'NETWORK' -o "$1" == 'PACMAN' -o "$1" == 'SOFTWARE' ] || die_error "debug \$1 ($1) is not a valid debug category" + [ -n "$2" ] || die_error "debug \$2 cannot be empty" + + mkdir -p $LOG_DIR || die_error "Cannot create log directory" if [ "$DEBUG" = "1" ] then - if [ "$var_UI_TYPE" = dia ] - then - echo -e "$str" > $LOG || die_error "Cannot debug $str to $LOG" - else - echo -e "$str" > $LOG || die_error "Cannot debug $str to $LOG" - fi - [ "$LOG_TO_FILE" = 1 ] && ( echo -e "$str" >> $LOGFILE || die_error "Cannot debug $str to $LOGFILE" ) - fi + str="[DEBUG $1 ] $2" + echo -e "$str" > $LOG || die_error "Cannot debug $str to $LOG" + [ "$LOG_TO_FILE" = 1 ] && ( echo -e "$str" >> $LOGFILE || die_error "Cannot debug $str to $LOGFILE" ) + fi } + # taken from setup printk() { -- cgit v1.2.3-54-g00ecf From 2943c75ea213347975eec9b4b92c96cae8214f50 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 7 Mar 2009 10:51:25 +0100 Subject: switched dialog to use autosizing everywhere. lets see what this gives... --- src/core/libs/lib-ui.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index a67388a..fcb5c83 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -44,7 +44,7 @@ show_warning () debug 'UI' "show_warning '$1': $2 ($type)" if [ "$var_UI_TYPE" = dia ] then - _dia_DIALOG --title "$1" --exit-label "Continue" --${type}box "$2" 18 70 || die_error "dialog could not show --${type}box $2. often this means a file does not exist" + _dia_DIALOG --title "$1" --exit-label "Continue" --${type}box "$2" 0 0 || die_error "dialog could not show --${type}box $2. often this means a file does not exist" else echo "WARNING: $1" [ "${type}" = msg ] && echo -e "$2" @@ -61,7 +61,7 @@ notify () debug 'UI' "notify: $@" if [ "$var_UI_TYPE" = dia ] then - _dia_DIALOG --msgbox "$@" 20 50 + _dia_DIALOG --msgbox "$@" 0 0 else echo -e "$@" fi @@ -88,7 +88,7 @@ infofy () #TODO: when using successive things, the screen can become full and yo str=`cat $DIA_SUCCESSIVE_ITEMS-$successive` fi [ "$succ_last" = 1 ] && rm $DIA_SUCCESSIVE_ITEMS-$successive - _dia_DIALOG --infobox "$str" 20 50 + _dia_DIALOG --infobox "$str" 0 0 else echo -e "$1" fi @@ -291,7 +291,7 @@ _dia_ask_checklist () list="$list $1 $2 $3" shift 3 done - _dia_DIALOG --checklist "$str" 30 60 20 $list 2>$ANSWER + _dia_DIALOG --checklist "$str" 0 0 0 $list 2>$ANSWER ret=$? ANSWER_CHECKLIST=`cat $ANSWER` debug 'UI' "_dia_ask_checklist: user checked ON: $ANSWER_CHECKLIST" @@ -324,7 +324,7 @@ _dia_ask_number () [ -n $2 ] && str2="min $2" [ -n $3 -a $3 != '0' ] && str2="$str2 max $3" [ -n "$str2" ] && str="$str ( $str2 )" - _dia_DIALOG --inputbox "$str" 8 65 $4 2>$ANSWER + _dia_DIALOG --inputbox "$str" 0 0 $4 2>$ANSWER ret=$? ANSWER_NUMBER=`cat $ANSWER` if [[ $ANSWER_NUMBER = *[^0-9]* ]] #TODO: handle exit state @@ -363,7 +363,7 @@ _dia_ask_option () shift 4 CANCEL_LABEL=Cancel [ $TYPE == optional ] && CANCEL_LABEL='Skip' - _dia_DIALOG $DEFAULT --cancel-label $CANCEL_LABEL --colors --title " $DIA_MENU_TITLE " --menu "$DIA_MENU_TEXT $EXTRA_INFO" 20 80 16 "$@" 2>$ANSWER + _dia_DIALOG $DEFAULT --cancel-label $CANCEL_LABEL --colors --title " $DIA_MENU_TITLE " --menu "$DIA_MENU_TEXT $EXTRA_INFO" 0 0 0 "$@" 2>$ANSWER ret=$? ANSWER_OPTION=`cat $ANSWER` debug 'UI' "dia_ask_option: ANSWER_OPTION: $ANSWER_OPTION, returncode (skip/cancel): $ret ($DIA_MENU_TITLE)" @@ -396,7 +396,7 @@ _dia_ask_password () _dia_ask_string () { exitcode=${3:-1} - _dia_DIALOG --inputbox "$1" 8 65 "$2" 2>$ANSWER + _dia_DIALOG --inputbox "$1" 0 0 "$2" 2>$ANSWER ret=$? ANSWER_STRING=`cat $ANSWER` debug 'UI' "_dia_ask_string: user entered $ANSWER_STRING" @@ -447,7 +447,7 @@ _dia_follow_progress () { title=$1 logfile=$2 - _dia_DIALOG --title "$1" --no-kill --tailboxbg "$2" 18 70 2>$ANSWER + _dia_DIALOG --title "$1" --no-kill --tailboxbg "$2" 0 0 2>$ANSWER } -- cgit v1.2.3-54-g00ecf From 177d1a660bbdd3f46e82bc888adc84cc785509a5 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 8 Mar 2009 18:44:32 +0100 Subject: support multiple debug categories --- src/core/libs/lib-ui.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index fcb5c83..df48715 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -105,11 +105,17 @@ log () } -# $1 = category. one of MAIN, PROCEDURE, UI, UI-INTERACTIVE, FS, MISC, NETWORK, PACMAN, SOFTWARE +# $1 = one or more categories (separated by spaces) from: MAIN, PROCEDURE, UI, UI-INTERACTIVE, FS, MISC, NETWORK, PACMAN, SOFTWARE +# You should always at least specify where you are (main, procedure or the name of the lib) and optionally further specification: eg in a ui function that works with pacman. +# This is very useful in ui-interactive where we always work with something else. # $2 = string to log debug () { - [ "$1" == 'MAIN' -o "$1" == 'PROCEDURE' -o "$1" == 'UI' -o "$1" == 'UI-INTERACTIVE' -o "$1" == 'FS' -o "$1" == 'MISC' -o "$1" == 'NETWORK' -o "$1" == 'PACMAN' -o "$1" == 'SOFTWARE' ] || die_error "debug \$1 ($1) is not a valid debug category" + valid_cats=(MAIN PROCEDURE UI UI-INTERACTIVE FS MISC NETWORK PACMAN SOFTWARE) + for cat in $1 + do + check_is_in $cat "${valid_cats[@]}" || die_error "debug \$1 contains a value ($cat) which is not a valid debug category" + done [ -n "$2" ] || die_error "debug \$2 cannot be empty" mkdir -p $LOG_DIR || die_error "Cannot create log directory" -- cgit v1.2.3-54-g00ecf From 122c7b94299080a049de507d8a1bc5d8ce2de78c Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Thu, 12 Mar 2009 19:33:22 +0100 Subject: todo update --- src/core/libs/lib-ui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index df48715..a8c242b 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -7,7 +7,7 @@ # TODO: figure out something to make dia windows always big enough, yet fit nicely in the terminal -# Taken from setup. we store dialog output in a file. TODO: can't we do this with variables? ASKDEV +# Taken from setup. we store dialog output in a file. TODO: a variable would be cleaner ANSWER=$RUNTIME_DIR/aif-dialog-answer DIA_MENU_TEXT="Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." DIA_SUCCESSIVE_ITEMS=$RUNTIME_DIR/aif-dia-successive-items -- cgit v1.2.3-54-g00ecf From 7de8cf4fe3d38f508c721fdd7c50963f40699892 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Thu, 12 Mar 2009 20:56:37 +0100 Subject: various fixes re:keymap/font. + auto updating rc.conf in all procedures --- src/core/libs/lib-misc.sh | 5 +++++ src/core/libs/lib-ui.sh | 18 +++++++++++++----- src/core/procedures/base | 6 ++++++ src/core/procedures/interactive | 3 ++- 4 files changed, 26 insertions(+), 6 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-misc.sh b/src/core/libs/lib-misc.sh index c30e4cb..327a4c5 100644 --- a/src/core/libs/lib-misc.sh +++ b/src/core/libs/lib-misc.sh @@ -87,3 +87,8 @@ dohwclock() { hwclock $HWCLOCK_PARAMS #tpowa does it without, but i would add --noadjtime here } +target_configure_initial_keymap_font () +{ + [ -n "$var_KEYMAP" ] && sed -i "s/^KEYMAP=.*/KEYMAP=\"$var_KEYMAP\"/" ${var_TARGET_DIR}/etc/rc.conf + [ -n "$var_CONSOLEFONT" ] && sed -i "s/^CONSOLEFONT=.*/CONSOLEFONT=\"$var_CONSOLEFONT\"/" ${var_TARGET_DIR}/etc/rc.conf +} \ No newline at end of file diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index a8c242b..9719cbf 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -12,10 +12,16 @@ ANSWER=$RUNTIME_DIR/aif-dialog-answer DIA_MENU_TEXT="Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." DIA_SUCCESSIVE_ITEMS=$RUNTIME_DIR/aif-dia-successive-items -#default keymap and consolefont configured on install CD. can be overridden -source /etc/rc.conf -var_KEYMAP=$KEYMAP -var_CONSOLEFONT=$CONSOLEFONT + +# get keymap/font (maybe configured by aif allready in another process or even in another shell) +# otherwise, take default keymap and consolefont as configured in /etc/rc.conf. can be overridden +# Note that the vars in /etc/rc.conf can also be empty! +[ -e $RUNTIME_DIR/aif-keymap ] && var_KEYMAP=` cat $RUNTIME_DIR/aif-keymap` +[ -e $RUNTIME_DIR/aif-consolefont ] && var_CONSOLEFONT=`cat $RUNTIME_DIR/aif-consolefont` +[ -z "$var_KEYMAP" ] && source /etc/rc.conf && var_KEYMAP=$KEYMAP +[ -z "$var_CONSOLEFONT" ] && source /etc/rc.conf && var_CONSOLEFONT=$CONSOLEFONT + + ### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ### @@ -645,11 +651,12 @@ 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" '' optional $KEYMAPS + ask_option "${var_KEYMAP:-no}" "Select A Keymap" '' optional $KEYMAPS if [ -n "$ANSWER_OPTION" ] then loadkeys -q $KBDDIR/keymaps/$ANSWER_OPTION var_KEYMAP=$ANSWER_OPTION + echo "$var_KEYMAP" > $RUNTIME_DIR/aif-keymap fi FONTS= @@ -669,5 +676,6 @@ set_keymap () setfont $KBDDIR/consolefonts/$var_CONSOLEFONT -C /dev/tty$i fi done + echo "$var_CONSOLEFONT" > $RUNTIME_DIR/aif-consolefont fi } diff --git a/src/core/procedures/base b/src/core/procedures/base index 88bd9c3..379b154 100644 --- a/src/core/procedures/base +++ b/src/core/procedures/base @@ -31,6 +31,7 @@ phase_system=(\ auto_fstab \ auto_network \ auto_locale \ + auto_keymap_font \ configure_system \ mkinitcpio \ locales \ @@ -169,6 +170,11 @@ worker_auto_locale () } +worker_auto_keymap_font () +{ + target_configure_initial_keymap_font +} + worker_configure_system () { #TODO: what to do here? diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index ca9e489..0e59066 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -78,7 +78,8 @@ mainmenu() check_depend worker package_list && \ check_depend worker select_source && execute worker install_packages && { execute worker auto_fstab ; \ ended_ok worker runtime_network && execute worker auto_network ; \ - execute worker auto_locale ; } && NEXTITEM=6 ;; + execute worker auto_locale ; \ + execute worker auto_keymap_font; } && NEXTITEM=6 ;; "6") check_depend worker install_packages && execute worker configure_system && { execute worker mkinitcpio ; \ execute worker locales ; -- cgit v1.2.3-54-g00ecf From a97a7ec396b082f8315a46bf57875c4088a9bbc8 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Thu, 12 Mar 2009 21:33:36 +0100 Subject: support for storing the pid of background wrapper processes + support for non-blocking following of text files (eg tail --pid) --- src/core/libs/lib-misc.sh | 5 +++-- src/core/libs/lib-software.sh | 4 ++-- src/core/libs/lib-ui.sh | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-misc.sh b/src/core/libs/lib-misc.sh index 327a4c5..0b77d93 100644 --- a/src/core/libs/lib-misc.sh +++ b/src/core/libs/lib-misc.sh @@ -3,6 +3,7 @@ # run a process in the background, and log it's stdout and stderr to a specific logfile # returncode is stored in $_exitcode +# pid of the backgrounded wrapper process is stored in BACKGROUND_PID (this is _not_ the pid of $2) # $1 identifier -> WARNING: do never ever use -'s or other fancy characters here. only numbers, letters and _ please. (because $_exitcode must be a valid bash variable!) # $2 command (will be eval'ed) # $3 logfile @@ -25,6 +26,7 @@ run_background () echo >> $3 rm -f $RUNTIME_DIR/aif-$1-running ) & + BACKGROUND_PID=$! sleep 2 } @@ -38,11 +40,10 @@ wait_for () while [ -f $RUNTIME_DIR/aif-$1-running ] do - #TODO: follow_progress dialog mode = nonblocking (so check and sleep is good), cli mode (tail -f )= blocking? (so check is probably not needed as it will be done) sleep 1 done - kill $(cat $ANSWER) #TODO: this may not work when mode = cli + kill $(cat $ANSWER) #TODO: this may not work when mode = cli (<--i wrote this before i used tail -f --pid. i don't remember what i meant with it). TODO: huh?? ANSWER? } diff --git a/src/core/libs/lib-software.sh b/src/core/libs/lib-software.sh index 5969ab6..51a6539 100644 --- a/src/core/libs/lib-software.sh +++ b/src/core/libs/lib-software.sh @@ -10,7 +10,7 @@ run_mkinitcpio() target_special_fs on run_background mkinitcpio "chroot $var_TARGET_DIR /sbin/mkinitcpio -p kernel26" $TMP_MKINITCPIO_LOG - follow_progress "Rebuilding initcpio images ..." $TMP_MKINITCPIO_LOG + follow_progress "Rebuilding initcpio images ..." $TMP_MKINITCPIO_LOG $BACKGROUND_PID wait_for mkinitcpio target_special_fs off @@ -31,7 +31,7 @@ installpkg() { [ -n "$TARGET_GROUPS" ] && ALL_PACKAGES="$ALL_PACKAGES "`list_packages group "$TARGET_GROUPS" | awk '{print $2}'` ALL_PACKAGES=`echo $ALL_PACKAGES` run_background pacman_installpkg "$PACMAN_TARGET --noconfirm -S $ALL_PACKAGES" $TMP_PACMAN_LOG #TODO: There may be something wrong here. See http://projects.archlinux.org/?p=installer.git;a=commitdiff;h=f504e9ecfb9ecf1952bd8dcce7efe941e74db946 ASKDEV (Simo) - follow_progress " Installing... Please Wait " $TMP_PACMAN_LOG + follow_progress " Installing... Please Wait " $TMP_PACMAN_LOG $BACKGROUND_PID wait_for pacman_installpkg diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 9719cbf..c438dc2 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -262,6 +262,7 @@ ask_yesno () # follow the progress of something by showing it's log, updating real-time # $1 title # $2 logfile +# $3 pid to monitor. if process stopped, stop following (only used in cli mode) follow_progress () { [ -z "$1" ] && die_error "follow_progress needs a title!" @@ -639,8 +640,8 @@ _cli_follow_progress () title=$1 logfile=$2 echo "Title: $1" - tail -f $2 - #TODO: don't block anymore when it's done + [ -n "$3" ] && tail -f $2 --pid=$3 + [ -z "$3" ] && tail -f $2 } set_keymap () -- cgit v1.2.3-54-g00ecf From 8ae2a7c43fb2ae4b6f01c57f35a526d5d32e3605 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Thu, 12 Mar 2009 22:03:18 +0100 Subject: follow_progress fix --- src/core/libs/lib-ui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index c438dc2..57c0383 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -267,8 +267,8 @@ follow_progress () { [ -z "$1" ] && die_error "follow_progress needs a title!" [ -z "$2" ] && die_error "follow_progress needs a logfile to follow!" - [ "$var_UI_TYPE" = dia ] && { _dia_follow_progress "$1" "$2" ; return $? ; } - [ "$var_UI_TYPE" = cli ] && { _cli_follow_progress "$1" "$2" ; return $? ; } + [ "$var_UI_TYPE" = dia ] && { _dia_follow_progress "$@" ; return $? ; } + [ "$var_UI_TYPE" = cli ] && { _cli_follow_progress "$@" ; return $? ; } } -- cgit v1.2.3-54-g00ecf From 9b9ad8567f1246322904ee2a603b7e6f7f69c768 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 13 Mar 2009 17:37:53 +0100 Subject: fix for kill dialogs forked process from the follow_progress call in wait_for --- src/core/libs/lib-misc.sh | 3 ++- src/core/libs/lib-software.sh | 4 ++-- src/core/libs/lib-ui.sh | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-misc.sh b/src/core/libs/lib-misc.sh index 0b77d93..9ce0fd8 100644 --- a/src/core/libs/lib-misc.sh +++ b/src/core/libs/lib-misc.sh @@ -34,6 +34,7 @@ run_background () # wait until a process is done # $1 identifier. WARNING! see above +# $2 pid of a process to kill when done (optional). useful for dialog --no-kill --tailboxbg's pid. wait_for () { [ -z "$1" ] && die_error "wait_for needs an identifier to known on which command to wait!" @@ -43,7 +44,7 @@ wait_for () sleep 1 done - kill $(cat $ANSWER) #TODO: this may not work when mode = cli (<--i wrote this before i used tail -f --pid. i don't remember what i meant with it). TODO: huh?? ANSWER? + [ -n "$2" ] && kill $2 } diff --git a/src/core/libs/lib-software.sh b/src/core/libs/lib-software.sh index 51a6539..455a3cc 100644 --- a/src/core/libs/lib-software.sh +++ b/src/core/libs/lib-software.sh @@ -11,7 +11,7 @@ run_mkinitcpio() run_background mkinitcpio "chroot $var_TARGET_DIR /sbin/mkinitcpio -p kernel26" $TMP_MKINITCPIO_LOG follow_progress "Rebuilding initcpio images ..." $TMP_MKINITCPIO_LOG $BACKGROUND_PID - wait_for mkinitcpio + wait_for mkinitcpio $FOLLOW_PID target_special_fs off @@ -33,7 +33,7 @@ installpkg() { run_background pacman_installpkg "$PACMAN_TARGET --noconfirm -S $ALL_PACKAGES" $TMP_PACMAN_LOG #TODO: There may be something wrong here. See http://projects.archlinux.org/?p=installer.git;a=commitdiff;h=f504e9ecfb9ecf1952bd8dcce7efe941e74db946 ASKDEV (Simo) follow_progress " Installing... Please Wait " $TMP_PACMAN_LOG $BACKGROUND_PID - wait_for pacman_installpkg + wait_for pacman_installpkg $FOLLOW_PID local _result='' diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 57c0383..dc207e6 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -460,7 +460,7 @@ _dia_follow_progress () { title=$1 logfile=$2 - _dia_DIALOG --title "$1" --no-kill --tailboxbg "$2" 0 0 2>$ANSWER + FOLLOW_PID=`_dia_DIALOG --title "$1" --no-kill --tailboxbg "$2" 0 0 2>&1 >/dev/null` } -- cgit v1.2.3-54-g00ecf From 49b6cbba082c7d9fd42d1a11713ad71ffebeaf27 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 15 Mar 2009 22:15:35 +0100 Subject: reset previous FOLLOW_PID --- src/core/libs/lib-ui.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index dc207e6..50d087a 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -267,6 +267,7 @@ follow_progress () { [ -z "$1" ] && die_error "follow_progress needs a title!" [ -z "$2" ] && die_error "follow_progress needs a logfile to follow!" + FOLLOW_PID= [ "$var_UI_TYPE" = dia ] && { _dia_follow_progress "$@" ; return $? ; } [ "$var_UI_TYPE" = cli ] && { _cli_follow_progress "$@" ; return $? ; } } -- cgit v1.2.3-54-g00ecf