OLD | NEW |
---|---|
(Empty) | |
1 #!/bin/bash | |
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 # Load common constants. This should be the first executable line. | |
8 # The path to common.sh should be relative to your script's location. | |
9 . "$(dirname $0)/common.sh" | |
10 | |
11 # Script must be run inside the chroot | |
12 restart_in_chroot_if_needed $* | |
13 | |
14 DEFINE_string version "" \ | |
15 "Assume current chroot version is this." | |
16 DEFINE_boolean force_latest "${FLAGS_false}" \ | |
17 "Assume latest version and recreate the version file" | |
18 DEFINE_boolean skipfirst "${FLAGS_false}" \ | |
19 "Skip the first upgrade. This may be dangerous." | |
20 | |
21 FLAGS "$@" || exit 1 | |
22 | |
23 VERSION_FILE=~/.version | |
24 | |
25 ###################################################################### | |
26 | |
27 # Latest version is the version of last upgrade.d file. | |
28 # Name format is ${number}_${short_description} | |
29 # Versions must be -n sorted, that is, the first continuous sequence | |
30 # of numbers is what counts. 12_ is before 111_, etc. | |
31 LATEST_VERSION=$( | |
32 ls "$(dirname $0)/upgrade.d" | grep "^[0-9]*_" | \ | |
33 sort -n | tail -n 1 | cut -f1 -d'_' | |
34 ) | |
35 CHROOT_VERSION=$(cat ${VERSION_FILE}) | |
36 # Check if it's a number. | |
37 if ! [ "${CHROOT_VERSION}" -ge "0" ] &> /dev/null; then | |
38 error "Your chroot version file ${VERSION_FILE} is bogus: ${CHROOT_VERSION}" | |
39 exit 1 | |
40 fi | |
41 | |
42 if [ -n "${FLAGS_force_latest}" ]; then | |
43 echo "${LATEST_VERSION}" > "${VERSION_FILE}" | |
44 exit 0 | |
45 fi | |
46 | |
47 if [ -n "${FLAGS_skipfirst}" ]; then | |
48 if [ "${CHROOT_VERSION}" -lt "${LATEST_VERSION}" ]; then | |
49 CHROOT_VERSION=$(expr ${CHROOT_VERSION} + 1) | |
50 fi | |
51 fi | |
52 | |
53 if [ -n "${FLAGS_version}" ]; then | |
54 # Check if it's a number. | |
55 if [ "${FLAGS_version}" -ge "0" ] &> /dev/null; then | |
56 CHROOT_VERSION="${FLAGS_version}" | |
57 else | |
58 error "Trying to force invalid version: ${FLAGS_version}" | |
59 exit 1 | |
60 fi | |
61 fi | |
62 | |
63 # default goes here | |
64 if ! [ -f "${VERSION_FILE}" ]; then | |
65 warn "Warning: chroot of unknown version, assuming 0" | |
66 echo "0" > "${VERSION_FILE}" | |
67 fi | |
68 | |
69 if [ "${LATEST_VERSION}" -gt "${CHROOT_VERSION}" ]; then | |
70 echo "Outdated chroot found" | |
71 | |
72 pushd "$(dirname $0)/upgrade.d/" 1> /dev/null | |
73 for n in $(seq "$(expr ${CHROOT_VERSION} + 1)" "${LATEST_VERSION}"); do | |
74 # Deprecation check; Deprecation can be done by removing old upgrade | |
75 # scripts and causing too old chroots to have to start over. | |
76 # This also means that the scripts have to form a continuous sequence. | |
77 if ! [ -f ${n}_* ]; then | |
78 error "Fatal: Upgrade ${n} doesn't exist." | |
79 error "Your chroot is too old, you need to re-create it!" | |
kliegs
2010/09/24 22:31:49
Why not just put the command here? Save people th
| |
80 exit 1 | |
81 fi | |
82 | |
83 info "Rollup $(echo ${n}_*)" | |
84 | |
85 # Attempt the upgrade. | |
86 # NOTE: We source the upgrade scripts because: | |
87 # 1) We can impose set -something on them. | |
88 # 2) They can reuse local variables and functions (fe. from common.sh) | |
89 # A side effect is that the scripts have to be internally enclosed in | |
90 # a code block, otherwise simply running "exit" in any of them would | |
91 # terminate the master script, and there would be no way to pass the | |
92 # return value from them. | |
93 if ! source ${n}_*; then | |
94 error "Fatal: failed to upgrade ${n}!" | |
95 exit 1 | |
96 fi | |
97 echo "${n}" > "${VERSION_FILE}" | |
98 done | |
99 popd 1> /dev/null | |
100 fi | |
OLD | NEW |