From ba9b80f15ad31509840926f7568ddfc57921ad60 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 31 Oct 2008 17:00:41 +0100 Subject: lots of changes related to making the choice of the UI between cli and dialog fully transparant. this is a work in progress --- src/fifa.sh | 70 +++++++++++++++++++++++++++++++-------------- src/lib/lib-ui.sh | 32 ++++++++++++++++++++- src/lib/whatsthis.txt | 5 ++-- src/profiles/profile-base | 7 +++-- src/profiles/profile-dieter | 4 +-- 5 files changed, 88 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/fifa.sh b/src/fifa.sh index 52635ca..28bc8c8 100755 --- a/src/fifa.sh +++ b/src/fifa.sh @@ -14,36 +14,63 @@ PACMAN_TARGET="pacman --root $TARGET_DIR --config /tmp/pacman.conf" usage () { - echo "$0 " - echo "If the profilename starts with 'http://' it will be wget'ed. Otherwise it's assumed to be a profile file like /home/arch/fifa/profile-" - echo "If you wrote your own profile, you can also save it yourself as /home/arch/fifa/profile-custom or something like that" - echo "Available profiles:" - ls -l /home/arch/fifa/profile-* - echo "Extra info:" - echo "There is a very basic but powerfull workflow defined by variables, phases and workers. Depending on the profile you choose (or write yourself), these will differ." - echo "they are very recognizable and are named like this:" - echo " - variable -> var_" - echo " - phase -> phase_ (a function that calls workers and maybe does some stuff by itself. There are 4 phases: preparation, basics, system, finish. (executed in that order)" - echo " - worker -> worker_ ( a worker function, called by a phase. implements some specific logic. eg runtime_packages, prepare_disks, package_list etc)" - echo "If you specify a profile name other then base, the base profile will be sourced first, then the specific profile. This way you only need to override specific things." - echo "Notes:" - echo " - you _can_ override _all_ variables and functions in this script, but you should be able to achieve your goals by overriding things of these 3 classes)" - echo " - you _must_ specify a profile, to avoid errors. take 'base' if unsure" - echo " - don't edit the base profile (or any other that comes by default), rather make your own" + if [ "$var_UI_TYPE" = dia ] + then + #TODO: do this + true + else + echo "$0 " + echo "If the profilename starts with 'http://' it will be wget'ed. Otherwise it's assumed to be a profile file like /home/arch/fifa/profile-" + echo "If you wrote your own profile, you can also save it yourself as /home/arch/fifa/profile-custom or something like that" + echo "Available profiles:" + ls -l /home/arch/fifa/profile-* + echo "Extra info:" + echo "There is a very basic but powerfull workflow defined by variables, phases and workers. Depending on the profile you choose (or write yourself), these will differ." + echo "they are very recognizable and are named like this:" + echo " - variable -> var_" + echo " - phase -> phase_ (a function that calls workers and maybe does some stuff by itself. There are 4 phases: preparation, basics, system, finish. (executed in that order)" + echo " - worker -> worker_ ( a worker function, called by a phase. implements some specific logic. eg runtime_packages, prepare_disks, package_list etc)" + echo "If you specify a profile name other then base, the base profile will be sourced first, then the specific profile. This way you only need to override specific things." + echo "Notes:" + echo " - you _can_ override _all_ variables and functions in this script, but you should be able to achieve your goals by overriding things of these 3 classes)" + echo " - you _must_ specify a profile, to avoid errors. take 'base' if unsure" + echo " - don't edit the base profile (or any other that comes by default), rather make your own" + fi } +##### "These functions would fit more in lib-ui, but we need them immediately" functions ###### + die_error () { - echo "ERROR: $@" + if [ "$var_UI_TYPE" = dia ] + then + DIALOG --msgbox "Error: $@" 0 0 + else + echo "ERROR: $@" + fi exit 2 } +notify () +{ + if [ "$var_UI_TYPE" = dia ] + then + #TODO: implement this + true + else + echo "$@" + fi +} + + +###### Core functions ###### + load_profile() { [ -z "$1" ] && die_error "load_profile needs a profile argument" - echo "Loading profile $1 ..." + notify "Loading profile $1 ..." if [[ $1 =~ ^http:// ]] then profile=/home/arch/fifa/profile-downloaded-`basename $1` @@ -60,7 +87,7 @@ load_library () [ -z "$1" ] && die_error "load_library needs a library argument" for library in $@ do - echo "Loading library $library ..." + notify "Loading library $library ..." source $library || die_error "Something went wrong while sourcing library $library" done } @@ -70,8 +97,8 @@ execute () { [ -z "$1" -o -z "$2" ] && die_error "Use the execute function like this: execute with type=phase/worker" [ "$1" != phase -a "$1" != worker ] && die_error "execute's first argument must be a valid type (phase/worker)" - [ "$1" = phase ] && echo "******* Executing phase $2" - [ "$1" = worker ] && echo "*** Executing worker $2" + [ "$1" = phase ] && notify "******* Executing phase $2" + [ "$1" = worker ] && notify "*** Executing worker $2" if type -t $1_$2 | grep -q function then PWD_BACKUP=`pwd` @@ -84,7 +111,6 @@ execute () - ###### perform actual logic ###### echo "Welcome to $TITLE" [ -z "$1" ] && usage && exit 1 diff --git a/src/lib/lib-ui.sh b/src/lib/lib-ui.sh index 5cd7ecc..37f316e 100644 --- a/src/lib/lib-ui.sh +++ b/src/lib/lib-ui.sh @@ -58,4 +58,34 @@ gui_ask_bootloader() "None" "\Zb\Z1Warning\Z0\ZB: you must install your own bootloader!" 2>$ANSWER cat $ANSWER } - \ No newline at end of file + + +# ask the user a password. return is stored in $PASSWORD or $PASSWORD_TYPE +# $1 type (optional. eg 'svn', 'ssh'). +cli_ask_password () +{ + if [ -n "$1" ] + then + true + fi +} + +cli_ask_yesno () +{ +} + +cli_ask_string () +{ +} + + +cli_ask_number () +{ +} + + +cli_ask_option () +{ +} + + \ No newline at end of file diff --git a/src/lib/whatsthis.txt b/src/lib/whatsthis.txt index 1125767..72e5e15 100644 --- a/src/lib/whatsthis.txt +++ b/src/lib/whatsthis.txt @@ -1,7 +1,7 @@ This directory contains several useful functions and scripts, ready to be used by fifa and it's profiles. -Right now, all this code is taken (and modified) from the 'real' arch linux install scripts +Most of this code is taken (and modified) from the 'real' arch linux install scripts code. (/arch/setup and /arch/quickinst). the modifications are mostly done to make the code more useable and to separate backend code from the user interface (which was tightly coupled in the original scripts) @@ -11,4 +11,5 @@ I couldn't find what license the code is under, but I assume this is okay.. if not let me know. The original code is at http://projects.archlinux.org/?p=installer.git;a=summary -Later on, maybe other code can be put here too. +I also wrote a few functions myself that I didn't find in the official +scripts (mostly separate ui functions) diff --git a/src/profiles/profile-base b/src/profiles/profile-base index 4c5f77c..72df3b1 100644 --- a/src/profiles/profile-base +++ b/src/profiles/profile-base @@ -7,6 +7,7 @@ var_PKG_SOURCE_TYPE='cd' var_PKG_FILE=/home/arch/fifa/package-list var_FILE_URL="file:///src/core/pkg" var_MIRRORLIST="/etc/pacman.d/mirrorlist" +var_UI_TYPE="cli" # set to cli or dia for dialog ###### Phases ( can be overridden by more specific profiles) ###### @@ -57,7 +58,7 @@ worker_prepare_disks () worker_package_list () { #TODO: sensible list of packages - echo "No actions specified" + true } @@ -75,12 +76,12 @@ worker_install_packages () worker_install_bootlader () { #TODO: autodetection or whatever - echo "No actions specified" + true } worker_configure_home () { - echo "No actions specified" + notify "No actions specified" } diff --git a/src/profiles/profile-dieter b/src/profiles/profile-dieter index a0c369f..8580fd4 100644 --- a/src/profiles/profile-dieter +++ b/src/profiles/profile-dieter @@ -4,7 +4,7 @@ var_RUNTIME_PACKAGES="svn" phase_preparation () { # All things that need to be done manually first - echo "A few manual things need to happen 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 ] @@ -25,7 +25,7 @@ phase_preparation () #TODO: find something against svn's interactive ssl cert checking. http://www.7php.net/svn-client-certificate-authentication-cache/ might help - echo "**** From now on. everything will be automatic. Enjoy the show!" + notify "**** From now on. everything will be automatic. Enjoy the show!" execute worker runtime_packages } -- cgit v1.2.3-54-g00ecf