summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDieter Plaetinck <dieter@plaetinck.be>2008-11-01 12:29:53 +0100
committerDieter Plaetinck <dieter@plaetinck.be>2008-11-01 12:29:53 +0100
commitd91ae3dbc9c145d83ffe1e6aeb0989aa47a7ee80 (patch)
treea8ed6b5078c91aebb9a6121569e36d0e544cf777
parent451e9389c1fcc2093c6c9d60cc4c7b1e93673bb0 (diff)
some implementation stuff done in lib-ui, adapted profile-dieter also a bit for it. still a long way to go
-rw-r--r--src/lib/lib-ui.sh139
-rw-r--r--src/profiles/profile-dieter14
2 files changed, 121 insertions, 32 deletions
diff --git a/src/lib/lib-ui.sh b/src/lib/lib-ui.sh
index 37f316e..657e07a 100644
--- a/src/lib/lib-ui.sh
+++ b/src/lib/lib-ui.sh
@@ -1,15 +1,72 @@
#!/bin/sh
+# TODO: lot's of implementation work still open in this library. especially the dialog stuff
-# DIALOG() taken from setup
-# an el-cheapo dialog wrapper
-#
-# parameters: see dialog(1)
-# returns: whatever dialog did
-DIALOG()
+
+# Taken from setup. we store dialog output in a file. TODO: can't we do this with variables?
+ANSWER="/tmp/.setup"
+
+
+
+### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ###
+
+
+# ask the user a password. return is stored in $PASSWORD or $<TYPE>_PASSWORD
+# $1 type (optional. eg 'svn', 'ssh').
+ask_password ()
{
- dialog --backtitle "$TITLE" --aspect 15 "$@"
- return $?
+ [ "$var_UI_TYPE" = dia ] && { _dia_ask_password $@ ; return $? }
+ [ "$var_UI_TYPE" = cli ] && { _cli_ask_password $@ ; return $? }
+}
+
+
+# ask a yes/no question.
+# $1 question
+# returns 0 if response is Y or y. 1 otherwise
+# TODO: support for default answer
+ask_yesno ()
+{
+ [ -z "$1" ] && die_error "ask_yesno needs a question!"
+ [ "$var_UI_TYPE" = dia ] && { _dia_ask_yesno $@ ; return $? }
+ [ "$var_UI_TYPE" = cli ] && { _cli_ask_yesno $@ ; return $? }
+}
+
+
+# ask for a string.
+# $1 question
+# echo's the string the user gave.
+# returns 1 if the user cancelled, 0 otherwise
+ask_string ()
+{
+ [ -z "$1"] && die_error "ask_string needs a question!"
+ [ "$var_UI_TYPE" = dia ] && { _dia_ask_string $@ ; return $? }
+ [ "$var_UI_TYPE" = cli ] && { _cli_ask_string $@ ; return $? }
+}
+
+
+# ask for a number.
+# $1 question
+# $2 lower limit (optional)
+# $3 upper limit (optional)
+# echo's the number the user said
+# 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!"
+ [ "$var_UI_TYPE" = dia ] && { _dia_ask_number $@ ; return $? }
+ [ "$var_UI_TYPE" = cli ] && { _cli_ask_number $@ ; return $? }
}
+
+
+# ask the user to choose something
+# TODO: exact implementation, which arguments etc?
+ask_option ()
+{
+ [ "$var_UI_TYPE" = dia ] && { _dia_ask_option $@ ; return $? }
+ [ "$var_UI_TYPE" = cli ] && { _cli_ask_option $@ ; return $? }
+}
+
+
+
# taken from setup
@@ -22,11 +79,30 @@ printk()
}
-# geteditor(). taken from original setup code. prepended gui_ because power users just export $EDITOR on the cmdline.
+
+
+
+### Internal functions, supposed to be only used internally in this library ###
+
+
+# DIALOG() taken from setup
+# an el-cheapo dialog wrapper
+#
+# parameters: see dialog(1)
+# returns: whatever dialog did
+_dia_DIALOG()
+{
+ dialog --backtitle "$TITLE" --aspect 15 "$@"
+ return $?
+}
+
+
+# geteditor(). taken from original setup code. prepended dia_ because power users just export $EDITOR on the cmdline.
# prompts the user to choose an editor
# sets EDITOR global variable
#
-gui_geteditor() {
+# TODO: clean this up
+_dia_geteditor() {
DIALOG --menu "Select a Text Editor to Use" 10 35 3 \
"1" "nano (easier)" \
"2" "vi" 2>$ANSWER
@@ -37,12 +113,12 @@ gui_geteditor() {
esac
}
-
+# 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)
-gui_getavaildisks()
+_dia_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
@@ -50,7 +126,8 @@ gui_getavaildisks()
# taken from setup code. edited to echo the choice, not perform it
-gui_ask_bootloader()
+# TODO: also an ugly function
+_dia_ask_bootloader()
{
DIALOG --colors --menu "Which bootloader would you like to use? Grub is the Arch default.\n\n" \
10 65 2 \
@@ -60,31 +137,49 @@ gui_ask_bootloader()
}
-# ask the user a password. return is stored in $PASSWORD or $PASSWORD_TYPE
-# $1 type (optional. eg 'svn', 'ssh').
-cli_ask_password ()
+_cli_ask_password ()
{
if [ -n "$1" ]
then
- true
- fi
+ type_l=`tr '[:upper:]' '[:lower:]' <<< $1`
+ type_u=`tr '[:lower:]' '[:upper:]' <<< $1`
+ else
+ type_l=
+ type_u=
+ fi
+
+ echo -n "Enter your $type_l password: "
+ stty -echo
+ [ -n "$type_u" ] && read ${type_u}_PASSWORD
+ [ -z "$type_u" ] && read PASSWORD
+ stty echo
+ echo
}
-cli_ask_yesno ()
+_cli_ask_yesno ()
{
+ echo -n "$1 (y/n)"
+ read answer
+ if [ "$answer" = y -o "$answer" = Y ]
+ then
+ return 0
+ else
+ return 1
+ fi
}
-cli_ask_string ()
+
+_cli_ask_string ()
{
}
-cli_ask_number ()
+_cli_ask_number ()
{
}
-cli_ask_option ()
+_cli_ask_option ()
{
}
diff --git a/src/profiles/profile-dieter b/src/profiles/profile-dieter
index 8580fd4..ae90b7b 100644
--- a/src/profiles/profile-dieter
+++ b/src/profiles/profile-dieter
@@ -5,20 +5,14 @@ phase_preparation ()
{
# All things that need to be done manually first
notify "A few manual things need to happen first..."
- echo -n "Do you want to (re)-configure your networking? (y/*)"
- read answer
- if [ "$answer" = y ]
+ if `ask_yesno "Do you want to (re)-configure your networking?"`
then
- donetwork #configure network by using lib-archboot function.
+ donetwork #configure network by using library
else
- echo "Ok. skipping network config"
+ notify "Ok. skipping network config"
fi
SVN_USERNAME=dieter
- stty -echo
- echo -n "Enter your svn password: "
- read SVN_PASSWORD
- stty echo
- echo
+ ask_password svn
SVN="svn --username $SVN_USERNAME --password $SVN_PASSWORD"
SVN_BASE=https://192.168.1.2/svn/repos
TARGET_HOST=mbp-santa-rosa #TODO: prompt user for this, or let him pass it as cmdline argument