#!/bin/sh # # /usr/local/sbin/deluser.local # Copyright 2001-2006 Jonas Smedegaard # # $Id: deluser.local,v 1.21 2006-07-16 12:34:00 jonas Exp $ # # Common deluser additions for Spiff and Xenux networks # # TODO: Allow local overriding of using /etc/mailname # OLDUSERNAME=$1 OLDUID=$2 OLDGID=$3 OLDHOMEDIR=$4 fullname() { getent passwd $NEWUSERNAME | awk -F: '{print $5}' | awk -F, '{print $1}'; } maildomain() { if [ -r /etc/mailname ]; then head -n 1 /etc/mailname; fi; } listlists() { if [ -x /usr/sbin/list_lists ]; then /usr/sbin/list_lists -ab -V "$1"; fi; } delfromlist() { /bin/echo "$1" | /usr/sbin/remove_members -f - "$2"; } . /etc/adduser.conf #. /etc/deluser.conf # Workaround: default deluser.conf is not sh-compatible (like adduser.conf) REMOVE_HOME=`grep REMOVE_HOME /etc/deluser.conf | awk -F= '{print $2}' | head -n 1 | sed 's/^ //g'` # Ignore non-human accounts silently [ "$OLDUID" -ge "$FIRST_UID" -a "$OLDUID" -le "$LAST_UID" ] || exit 0 [ -f /etc/local/users.conf ] && . /etc/local/users.conf # Samba password if [ -x /usr/bin/pdbedit ]; then /usr/bin/pdbedit -x -u "$OLDUSERNAME" elif [ -e /etc/samba/smbpasswd -a -x /usr/bin/smbpasswd ]; then /usr/bin/smbpasswd -x $OLDUSERNAME || true fi #TODO: Netatalk password # Mailinglists maildomain="`maildomain`" if [ -n "$maildomain" ]; then lists="`listlists "$maildomain"`" if [ -n "$lists" ]; then echo "Unsubscribing $OLDUSERNAME@$maildomain from mailinglists..." fi for list in $lists; do delfromlist "$OLDUSERNAME@$maildomain" "$list" done fi # Check for dummy shared files if enabled in /etc/local/users.conf if [ -n "$DUMMYSHAREDDIR" ]; then if [ -d $DUMMYSHAREDDIR/$OLDUSERNAME -a -n "$OLDUSERNAME" ]; then echo -n "It seems this was a dummy user. Remove shared files (y/N)? " read remove_files case $remove_files in y|Y) rm -rf $DUMMYSHAREDDIR/$OLDUSERNAME ;; esac fi fi # Workaround: It seems deluser avoids symlinks when told to remove homedir if [ "$REMOVE_HOME" = "1" -a -d $OLDHOMEDIR ]; then echo "Removing $OLDHOMEDIR..." rm -rf $OLDHOMEDIR fi