blob: 795cd15508682e59b7284eba16d957899e10e9a0 (
plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#!/bin/bash
###### Set some default variables or get them from the setup script ######
TITLE="Flexible Installer Framework for Arch linux"
LOG="/dev/tty7"
###### 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 <procedurename>\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>. See README\n
Available procedures on the filesystem:
`find /home/arch/fifa/core/procedures -type f`\n
`find /home/arch/fifa/user/*/procedures -type f 2>/dev/null`"
echo -e "$msg"
}
##### TMP functions that we need during early bootstrap but will be overidden with decent functions by libraries ######
notify ()
{
echo -e "$@"
}
log ()
{
echo -e "[LOG] `date +"%Y-%m-%d %H:%M:%S"` $@"
echo -e "[LOG] `date +"%Y-%m-%d %H:%M:%S"` $@" >$LOG
}
###### Core functions ######
# $1 module name
load_module ()
{
[ -z "$1" ] && die_error "load_module needs a module argument"
log "Loading module $1 ..."
path=/home/arch/fifa/user/"$1"
[ "$1" = core ] && path=/home/arch/fifa/core
for submodule in lib #procedure don't load procedures automatically!
do
if [ ! -d "$path/${submodule}s" ]
then
# ignore this problem for not-core modules
[ "$1" = core ] && die_error "$path/${submodule}s does not exist. something is horribly wrong with this installation"
else
shopt -s nullglob
for i in "$path/${submodule}s"/*
do
load_${submodule} "$1" "`basename "$i"`"
done
fi
done
}
# $1 module name
# $2 procedure name
load_procedure()
{
[ -z "$1" ] && die_error "load_procedure needs a module as \$1 and procedure as \$2"
[ -z "$2" ] && die_error "load_procedure needs a procedure as \$2"
if [ "$1" = 'http:' ]
then
log "Loading procedure $2 ..."
procedure=/home/arch/fifa/runtime/procedure-downloaded-`basename $2`
wget "$2" -q -O $procedure >/dev/null || die_error "Could not download procedure $2"
else
log "Loading procedure $1/procedures/$2 ..."
procedure=/home/arch/fifa/user/"$1"/procedures/"$2"
[ "$1" = core ] && procedure=/home/arch/fifa/core/procedures/"$2"
fi
[ -f "$procedure" ] && source "$procedure" || die_error "Something went wrong while sourcing procedure $procedure"
}
# $1 module name
# $2 library name
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/fifa/user/"$1"/libs/"$2"
[ "$1" = core ] && lib=/home/arch/fifa/core/libs/"$2"
source $lib || die_error "Something went wrong while sourcing library $lib"
}
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
then
PWD_BACKUP=`pwd`
$to_execute "$@"
ret=$?
cd $PWD_BACKUP
else
die_error "$to_execute is not defined!"
fi
return $ret
}
depend_module ()
{
load_module "$1"
}
depend_procedure ()
{
load_procedure "$1" "$2"
}
start_process ()
{
execute phase preparation
execute phase basics
execute phase system
execute phase finish
}
# use this function to stop the installation procedure.
# $1 exit code (optional)
stop_installer ()
{
log "-------------- STOPPING INSTALLATION ----------"
exit $1
}
###### perform actual logic ######
echo "Welcome to $TITLE"
log "################## START OF INSTALLATION ##################"
[ -z "$1" ] && usage && exit 1
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"
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
PACMAN=pacman
PACMAN_TARGET="pacman --root $var_TARGET_DIR --config /tmp/pacman.conf"
start_process
exit 0
|