OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 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 script modifies a base image to act as a recovery installer. | 7 # This script modifies a base image to act as a recovery installer. |
8 # If no kernel image is supplied, it will build a devkeys signed recovery | 8 # If no kernel image is supplied, it will build a devkeys signed recovery |
9 # kernel. Alternatively, a signed recovery kernel can be used to | 9 # kernel. Alternatively, a signed recovery kernel can be used to |
10 # create a Chromium OS recovery image. | 10 # create a Chromium OS recovery image. |
11 | 11 |
12 # Load common constants. This should be the first executable line. | 12 # --- BEGIN COMMON.SH BOILERPLATE --- |
13 # The path to common.sh should be relative to your script's location. | 13 # Load common CrOS utilities. Inside the chroot this file is installed in |
14 . "$(dirname "$0")/common.sh" | 14 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 15 # location. |
| 16 find_common_sh() { |
| 17 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) |
| 18 local path |
| 19 |
| 20 SCRIPT_ROOT= |
| 21 for path in "${common_paths[@]}"; do |
| 22 if [ -r "${path}/common.sh" ]; then |
| 23 SCRIPT_ROOT=${path} |
| 24 break |
| 25 fi |
| 26 done |
| 27 } |
| 28 |
| 29 find_common_sh |
| 30 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 31 # --- END COMMON.SH BOILERPLATE --- |
| 32 |
| 33 # Need to be inside the chroot to load chromeos-common.sh |
| 34 assert_inside_chroot |
15 | 35 |
16 # Load functions and constants for chromeos-install | 36 # Load functions and constants for chromeos-install |
17 . "$(dirname "$0")/chromeos-common.sh" | 37 . "/usr/lib/installer/chromeos-common.sh" || \ |
| 38 die "Unable to load /usr/lib/installer/chromeos-common.sh" |
18 | 39 |
19 # For update_partition_table | 40 # For update_partition_table |
20 . "$(dirname "$0")/resize_stateful_partition.sh" | 41 . "${SCRIPT_ROOT}/resize_stateful_partition.sh" || \ |
21 | 42 die "Unable to load ${SCRIPT_ROOT}/resize_stateful_partition.sh" |
22 | |
23 # We need to be in the chroot to emerge test packages. | |
24 assert_inside_chroot | |
25 | 43 |
26 get_default_board | 44 get_default_board |
27 | 45 |
28 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b | 46 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b |
29 DEFINE_integer statefulfs_sectors 4096 \ | 47 DEFINE_integer statefulfs_sectors 4096 \ |
30 "Number of sectors to use for the stateful filesystem when minimizing" | 48 "Number of sectors to use for the stateful filesystem when minimizing" |
31 # Skips the build steps and just does the kernel swap. | 49 # Skips the build steps and just does the kernel swap. |
32 DEFINE_string kernel_image "" \ | 50 DEFINE_string kernel_image "" \ |
33 "Path to a pre-built recovery kernel" | 51 "Path to a pre-built recovery kernel" |
34 DEFINE_string kernel_outfile "" \ | 52 DEFINE_string kernel_outfile "" \ |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 set -e | 382 set -e |
365 set -u | 383 set -u |
366 | 384 |
367 IMAGE_DIR="$(dirname "$FLAGS_image")" | 385 IMAGE_DIR="$(dirname "$FLAGS_image")" |
368 IMAGE_NAME="$(basename "$FLAGS_image")" | 386 IMAGE_NAME="$(basename "$FLAGS_image")" |
369 RECOVERY_IMAGE="${FLAGS_to:-$IMAGE_DIR/recovery_image.bin}" | 387 RECOVERY_IMAGE="${FLAGS_to:-$IMAGE_DIR/recovery_image.bin}" |
370 RECOVERY_KERNEL_IMAGE=\ | 388 RECOVERY_KERNEL_IMAGE=\ |
371 "${FLAGS_kernel_outfile:-${IMAGE_DIR}/recovery_vmlinuz.image}" | 389 "${FLAGS_kernel_outfile:-${IMAGE_DIR}/recovery_vmlinuz.image}" |
372 RECOVERY_KERNEL_VBLOCK="${RECOVERY_KERNEL_IMAGE}.vblock" | 390 RECOVERY_KERNEL_VBLOCK="${RECOVERY_KERNEL_IMAGE}.vblock" |
373 STATEFUL_DIR="$IMAGE_DIR/stateful_partition" | 391 STATEFUL_DIR="$IMAGE_DIR/stateful_partition" |
374 SCRIPTS_DIR=$(dirname "$0") | 392 SCRIPTS_DIR=${SCRIPT_ROOT} |
375 | 393 |
376 # Mounts gpt image and sets up var, /usr/local and symlinks. | 394 # Mounts gpt image and sets up var, /usr/local and symlinks. |
377 # If there's a dev payload, mount stateful | 395 # If there's a dev payload, mount stateful |
378 # offset=$(partoffset "${FLAGS_from}/${filename}" 1) | 396 # offset=$(partoffset "${FLAGS_from}/${filename}" 1) |
379 # sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \ | 397 # sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \ |
380 # "${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}" | 398 # "${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}" |
381 # If not, resize stateful to 1 sector. | 399 # If not, resize stateful to 1 sector. |
382 # | 400 # |
383 | 401 |
384 if [ $FLAGS_kernel_image_only -eq $FLAGS_TRUE -a \ | 402 if [ $FLAGS_kernel_image_only -eq $FLAGS_TRUE -a \ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 438 |
421 trap cleanup EXIT | 439 trap cleanup EXIT |
422 | 440 |
423 maybe_resize_stateful # Also copies the image if needed. | 441 maybe_resize_stateful # Also copies the image if needed. |
424 | 442 |
425 install_recovery_kernel | 443 install_recovery_kernel |
426 | 444 |
427 echo "Recovery image created at $RECOVERY_IMAGE" | 445 echo "Recovery image created at $RECOVERY_IMAGE" |
428 print_time_elapsed | 446 print_time_elapsed |
429 trap - EXIT | 447 trap - EXIT |
OLD | NEW |