Skip to content

Commit

Permalink
Add some sanity checks to the upgrade code
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijskooijman committed Oct 1, 2012
1 parent af4a8e8 commit 7b95e10
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 18 additions & 2 deletions etc/webc/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,14 +129,19 @@ 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"
local _NUMBER="0"
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" \
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions etc/webc/live-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 7b95e10

Please sign in to comment.