Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some sanity checks to the upgrade code

  • Loading branch information...
commit 7b95e10c7e0e07b3dd130ea90f5e0b3b933a0701 1 parent af4a8e8
@matthijskooijman matthijskooijman authored
Showing with 26 additions and 4 deletions.
  1. +18 −2 etc/webc/functions.sh
  2. +8 −2 etc/webc/live-config.sh
View
20 etc/webc/functions.sh
@@ -83,6 +83,10 @@ extract_kernel() {
local kernel=$(git --git-dir "${git_repo}" show "${git_revision}:boot" | grep ^vmlinuz-.*-${flavour}$ | head -n 1)
local initrd=$(git --git-dir "${git_repo}" show "${git_revision}:boot" | grep ^initrd.img-.*-${flavour}$ | head -n 1)
+ if [ -z "$kernel" -o -z "$initrd" ]; then
+ logs "No kernel or initrd found in revision ${git_revision} for flavour ${flavour}!"
+ fi
+
# Fetch the actual files
git --git-dir "${git_repo}" show "${git_revision}:boot/${kernel}" > ${dir}/vmlinuz${postfix}
git --git-dir "${git_repo}" show "${git_revision}:boot/${initrd}" > ${dir}/initrd${postfix}.img
@@ -125,6 +129,11 @@ generate_live_config()
# TODO: Unhardcode this list
local flavours="486 686-pae"
+ if ! [ -r "${dir}/boot/live.cfg.in" ]; then
+ logs "live.cfg.in not found, skipping bootloader update!"
+ return 1
+ fi
+
# The code below is based on lb_binary_syslinux from
# live-build and is intended to recreate the same live.cfg
rm -f "${dir}/boot/live.cfg"
@@ -132,7 +141,7 @@ generate_live_config()
for _FLAVOUR in ${flavours}; do
_NUMBER="$((${_NUMBER} + 1))"
- extract_kernel "${dir}/live" "${_FLAVOUR}" "${_NUMBER}" "${git_repo}" "${git_revision}"
+ extract_kernel "${dir}/live" "${_FLAVOUR}" "${_NUMBER}" "${git_repo}" "${git_revision}" || continue
sed -e "s|@FLAVOUR@|${_FLAVOUR}|g" \
-e "s|@KERNEL@|/live/vmlinuz${_NUMBER}|g" \
@@ -158,12 +167,19 @@ generate_installed_config()
# Install the same kernel flavour as we're currently running
local flavour=$(cmdline_get kernel-flavour)
+ # If no flavour was given, fall back to any available flavour
+ # (rather than blowing up...)
+ if [ -z "${flavour}" ]; then
+ logs "No kernel flavour found, skipping bootloader update!"
+ return 1
+ fi
+
# The bootparams to pass (we keep the kernel flavour used in the
# cmdline, so it can be used again on upgrades).
local bootparams="$(get_bootparams "$git_repo" "$git_revision") kernel-flavour=${flavour}"
# Extract the kernel and initrd from git
- extract_kernel "${dir}/live" "${flavour}" "" "${git_repo}" "${git_revision}"
+ extract_kernel "${dir}/live" "${flavour}" "" "${git_repo}" "${git_revision}" || return 1
# Generate global extlinux config file
cat<<EOF > ${dir}/boot/extlinux/extlinux.conf
View
10 etc/webc/live-config.sh
@@ -251,12 +251,18 @@ update_cmdline() {
if [ -f /live/image/boot/live.cfg.in ]; then
# This is the "live" version, which
# offers a boot menu
- generate_live_config /live/image "${git_repo}" "${git_revision}"
+ if ! generate_live_config /live/image "${git_repo}" "${git_revision}"; then
+ logs "Updating bootloader config failed!"
+ return
+ fi
else
# This is the "installed" version, which
# does not show a boot prompt and just
# boots the default entry
- generate_installed_config /live/image "${git_repo}" "${git_revision}"
+ if ! generate_installed_config /live/image "${git_repo}" "${git_revision}"; then
+ logs "Updating bootloader config failed!"
+ return
+ fi
fi
logs "Updated bootloader to boot from ${git_revision}"
Please sign in to comment.
Something went wrong with that request. Please try again.