blob: 0c1bd004ede529ac3f8398c11b51ace174066b40 [file] [log] [blame]
Chris Sosaa73ec162010-05-03 20:18:02 -07001#!/bin/sh
2
3# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This scripts performs update of stateful partition directories useful for
8# dev_mode.
9
Chris Sosa1bf56372010-09-08 13:26:20 -070010. /usr/lib/shflags
11
12# Constants for states.
13CLEAN_STATE="clean"
14OLD_STATE="old"
15
16DEFINE_string stateful_change "${OLD_STATE}" \
17 "The state of the new stateful partition - used in update testing."
18
19FLAGS "$@" || exit 1
20
Chris Sosaa73ec162010-05-03 20:18:02 -070021# Die on error.
22set -e
23
Chris Sosaca4a9252010-09-09 13:48:51 -070024remove_quotes() {
25 echo "$1" | sed -e "s/^'//; s/'$//"
26}
27
Chris Sosa1bf56372010-09-08 13:26:20 -070028update_dev_image () {
29 LSB_RELEASE="/etc/lsb-release"
30 STATEFUL_DIR="/mnt/stateful_partition"
Chris Sosaa73ec162010-05-03 20:18:02 -070031
Chris Sosaca4a9252010-09-09 13:48:51 -070032 if [ -n "${FLAGS_ARGV}" ]; then
33 BASE_UPDATE_URL=$(remove_quotes "${FLAGS_ARGV}")
Chris Sosa1bf56372010-09-08 13:26:20 -070034 else
Chris Sosa05491b12010-11-08 17:14:16 -080035 if [ -f "${STATEFUL_DIR}${LSB_RELEASE}" ]; then
36 DEVSERVER_URL=$(grep CHROMEOS_DEVSERVER ${STATEFUL_DIR}${LSB_RELEASE} | \
Chris Sosa1bf56372010-09-08 13:26:20 -070037 cut -f 2 -d '=')
38 fi
Chris Sosa05491b12010-11-08 17:14:16 -080039 if [ -z "${DEVSERVER_URL}" ]; then
40 DEVSERVER_URL=$(grep CHROMEOS_DEVSERVER ${LSB_RELEASE} | cut -f 2 -d '=')
Chris Sosa1bf56372010-09-08 13:26:20 -070041 fi
42 # Sanity check.
Chris Sosa05491b12010-11-08 17:14:16 -080043 if [ -z "${DEVSERVER_URL}" ]; then
Chris Sosa1bf56372010-09-08 13:26:20 -070044 echo >&2 "No CHROMEOS_DEVSERVER URL found in lsb-release file"
45 exit 1
46 fi
47 # Devserver URL should never contain "/update"
Chris Sosa05491b12010-11-08 17:14:16 -080048 DEVSERVER_URL=$(echo ${DEVSERVER_URL} | sed -e 's#/update##')
49 BASE_UPDATE_URL="${DEVSERVER_URL}/static"
Eric Li94a671e2010-08-02 17:58:50 -070050 fi
Chris Sosa1bf56372010-09-08 13:26:20 -070051
Chris Sosa05491b12010-11-08 17:14:16 -080052 STATEFUL_UPDATE_URL="${BASE_UPDATE_URL}/stateful.tgz"
Chris Sosa4195fad2010-11-09 14:47:35 -080053 echo "Downloading stateful payload from ${STATEFUL_UPDATE_URL}"
54 # Download and unzip directories onto the stateful partition.
Chris Sosa05491b12010-11-08 17:14:16 -080055 eval "wget -qS -T 300 -O - \"${STATEFUL_UPDATE_URL}\"" | \
Chris Sosaa7ae5ba2010-11-12 13:20:53 -080056 tar --ignore-command-error --overwrite --directory=${STATEFUL_DIR} -xz
Chris Sosa1bf56372010-09-08 13:26:20 -070057 echo >&2 "Successfully downloaded update"
Chris Sosa05491b12010-11-08 17:14:16 -080058
Chris Sosa4195fad2010-11-09 14:47:35 -080059 if [ -d "${STATEFUL_DIR}/var_new" ] && [ -d "${STATEFUL_DIR}/dev_image_new" ]
60 then
Chris Sosad1371712010-09-28 14:53:43 -070061 echo >&2 "Notifying startup that an update is available"
Chris Sosa05491b12010-11-08 17:14:16 -080062 touch "${STATEFUL_DIR}/.update_available"
Chris Sosa1bf56372010-09-08 13:26:20 -070063 else
64 echo >&2 "No update available"
Eric Li94a671e2010-08-02 17:58:50 -070065 fi
Chris Sosa1bf56372010-09-08 13:26:20 -070066}
67
68update_old_state () {
Chris Sosa05491b12010-11-08 17:14:16 -080069 echo >&2 "Performing standard stateful update."
Chris Sosa1bf56372010-09-08 13:26:20 -070070}
71
72update_clean_state () {
73 echo >&2 "Restoring state to factory_install with dev_image."
74 echo "fast test" > "/mnt/stateful_partition/factory_install_reset"
75}
76
77main () {
78 update_dev_image
79 if [ "${FLAGS_stateful_change}" = "${OLD_STATE}" ]; then
80 update_old_state
81 elif [ "${FLAGS_stateful_change}" = "${CLEAN_STATE}" ]; then
82 update_clean_state
83 else
84 echo >&2 "Invalid state given to stateful update. Aborting..."
Eric Li94a671e2010-08-02 17:58:50 -070085 exit 1
86 fi
Chris Sosa1bf56372010-09-08 13:26:20 -070087}
Sean O'Connora7f867e2010-05-27 17:53:32 -070088
Chris Sosa1bf56372010-09-08 13:26:20 -070089main $@