Skip to content

Commit 2a9c843

Browse files
authored
Merge pull request #105 from grantemsley/pipasswd
Allow altering pi account
2 parents 1668908 + 88a0894 commit 2a9c843

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/modules/admin-toolkit/config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
######### User Required Section ###########################
1414
#
1515
# Adding another user requires at least a username.
16+
# If the user already exists, it will not be recreated,
17+
# but the password and ssh keys will be changed.
1618
# A home folder will be created.
1719
# The default profile will be set to bash.
1820
# Default password is raspberry. PLEASE CHANGE THIS.
1921
# User will be added to the sudo and adm group.
2022
#
23+
# If the user specified is not pi, pi's password will be
24+
# set to a randomly generated string.
25+
#
2126
###########################################################
2227

2328
# add user name, If left "default", no user will be added.

src/modules/admin-toolkit/start_chroot_script

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@ install_cleanup_trap
1818
if [ "$ADMIN_TOOLKIT_NAME" != "default" ]
1919
then
2020

21-
# add user
21+
# add user if it doesn't already exist
2222
if [ "$ADMIN_TOOLKIT_FULLNAME" != "default" ]
2323
then
2424
echo "Adding user $ADMIN_TOOLKIT_NAME with GECOS fields"
25-
useradd -m -s $(which bash) -G sudo,adm "${ADMIN_TOOLKIT_NAME}" -c "${ADMIN_TOOLKIT_FULLNAME}"
25+
id "${ADMIN_TOOLKIT_NAME}" || useradd -m -s $(which bash) -G sudo,adm "${ADMIN_TOOLKIT_NAME}" -c "${ADMIN_TOOLKIT_FULLNAME}"
2626
else
2727
echo "Adding user $ADMIN_TOOLKIT_NAME"
28-
useradd -m -s $(which bash) -G sudo,adm "${ADMIN_TOOLKIT_NAME}"
28+
id "${ADMIN_TOOLKIT_NAME}" || useradd -m -s $(which bash) -G sudo,adm "${ADMIN_TOOLKIT_NAME}"
2929
fi
3030

3131
# check for override password
3232
if [ "$ADMIN_TOOLKIT_PASSWORD" != "default" ]
3333
then
3434
echo "${ADMIN_TOOLKIT_NAME}:${ADMIN_TOOLKIT_PASSWORD}" | chpasswd
35-
RANDOM_PW=$(date +%s | sha256sum | base64 | head -c 32)
36-
echo "pi:${RANDOM_PW}" | chpasswd
35+
# if creating a user other than 'pi', set pi's password to a random string
36+
if [ "${ADMIN_TOOLKIT_NAME}" != "pi" ]
37+
then
38+
RANDOM_PW=$(date +%s | sha256sum | base64 | head -c 32)
39+
echo "pi:${RANDOM_PW}" | chpasswd
40+
fi
3741
else
3842
echo "${ADMIN_TOOLKIT_NAME}:raspberry" | chpasswd
3943
fi

0 commit comments

Comments
 (0)