#!/bin/sh # # Copyright © 2001-2006, 2010, Jonas Smedegaard # Description: Deluser extensions for Redpill # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, 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 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # TODO: Allow local overriding of using /etc/mailname # TODO: Print list (not email) for each mailinglist, and all on one line # TODO: Unmount eventual bind mounts # 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