1
0
mirror of https://github.com/elisspace/rtinst.git synced 2026-08-29 23:52:13 +00:00
Files
rtinst/scripts/rtremove
2015-11-08 19:20:45 +00:00

68 lines
2.7 KiB
Bash

#!/bin/bash
######################################################################
#
# Copyright (c) 2015 arakasi72 (https://github.com/arakasi72)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# --> Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
#
######################################################################
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin
passfile='/etc/nginx/.htpasswd'
if [ -z "$SUDO_USER" -a "$LOGNAME" != "root" ]; then
echo "Must be run from root or using sudo" && exit 1
fi
confirm_name=1
while [ $confirm_name = 1 ]
do
read -p "Enter user to delete: " answer
user=$answer
check_name=1
while [ $check_name = 1 ]
do
echo "Warning if you continue you will permanently delete the user and all their data"
read -p "Is $user correct, y to continue, n to exit? " answer
case $answer in [Yy]* ) confirm_name=0 && check_name=0 ;;
[Nn]* ) exit ;;
* ) echo "Enter y or n";;
esac
done
done
if [ "$user" = "$SUDO_USER" ]; then
echo "Cannot delete yourself" && exit 1
elif [ "$user" = "root" ]; then
echo "Cannot delete root" && exit 1
elif [ -z "$user" ]; then
echo "User entry is blank" && exit 1
elif ! id -u $user >/dev/null 2>&1 ; then
echo "$user does not exist" && exit 1
fi
echo
echo "Deleting $user"
passwd -l $user
killall -KILL -u $user
crontab -u $user -r
if [ -d /var/www/rutorrent/conf/users/$user ]; then
rm -r /var/www/rutorrent/conf/users/$user
fi
htpasswd -D $passfile $user
deluser --remove-home $user
rm -r /var/run/screen/S-$user
ssh_allow=$(grep "$user" /etc/ssh/sshd_config)
if ! [ -z "$ssh_allow" ]; then
sed -i "s/ $user//g" /etc/ssh/sshd_config
service ssh restart
fi