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