blob: 08b5bd39c924893ba6b9a94b06303b41f2bf6c1d [file] [log] [blame]
Darin Petkovd9072f12010-08-03 10:02:08 -07001#!/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
Gaurav Shah37522c92010-08-04 15:20:52 -070013# Usage: ./customize_image.sh <image.bin> <root_password>
14
15# Load common constants and variables.
16. "$(dirname "$0")/common.sh"
Darin Petkovd9072f12010-08-03 10:02:08 -070017
18readonly ROOTFS_DIR=$(mktemp -d)
19readonly GPT=cgpt
20
21cleanup() {
22 set +e
23 echo Cleaning up...
24 sudo umount -d "$ROOTFS_DIR"
25 rm -rf "$ROOTFS_DIR"
26}
27
28failure() {
29 cleanup
30 exit 1
31}
32
Darin Petkovd9072f12010-08-03 10:02:08 -070033change_root_password() {
34 local password=$1
35 echo "Changing root password to '$password'..."
36 local crypted_password="$(echo $password | openssl passwd -1 -stdin)"
37 local temp_shadow="$ROOTFS_DIR/etc/tempshadow"
38 echo "root:$crypted_password:14500:0:::::" \
39 | sudo tee "$temp_shadow" > /dev/null
40 grep -Ev ^root: "$ROOTFS_DIR/etc/shadow" \
41 | sudo tee -a "$temp_shadow" > /dev/null
42 sudo mv -f "$temp_shadow" "$ROOTFS_DIR/etc/shadow"
43}
44
45main() {
46 local image=$1
47 local root_password=$2
48 if [ $# -ne 2 ]; then
49 echo "Usage: $0 <image.bin> <root_password>"
50 exit 1
51 fi
52
53 set -e
54 trap failure EXIT
Gaurav Shah37522c92010-08-04 15:20:52 -070055 mount_image_partition "$image" 3 $ROOTFS_DIR
Darin Petkovd9072f12010-08-03 10:02:08 -070056 change_root_password "$root_password"
57 cleanup
58 echo "Done."
59 trap - EXIT
60}
61
62main $@