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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/image_signing/customize_image
diff --git a/scripts/image_signing/customize_image b/scripts/image_signing/customize_image
new file mode 100755
index 0000000000000000000000000000000000000000..2496c392dc39603670c0d18f8f7fdca98e43d326
--- /dev/null
+++ b/scripts/image_signing/customize_image
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Customize a Chrome OS release image. The cgpt utility must be on the
+# sudo path.
+#
+# The following changes are applied:
+# - Set the root password.
+
+# Usage: ./customize_image <image.bin> <root_password>
+
+readonly ROOTFS_DIR=$(mktemp -d)
+readonly GPT=cgpt
+
+cleanup() {
+ set +e
+ echo Cleaning up...
+ sudo umount -d "$ROOTFS_DIR"
+ rm -rf "$ROOTFS_DIR"
+}
+
+failure() {
+ cleanup
+ exit 1
+}
+
+# Read GPT table to find the starting location of a specific partition.
+# Args: DEVICE PARTNUM
+# Returns: offset (in sectors) of partition PARTNUM
+partoffset() {
+ sudo $GPT show -b -i $2 $1
+}
+
+mount_image() {
+ local image=$1
+ echo "Mounting image '$image'..."
+ local offset=$(partoffset "$image" 3)
+ sudo mount -o loop,offset=$((offset * 512)) "$image" "$ROOTFS_DIR"
+}
+
+change_root_password() {
+ local password=$1
+ echo "Changing root password to '$password'..."
+ local crypted_password="$(echo $password | openssl passwd -1 -stdin)"
+ local temp_shadow="$ROOTFS_DIR/etc/tempshadow"
+ echo "root:$crypted_password:14500:0:::::" \
+ | sudo tee "$temp_shadow" > /dev/null
+ grep -Ev ^root: "$ROOTFS_DIR/etc/shadow" \
+ | sudo tee -a "$temp_shadow" > /dev/null
+ sudo mv -f "$temp_shadow" "$ROOTFS_DIR/etc/shadow"
+}
+
+main() {
+ local image=$1
+ local root_password=$2
+ if [ $# -ne 2 ]; then
+ echo "Usage: $0 <image.bin> <root_password>"
+ exit 1
+ fi
+
+ set -e
+ trap failure EXIT
+ mount_image "$image"
+ change_root_password "$root_password"
+ cleanup
+ echo "Done."
+ trap - EXIT
+}
+
+main $@
« 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