| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2011 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 # Script to set the password for the shared user account. Stores the | 7 # Script to set the password for the shared user account. Stores the MD5crypt'd |
| 8 # MD5crypt'd password to a file, for use by customize_rootfs.sh. | 8 # password to a file inside chroot, for use by build_image. |
| 9 | 9 |
| 10 # --- BEGIN COMMON.SH BOILERPLATE --- | 10 # This can only run inside the chroot. |
| 11 # Load common CrOS utilities. Inside the chroot this file is installed in | 11 . "/usr/lib/crosutils/common.sh" || exit 1 |
| 12 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's | |
| 13 # location. | |
| 14 find_common_sh() { | |
| 15 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) | |
| 16 local path | |
| 17 | |
| 18 SCRIPT_ROOT= | |
| 19 for path in "${common_paths[@]}"; do | |
| 20 if [ -r "${path}/common.sh" ]; then | |
| 21 SCRIPT_ROOT=${path} | |
| 22 break | |
| 23 fi | |
| 24 done | |
| 25 } | |
| 26 | |
| 27 find_common_sh | |
| 28 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) | |
| 29 # --- END COMMON.SH BOILERPLATE --- | |
| 30 | |
| 31 # Script must be run inside the chroot | |
| 32 restart_in_chroot_if_needed "$@" | |
| 33 | |
| 34 FLAGS_HELP="USAGE: $0 [flags]" | |
| 35 | |
| 36 # TODO(petkov): This flag and setting of src/scripts/shared_user_passwd.txt can | |
| 37 # go away once the transition dust settles. | |
| 38 DEFINE_boolean move_to_etc ${FLAGS_FALSE} \ | |
| 39 "Move src/scripts/shared_user_passwd.txt to /etc." | |
| 40 | |
| 41 # Parse command line | |
| 42 FLAGS "$@" || exit 1 | |
| 43 eval set -- "${FLAGS_ARGV}" | |
| 44 | 12 |
| 45 # Die on any errors. | 13 # Die on any errors. |
| 46 set -e | 14 set -e |
| 47 | 15 |
| 48 CRYPTED_PASSWD_FILE="${SCRIPTS_DIR}/shared_user_passwd.txt" | |
| 49 SHARED_USER_PASSWD_FILE="/etc/shared_user_passwd.txt" | 16 SHARED_USER_PASSWD_FILE="/etc/shared_user_passwd.txt" |
| 50 | 17 |
| 51 if [ ${FLAGS_move_to_etc} -eq ${FLAGS_TRUE} ]; then | |
| 52 if [ -r "${CRYPTED_PASSWD_FILE}" ]; then | |
| 53 cat "${CRYPTED_PASSWD_FILE}" | sudo_clobber "${SHARED_USER_PASSWD_FILE}" | |
| 54 echo "Copied ${CRYPTED_PASSWD_FILE} to ${SHARED_USER_PASSWD_FILE}." | |
| 55 fi | |
| 56 exit 0 | |
| 57 fi | |
| 58 | |
| 59 # Get password | 18 # Get password |
| 60 read -p "Enter password for shared user account: " PASSWORD | 19 read -p "Enter password for shared user account: " PASSWORD |
| 61 | 20 |
| 62 CRYPTED_PASSWD="$(echo "$PASSWORD" | openssl passwd -1 -stdin)" | 21 CRYPTED_PASSWD="$(echo "$PASSWORD" | openssl passwd -1 -stdin)" |
| 63 PASSWORD="gone now" | 22 PASSWORD="gone now" |
| 64 | 23 |
| 65 echo "${CRYPTED_PASSWD}" > "${CRYPTED_PASSWD_FILE}" | |
| 66 echo "${CRYPTED_PASSWD}" | sudo_clobber "${SHARED_USER_PASSWD_FILE}" | 24 echo "${CRYPTED_PASSWD}" | sudo_clobber "${SHARED_USER_PASSWD_FILE}" |
| 67 echo "Password set in ${CRYPTED_PASSWD_FILE} and ${SHARED_USER_PASSWD_FILE}" | 25 echo "Password set in ${SHARED_USER_PASSWD_FILE}" |
| OLD | NEW |