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

Side by Side Diff: scripts/image_signing/set_chronos_password.sh

Issue 3164006: Cleanup set_chronos_passowrd script. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git
Patch Set: rebase to master 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 | « scripts/image_signing/common.sh ('k') | 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
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 # Customizes a Chrome OS release image by setting the chronos user password. 7 # Customizes a Chrome OS release image by setting the chronos user password.
8 8
9 # Usage: ./set_chronos_password.sh <image.bin> <chronos_password> 9 # Usage: ./set_chronos_password.sh <image.bin> <chronos_password>
10 10
11 # Load common constants and variables. 11 # Load common constants and variables.
12 . "$(dirname "$0")/common.sh" 12 . "$(dirname "$0")/common.sh"
13 13
14 readonly ROOTFS_DIR=$(mktemp -d)
15
16 cleanup() {
17 set +e
18 echo Cleaning up...
19 sudo umount -d "$ROOTFS_DIR"
20 rm -rf "$ROOTFS_DIR"
21 }
22
23 failure() {
24 cleanup
25 exit 1
26 }
27
28 change_chronos_password() { 14 change_chronos_password() {
29 local password=$1 15 local rootfs=$1
16 local password=$2
30 echo "Changing chronos password to '$password'..." 17 echo "Changing chronos password to '$password'..."
31 local crypted_password="$(echo $password | openssl passwd -1 -stdin)" 18 local crypted_password="$(echo $password | openssl passwd -1 -stdin)"
32 local temp_shadow="$ROOTFS_DIR/etc/tempshadow" 19 local temp_shadow="$rootfs/etc/tempshadow"
33 echo "chronos:$crypted_password:14500:0:99999::::" \ 20 echo "chronos:$crypted_password:14500:0:99999::::" \
34 | sudo tee "$temp_shadow" > /dev/null 21 | sudo tee "$temp_shadow" > /dev/null
35 grep -Ev ^chronos: "$ROOTFS_DIR/etc/shadow" \ 22 grep -Ev ^chronos: "$rootfs/etc/shadow" \
36 | sudo tee -a "$temp_shadow" > /dev/null 23 | sudo tee -a "$temp_shadow" > /dev/null
37 sudo mv -f "$temp_shadow" "$ROOTFS_DIR/etc/shadow" 24 sudo mv -f "$temp_shadow" "$rootfs/etc/shadow"
38 } 25 }
39 26
40 main() { 27 main() {
28 set -e
29
41 local image=$1 30 local image=$1
42 local chronos_password=$2 31 local chronos_password=$2
43 if [ $# -ne 2 ]; then 32 if [ $# -ne 2 ]; then
44 echo "Usage: $0 <image.bin> <chronos_password>" 33 echo "Usage: $PROG <image.bin> <chronos_password>"
45 exit 1 34 exit 1
46 fi 35 fi
47 36
48 set -e 37 local rootfs=$(mktemp -d)
49 trap failure EXIT 38 mount_image_partition "$image" 3 "$rootfs"
50 mount_image_partition "$image" 3 $ROOTFS_DIR 39 trap "sudo umount -d $rootfs; rm -rf $rootfs" EXIT
51 change_chronos_password "$chronos_password" 40 change_chronos_password "$rootfs" "$chronos_password"
52 cleanup
53 touch "$image" # Updates the image modification time. 41 touch "$image" # Updates the image modification time.
54 echo "Done." 42 echo "Done."
55 trap - EXIT
56 } 43 }
57 44
58 main $@ 45 main $@
OLDNEW
« no previous file with comments | « scripts/image_signing/common.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698