blob: a2ffd5400e0758d2a497227c56715214132d125d (
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
|
panic()
{
echo $@
if [ -e /bin/busybox ]; then
FS1='(initramfs) ' exec /bin/busybox sh
else
FS1='(initramfs) ' exec /bin/sh
fi
}
render()
{
eval "echo -n \${$@}"
}
set_initlist()
{
unset initlist
for si_x in ${initdir}/*; do
if [ ! -x ${si_x} ]; then
continue
fi
initlist="${initlist} $(basename ${si_x})"
done
}
reduce_satisfied()
{
deplist="$(render array_${1})"
for rs_x in ${runlist}; do
pop_list_item ${rs_x} ${deplist}
deplist=${tmppop}
done
eval array_${1}=\"${deplist}\"
}
get_prereqs()
{
set_initlist
for gp_x in ${initlist}; do
tmp=$(${initdir}/${gp_x} prereqs)
eval array_${gp_x}=\"${tmp}\"
done
}
count_unsatisfied()
{
set - ${@}
return ${#}
}
# Removes $1 from initlist
pop_list_item()
{
item=${1}
shift
set - ${@}
unset tmppop
# Iterate
for pop in ${@}; do
if [ ${pop} = ${item} ]; then
continue
fi
tmppop="${tmppop} ${pop}"
done
}
# This function generates the runlist, so we clear it first.
reduce_prereqs()
{
unset runlist
set_initlist
set - ${initlist}
i=$#
# Loop until there's no more in the queue to loop through
while [ ${i} -ne 0 ]; do
oldi=${i}
for rp_x in ${initlist}; do
reduce_satisfied ${rp_x}
count_unsatisfied $(render array_${rp_x})
cnt=${?}
if [ ${cnt} -eq 0 ]; then
runlist="${runlist} ${rp_x}"
pop_list_item ${rp_x} ${initlist}
initlist=${tmppop}
i=$((${i} - 1))
fi
done
if [ ${i} -eq ${oldi} ]; then
echo "PANIC: Circular dependancy. Exiting." >&2
exit 1
fi
done
}
call_scripts()
{
echo ${runlist}
for cs_x in ${runlist}; do
${initdir}/${cs_x}
done
}
run_scripts()
{
initdir=${1}
get_prereqs
reduce_prereqs
call_scripts
}
|