-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebuild-kernels.sh
executable file
·202 lines (148 loc) · 2.7 KB
/
rebuild-kernels.sh
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
set -euo pipefail
source common/rc
me=${0##*/}
spawn_id=
DONE="[32;1mDONE[0m"
FAILED="[31;1mFAILED[0m"
targetdir="$(pwd)/targets"
quiet=
override_linux=
usage()
{
cat <<EOF
$me
Usage: $me [OPTION] TARGETS...
Known values for OPTION are:
-h|--help display this help and exit
-q|--quiet all outputs are redirected to a logfile per machine
-t|--targetdir <DIR> target directory (default: "$targetdir")
--override-linux <DIR> linux sources
Default targets are:
${TARGETS[@]}
EOF
exit 1
}
# runtime dependencies
for cmd in jq expect; do
if ! command -v $cmd &> /dev/null; then
echo "$me: please install '$cmd' command"
exit 1
fi
done
shortargs="hqt:c:"
longargs="help,quiet,targetdir:,override-linux:"
if ! tmp=$(getopt -o "$shortargs" -l "$longargs" -- "$@"); then
usage
fi
eval set -- "$tmp"
unset tmp
while true; do
case "$1" in
"-h" | "--help" )
usage
;;
"-q" | "--quiet" )
quiet=1
shift 1
;;
"-t" | "--targetdir" )
targetdir="$2"
shift 2
;;
"--override-linux" )
override_linux="$2"
shift 2
;;
"--" )
shift 1
break
;;
* )
break
;;
esac
done
linux_reconfigure()
{
expect - <<EOF 2>&3
set timeout -1
proc error {MSG} {
puts -nonewline stderr " \$MSG"
}
proc info {MSG} {
puts -nonewline stderr " \$MSG"
}
spawn -noecho make linux-reconfigure
expect {
"make: \*\*\* * Error" {
error "MAKE"
exit 1
}
">>> linux-headers*Syncing from source dir" {
info "headers"
exp_continue
}
">>> linux-headers" {
exp_continue
}
">>> linux*Syncing from source dir" {
info "sync"
exp_continue
}
">>> linux*Configuring" {
info "configure"
exp_continue
}
">>> linux*Building" {
info "build"
exp_continue
}
">>> linux*Installing to target" {
info "target"
exp_continue
}
">>> linux*Installing to images directory" {
info "image"
exp_continue
}
eof
}
spawn -noecho make all
expect {
"make: \*\*\* * Error" {
error "MAKE"
exit 1
}
">>> Generation filesystem image" {
info "rootfs"
exp_continue
}
">>> Executing post-image script" {
info "postimage"
exp_continue
}
eof
}
EOF
}
exec 3>&1
targets=(${*:-"${TARGETS[@]}"})
for target in "${targets[@]}"; do
logfile="linux-reconfigure.${target}.log"
rm -f "$logfile"
if [ -n "$quiet" ]; then
exec 1>>"$logfile" 2>&1
fi
echo -n "linux-reconfigure $target:" >&3
pushd "${targetdir}/${target}" >/dev/null
rm -f "local.mk"
if [ -n "$override_linux" ]; then
echo "LINUX_OVERRIDE_SRCDIR = $override_linux" >"local.mk"
fi
begin=$(date +%s)
linux_reconfigure && pass=$DONE || pass=$FAILED
end=$(date +%s)
echo " $pass $((end - begin))s" >&3
popd >/dev/null
done