command -v fetch_url > /dev/null || . /lib/url-lib.sh
command -v unpack_img > /dev/null || . /lib/img-lib.sh
-read url < /tmp/liveupdates.info
+read -r url < /tmp/liveupdates.info
info "fetching live updates from $url"
-fetch_url "$url" /tmp/updates.img
-if [ $? != 0 ]; then
+if ! fetch_url "$url" /tmp/updates.img; then
warn "failed to fetch update image!"
warn "url: $url"
return 1
fi
-unpack_img /tmp/updates.img /updates.tmp.$$
-if [ $? != 0 ]; then
+if ! unpack_img /tmp/updates.img /updates.tmp.$$; then
warn "failed to unpack update image!"
warn "url: $url"
return 1
fi
+
copytree /updates.tmp.$$ /updates
+
mv /tmp/liveupdates.info /tmp/liveupdates.done
imgfile=
#retry until the imgfile is populated with data or the max retries
i=1
-while [ "$i" -le $RETRIES ]; do
+while [ "$i" -le "$RETRIES" ]; do
imgfile=$(fetch_url "$liveurl")
+ # shellcheck disable=SC2181
if [ $? != 0 ]; then
warn "failed to download live image: error $?"
imgfile=
fi
- if [ ! -z "$imgfile" -a -s "$imgfile" ]; then
+ if [ -n "$imgfile" -a -s "$imgfile" ]; then
break
else
- if [ $i -ge $RETRIES ]; then
+ if [ $i -ge "$RETRIES" ]; then
warn "failed to download live image after $i attempts."
exit 1
fi
- sleep $SLEEP
+ sleep "$SLEEP"
fi
i=$((i + 1))
done > /tmp/livenet.downloaded
# TODO: couldn't dmsquash-live-root handle this?
-if [ ${imgfile##*.} = "iso" ]; then
+if [ "${imgfile##*.}" = "iso" ]; then
root=$(losetup -f)
- losetup $root $imgfile
+ losetup "$root" "$imgfile"
else
root=$imgfile
fi
-exec /sbin/dmsquash-live-root $root
+exec /sbin/dmsquash-live-root "$root"
inst_hook initqueue/online 95 "$moddir/fetch-liveupdate.sh"
inst_script "$moddir/livenetroot.sh" "/sbin/livenetroot"
if dracut_module_included "systemd-initrd"; then
- inst_script "$moddir/livenet-generator.sh" $systemdutildir/system-generators/dracut-livenet-generator
+ inst_script "$moddir/livenet-generator.sh" "$systemdutildir"/system-generators/dracut-livenet-generator
fi
dracut_need_initqueue
}
fi
echo "$updates" > /tmp/liveupdates.info
echo '[ -e /tmp/liveupdates.done ]' > \
- $hookdir/initqueue/finished/liveupdates.sh
+ "$hookdir"/initqueue/finished/liveupdates.sh
fi
str_starts "$root" "live:" && liveurl="$root"
info "livenet: root image at $liveurl"
netroot="livenet:$liveurl"
root="livenet" # quiet complaints from init
+ # shellcheck disable=SC2034
rootok=1
wait_for_dev -n /dev/root
else