@@ -37,7 +37,8 @@ function stack() {
37
37
echo -ne " from "
38
38
fi
39
39
indent=" true"
40
- local file=" $( basename " ${BASH_SOURCE["${frame}"]} " ) "
40
+ local file
41
+ file=" $( basename " ${BASH_SOURCE["${frame}"]} " ) "
41
42
local line=" ${BASH_LINENO["$((frame-1))"]} " # ???
42
43
local func=" ${FUNCNAME["${frame}"]:- } "
43
44
echo -e " ${func} () ${file} :${line} "
@@ -58,7 +59,8 @@ function errexit() {
58
59
stack 1 >&2 # skip this frame
59
60
60
61
# Exit, really, right now.
61
- local pgid=" $( cat /proc/self/stat | awk ' {print $5}' ) "
62
+ local pgid
63
+ pgid=" $( awk ' {print $5}' /proc/self/stat) "
62
64
kill -- -" ${pgid} "
63
65
}
64
66
@@ -133,22 +135,24 @@ function file_to_package() {
133
135
fwd=" ${ROOT_FWD_LINKS[i]} "
134
136
rev=" ${ROOT_REV_LINKS[i]} "
135
137
if [[ " ${file} " =~ ^" ${fwd} /" ]]; then
136
- alt=" $( echo " $ {file} " | sed " s|^ ${fwd} | ${rev} | " ) "
138
+ alt=" ${file/# " ${fwd} " / " ${rev} " } "
137
139
break
138
140
elif [[ " ${file} " =~ ^" ${rev} /" ]]; then
139
- alt=" $( echo " $ {file} " | sed " s|^ ${rev} | ${fwd} | " ) "
141
+ alt=" ${file/# " ${rev} " / " ${fwd} " } "
140
142
break
141
143
fi
142
- i=$(( $ i+ 1 ))
144
+ i=$(( i+ 1 ))
143
145
done
144
146
145
147
local out=" "
146
148
local result=" "
147
149
out=" $( dpkg-query --search " ${file} " 2>&1 ) "
150
+ # shellcheck disable=SC2181
148
151
if [[ $? == 0 ]]; then
149
152
result=" ${out} "
150
153
elif [[ -n " ${alt} " ]]; then
151
154
out=" $( dpkg-query --search " ${alt} " 2>&1 ) "
155
+ # shellcheck disable=SC2181
152
156
if [[ $? == 0 ]]; then
153
157
result=" ${out} "
154
158
fi
@@ -171,7 +175,8 @@ function ensure_dir_in_staging() {
171
175
local dir=" $2 "
172
176
173
177
if [[ ! -e " ${staging} /${dir} " ]]; then
174
- local rel=" $( echo " ${dir} " | sed ' s|^/||' ) "
178
+ # Stript the leading /
179
+ local rel=" ${dir/# \/ / } "
175
180
tar -C / -c --no-recursion --dereference " ${rel} " | tar -C " ${staging} " -x
176
181
fi
177
182
}
@@ -182,13 +187,15 @@ function stage_one_file() {
182
187
local file=" $2 "
183
188
184
189
# copy the real form of the named path
185
- local real=" $( realpath " ${file} " ) "
190
+ local real
191
+ real=" $( realpath " ${file} " ) "
186
192
cp -a --parents " ${real} " " ${staging} "
187
193
188
194
# recreate symlinks, even on intermediate path elements
189
195
if [[ " ${file} " != " ${real} " ]]; then
190
196
if [[ ! -e " ${staging} /${file} " ]]; then
191
- local dir=" $( dirname " ${file} " ) "
197
+ local dir
198
+ dir=" $( dirname " ${file} " ) "
192
199
ensure_dir_in_staging " ${staging} " " ${dir} "
193
200
ln -s " ${real} " " ${staging} /${file} "
194
201
fi
@@ -252,7 +259,8 @@ function stage_one_package() {
252
259
local i=0
253
260
for s in " ${sums[@]} " ; do
254
261
if [[ " ${sum} " == " ${s} " ]]; then
255
- local dir=" $( dirname " ${file} " ) "
262
+ local dir
263
+ dir=" $( dirname " ${file} " ) "
256
264
ensure_dir_in_staging " ${staging} " " $( dirname " ${file} " ) "
257
265
ln -s " ${names[$i]} " " ${staging} /${file} "
258
266
found=" true"
@@ -296,15 +304,17 @@ function stage_packages() {
296
304
local pkg
297
305
for pkg; do
298
306
echo " staging package ${pkg} "
299
- local du_before=" $( du -sk " ${staging} " | cut -f1) "
307
+ local du_before
308
+ du_before=" $( du -sk " ${staging} " | cut -f1) "
300
309
indent apt-get -y -qq -o Dpkg::Use-Pty=0 --no-install-recommends install " ${pkg} "
301
310
stage_one_package " $staging " " ${pkg} "
302
311
while read -r dep; do
303
312
DBG " staging dependent package ${dep} "
304
313
indent stage_one_package " ${staging} " " ${dep} "
305
314
done < <( get_dependent_packages " ${pkg} " )
306
- local du_after=" $( du -sk " ${staging} " | cut -f1) "
307
- indent echo " package ${pkg} size: +$(( $du_after - $du_before )) kB (of ${du_after} kB)"
315
+ local du_after
316
+ du_after=" $( du -sk " ${staging} " | cut -f1) "
317
+ indent echo " package ${pkg} size: +$(( du_after - du_before )) kB (of ${du_after} kB)"
308
318
done
309
319
}
310
320
@@ -355,10 +365,12 @@ function stage_binaries() {
355
365
local bin
356
366
for bin; do
357
367
echo " staging binary ${bin} "
358
- local du_before=" $( du -sk " ${staging} " | cut -f1) "
368
+ local du_before
369
+ du_before=" $( du -sk " ${staging} " | cut -f1) "
359
370
stage_one_binary " ${staging} " " ${bin} "
360
- local du_after=" $( du -sk " ${staging} " | cut -f1) "
361
- indent echo " binary ${bin} size: +$(( $du_after - $du_before )) kB (of ${du_after} kB)"
371
+ local du_after
372
+ du_after=" $( du -sk " ${staging} " | cut -f1) "
373
+ indent echo " binary ${bin} size: +$(( du_after - du_before )) kB (of ${du_after} kB)"
362
374
done
363
375
}
364
376
@@ -369,10 +381,12 @@ function stage_files() {
369
381
local bin
370
382
for file; do
371
383
echo " staging file ${file} "
372
- local du_before=" $( du -sk " ${staging} " | cut -f1) "
384
+ local du_before
385
+ du_before=" $( du -sk " ${staging} " | cut -f1) "
373
386
stage_one_file " ${staging} " " ${file} "
374
- local du_after=" $( du -sk " ${staging} " | cut -f1) "
375
- indent echo " file ${file} size: +$(( $du_after - $du_before )) kB (of ${du_after} kB)"
387
+ local du_after
388
+ du_after=" $( du -sk " ${staging} " | cut -f1) "
389
+ indent echo " file ${file} size: +$(( du_after - du_before )) kB (of ${du_after} kB)"
376
390
done
377
391
}
378
392
0 commit comments