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

Side by Side Diff: scripts/image_signing/customize_image

Issue 3061045: Add a customize_image script. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git
Patch Set: Address review comments. Created 10 years, 4 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 | Annotate | Revision Log
« 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
(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 # Customize a Chrome OS release image. The cgpt utility must be on the
8 # sudo path.
9 #
10 # The following changes are applied:
11 # - Set the root password.
12
13 # Usage: ./customize_image <image.bin> <root_password>
14
15 readonly ROOTFS_DIR=$(mktemp -d)
16 readonly GPT=cgpt
17
18 cleanup() {
19 set +e
20 echo Cleaning up...
21 sudo umount -d "$ROOTFS_DIR"
22 rm -rf "$ROOTFS_DIR"
23 }
24
25 failure() {
26 cleanup
27 exit 1
28 }
29
30 # Read GPT table to find the starting location of a specific partition.
31 # Args: DEVICE PARTNUM
32 # Returns: offset (in sectors) of partition PARTNUM
33 partoffset() {
34 sudo $GPT show -b -i $2 $1
35 }
36
37 mount_image() {
38 local image=$1
39 echo "Mounting image '$image'..."
40 local offset=$(partoffset "$image" 3)
41 sudo mount -o loop,offset=$((offset * 512)) "$image" "$ROOTFS_DIR"
42 }
43
44 change_root_password() {
45 local password=$1
46 echo "Changing root password to '$password'..."
47 local crypted_password="$(echo $password | openssl passwd -1 -stdin)"
48 local temp_shadow="$ROOTFS_DIR/etc/tempshadow"
49 echo "root:$crypted_password:14500:0:::::" \
50 | sudo tee "$temp_shadow" > /dev/null
51 grep -Ev ^root: "$ROOTFS_DIR/etc/shadow" \
52 | sudo tee -a "$temp_shadow" > /dev/null
53 sudo mv -f "$temp_shadow" "$ROOTFS_DIR/etc/shadow"
54 }
55
56 main() {
57 local image=$1
58 local root_password=$2
59 if [ $# -ne 2 ]; then
60 echo "Usage: $0 <image.bin> <root_password>"
61 exit 1
62 fi
63
64 set -e
65 trap failure EXIT
66 mount_image "$image"
67 change_root_password "$root_password"
68 cleanup
69 echo "Done."
70 trap - EXIT
71 }
72
73 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