Skip to content

Commit 21c6b03

Browse files
isimhaGerrit
authored and
Gerrit
committed
Added password arg to set_shared_user_password.sh
BUG=none TEST=Ran script, from within chroot, with no args(prompts for password), one password arg, and multiple args(prints usage and exits), and each time echo'd the password before it is encrypted. Each time it is correct. From outside chroot, it only prints an error and exits. Change-Id: I9380511e8784e4979e664281c751fe6e6defe7ab Reviewed-on: https://gerrit.chromium.org/gerrit/25397 Tested-by: Isaac Simha <[email protected]> Reviewed-by: Brian Harring <[email protected]> Commit-Ready: Isaac Simha <[email protected]>
1 parent 194af5e commit 21c6b03

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

set_shared_user_password.sh

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
#!/bin/bash
22

3-
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3+
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be
55
# found in the LICENSE file.
66

77
# Script to set the password for the shared user account. Stores the MD5crypt'd
88
# password to a file inside chroot, for use by build_image.
99

10-
# This can only run inside the chroot.
11-
. "$(dirname "$0")/common.sh" || exit 1
10+
# Make sure common.sh is here.
11+
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
12+
. "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; }
13+
14+
assert_inside_chroot
1215

1316
# Die on any errors.
1417
switch_to_strict_mode
1518

1619
SHARED_USER_PASSWD_FILE="/etc/shared_user_passwd.txt"
1720

18-
# Get password
19-
read -p "Enter password for shared user account: " PASSWORD
21+
# If optional password argument is supplied, set password to that.
22+
if [[ $# > 1 ]]; then
23+
echo "Too many arguments."
24+
echo "usage: $0 [password]"
25+
exit 1
26+
elif [[ $# == 1 ]]; then
27+
PASSWORD=$1
28+
exec "$0" < <(echo "$PASSWORD")
29+
else
30+
# Get password
31+
read -s -p "Enter password for shared user account: " PASSWORD
32+
fi
2033

2134
CRYPTED_PASSWD="$(echo "$PASSWORD" | openssl passwd -1 -stdin)"
2235
PASSWORD="gone now"

0 commit comments

Comments
 (0)