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 # Customize a Chrome OS release image. The cgpt utility must be on the | 7 # Customizes a Chrome OS release image by setting the chronos user password. |
8 # sudo path. | |
9 # | |
10 # The following changes are applied: | |
11 # - Set the root password. | |
12 | 8 |
13 # Usage: ./customize_image.sh <image.bin> <root_password> | 9 # Usage: ./set_chronos_password.sh <image.bin> <chronos_password> |
djmm
2010/08/11 17:35:47
A standard I've been pushing in scripts is to set
petkov
2010/08/11 18:07:27
Done in http://codereview.chromium.org/3164006/sho
| |
14 | 10 |
15 # Load common constants and variables. | 11 # Load common constants and variables. |
16 . "$(dirname "$0")/common.sh" | 12 . "$(dirname "$0")/common.sh" |
17 | 13 |
18 readonly ROOTFS_DIR=$(mktemp -d) | 14 readonly ROOTFS_DIR=$(mktemp -d) |
19 readonly GPT=cgpt | |
20 | 15 |
21 cleanup() { | 16 cleanup() { |
22 set +e | 17 set +e |
23 echo Cleaning up... | 18 echo Cleaning up... |
24 sudo umount -d "$ROOTFS_DIR" | 19 sudo umount -d "$ROOTFS_DIR" |
25 rm -rf "$ROOTFS_DIR" | 20 rm -rf "$ROOTFS_DIR" |
26 } | 21 } |
27 | 22 |
28 failure() { | 23 failure() { |
29 cleanup | 24 cleanup |
30 exit 1 | 25 exit 1 |
31 } | 26 } |
32 | 27 |
33 change_root_password() { | 28 change_chronos_password() { |
34 local password=$1 | 29 local password=$1 |
35 echo "Changing root password to '$password'..." | 30 echo "Changing chronos password to '$password'..." |
36 local crypted_password="$(echo $password | openssl passwd -1 -stdin)" | 31 local crypted_password="$(echo $password | openssl passwd -1 -stdin)" |
37 local temp_shadow="$ROOTFS_DIR/etc/tempshadow" | 32 local temp_shadow="$ROOTFS_DIR/etc/tempshadow" |
38 echo "root:$crypted_password:14500:0:::::" \ | 33 echo "chronos:$crypted_password:14500:0:99999::::" \ |
39 | sudo tee "$temp_shadow" > /dev/null | 34 | sudo tee "$temp_shadow" > /dev/null |
40 grep -Ev ^root: "$ROOTFS_DIR/etc/shadow" \ | 35 grep -Ev ^chronos: "$ROOTFS_DIR/etc/shadow" \ |
41 | sudo tee -a "$temp_shadow" > /dev/null | 36 | sudo tee -a "$temp_shadow" > /dev/null |
42 sudo mv -f "$temp_shadow" "$ROOTFS_DIR/etc/shadow" | 37 sudo mv -f "$temp_shadow" "$ROOTFS_DIR/etc/shadow" |
43 } | 38 } |
44 | 39 |
45 main() { | 40 main() { |
46 local image=$1 | 41 local image=$1 |
47 local root_password=$2 | 42 local chronos_password=$2 |
48 if [ $# -ne 2 ]; then | 43 if [ $# -ne 2 ]; then |
49 echo "Usage: $0 <image.bin> <root_password>" | 44 echo "Usage: $0 <image.bin> <chronos_password>" |
50 exit 1 | 45 exit 1 |
51 fi | 46 fi |
52 | 47 |
53 set -e | 48 set -e |
54 trap failure EXIT | 49 trap failure EXIT |
55 mount_image_partition "$image" 3 $ROOTFS_DIR | 50 mount_image_partition "$image" 3 $ROOTFS_DIR |
56 change_root_password "$root_password" | 51 change_chronos_password "$chronos_password" |
57 cleanup | 52 cleanup |
53 touch "$image" # Updates the image modification time. | |
58 echo "Done." | 54 echo "Done." |
59 trap - EXIT | 55 trap - EXIT |
60 } | 56 } |
61 | 57 |
62 main $@ | 58 main $@ |
OLD | NEW |