Add new user to sudoers and remove generic image user from sudoers

This commit is contained in:
Bob Mottram 2015-12-02 17:37:48 +00:00
parent a860fb6129
commit a58766dc10
1 changed files with 10 additions and 2 deletions

View File

@ -691,8 +691,16 @@ function interactive_configuration {
if [[ $possible_username != $GENERIC_IMAGE_USERNAME ]]; then if [[ $possible_username != $GENERIC_IMAGE_USERNAME ]]; then
MY_USERNAME=$(cat $data) MY_USERNAME=$(cat $data)
useradd -m -s /bin/bash $MY_USERNAME useradd -m -s /bin/bash $MY_USERNAME
echo "${MY_USERNAME}:$(printf `cat $IMAGE_PASSWORD_FILE`)" | chpasswd if [ -d /home/$MY_USERNAME ]; then
break echo "${MY_USERNAME}:$(printf `cat $IMAGE_PASSWORD_FILE`)" | chpasswd
# Add the user as a sudoer - they will be the new admin user
if ! grep -q "$MY_USERNAME ALL=(ALL) ALL" /etc/sudoers; then
echo "$MY_USERNAME ALL=(ALL) ALL" >> /etc/sudoers
# remove the generic image admin user from sudoers
sed -i "s|${GENERIC_IMAGE_USERNAME}.*||g" /etc/sudoers
fi
break
fi
fi fi
fi fi
fi fi