summaryrefslogtreecommitdiff
path: root/deluser.local
blob: 52c564335f0c08451d740f4f9d5a2c1b5c4ce666 (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2001-2006, 2010, Jonas Smedegaard <dr@jones.dk>
  4. # Description: Deluser extensions for Redpill <http://www.redpill.dk>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # TODO: Allow local overriding of using /etc/mailname
  20. # TODO: Print list (not email) for each mailinglist, and all on one line
  21. #
  22. OLDUSERNAME=$1
  23. OLDUID=$2
  24. OLDGID=$3
  25. OLDHOMEDIR=$4
  26. fullname() { getent passwd $NEWUSERNAME | awk -F: '{print $5}' | awk -F, '{print $1}'; }
  27. maildomain() { if [ -r /etc/mailname ]; then head -n 1 /etc/mailname; fi; }
  28. listlists() { if [ -x /usr/sbin/list_lists ]; then /usr/sbin/list_lists -ab -V "$1"; fi; }
  29. delfromlist() { /bin/echo "$1" | /usr/sbin/remove_members -f - "$2"; }
  30. . /etc/adduser.conf
  31. #. /etc/deluser.conf
  32. # Workaround: default deluser.conf is not sh-compatible (like adduser.conf)
  33. REMOVE_HOME=`grep REMOVE_HOME /etc/deluser.conf | awk -F= '{print $2}' | head -n 1 | sed 's/^ //g'`
  34. # Ignore non-human accounts silently
  35. [ "$OLDUID" -ge "$FIRST_UID" -a "$OLDUID" -le "$LAST_UID" ] || exit 0
  36. [ -f /etc/local/users.conf ] && . /etc/local/users.conf
  37. # Samba password
  38. if [ -x /usr/bin/pdbedit ]; then
  39. /usr/bin/pdbedit -x -u "$OLDUSERNAME"
  40. elif [ -e /etc/samba/smbpasswd -a -x /usr/bin/smbpasswd ]; then
  41. /usr/bin/smbpasswd -x $OLDUSERNAME || true
  42. fi
  43. #TODO: Netatalk password
  44. # Mailinglists
  45. maildomain="`maildomain`"
  46. if [ -n "$maildomain" ]; then
  47. lists="`listlists "$maildomain"`"
  48. if [ -n "$lists" ]; then
  49. echo "Unsubscribing $OLDUSERNAME@$maildomain from mailinglists..."
  50. fi
  51. for list in $lists; do
  52. delfromlist "$OLDUSERNAME@$maildomain" "$list"
  53. done
  54. fi
  55. # Check for dummy shared files if enabled in /etc/local/users.conf
  56. if [ -n "$DUMMYSHAREDDIR" ]; then
  57. if [ -d $DUMMYSHAREDDIR/$OLDUSERNAME -a -n "$OLDUSERNAME" ]; then
  58. echo -n "It seems this was a dummy user. Remove shared files (y/N)? "
  59. read remove_files
  60. case $remove_files in
  61. y|Y)
  62. rm -rf $DUMMYSHAREDDIR/$OLDUSERNAME
  63. ;;
  64. esac
  65. fi
  66. fi
  67. # Workaround: It seems deluser avoids symlinks when told to remove homedir
  68. if [ "$REMOVE_HOME" = "1" -a -d $OLDHOMEDIR ]; then
  69. echo "Removing $OLDHOMEDIR..."
  70. rm -rf $OLDHOMEDIR
  71. fi