OLD | NEW |
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 # This is the autoupdater for Memento. When called it consults Omaha to see | 7 # This is the autoupdater for Memento. When called it consults Omaha to see |
8 # if there's an update available. If so, it downloads it to the other | 8 # if there's an update available. If so, it downloads it to the other |
9 # partition on the Memento USB stick, then alters the MBR and partitions | 9 # partition on the Memento USB stick, then alters the MBR and partitions |
10 # as needed so the next reboot will boot into the newly installed partition. | 10 # as needed so the next reboot will boot into the newly installed partition. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 if [ -z "${FLAGS_dst_partition}" ]; then | 71 if [ -z "${FLAGS_dst_partition}" ]; then |
72 # make sure update hasn't already completed | 72 # make sure update hasn't already completed |
73 UPDATED_COMPLETED_FILE="/tmp/memento_autoupdate_completed" | 73 UPDATED_COMPLETED_FILE="/tmp/memento_autoupdate_completed" |
74 if [ -f "$UPDATED_COMPLETED_FILE" ] | 74 if [ -f "$UPDATED_COMPLETED_FILE" ] |
75 then | 75 then |
76 exit 0 | 76 exit 0 |
77 fi | 77 fi |
78 fi | 78 fi |
79 | 79 |
80 if ( set -o noclobber; echo "$$" > "$PID_FILE") 2> /dev/null; | 80 if ( set -o noclobber; echo "$$" > "$PID_FILE") 2> /dev/null; |
81 then | 81 then |
82 true | 82 true |
83 else | 83 else |
84 log "Failed to acquire lockfile: $PID_FILE." | 84 log "Failed to acquire lockfile: $PID_FILE." |
85 log "Held by $(cat $PID_FILE)" | 85 log "Held by $(cat $PID_FILE)" |
86 exit 1 | 86 exit 1 |
87 fi | 87 fi |
88 # remove lockfile when we exit | 88 # remove lockfile when we exit |
89 trap 'rm -f "$PID_FILE"; log Memento AutoUpdate terminating; exit $?' \ | 89 trap 'rm -f "$PID_FILE"; log Memento AutoUpdate terminating; exit $?' \ |
90 INT TERM EXIT | 90 INT TERM EXIT |
91 | 91 |
92 log Memento AutoUpdate starting | 92 log Memento AutoUpdate starting |
93 | 93 |
94 # See if we're forcing an update from a specific URL | 94 # See if we're forcing an update from a specific URL |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 LOCAL_DEV=$(rootdev) | 145 LOCAL_DEV=$(rootdev) |
146 | 146 |
147 # We install onto the other partition so if we end in 3, other ends in 5, and | 147 # We install onto the other partition so if we end in 3, other ends in 5, and |
148 # vice versa | 148 # vice versa |
149 if [ -n "${FLAGS_dst_partition}" ]; then | 149 if [ -n "${FLAGS_dst_partition}" ]; then |
150 INSTALL_DEV="${FLAGS_dst_partition}" | 150 INSTALL_DEV="${FLAGS_dst_partition}" |
151 else | 151 else |
152 INSTALL_DEV=$(echo $LOCAL_DEV | tr '35' '53') | 152 INSTALL_DEV=$(echo $LOCAL_DEV | tr '35' '53') |
153 fi | 153 fi |
154 NEW_PART_NUM=${INSTALL_DEV##*/*[a-z]} | 154 NEW_PART_NUM=${INSTALL_DEV##*/*[a-z]} |
155 # The kernel needs to be installed to its own partition. | 155 # The kernel needs to be installed to its own partition. |
156 # partitions 2&3 are image A, partitions 4&5 are image B. | 156 # partitions 2&3 are image A, partitions 4&5 are image B. |
157 if [ -z "${FLAGS_kernel_partition}" ]; then | 157 if [ -z "${FLAGS_kernel_partition}" ]; then |
158 KINSTALL_DEV=$(echo $INSTALL_DEV | tr '35' '24') | 158 KINSTALL_DEV=$(echo $INSTALL_DEV | tr '35' '24') |
159 else | 159 else |
160 KINSTALL_DEV="${FLAGS_kernel_partition}" | 160 KINSTALL_DEV="${FLAGS_kernel_partition}" |
161 fi | 161 fi |
162 | 162 |
163 if [ "$KINSTALL_DEV" = "$INSTALL_DEV" ]; then | 163 if [ "$KINSTALL_DEV" = "$INSTALL_DEV" ]; then |
164 log "kernel install partition the same as rootfs install partition!" | 164 log "kernel install partition the same as rootfs install partition!" |
165 log " (${KINSTALL_DEV})" | 165 log " (${KINSTALL_DEV})" |
166 exit 1 | 166 exit 1 |
167 fi | 167 fi |
168 | 168 |
169 # Find whole disk device. | 169 # Find whole disk device. |
170 ROOT_DEV=${INSTALL_DEV%%[0-9]*} | 170 ROOT_DEV=${INSTALL_DEV%%[0-9]*} |
171 | 171 |
172 # Do some device sanity checks. | 172 # Do some device sanity checks. |
173 if ! expr match "$LOCAL_DEV" '^/dev/[a-z][a-z]*[123458]$' > /dev/null | 173 if [ ! -b "$LOCAL_DEV" ] |
174 then | 174 then |
175 log "didnt find good local device. local: $LOCAL_DEV install: $INSTALL_DEV" | 175 log "didnt find good local device. local: $LOCAL_DEV install: $INSTALL_DEV" |
176 exit 1 | 176 exit 1 |
177 fi | 177 fi |
178 if ! expr match "$INSTALL_DEV" '^/dev/[a-z][a-z]*[123458]$' > /dev/null | 178 if [ ! -b "$INSTALL_DEV" ] |
179 then | 179 then |
180 log "didnt find good install device. local: $LOCAL_DEV install: $INSTALL_DEV" | 180 log "didnt find good install device. local: $LOCAL_DEV install: $INSTALL_DEV" |
181 exit 1 | 181 exit 1 |
182 fi | 182 fi |
183 if [ "$LOCAL_DEV" == "$INSTALL_DEV" ] | 183 if [ "$LOCAL_DEV" == "$INSTALL_DEV" ] |
184 then | 184 then |
185 log local and installation device are the same: "$LOCAL_DEV" | 185 log local and installation device are the same: "$LOCAL_DEV" |
186 exit 1 | 186 exit 1 |
187 fi | 187 fi |
188 | 188 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 function abort_update_if_cmd_failed { | 277 function abort_update_if_cmd_failed { |
278 abort_update_if_cmd_failed_long "$?" "!!" | 278 abort_update_if_cmd_failed_long "$?" "!!" |
279 } | 279 } |
280 | 280 |
281 if [ $FLAGS_skip_postinst -eq $FLAGS_FALSE ]; then | 281 if [ $FLAGS_skip_postinst -eq $FLAGS_FALSE ]; then |
282 # tell the new image to make itself "ready" | 282 # tell the new image to make itself "ready" |
283 log running postinst on the downloaded image | 283 log running postinst on the downloaded image |
284 MOUNTPOINT=/tmp/newpart | 284 MOUNTPOINT=/tmp/newpart |
285 mkdir -p "$MOUNTPOINT" | 285 mkdir -p "$MOUNTPOINT" |
286 mount "$INSTALL_DEV" "$MOUNTPOINT" | 286 mount "$INSTALL_DEV" "$MOUNTPOINT" |
287 | 287 |
288 # Check version of new software if not forcing a dst partition | 288 # Check version of new software if not forcing a dst partition |
289 if [ -z "${FLAGS_dst_partition}" ]; then | 289 if [ -z "${FLAGS_dst_partition}" ]; then |
290 NEW_VERSION=$(grep ^GOOGLE_RELEASE "$MOUNTPOINT"/etc/lsb-release | \ | 290 NEW_VERSION=$(grep ^GOOGLE_RELEASE "$MOUNTPOINT"/etc/lsb-release | \ |
291 cut -d = -f 2-) | 291 cut -d = -f 2-) |
292 if [ "x$NEW_VERSION" = "x" ] | 292 if [ "x$NEW_VERSION" = "x" ] |
293 then | 293 then |
294 log "Can't find new version number. aborting update" | 294 log "Can't find new version number. aborting update" |
295 umount "$MOUNTPOINT" | 295 umount "$MOUNTPOINT" |
296 rmdir "$MOUNTPOINT" | 296 rmdir "$MOUNTPOINT" |
297 exit 1 | 297 exit 1 |
298 else | 298 else |
299 # See if it's newer than us | 299 # See if it's newer than us |
300 if [ "${FLAGS_force_update}" != "${FLAGS_TRUE}" ] && | 300 if [ "${FLAGS_force_update}" != "${FLAGS_TRUE}" ] && |
301 version_number_greater_than "$APP_VERSION" "$NEW_VERSION" | 301 version_number_greater_than "$APP_VERSION" "$NEW_VERSION" |
302 then | 302 then |
303 log "Can't upgrade to older version: " "$NEW_VERSION" | 303 log "Can't upgrade to older version: " "$NEW_VERSION" |
304 umount "$MOUNTPOINT" | 304 umount "$MOUNTPOINT" |
305 rmdir "$MOUNTPOINT" | 305 rmdir "$MOUNTPOINT" |
306 exit 1 | 306 exit 1 |
307 fi | 307 fi |
308 fi | 308 fi |
309 fi | 309 fi |
310 | 310 |
311 "$MOUNTPOINT"/postinst "$INSTALL_DEV" 2>&1 | cat >> "$MEMENTO_AU_LOG" | 311 "$MOUNTPOINT"/postinst "$INSTALL_DEV" 2>&1 | cat >> "$MEMENTO_AU_LOG" |
312 [ "${PIPESTATUS[*]}" = "0 0" ] | 312 [ "${PIPESTATUS[*]}" = "0 0" ] |
313 POSTINST_RETURN_CODE=$? | 313 POSTINST_RETURN_CODE=$? |
314 umount "$MOUNTPOINT" | 314 umount "$MOUNTPOINT" |
315 rmdir "$MOUNTPOINT" | 315 rmdir "$MOUNTPOINT" |
316 | 316 |
317 # If it failed, don't update MBR but just to be safe, zero out a page of | 317 # If it failed, don't update MBR but just to be safe, zero out a page of |
318 # install device. | 318 # install device. |
319 abort_update_if_cmd_failed_long "$POSTINST_RETURN_CODE" "$MOUNTPOINT"/postinst | 319 abort_update_if_cmd_failed_long "$POSTINST_RETURN_CODE" "$MOUNTPOINT"/postinst |
320 # postinstall on new partition succeeded. | 320 # postinstall on new partition succeeded. |
321 fi | 321 fi |
322 | 322 |
323 # flush linux caches; seems to be necessary | |
324 sync | |
325 echo 3 > /proc/sys/vm/drop_caches | |
326 # Configure the PMBR to boot the new image. | |
327 # TODO: ChromeOS EFI BIOS will need a different command to set the GPT | |
328 # partition attributes bits to mark the new image as bootable. | |
329 # NOTE: This won't work for ARM, because we'll need to regenerate the U-Boot | |
330 # script when the kernel size and location are changed. Luckily it won't | |
331 # matter because we'll ship with the GPT-based selection process. The U-Boot | |
332 # script is just a temporary hack for bringup. | |
333 # FIX: The current gpt tool requires a -b arg to specify the PMBR bootcode. We | |
334 # don't want to change the code, so we have to extract it, then put it back. | |
335 # We'll fix this RSN. | |
336 dd if=${ROOT_DEV} bs=512 count=1 of=/tmp/oldpmbr.bin | |
337 gpt -S boot -i $NEW_PART_NUM -b /tmp/oldpmbr.bin ${ROOT_DEV} 2>&1 | \ | |
338 cat >> "$MEMENTO_AU_LOG" | |
339 abort_update_if_cmd_failed | |
340 | |
341 if [ -z "${FLAGS_dst_partition}" ]; then | 323 if [ -z "${FLAGS_dst_partition}" ]; then |
342 # mark update as complete so we don't try to update again | 324 # mark update as complete so we don't try to update again |
343 touch "$UPDATED_COMPLETED_FILE" | 325 touch "$UPDATED_COMPLETED_FILE" |
344 fi | 326 fi |
345 | 327 |
| 328 # Flush linux caches; seems to be necessary |
| 329 sync |
| 330 echo 3 > /proc/sys/vm/drop_caches |
| 331 |
346 # tell user to reboot | 332 # tell user to reboot |
347 log Autoupdate applied. You should now reboot | 333 log Autoupdate applied. You should now reboot |
348 echo UPDATED | 334 echo UPDATED |
OLD | NEW |