1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#!/bin/bash
###### Set some default variables ######
TITLE="Arch Linux Installation Framework"
LOG="/dev/tty7"
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
###### Early bootstrap ######
# load the lib-ui, it is one we need everywhere so we must load it early.
source $LIB_CORE/libs/lib-ui.sh || ( echo "Something went wrong while sourcing library $LIB_CORE/libs/lib-ui.sh" >&2 && exit 2)
# load the lib-flowcontrol. we also need some of it's functions early (like usage()).
source $LIB_CORE/libs/lib-flowcontrol.sh || ( echo "Something went wrong while sourcing library $LIB_CORE/libs/lib-flowcontrol.sh" >&2 && exit 2)
# lib-misc. we need it early, at least for check_is_in whis is used by the debug function.
source $LIB_CORE/libs/lib-misc.sh || ( echo "Something went wrong while sourcing library $LIB_CORE/libs/lib-misc.sh" >&2 && exit 2)
# default function to process additional arguments. can be overridden by procedures.
process_args ()
{
true
}
###### perform actual logic ######
echo "Welcome to $TITLE"
mount -o remount,rw / &>/dev/null
cleanup_runtime
### 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
#DEBUG: don't touch it. it can be set in the env
arg_ui_type=
LOG_TO_FILE=0
module=
procedure=
# 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"
# 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)
[ -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
LOG_TO_FILE=1
;;
l)
LOG_TO_FILE=1
;;
p)
die_error "If you pass -p <procedurename>, it must be the FIRST option"
;;
h)
usage
exit
;;
?)
# 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
done
# 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
# NOTE: Pacman will run with currently active locale, if you want to parse output, you should prefix with LANG=C
PACMAN=pacman
PACMAN_TARGET="pacman --root $var_TARGET_DIR --config /tmp/pacman.conf"
start_installer
start_process
stop_installer
|