2015-10-26 16:11:37 +01:00
|
|
|
#!/bin/bash
|
2016-02-12 20:43:08 +01:00
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
|
|
|
|
# Removes a user from the system
|
|
|
|
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2016-02-13 23:09:27 +01:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2016-02-12 20:43:08 +01:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2016-02-13 23:09:27 +01:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
2016-02-12 20:43:08 +01:00
|
|
|
#
|
2016-02-13 23:09:27 +01:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-10-26 16:11:37 +01:00
|
|
|
|
2015-11-27 12:42:16 +01:00
|
|
|
PROJECT_NAME='freedombone'
|
|
|
|
|
2015-11-27 17:52:23 +01:00
|
|
|
export TEXTDOMAIN=${PROJECT_NAME}-rmuser
|
2015-11-27 12:42:16 +01:00
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
|
|
|
|
2015-10-26 16:11:37 +01:00
|
|
|
MY_USERNAME=$1
|
2015-12-08 17:22:48 +01:00
|
|
|
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
|
2015-10-26 16:11:37 +01:00
|
|
|
|
|
|
|
if [ ! $MY_USERNAME ]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $'Please specify a username to remove'
|
2015-10-26 16:11:37 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-02-12 20:45:02 +01:00
|
|
|
if [[ $MY_USERNAME == 'git' || $MY_USERNAME == 'mirrors' ]]; then
|
|
|
|
echo $'Cannot remove reserved users'
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2015-10-26 16:11:37 +01:00
|
|
|
if [ ! -d /home/$MY_USERNAME ]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"Home directory does not exist for $MY_USERNAME"
|
2016-02-12 20:45:02 +01:00
|
|
|
exit 3
|
2015-10-26 16:11:37 +01:00
|
|
|
fi
|
|
|
|
|
2015-10-27 11:28:46 +01:00
|
|
|
if [ ! -f $COMPLETION_FILE ]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"$COMPLETION_FILE not found"
|
2016-02-12 20:45:02 +01:00
|
|
|
exit 4
|
2015-10-26 16:11:37 +01:00
|
|
|
fi
|
|
|
|
|
2015-10-27 12:14:08 +01:00
|
|
|
if ! grep -q "Admin user" $COMPLETION_FILE; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"No admin user specified in $COMPLETION_FILE"
|
2016-02-12 20:45:02 +01:00
|
|
|
exit 5
|
2015-10-27 11:28:46 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
|
|
|
|
if [ ! $ADMIN_USERNAME ]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"No admin username specified in $COMPLETION_FILE"
|
2016-02-12 20:45:02 +01:00
|
|
|
exit 6
|
2015-10-27 11:28:46 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $MY_USERNAME == $ADMIN_USERNAME ]]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"The administrator user cannot be removed"
|
2016-02-12 20:45:02 +01:00
|
|
|
exit 7
|
2015-10-27 11:28:46 +01:00
|
|
|
fi
|
|
|
|
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $'>>> REMOVE USER <<<'
|
|
|
|
read -p $"Do you really wish to remove the user '$MY_USERNAME' (y/n) ?" yn
|
2015-10-26 16:11:37 +01:00
|
|
|
if [[ $yn != 'y' && $yn != 'Y' && $yn != 'yes' && $yn != 'Yes' && $yn != 'YES' ]]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"User $MY_USERNAME was not removed"
|
2016-02-12 20:45:02 +01:00
|
|
|
exit 8
|
2015-10-26 16:11:37 +01:00
|
|
|
fi
|
|
|
|
|
2015-11-02 11:56:02 +01:00
|
|
|
if grep -q "install_xmpp" $COMPLETION_FILE; then
|
2015-12-08 17:22:48 +01:00
|
|
|
${PROJECT_NAME}-rmxmpp -e "$MY_USERNAME@$HOSTNAME"
|
2015-11-02 11:56:02 +01:00
|
|
|
fi
|
2015-10-26 16:11:37 +01:00
|
|
|
|
2015-10-27 11:50:41 +01:00
|
|
|
if grep -q "Blog domain" $COMPLETION_FILE; then
|
|
|
|
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
|
|
|
|
if [ -f /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini ]; then
|
|
|
|
rm /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-11-02 11:56:02 +01:00
|
|
|
if grep -q "install_sip" $COMPLETION_FILE; then
|
2015-12-08 17:22:48 +01:00
|
|
|
${PROJECT_NAME}-rmsipuser $MY_USERNAME
|
2015-11-02 11:56:02 +01:00
|
|
|
fi
|
|
|
|
|
2016-02-12 20:42:16 +01:00
|
|
|
if grep -q "GNU Social domain" $COMPLETION_FILE; then
|
|
|
|
MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
|
|
|
|
if [ -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
|
|
|
|
cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
|
|
|
|
php scripts/deleteprofile.php -n $MY_USERNAME -y
|
|
|
|
echo $'Removed GNU Social user'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-03-05 19:43:01 +01:00
|
|
|
if [ -f /etc/nginx/.htpasswd ]; then
|
|
|
|
if grep "${MY_USERNAME}:" /etc/nginx/.htpasswd; then
|
|
|
|
htpasswd -D /etc/nginx/.htpasswd $MY_USERNAME
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-03-11 18:26:17 +01:00
|
|
|
if grep -q "install_owncloud_repo" $COMPLETION_FILE; then
|
|
|
|
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
|
2016-03-12 14:04:20 +01:00
|
|
|
/var/www/owncloud/occ user:delete $MY_USERNAME
|
2016-03-11 18:26:17 +01:00
|
|
|
fi
|
2015-11-10 13:20:55 +01:00
|
|
|
|
2015-10-26 16:11:37 +01:00
|
|
|
userdel -r $MY_USERNAME
|
|
|
|
|
|
|
|
if [ -d /home/$MY_USERNAME ]; then
|
|
|
|
rm -rf /home/$MY_USERNAME
|
|
|
|
fi
|
|
|
|
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"User $MY_USERNAME was removed"
|
2015-10-26 16:11:37 +01:00
|
|
|
|
|
|
|
exit 0
|