summaryrefslogtreecommitdiff
path: root/adduser.local
blob: a67e8e94e804dfb414be22b63308477daa6edb36 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/sbin/adduser.local
  4. # Copyright 2001-2002 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: adduser.local,v 1.18 2005-12-20 01:10:56 jonas Exp $
  7. #
  8. # Common adduser additions for Spiff and Xenux networks
  9. #
  10. # TODO: Allow local overriding of using /etc/mailname
  11. # TODO: Only ask additional questions if real user
  12. # TODO: handle samba passwords in /var/lib/samba/passdb.tdb
  13. #
  14. set -e
  15. NEWUSERNAME=$1
  16. NEWUID=$2
  17. NEWGID=$3
  18. NEWHOMEDIR=$4
  19. function fullname() { getent passwd $NEWUSERNAME | awk -F: '{print $5}' | awk -F, '{print $1}'; }
  20. function maildomain() { if [ -r /etc/mailname ]; then head -n 1 /etc/mailname; else hostname -d; fi; }
  21. function listlists() { if [ -x /usr/sbin/list_lists ]; then /usr/sbin/list_lists -ab; fi; }
  22. function add2list() { /bin/echo "`fullname` <$NEWUSERNAME@`maildomain`>" | /usr/sbin/add_members -w y -a y -r - $1; }
  23. . /etc/adduser.conf
  24. # Ignore non-human accounts silently
  25. [ "$NEWUID" -ge "$FIRST_UID" -a "$NEWUID" -le "$LAST_UID" ] || exit 0
  26. [ -f /etc/local/users.conf ] && . /etc/local/users.conf
  27. # Samba password
  28. #FIXME: Check if enabled in samba.conf (or included files!)
  29. if [ -x /usr/bin/pdbedit ] || [ -x /usr/bin/smbpasswd ]; then
  30. echo -n "Add samba access to the account (y/N)? "
  31. read sambaaccount
  32. case $sambaaccount in
  33. y|Y)
  34. if [ -x /usr/bin/pdbedit ]; then
  35. /usr/bin/pdbedit -a -u "$NEWUSERNAME"
  36. elif [ -x /usr/bin/smbpasswd ] && [ -f /etc/samba/smbpasswd ]; then
  37. /usr/bin/smbpasswd -a $NEWUSERNAME
  38. fi
  39. ;;
  40. esac
  41. fi
  42. # Mail forwarding
  43. if [ -x /usr/local/sbin/userforward ]; then
  44. echo -n "Forward mail to an external account (y/N)? "
  45. read mailforward
  46. case $mailforward in
  47. y|Y)
  48. echo -n "Enter external email address: "
  49. read mail_address
  50. case $mail_address in
  51. ?*@?*.*)
  52. /usr/local/sbin/userforward $NEWUSERNAME $mail_address
  53. ;;
  54. ?*)
  55. echo "That wasn't a proper email address - skipping..."
  56. ;;
  57. esac
  58. ;;
  59. esac
  60. fi
  61. # Mailing lists
  62. for list in `listlists`; do
  63. echo -n "Subscribe to mailinglist $list (y/N)? "
  64. read subscribe
  65. case $subscribe in
  66. y|Y)
  67. add2list $list;;
  68. esac
  69. done
  70. if [ -f /etc/local/users.conf ]; then
  71. . /etc/local/users.conf
  72. if [ -n "$USERS_GROUPNAME" ]; then
  73. addgroup $NEWUSERNAME $USERS_GROUPNAME
  74. fi
  75. if [ -n "$REALUSERS_GROUPNAME" ]; then
  76. echo "This system has both dummy and real users:"
  77. echo " Dummy users have read access to specific files."
  78. echo " Real users have read/write access to personal files."
  79. echo -n "Is this a dummy user (Y/n)? "
  80. read realuser
  81. case $realuser in
  82. y|Y|"")
  83. ;;
  84. *)
  85. addgroup $NEWUSERNAME $REALUSERS_GROUPNAME
  86. ;;
  87. esac
  88. fi
  89. fi
  90. #if [ -n "$REALUSERS_GROUPNAME" ]; then
  91. cat <<+
  92. Is this a remote or local user (with need for physical
  93. access to devices like CD-ROM, soundcard and modem needed)?
  94. +
  95. echo -n "Grant this user access to local utilities (y/N)?"
  96. read localuser
  97. case $localuser in
  98. y|Y)
  99. for group in floppy dialout cdrom audio video games; do
  100. addgroup $NEWUSERNAME $group
  101. done
  102. ;;
  103. *)
  104. ;;
  105. esac
  106. #fi
  107. if [ -x /usr/local/sbin/user-init ]; then
  108. /usr/local/sbin/user-init $NEWUSERNAME
  109. fi