Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 120 lines (102 sloc) 3.575 kb
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
#!/bin/bash
. "/etc/webc/functions.sh"
. "/etc/webc/webc.conf"

cmdline_has debug && set -x

upgrade() {

# webc.conf exports the currently mounted git revision
if test -z "$current_git_revision"; then
logs "No current revision found, not running git-fs? Skipping upgrade"
return
fi

# See to what we should be updating. fetch_revision is
# the revision we should fetch from the git server (it
# can only be a branch or tag name, since we can't fetch
# a sha directly).
# update_revision is optional and can be used to specify
# a sha of a revision to update to (but it must be
# "included" in the fetch triggered by fetch_revision).
# If no update_revision is given, the revision specified
# by fetch_revision is used.
#
# Note that there is a third revision parameter,
# git_revision, which must always contain a sha and must
# only be used on the real kernel cmdline in the
# bootloader config to tell the initrd which revision to
# mount. It is automatically generated below based on
# fetch_revision / update_revision.

if cmdline_has fetch-revision
then
fetch_revision=$(cmdline_get fetch-revision)
else
fetch_revision=master
fi

update_revision=$(cmdline_get update-revision)

logs "Fetching git revision ${fetch_revision}"

# Fetch the git revision. It will not be stored
# in any local branch, just in FETCH_HEAD.
rm -f /.git/FETCH_HEAD
if ! git --git-dir "${git_repo}" fetch --depth=1 --quiet origin "${fetch_revision}" || ! git --git-dir "${git_repo}" rev-parse --verify --quiet FETCH_HEAD
then
# Fetching the revision failed, to prevent an
# unbootable system, bail out now. Since we're not
# updating /live/image/live/webc-cmdline, this will be
# retried after the next reboot.
logs "Fetching git revision ${fetch_revision} failed"
return
fi

if test -z "$(git --git-dir "${git_repo}" tag --contains FETCH_HEAD)"
then
# If there is no tag that contains the
# downloaded revision yet, create one. Keeping a
# tag for every revision downloaded allows git
# fetch to not download these revisions again
# (since it does not take into account all
# commit objects in the repository, only named
# refs when telling the server what we already
# have).
git tag "fetched-${fetch_revision}-$(date '+%s')" FETCH_HEAD
fi

# Get the sha has of the latest revision we just fetched
git_revision=$(git --git-dir "${git_repo}" rev-parse FETCH_HEAD)
logs "Successfully fetched git revision (got ${git_revision})"

# TODO: Also enter this if when boot_append was changed
if test "${current_git_revision}" != "${git_revision}"
then
# The config says we should be running a different
# revision than we're currently running, so change our
# bootloader config to make sure that happens.

if test -f /live/image/boot/live.cfg.in
then
# This is the "live" version, which
# offers a boot menu
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
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}"
else
logs "Already running ${current_git_revision}, no upgrade needed"
fi
}

logs "Upgrade waiting to be triggered."
wait_for $upgrade_pipe 2>/dev/null

if cmdline_has noupgrade
then
logs "Upgrade disabled."
else
upgrade
fi

echo ACK > $upgrade_pipe

# upgrade should restart via inittab and get blocked
# until $upgrade_pipe is re-created
Something went wrong with that request. Please try again.