summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDieter Plaetinck <dieter@plaetinck.be>2008-11-09 23:16:41 +0100
committerDieter Plaetinck <dieter@plaetinck.be>2008-11-09 23:16:41 +0100
commitf47795374171c3eef8389201208acb6cc965721d (patch)
treeb8993b96a0da6609466865291fdea43048ea8717
parent0d9b48c94617b7f89bdec8794a61df26ba4f45d9 (diff)
exit status is maintained for phases and workers. reporting added. phases are now arrays that list the workers. phase logic reorganized in dieters automatic procedure
-rw-r--r--README3
-rw-r--r--TODO9
-rw-r--r--src/core/procedures/base52
-rw-r--r--src/core/procedures/interactive2
-rwxr-xr-xsrc/fifa.sh63
-rw-r--r--unofficial/modules/dieter/procedures/automatic50
6 files changed, 112 insertions, 67 deletions
diff --git a/README b/README
index 47e1311..681fd8d 100644
--- a/README
+++ b/README
@@ -38,7 +38,7 @@ There is a very basic but powerful workflow defined by variables, phases and wor
Depending on the procedure you choose (or write yourself), these will differ
In the code, they are very recognizable and are named like this:
- variable -> var_<foo>
- - phase -> phase_<bar> (a function that calls workers and maybe does some stuff by itself.)
+ - phase -> phase_<bar> (an array in which each element is a worker to be executed, with optionally arguments for that worker)
There are 4 phases: preparation, basics, system, finish. (executed in that order)
- worker -> worker_<baz> ( a worker function, called by a phase. implements some specific logic.
eg runtime_packages, prepare_disks, package_list etc)
@@ -52,6 +52,7 @@ Notes:
overriding only the 3 basic things and the start_process function, and only in procedures.
- you _must_ specify a procedure, to avoid errors. take 'base' if unsure
- don't edit the base procedure (or any other core item), rather make your own. It's easy!
+ - you're not supposed to define new phases. just override them. logic goes in workers/libariers
Modules are the building blocks in fifa. They can contain libraries (for
user interfaces, backend logic, etc) and procedures (how an installation
diff --git a/TODO b/TODO
index 7ce3ed2..1d35451 100644
--- a/TODO
+++ b/TODO
@@ -1,15 +1,6 @@
* go over ALL files and check all function/executable calls are to existing
things (eg no dirty leftovers for functions that have been renamed)
* same for variables
-* in execute function: check exitcode of command and maintain variables like
-worker_install_packages_exit=$?. Useful for: abstracting the phase
-regulation in procedures like core/interactive, and also for reports at the
-end of automatic installations
-* phases should be specified as vars. eg phase_preparation='worker1 worker2'
- advantages -> even easier syntax/overriding
- we can easily track on a higher level (execute function) whether all workers
-executed succesfully for a phase and set the exit state of that phase
- moves all backend logic from phase to worker.
* make interactive procedure working well.
* base procedure wordt implementatie van alles wat auto gaat uit setup script, other steps warning 'not implemented'
* in elke phase een lege worker die te overriden valt zoda we geen phases
diff --git a/src/core/procedures/base b/src/core/procedures/base
index dd2842e..2c76d16 100644
--- a/src/core/procedures/base
+++ b/src/core/procedures/base
@@ -8,39 +8,28 @@ var_UI_TYPE="cli" # set to cli or dia for dialog
###### Phases ( can be overridden by more specific procedures) ######
-phase_preparation ()
-{
- execute worker select_source
- execute worker runtime_network
- execute worker runtime_packages
-}
+phase_preparation=(\
+ select_source \
+ runtime_network \
+ runtime_packages)
+phase_basics=(\
+ set_clock \
+ prepare_disks)
-phase_basics ()
-{
- execute worker set_clock
- execute worker prepare_disks
-}
+phase_system=(\
+ package_list \
+ install_packages \
+ auto_fstab \
+ auto_network \
+ auto_locale \
+ configure_system \
+ mkinitcpio \
+ locales \
+ install_bootloader)
-phase_system ()
-{
- execute worker package_list
- execute worker install_packages
- execute worker auto_fstab #TODO: exact names of these 3
- execute worker auto_network
- execute worker auto_locale
- execute worker configure_system
- execute worker mkinitcpio
- execute worker locales
- execute worker install_bootloader
-}
-
-
-phase_finish ()
-{
- true
-}
+phase_finish=(msg_report)
@@ -153,3 +142,8 @@ worker_install_bootlader ()
#TODO: ask which disk, install grub on it
true
}
+
+worker_msg_report ()
+{
+ show_report
+}
diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive
index 85e47b2..3bc8ee4 100644
--- a/src/core/procedures/interactive
+++ b/src/core/procedures/interactive
@@ -27,7 +27,7 @@ start_process ()
#####################
## begin execution ##
- # install stages
+ # install stages #TODO: now that exit states of all workers are maintained by the execute function, we can probably simplify this
S_SRC=0 # choose install medium
S_NET=0 # network configuration
S_CLOCK=0 # clock and timezone
diff --git a/src/fifa.sh b/src/fifa.sh
index 795cd15..0812902 100755
--- a/src/fifa.sh
+++ b/src/fifa.sh
@@ -103,20 +103,37 @@ execute ()
{
[ -z "$1" -o -z "$2" ] && die_error "Use the execute function like this: execute <type> <name> with type=phase/worker"
[ "$1" != phase -a "$1" != worker ] && die_error "execute's first argument must be a valid type (phase/worker)"
- [ "$1" = phase ] && log "******* Executing phase $2"
- [ "$1" = worker ] && log "*** Executing worker $2"
- to_execute=$1_$2
- shift 2
- if type -t $to_execute | grep -q function
+ PWD_BACKUP=`pwd`
+ object=$1_$2
+
+ if [ "$1" = worker ]
then
- PWD_BACKUP=`pwd`
- $to_execute "$@"
- ret=$?
- cd $PWD_BACKUP
- else
- die_error "$to_execute is not defined!"
+ log "*** Executing worker $2"
+ if type -t $object | grep -q function
+ then
+ shift 2
+ $object "$@"
+ ret=$?
+ exit_var=exit_$object
+ read $exit_var <<< $ret # maintain exit status of each worker
+ else
+ die_error "$object is not defined!"
+ fi
+ elif [ "$1" = phase ]
+ then
+ log "******* Executing phase $2"
+ exit_var=exit_$object
+ read $exit_var <<< 0
+
+ eval phase_array=$(declare | grep -e "^${object}=" | cut -d"=" -f 2-) # props to jedinerd at #bash for this hack.
+ for worker_str in "${phase_array[@]}" # worker_str contains the name of the worker and optionally any arguments
+ do
+ execute worker $worker_str || read $exit_var <<< $? # assign last failing exit code to exit_phase_<phasename>, if any.
+ done
+ ret={!exit_var}
fi
+ cd $PWD_BACKUP
return $ret
}
@@ -142,6 +159,30 @@ start_process ()
}
+show_report () #TODO: abstract UI method (cli/dia)
+{
+ echo "Execution Report:"
+ echo "-----------------"
+ for phase in preparation basics system finish
+ do
+ object=phase_$phase
+ exit_var=exit_$object
+ ret={!exit_var}
+ echo -n "Phase $phase: "
+ [ "$ret" = "0" ] && echo "Success" || echo "Failed"
+ eval phase_array=$(declare | grep -e "^${object}=" | cut -d"=" -f 2-)
+ for worker_str in "${phase_array[@]}"
+ do
+ worker=${worker_str%% *}
+ exit_var=exit_worker_$worker
+ ret={!exit_var}
+ echo -n " > Worker $worker: "
+ [ "$ret" = "0" ] && echo "Success" || echo "Failed"
+ done
+ done
+}
+
+
# use this function to stop the installation procedure.
# $1 exit code (optional)
stop_installer ()
diff --git a/unofficial/modules/dieter/procedures/automatic b/unofficial/modules/dieter/procedures/automatic
index 6720a9a..0bc5284 100644
--- a/unofficial/modules/dieter/procedures/automatic
+++ b/unofficial/modules/dieter/procedures/automatic
@@ -4,29 +4,29 @@ depend_procedure core base
var_RUNTIME_PACKAGES="svn"
-phase_preparation ()
+phase_preparation=(\
+ msg_manual \
+ runtime_network \
+ runtime_svn \
+ msg_automatic \
+ select_source \
+ runtime_packages \
+ runtime_yaourt)
+
+phase_finish=(configure_home msg_report)
+
+
+
+worker_msg_manual ()
{
# All things that need to be done manually first
notify "A few manual things need to happen first..."
- execute worker runtime_network
- SVN_USERNAME=dieter
- ask_password svn #TODO: if user entered incorrect password, the install process will just fail..
- SVN="svn --username $SVN_USERNAME --password $SVN_PASSWORD"
- SVN_BASE=https://192.168.1.2/svn/repos
- TARGET_HOST=desktop-a7n8x #TODO: prompt user for this, or let him pass it as cmdline argument (and check with svn info)
-
- notify "**** From now on. everything will be automatic. Enjoy the show!" # not true: you need pass for dm_crypt
- _accept_ssl_cert
-
- execute worker select_source
- execute worker runtime_packages
- _yaourt_replace_pacman
}
-phase_finish ()
+worker_msg_automatic ()
{
- execute worker configure_home
+ notify "**** From now on. everything will be automatic. Enjoy the show!" # not true: you need pass for dm_crypt
}
@@ -42,6 +42,17 @@ worker_runtime_network ()
}
+worker_runtime_svn ()
+{
+ SVN_USERNAME=dieter
+ ask_password svn #TODO: if user entered incorrect password, the install process will just fail..
+ SVN="svn --username $SVN_USERNAME --password $SVN_PASSWORD"
+ SVN_BASE=https://192.168.1.2/svn/repos
+ TARGET_HOST=desktop-a7n8x #TODO: prompt user for this, or let him pass it as cmdline argument (and check with svn info)
+ _accept_ssl_cert
+}
+
+
worker_prepare_disks ()
{
modprobe dm-crypt || die_error "Cannot modprobe dm-crypt"
@@ -109,8 +120,15 @@ worker_set_clock ()
true
}
+
worker_install_bootloader ()
{
install-grub /dev/sda
}
+
+worker_runtime_yaourt ()
+{
+ _yaourt_replace_pacman
+}
+