summaryrefslogtreecommitdiff
path: root/deluser.local
blob: 2243beb78b06098e133b456d21de76f21727c1c7 (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. # TODO: Unmount eventual bind mounts
  22. #
  23. OLDUSERNAME=$1
  24. OLDUID=$2
  25. OLDGID=$3
  26. OLDHOMEDIR=$4
  27. fullname() { getent passwd $NEWUSERNAME | awk -F: '{print $5}' | awk -F, '{print $1}'; }
  28. maildomain() { if [ -r /etc/mailname ]; then head -n 1 /etc/mailname; fi; }
  29. listlists() { if [ -x /usr/sbin/list_lists ]; then /usr/sbin/list_lists -ab -V "$1"; fi; }
  30. delfromlist() { /bin/echo "$1" | /usr/sbin/remove_members -f - "$2"; }
  31. . /etc/adduser.conf
  32. #. /etc/deluser.conf
  33. # Workaround: default deluser.conf is not sh-compatible (like adduser.conf)
  34. REMOVE_HOME=`grep REMOVE_HOME /etc/deluser.conf | awk -F= '{print $2}' | head -n 1 | sed 's/^ //g'`
  35. # Ignore non-human accounts silently
  36. [ "$OLDUID" -ge "$FIRST_UID" -a "$OLDUID" -le "$LAST_UID" ] || exit 0
  37. [ -f /etc/local/users.conf ] && . /etc/local/users.conf
  38. # Samba password
  39. if [ -x /usr/bin/pdbedit ]; then
  40. /usr/bin/pdbedit -x -u "$OLDUSERNAME"
  41. elif [ -e /etc/samba/smbpasswd -a -x /usr/bin/smbpasswd ]; then
  42. /usr/bin/smbpasswd -x $OLDUSERNAME || true
  43. fi
  44. #TODO: Netatalk password
  45. # Mailinglists
  46. maildomain="`maildomain`"
  47. if [ -n "$maildomain" ]; then
  48. lists="`listlists "$maildomain"`"
  49. if [ -n "$lists" ]; then
  50. echo "Unsubscribing $OLDUSERNAME@$maildomain from mailinglists..."
  51. fi
  52. for list in $lists; do
  53. delfromlist "$OLDUSERNAME@$maildomain" "$list"
  54. done
  55. fi
  56. # Check for dummy shared files if enabled in /etc/local/users.conf
  57. if [ -n "$DUMMYSHAREDDIR" ]; then
  58. if [ -d $DUMMYSHAREDDIR/$OLDUSERNAME -a -n "$OLDUSERNAME" ]; then
  59. echo -n "It seems this was a dummy user. Remove shared files (y/N)? "
  60. read remove_files
  61. case $remove_files in
  62. y|Y)
  63. rm -rf $DUMMYSHAREDDIR/$OLDUSERNAME
  64. ;;
  65. esac
  66. fi
  67. fi
  68. # Workaround: It seems deluser avoids symlinks when told to remove homedir
  69. if [ "$REMOVE_HOME" = "1" -a -d $OLDHOMEDIR ]; then
  70. echo "Removing $OLDHOMEDIR..."
  71. rm -rf $OLDHOMEDIR
  72. fi