|
|
A bit more thorough...
#!/bin/sh
##
# rmuser
# This script will remove user accounts on OS X 10.2.x
# author: gatorparrots
# problems or suggestions can be posted to the macfora.com OS X UNIX forum
#
# usage: rmuser [username]
##
if [ $# -eq 0 ]; then
printf "usage: rmuser [username]\n"
printf "User account and user's homedir will be irretrievably removed.\n" >&2
exit 2
fi
username=$1
#safety checks
if [ "$username" = "root" ]; then
echo "That's not a wise thing to do."
exit 1
fi
if [ -z "`niutil -read . /users/$username 2> /dev/null `" ]; then
echo "$username does not exit."
exit 2
fi
# Need to be a sudoer to remove user
sudo -p "Please authenticate to remove user (administrator password): " printf "" || {
echo "Abort: could not authenticate" >&2
exit 1
}
userID=$(niutil -readprop . /users/$username uid)
#remove configuration files and other vestiges
if sudo [ -f /var/db/samba/hash/$username ]; then
sudo rm -f /var/db/samba/hash/$username
fi
if sudo [ -f "/etc/httpd/users/$username.conf" ]; then
sudo rm -f "/etc/httpd/users/$username.conf"
fi
if [ -f "/Users/Deleted Users/$username.dmg" ]; then
sudo rm -f "/Users/Deleted Users/$username.dmg"
fi
if sudo [ -f "/Library/Application Support/SyncService/$userID" ]; then
sudo rm -rf "/Library/Application Support/SyncService/$userID"
fi
if sudo [ -d /private/tmp/$userID ]; then
sudo rm -rf /private/tmp/$userID
fi
sudo rm -rf /.Trashes/$userID
sudo rm -rf /Volumes/*/.Trashes/$userID
sudo rm -f /Library/caches/*.$username
sudo rm -f /Library/caches/*.$userID
sudo rm -f "/Library/caches/Desktop Pictures/$username.*"
##You may wish to retain the user's homedir; if so, comment lines below
userhome="`niutil -readprop . /users/$username home`"
sudo rm -rf $userhome
#remove admin status, if exists
sudo niutil -destroyval . /groups/admin users $username
#remove user
sudo niutil -destroy . /users/$username
sudo niutil -resync .
#reassign file ownership to main owner (501)
#comment out or change reassignment UID, if desired
sudo find / -user $userID -exec chown 501 {} \;
echo 'User account "'$username'" removed.'
GeekLog ate the backslash...
Near the end of the script, the UID reassignment code should be:
sudo find / -user $userID -exec chown 501 {} \;
GeekLog ate the backslash II
sudo find / -user $userID -exec chown 501 {} \;
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.09 seconds |
|