diff --git a/hdd/adduser.sh b/hdd/adduser.sh index 0f760f4897db11f3ca9a66056b8cab9a6910473b..7a4042bfea66c710abd2dec14ae9003443ed9271 100755 --- a/hdd/adduser.sh +++ b/hdd/adduser.sh @@ -93,6 +93,28 @@ add (){ fi } +remove_user(){ + + userDetail=$1 + userName=$( echo $userDetail | cut -d':' -f1 ); + echo $0": Removendo usuário "$userName" do passwd e shadow" + + #remove from passwd + temp=mktemp; + sed "/^$userDetail:/d" /etc/passwd > $temp + cp $temp /etc/passwd + chown root:root /etc/passwd + chmod 644 /etc/passwd + rm $temp + + #remove from shadow + temp=mktemp; + sed "/^$userName:/d" /etc/shadow > $temp + cp $temp /etc/shadow + chown root:shadow /etc/shadow + chmod 640 /etc/shadow + rm $temp +} #This script can only be executed by a root/sudoer user if [ "$(/usr/bin/id -r -u)" != "0" ]; then @@ -157,12 +179,14 @@ fi checkName=$( cat /etc/passwd | cut -d':' -f1-3 | grep -e "^$username:" ) if [ -z "$checkName" ]; then #remove "$checkName" + remove_user "$checkName" echo $0": encontrei outro usuario local com o mesmo nome, devo remove-lo" fi checkID=$( cat /etc/passwd | cut -d':' -f1-3 | grep -e ":$uID$" ) if [ -z "$checkID" ]; then #remove "$checkID" + remove_user "$checkID" echo $0": encontrei outro usuario local com o mesmo id, devo remove-lo" fi