diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2009-02-22 17:29:59 +0100 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2009-02-22 17:29:59 +0100 |
commit | 71f5510aaaa20ae5ae9c773dca12028bd96aafdf (patch) | |
tree | c3dee60f77a5c2954bf0a9a4e73befd0b916460e /src/aif.sh | |
parent | f9126402b343aea8f2766bc16c10577b833b6703 (diff) | |
parent | f4bd7c36b44da0c9a5985868aa8b0183cd4414c8 (diff) |
pull in a shitload of fixes and some features from the experimental branch
Diffstat (limited to 'src/aif.sh')
-rwxr-xr-x | src/aif.sh | 116 |
1 files changed, 74 insertions, 42 deletions
@@ -1,10 +1,14 @@ #!/bin/bash + ###### Set some default variables ###### TITLE="Arch Linux Installation Framework" LOG="/dev/tty7" -RUNTIME_DIR=/home/arch/aif/runtime -LOGFILE=$RUNTIME_DIR/aif.log +LIB_CORE=/usr/lib/aif/core +LIB_USER=/usr/lib/aif/user +RUNTIME_DIR=/tmp/aif +LOG_DIR=/var/log/aif +LOGFILE=$LOG_DIR/aif.log ###### Miscalleaneous functions ###### @@ -12,17 +16,21 @@ LOGFILE=$RUNTIME_DIR/aif.log 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 <procedurename> Select a procedure + msg="aif -p <procedurename> Select a procedure # If given, this *must* be the first option -i <dia/cli> Override interface type (optional) -d Explicitly enable debugging (optional) -l Explicitly enable logging to file (optional) -h Help: show usage (optional)\n 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 '<modulename>/' it will be loaded from user module <modulename>.\n -For more info, see the README which you can find in /home/arch/aif/docs\n -Available procedures on the filesystem: -`find /home/arch/aif/core/procedures -type f`\n -`find /home/arch/aif/user/*/procedures -type f 2>/dev/null`" +For more info, see the README which you can find in /usr/share/aif/docs\n +Available procedures: +==core== +`find $LIB_CORE/procedures -type f | sed \"s#$LIB_CORE/procedures/##\"` +==user== +`find $LIB_USER/*/procedures -type f 2>/dev/null | sed \"s#$LIB_USER/\(.*\)/procedures/#\1/#\"`" + [ -n "$procedure" ] && msg="$msg\nProcedure ($procedure) specific options:\n$var_ARGS_USAGE" + echo -e "$msg" } @@ -38,6 +46,7 @@ notify () log () { + mkdir -p $LOG_DIR || die_error "Cannot create log directory" str="[LOG] `date +"%Y-%m-%d %H:%M:%S"` $@" echo -e "$str" > $LOG [ "$LOG_TO_FILE" = 1 ] && echo -e "$str" >> $LOGFILE @@ -46,6 +55,7 @@ log () debug () { + mkdir -p $LOG_DIR || die_error "Cannot create log directory" str="[DEBUG] $@" if [ "$DEBUG" = "1" ] then @@ -63,8 +73,8 @@ load_module () { [ -z "$1" ] && die_error "load_module needs a module argument" log "Loading module $1 ..." - path=/home/arch/aif/user/"$1" - [ "$1" = core ] && path=/home/arch/aif/core + path=$LIB_USER/"$1" + [ "$1" = core ] && path=$LIB_CORE for submodule in lib #procedure don't load procedures automatically! do @@ -97,8 +107,8 @@ load_procedure() wget "$2" -q -O $procedure >/dev/null || die_error "Could not download procedure $2" else log "Loading procedure $1/procedures/$2 ..." - procedure=/home/arch/aif/user/"$1"/procedures/"$2" - [ "$1" = core ] && procedure=/home/arch/aif/core/procedures/"$2" + procedure=$LIB_USER/"$1"/procedures/"$2" + [ "$1" = core ] && procedure=$LIB_CORE/procedures/"$2" fi [ -f "$procedure" ] && source "$procedure" || die_error "Something went wrong while sourcing procedure $procedure" } @@ -111,8 +121,8 @@ load_lib () [ -z "$1" ] && die_error "load_library needs a module als \$1 and library as \$2" [ -z "$2" ] && die_error "load_library needs a library as \$2" log "Loading library $1/libs/$2 ..." - lib=/home/arch/aif/user/"$1"/libs/"$2" - [ "$1" = core ] && lib=/home/arch/aif/core/libs/"$2" + lib=$LIB_USER/"$1"/libs/"$2" + [ "$1" = core ] && lib=$LIB_CORE/libs/"$2" source $lib || die_error "Something went wrong while sourcing library $lib" } @@ -272,14 +282,57 @@ module= procedure= -# TODO: you cannot override $var_OPTS_STRING, nor process_args. because profile not sourced yet -# we will hit '?)' and exit 5 -# solutions? don't make $var_OPTS_STRING overridable, source correct profile as early as possible so process_args gets known. remove the '?)' catchall (eg put it in the default process_args) so we don't hit it accidentially + # in that case -p needs to be the first option, but that's doable imho # an alternative would be to provide an argumentstring for the profile. eg aif -p profile -a "-a a -b b -c c" -var_OPTS_STRING=":i:dlp:" # you can override this variable in your procedure. -while getopts $var_OPTS_STRING OPTION +# you can override these variables in your procedures +var_OPTS_STRING="" +var_ARGS_USAGE="" + +# Processes args that were not already matched by the basic rules. +process_args () +{ + # known options: we don't know any yet + # return 0 + + # if we are still here, we didn't return 0 for a known option. hence this is an unknown option + usage + exit 5 +} + + +# Check if the first args are -p <procedurename>. If so, we can load the procedure, and hence $var_OPTS_STRING and process_args can be overridden +if [ "$1" = '-p' ] +then + [ -z "$2" ] && usage && exit 1 + # note that we allow procedures like http://foo/bar. module -> http:, procedure -> http://foo/bar. + if [[ $2 =~ ^http:// ]] + then + module=http + procedure="$2" + elif grep -q '\/' <<< "$2" + then + #user specified module/procedure + module=`dirname "$2"` + procedure=`basename "$2"` + else + module=core + procedure="$2" + fi + + shift 2 +fi + +# If no procedure given, bail out +[ -z "$procedure" ] && usage && exit 5 + +load_module core +[ "$module" != core -a "$module" != http ] && load_module "$module" + +load_procedure "$module" "$procedure" + +while getopts ":i:dlp:$var_OPTS_STRING" OPTION do case $OPTION in i) @@ -295,41 +348,20 @@ do LOG_TO_FILE=1 ;; p) - [ -z "$OPTARG" ] && usage && exit 1 - # note that we allow procedures like http://foo/bar. module -> http:, procedure -> http://foo/bar. - if [[ $OPTARG =~ ^http:// ]] - then - module=http - procedure="$OPTARG" - elif grep -q '\/' <<< "$OPTARG" - then - #user specified module/procedure - module=`dirname "$OPTARG"` - procedure=`basename "$OPTARG"` - else - module=core - procedure="$OPTARG" - fi + die_error "If you pass -p <procedurename>, it must be the FIRST option" ;; h) usage exit ;; ?) - usage - exit 5 + # If we hit something elso, call process_args + process_args -$OPTION $OPTARG # you can override this function in your profile to parse additional arguments and/or override the behavior above ;; 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 && exit 5 - -load_module core -[ "$module" != core -a "$module" != http ] && load_module "$module" - -load_procedure "$module" "$procedure" # Set pacman vars. allow procedures to have set $var_TARGET_DIR (TODO: look up how delayed variable substitution works. then we can put this at the top again) # flags like --noconfirm should not be specified here. it's up to the procedure to decide the interactivity |