From b2aaf8f173e56cb11bf9a6090dfcda4fc956074c Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 9 Dec 2008 15:39:00 +0100 Subject: basic overridable implementation of commandline argument parsing --- src/aif.sh | 81 +++++++++++++++++++++++++++++++---------- src/core/procedures/base | 7 ++++ src/core/procedures/interactive | 8 +++- 3 files changed, 76 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/aif.sh b/src/aif.sh index 095256b..2e3c0de 100755 --- a/src/aif.sh +++ b/src/aif.sh @@ -5,15 +5,16 @@ TITLE="Arch Linux Installation Framework" LOG="/dev/tty7" LOGFILE=/home/arch/aif/runtime/aif.log -#TODO: maybe we could use optional flags to en/disable logging to a file, override UI_TYPE etc. - - ###### 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="$0 \n + msg="$0 -p Select a procedure\n + -i Override interface type (optional)\n + -d Explicitly enable debugging (optional)\n + -l Explicitly enable logging to file (optional)\n + -h Help: show usage (optional) If the procedurename starts with 'http://' it will be wget'ed. Otherwise it's assumed to be a procedure in the VFS tree If the procedurename is prefixed with '/' it will be loaded from user module . See README\n Available procedures on the filesystem: @@ -231,6 +232,11 @@ show_report () #TODO: abstract UI method (cli/dia) } +process_args () +{ +} + + # use this function to stop the installation procedure. # $1 exit code (optional) stop_installer () @@ -247,20 +253,6 @@ log "################## START OF INSTALLATION ##################" mount -o remount,rw / &>/dev/null -# note that we allow procedures like http://foo/bar. module -> http:, procedure -> http://foo/bar. -if [[ $1 =~ ^http:// ]] -then - module=http - procedure="$1" -elif grep -q '\/' <<< "$1" -then - #user specified module/procedure - module=`dirname "$1"` - procedure=`basename "$1"` -else - module=core - procedure="$1" -fi load_module core [ "$module" != core -a "$module" != http ] && load_module "$module" @@ -272,6 +264,57 @@ load_procedure "$module" "$procedure" PACMAN=pacman PACMAN_TARGET="pacman --root $var_TARGET_DIR --config /tmp/pacman.conf" + +### Set configuration values ### +# note : you're free to use or ignore these in your procedure. probably you want to use these variables to override defaults in your configure worker + +var_OPTS_STRING=":i:dlp:" # you can override this variable in your procedure. +while getopts $var_OPTS_STRING OPTION +do + case $OPTION in + i) + [ -z "$OPTARG" ] && usage && exit 1 #TODO: check if it's necessary to do this. the ':' in $var_OPTS_STRING might be enough + [ "$OPTARG" != cli -a "$OPTARG" = !dia ] && die_error "-i must be dia or cli" + arg_ui_type=$OPTARG + ;; + d) + export DEBUG=1 + ;; + l) + LOG_TO_FILE=1 #TODO: implement using this variable + ;; + p) + [ -z "$OPTARG" ] && usage && exit 1 + # note that we allow procedures like http://foo/bar. module -> http:, procedure -> http://foo/bar. + if [[ $1 =~ ^http:// ]] + then + module=http + procedure="$1" + elif grep -q '\/' <<< "$1" + then + #user specified module/procedure + module=`dirname "$1"` + procedure=`basename "$1"` + else + module=core + procedure="$1" + fi + ;; + h) + usage + stop_installer + ;; + ?) + usage + stop_installer 5 + ;; + esac + + process_args $OPTION $OPTARG # you can override this function in your profile to parse additional arguments and/or override the behavior above +done + +[ -z "$procedure" ] && usage && stop_installer 5 + start_process -exit 0 +stop_installer diff --git a/src/core/procedures/base b/src/core/procedures/base index 24131dd..c163a0e 100644 --- a/src/core/procedures/base +++ b/src/core/procedures/base @@ -8,6 +8,7 @@ var_UI_TYPE="cli" # set to cli or dia for dialog ###### Phases ( can be overridden by more specific procedures) ###### phase_preparation=(\ + configure \ intro \ select_source \ runtime_network \ @@ -44,6 +45,12 @@ worker_intro () } +worker_configure () +{ + var_UI_TYPE=${arg_ui_type:-cli} +} + + worker_select_source () { var_PKG_SOURCE_TYPE='cd' diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index 9739cd3..c01c0fa 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -35,7 +35,7 @@ start_process () ##################### ## begin execution ## - var_UI_TYPE=dia + execute worker configure execute worker intro @@ -190,6 +190,12 @@ worker_intro () } +worker_configure () +{ + var_UI_TYPE=${arg_ui_type:-dia} +} + + # select_packages() # prompts the user to select packages to install worker_package_list() { -- cgit v1.2.3-54-g00ecf