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