mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-02 06:03:54 +00:00
For now, it just updates the root password. BUG=5080 TEST=ran the script,tried the image Review URL: http://codereview.chromium.org/3061045
74 lines
1.6 KiB
Bash
Executable File
74 lines
1.6 KiB
Bash
Executable File
#!/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 $@
|