| Index: src/platform/memento_softwareupdate/memento_updater.sh
|
| diff --git a/src/platform/memento_softwareupdate/memento_updater.sh b/src/platform/memento_softwareupdate/memento_updater.sh
|
| old mode 100755
|
| new mode 100644
|
| index 3ce2fa375a1b91ba70e7f8b8ea2d568bdea6e033..37e507733c1019bbe52aa88c211912a8d2965af6
|
| --- a/src/platform/memento_softwareupdate/memento_updater.sh
|
| +++ b/src/platform/memento_softwareupdate/memento_updater.sh
|
| @@ -14,7 +14,25 @@
|
| # window should be about 1 second or less, and we tolerate that since this
|
| # is for testing and not a real autoupdate solution for the long run.
|
|
|
| -source `dirname "$0"`/memento_updater_logging.sh
|
| +source `dirname "$0"`/memento_updater_logging.sh || exit 1
|
| +. /usr/lib/shflags || exit 1
|
| +
|
| +DEFINE_boolean force_update $FLAGS_FALSE \
|
| + "Force update"
|
| +DEFINE_string install_url "" \
|
| + "Skip Omaha; Install image at this URL."
|
| +DEFINE_string install_url_checksum "" \
|
| + "When using --install_url, the corresponding checksum"
|
| +DEFINE_string dst_partition "" \
|
| + "If set, force installation onto the partition given."
|
| +DEFINE_boolean allow_removable_boot $FLAGS_FALSE \
|
| + "Run even if booted from removable media."
|
| +DEFINE_string force_track "" \
|
| + "If set, force a given track to be sent to Omaha"
|
| +
|
| +# Parse command line
|
| +FLAGS "$@" || exit 1
|
| +eval set -- "${FLAGS_ARGV}"
|
|
|
| # make sure we're root
|
| if [ "root" != $(whoami) ]
|
| @@ -32,18 +50,23 @@ then
|
| fi
|
|
|
| # make sure we're not booted from USB
|
| -HAS_INITRD=$(grep ' initrd=' /proc/cmdline | wc -l)
|
| -if [ "$HAS_INITRD" = "1" ]
|
| -then
|
| +ROOTDEV=$(rootdev)
|
| +# Remove numbers at end of rootfs device.
|
| +SRC=${ROOTDEV%%[0-9]*}
|
| +REMOVABLE=$(cat /sys/block/${SRC#/dev/}/removable)
|
| +if [[ "$REMOVABLE" = "1" && \
|
| + "${FLAGS_allow_removable_boot}" = "${FLAGS_FALSE}" ]]; then
|
| log not updating because we booted from USB
|
| exit 1
|
| fi
|
|
|
| -# make sure update hasn't already completed
|
| -UPDATED_COMPLETED_FILE="/tmp/memento_autoupdate_completed"
|
| -if [ -f "$UPDATED_COMPLETED_FILE" ]
|
| -then
|
| - exit 0
|
| +if [ -z "${FLAGS_dst_partition}" ]; then
|
| + # make sure update hasn't already completed
|
| + UPDATED_COMPLETED_FILE="/tmp/memento_autoupdate_completed"
|
| + if [ -f "$UPDATED_COMPLETED_FILE" ]
|
| + then
|
| + exit 0
|
| + fi
|
| fi
|
|
|
| if ( set -o noclobber; echo "$$" > "$PID_FILE") 2> /dev/null;
|
| @@ -58,16 +81,10 @@ fi
|
| trap 'rm -f "$PID_FILE"; log Memento AutoUpdate terminating; exit $?' \
|
| INT TERM EXIT
|
|
|
| -if [ x$1 = "x-f" ]; then
|
| - log "Forced update requested"
|
| - ForceUpdate="yes"
|
| - shift
|
| -fi
|
| -
|
| log Memento AutoUpdate starting
|
|
|
| # See if we're forcing an update from a specific URL
|
| -if [ "x" = "x$1" ]
|
| +if [ -z "$FLAGS_install_url" ]
|
| then
|
| # abort if autoupdates have been disabled, but only when an update image
|
| # isn't forced
|
| @@ -79,17 +96,25 @@ then
|
| fi
|
|
|
| # check w/ omaha to see if there's an update
|
| - if [ "$ForceUpdate" = "yes" ]; then
|
| - OMAHA_CHECK_OUTPUT=$(`dirname "$0"`/ping_omaha.sh "ForcedUpdate")
|
| - else
|
| - OMAHA_CHECK_OUTPUT=$(`dirname "$0"`/ping_omaha.sh)
|
| + EXTRA_PING_ARGS=""
|
| + if [ "${FLAGS_force_track}" != "" ]; then
|
| + EXTRA_PING_ARGS="${EXTRA_PING_ARGS} --track=${FLAGS_force_track}"
|
| + fi
|
| + if [ ${FLAGS_force_update} -eq ${FLAGS_TRUE} ]; then
|
| + EXTRA_PING_ARGS="${EXTRA_PING_ARGS} --app_version=ForcedUpdate"
|
| fi
|
| + OMAHA_CHECK_OUTPUT=$(`dirname "$0"`/ping_omaha.sh ${EXTRA_PING_ARGS})
|
| IMG_URL=$(echo "$OMAHA_CHECK_OUTPUT" | grep '^URL=' | cut -d = -f 2-)
|
| CHECKSUM=$(echo "$OMAHA_CHECK_OUTPUT" | grep '^HASH=' | cut -d = -f 2-)
|
| else
|
| - log User forced an update from: "$1" checksum: "$2"
|
| - IMG_URL="$1"
|
| - CHECKSUM="$2"
|
| + if [ -z "$FLAGS_install_url_checksum" ]; then
|
| + log Specified --install_url, but not --install_url_checksum. Aborting.
|
| + exit 1
|
| + fi
|
| + log User forced an update from: "$FLAGS_install_url" checksum: \
|
| + "$FLAGS_install_url_checksum"
|
| + IMG_URL="$FLAGS_install_url"
|
| + CHECKSUM="$FLAGS_install_url_checksum"
|
| fi
|
|
|
| APP_VERSION=$(echo "$OMAHA_CHECK_OUTPUT" | grep '^APP_VERSION=' | \
|
| @@ -100,7 +125,7 @@ then
|
| log no update
|
| exit 0
|
| fi
|
| -# TODO(adlr): make sure we have enough space for the download. we are
|
| +# TODO(adlr): make sure we have enough space for the download. This script is
|
| # already correct if we don't have space, but it would be nice to fail
|
| # fast.
|
| log Update Found: $IMG_URL checksum: $CHECKSUM
|
| @@ -110,7 +135,11 @@ LOCAL_DEV=$(rootdev)
|
|
|
| # We install onto the other partition so if we end in 3, other ends in 5, and
|
| # vice versa
|
| -INSTALL_DEV=$(echo $LOCAL_DEV | tr '35' '53')
|
| +if [ -n "${FLAGS_dst_partition}" ]; then
|
| + INSTALL_DEV="${FLAGS_dst_partition}"
|
| +else
|
| + INSTALL_DEV=$(echo $LOCAL_DEV | tr '35' '53')
|
| +fi
|
| NEW_PART_NUM=${INSTALL_DEV##*/*[a-z]}
|
| # The kernel needs to be installed to its own partition. We'll handle that in
|
| # the postinst script (from the new rootfs). partitions 2&3 are image A,
|
| @@ -118,7 +147,7 @@ NEW_PART_NUM=${INSTALL_DEV##*/*[a-z]}
|
| KINSTALL_DEV=$(echo $INSTALL_DEV | tr '35' '24')
|
|
|
| # Find whole disk device.
|
| -ROOT_DEV=${LOCAL_DEV%%[0-9]*}
|
| +ROOT_DEV=${INSTALL_DEV%%[0-9]*}
|
|
|
| # Do some device sanity checks.
|
| if ! expr match "$LOCAL_DEV" '^/dev/[a-z][a-z]*[12345]$' > /dev/null
|
| @@ -212,24 +241,26 @@ MOUNTPOINT=/tmp/newpart
|
| mkdir -p "$MOUNTPOINT"
|
| mount "$INSTALL_DEV" "$MOUNTPOINT"
|
|
|
| -# Check version of new software
|
| -NEW_VERSION=$(grep ^GOOGLE_RELEASE "$MOUNTPOINT"/etc/lsb-release | \
|
| - cut -d = -f 2-)
|
| -if [ "x$NEW_VERSION" = "x" ]
|
| -then
|
| - log "Can't find new version number. aborting update"
|
| - umount "$MOUNTPOINT"
|
| - rmdir "$MOUNTPOINT"
|
| - exit 1
|
| -else
|
| - # See if it's newer than us
|
| - if [ "$ForceUpdate" != "yes" ] &&
|
| - version_number_greater_than "$APP_VERSION" "$NEW_VERSION"
|
| +# Check version of new software if not forcing a dst partition
|
| +if [ -z "${FLAGS_dst_partition}" ]; then
|
| + NEW_VERSION=$(grep ^GOOGLE_RELEASE "$MOUNTPOINT"/etc/lsb-release | \
|
| + cut -d = -f 2-)
|
| + if [ "x$NEW_VERSION" = "x" ]
|
| then
|
| - log "Can't upgrade to older version: " "$NEW_VERSION"
|
| + log "Can't find new version number. aborting update"
|
| umount "$MOUNTPOINT"
|
| rmdir "$MOUNTPOINT"
|
| exit 1
|
| + else
|
| + # See if it's newer than us
|
| + if [ "${FLAGS_force_update}" != "${FLAGS_TRUE}" ] &&
|
| + version_number_greater_than "$APP_VERSION" "$NEW_VERSION"
|
| + then
|
| + log "Can't upgrade to older version: " "$NEW_VERSION"
|
| + umount "$MOUNTPOINT"
|
| + rmdir "$MOUNTPOINT"
|
| + exit 1
|
| + fi
|
| fi
|
| fi
|
|
|
| @@ -258,11 +289,6 @@ function abort_update_if_cmd_failed {
|
| abort_update_if_cmd_failed_long "$POSTINST_RETURN_CODE" "$MOUNTPOINT"/postinst
|
|
|
| # postinstall on new partition succeeded.
|
| -# fix up MBR and make our own partition not something casper will find
|
| -
|
| -# update MBR to make the other partition bootable
|
| -# the slash-magic converts '/' -> '\/' so it's valid in a regex
|
| -log updating MBR of usb device
|
|
|
| # flush linux caches; seems to be necessary
|
| sync
|
| @@ -282,8 +308,10 @@ gpt -S boot -i $NEW_PART_NUM -b /tmp/oldpmbr.bin ${ROOT_DEV} 2>&1 | \
|
| cat >> "$MEMENTO_AU_LOG"
|
| abort_update_if_cmd_failed
|
|
|
| -# mark update as complete so we don't try to update again
|
| -touch "$UPDATED_COMPLETED_FILE"
|
| +if [ -z "${FLAGS_dst_partition}" ]; then
|
| + # mark update as complete so we don't try to update again
|
| + touch "$UPDATED_COMPLETED_FILE"
|
| +fi
|
|
|
| # tell user to reboot
|
| log Autoupdate applied. You should now reboot
|
|
|