Don't allow removal of reserved usernames

This commit is contained in:
Bob Mottram 2016-02-12 19:45:02 +00:00
parent 07f7129351
commit 020d6bfaef
1 changed files with 11 additions and 6 deletions

View File

@ -42,37 +42,42 @@ if [ ! $MY_USERNAME ]; then
exit 1
fi
if [[ $MY_USERNAME == 'git' || $MY_USERNAME == 'mirrors' ]]; then
echo $'Cannot remove reserved users'
exit 2
fi
if [ ! -d /home/$MY_USERNAME ]; then
echo $"Home directory does not exist for $MY_USERNAME"
exit 2
exit 3
fi
if [ ! -f $COMPLETION_FILE ]; then
echo $"$COMPLETION_FILE not found"
exit 3
exit 4
fi
if ! grep -q "Admin user" $COMPLETION_FILE; then
echo $"No admin user specified in $COMPLETION_FILE"
exit 4
exit 5
fi
ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
if [ ! $ADMIN_USERNAME ]; then
echo $"No admin username specified in $COMPLETION_FILE"
exit 5
exit 6
fi
if [[ $MY_USERNAME == $ADMIN_USERNAME ]]; then
echo $"The administrator user cannot be removed"
exit 6
exit 7
fi
echo $'>>> REMOVE USER <<<'
read -p $"Do you really wish to remove the user '$MY_USERNAME' (y/n) ?" yn
if [[ $yn != 'y' && $yn != 'Y' && $yn != 'yes' && $yn != 'Yes' && $yn != 'YES' ]]; then
echo $"User $MY_USERNAME was not removed"
exit 7
exit 8
fi
if grep -q "install_xmpp" $COMPLETION_FILE; then