Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: src/scripts/image_to_live.sh

Issue 1705023: Cleans up image_to_live changes and handles errors more gracefully (Closed) Base URL: ssh://git@chromiumos-git//chromeos
Patch Set: Fix english Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Script to update an image onto a live running ChromiumOS instance. 7 # Script to update an image onto a live running ChromiumOS instance.
8 8
9 # Load common constants. This should be the first executable line. 9 # Load common constants. This should be the first executable line.
10 # The path to common.sh should be relative to your script's location. 10 # The path to common.sh should be relative to your script's location.
(...skipping 13 matching lines...) Expand all
24 function kill_all_devservers { 24 function kill_all_devservers {
25 # Using ! here to avoid exiting with set -e is insufficient, so use 25 # Using ! here to avoid exiting with set -e is insufficient, so use
26 # || true instead. 26 # || true instead.
27 pkill -fx ".*devserver\.py" || true 27 pkill -fx ".*devserver\.py" || true
28 } 28 }
29 29
30 function cleanup { 30 function cleanup {
31 echo "Killing dev server." 31 echo "Killing dev server."
32 kill_all_devservers 32 kill_all_devservers
33 cleanup_remote_access 33 cleanup_remote_access
34 rm -rf "${TMP}"
35 }
36
37 function unmount_gpt {
34 ./mount_gpt_image.sh -mu 38 ./mount_gpt_image.sh -mu
35 rm -rf "${TMP}"
36 } 39 }
37 40
38 function remote_reboot_sh { 41 function remote_reboot_sh {
39 rm -f "${TMP_KNOWN_HOSTS}" 42 rm -f "${TMP_KNOWN_HOSTS}"
40 remote_sh "$@" 43 remote_sh "$@"
41 } 44 }
42 45
43 function start_dev_server { 46 function start_dev_server {
44 kill_all_devservers 47 kill_all_devservers
45 if [ ${FLAGS_verbose} -eq ${FLAGS_FALSE} ]; then 48 if [ ${FLAGS_verbose} -eq ${FLAGS_FALSE} ]; then
46 ./enter_chroot.sh "./start_devserver > /dev/null 2>&1" & 49 ./enter_chroot.sh "./start_devserver > /dev/null 2>&1" &
47 else 50 else
48 ./enter_chroot.sh "./start_devserver" & 51 ./enter_chroot.sh "./start_devserver" &
49 fi 52 fi
50 echo -n "Waiting on devserver to start" 53 echo -n "Waiting on devserver to start"
51 until netstat -anp 2>&1 | grep 8080 > /dev/null; do 54 until netstat -anp 2>&1 | grep 8080 > /dev/null; do
52 sleep .5 55 sleep .5
53 echo -n "." 56 echo -n "."
54 done 57 done
55 echo "" 58 echo ""
56 } 59 }
57 60
61 # Copys new stateful var and developer directories to updating system.
62 # chromeos_startup checks for .update_available on next boot and updates
63 # the stateful directories.
58 function copy_stateful_tarball { 64 function copy_stateful_tarball {
59 echo "Starting stateful update." 65 echo "Starting stateful update."
60 # Mounts most recent image stateful dir to /tmp/s 66 # Mounts most recent image stateful dir to /tmp/s
61 ./mount_gpt_image.sh -m 67 ./mount_gpt_image.sh -m
68 trap "unmount_gpt && cleanup" EXIT
69
62 # Create tar files for the stateful partition. 70 # Create tar files for the stateful partition.
63 cd /tmp/s/var && sudo tar -cf /tmp/var.tar . && cd - 71 if [ ! -d /tmp/s/var ] || [ ! -d /tmp/s/dev_image ] ; then
64 cd /tmp/s/dev_image && sudo tar -cf /tmp/developer.tar . && cd - 72 echo "No stateful directories found to copy. Continuing update."
65 # Copy over tar files. 73 else
66 remote_cp /tmp/var.tar /tmp 74 pushd /tmp/s/var && sudo tar -czf /tmp/var.tgz . && popd
67 remote_cp /tmp/developer.tar /tmp 75 pushd /tmp/s/dev_image && sudo tar -czf /tmp/developer.tgz . && popd
68 remote_sh "mkdir /mnt/stateful_partition/var_new &&\ 76 # Copy over tar files.
69 mkdir /mnt/stateful_partition/dev_image_new &&\ 77 local s_dir="/mnt/stateful_partition"
70 tar -xf /tmp/var.tar -C /mnt/stateful_partition/var_new &&\ 78 remote_cp /tmp/var.tgz /tmp
71 tar -xf /tmp/developer.tar \ 79 remote_cp /tmp/developer.tgz /tmp
72 -C /mnt/stateful_partition/dev_image_new &&\ 80 remote_sh "rm -rf $s_dir/var_new $s_dir/dev_image_new &&\
73 touch /mnt/stateful_partition/.update_available" 81 mkdir $s_dir/var_new $s_dir/dev_image_new &&\
82 tar -xzf /tmp/var.tgz -C $s_dir/var_new &&\
83 tar -xzf /tmp/developer.tgz -C $s_dir/dev_image_new &&\
84 touch $s_dir/.update_available"
85 fi
74 # unmounts stateful partition 86 # unmounts stateful partition
75 ./mount_gpt_image.sh -mu 87 ./mount_gpt_image.sh -mu
88
89 trap cleanup EXIT
76 } 90 }
77 91
78 function prepare_update_metadata { 92 function prepare_update_metadata {
79 remote_sh "mount -norw,remount /" 93 remote_sh "mount -norw,remount /"
80 94
81 if [[ ${FLAGS_ignore_version} -eq ${FLAGS_TRUE} ]]; then 95 if [[ ${FLAGS_ignore_version} -eq ${FLAGS_TRUE} ]]; then
82 echo "Forcing update independent of the current version" 96 echo "Forcing update independent of the current version"
83 remote_sh "cat /etc/lsb-release |\ 97 remote_sh "cat /etc/lsb-release |\
84 grep -v CHROMEOS_RELEASE_VERSION > /etc/lsb-release~;\ 98 grep -v CHROMEOS_RELEASE_VERSION > /etc/lsb-release~;\
85 mv /etc/lsb-release~ /etc/lsb-release; \ 99 mv /etc/lsb-release~ /etc/lsb-release; \
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 209
196 prepare_update_metadata 210 prepare_update_metadata
197 211
198 if ! run_auto_update; then 212 if ! run_auto_update; then
199 echo "Update was not successful." 213 echo "Update was not successful."
200 exit 1 214 exit 1
201 fi 215 fi
202 216
203 if ! copy_stateful_tarball; then 217 if ! copy_stateful_tarball; then
204 echo "Stateful update was not successful." 218 echo "Stateful update was not successful."
205 exit 1
206 fi 219 fi
207 220
208 remote_reboot 221 remote_reboot
209 222
210 if [[ ${FLAGS_update_hostkey} -eq ${FLAGS_TRUE} ]]; then 223 if [[ ${FLAGS_update_hostkey} -eq ${FLAGS_TRUE} ]]; then
211 local known_hosts="${HOME}/.ssh/known_hosts" 224 local known_hosts="${HOME}/.ssh/known_hosts"
212 cp "${known_hosts}" "${known_hosts}~" 225 cp "${known_hosts}" "${known_hosts}~"
213 grep -v "^${FLAGS_remote} " "${known_hosts}" > "${TMP}/new_known_hosts" 226 grep -v "^${FLAGS_remote} " "${known_hosts}" > "${TMP}/new_known_hosts"
214 cat "${TMP}/new_known_hosts" "${TMP_KNOWN_HOSTS}" > "${known_hosts}" 227 cat "${TMP}/new_known_hosts" "${TMP_KNOWN_HOSTS}" > "${known_hosts}"
215 chmod 0640 "${known_hosts}" 228 chmod 0640 "${known_hosts}"
216 echo "New updated in ${known_hosts}, backup made." 229 echo "New updated in ${known_hosts}, backup made."
217 fi 230 fi
218 231
219 remote_sh "grep ^CHROMEOS_RELEASE_DESCRIPTION= /etc/lsb-release" 232 remote_sh "grep ^CHROMEOS_RELEASE_DESCRIPTION= /etc/lsb-release"
220 local release_description=$(echo $REMOTE_OUT | cut -d '=' -f 2) 233 local release_description=$(echo $REMOTE_OUT | cut -d '=' -f 2)
221 echo "Update was successful and rebooted to $release_description" 234 echo "Update was successful and rebooted to $release_description"
222 235
223 return 0 236 return 0
224 } 237 }
225 238
226 main $@ 239 main $@
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698