summaryrefslogtreecommitdiff
path: root/adduser.local
blob: ff6c44183f4ca187244e361b0cdc3997d2ca726d (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2001-2006, 2010, Jonas Smedegaard <dr@jones.dk>
  4. # Description: Adduser 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: Only ask additional questions if real user
  21. # TODO: handle samba passwords in /var/lib/samba/passdb.tdb
  22. # TODO: Invent a way to flag for INTERACTIVE without abusing VERBOSE
  23. #
  24. set -e
  25. NEWUSERNAME=$1
  26. NEWUID=$2
  27. NEWGID=$3
  28. NEWHOMEDIR=$4
  29. fullname() { getent passwd $NEWUSERNAME | awk -F: '{print $5}' | awk -F, '{print $1}'; }
  30. maildomain() { if [ -r /etc/mailname ]; then head -n 1 /etc/mailname; fi; }
  31. listlists() { if [ -x /usr/sbin/list_lists ]; then /usr/sbin/list_lists -ab -V "$1"; fi; }
  32. add2list() { /bin/echo "$1" | /usr/sbin/add_members -w y -a y -r - "$2"; }
  33. . /etc/adduser.conf
  34. # Ignore non-human accounts silently
  35. [ "$NEWUID" -ge "$FIRST_UID" -a "$NEWUID" -le "$LAST_UID" ] || exit 0
  36. [ ! -r /etc/local/users.conf ] || . /etc/local/users.conf
  37. # resolve account profiles
  38. case "$NEWUSERNAME" in
  39. www-*)
  40. profile_aux=1
  41. profile_web=1
  42. ;;
  43. *-*)
  44. profile_aux=1
  45. ;;
  46. *)
  47. ;;
  48. esac
  49. # Samba password
  50. #FIXME: Check if enabled in samba.conf (or included files!)
  51. if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && ([ -x /usr/bin/pdbedit ] || [ -x /usr/bin/smbpasswd ]); then
  52. echo -n "Add samba access to the account (y/N)? "
  53. read sambaaccount
  54. case $sambaaccount in
  55. y|Y)
  56. if [ -x /usr/bin/pdbedit ]; then
  57. /usr/bin/pdbedit -a -u "$NEWUSERNAME"
  58. elif [ -x /usr/bin/smbpasswd ] && [ -f /etc/samba/smbpasswd ]; then
  59. /usr/bin/smbpasswd -a $NEWUSERNAME
  60. fi
  61. ;;
  62. esac
  63. fi
  64. # Mail forwarding
  65. if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -x /usr/local/sbin/userforward ]; then
  66. echo -n "Forward mail to an external account (y/N)? "
  67. read mailforward
  68. case $mailforward in
  69. y|Y)
  70. echo -n "Enter external email address: "
  71. read mail_address
  72. case $mail_address in
  73. ?*@?*.*)
  74. /usr/local/sbin/userforward $NEWUSERNAME $mail_address
  75. ;;
  76. ?*)
  77. echo "That wasn't a proper email address - skipping..."
  78. ;;
  79. esac
  80. ;;
  81. esac
  82. fi
  83. # Mailing lists
  84. maildomain="`maildomain`"
  85. if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$maildomain" ]; then
  86. echo -n "Subscribe $NEWUSERNAME@$maildomain to mailinglists (y/N)? "
  87. read subscribe
  88. case $subscribe in
  89. y|Y)
  90. if [ -n "$fullname" ]; then
  91. subscriber="`fullname` <$NEWUSERNAME@$maildomain>"
  92. else
  93. subscriber="$NEWUSERNAME@$maildomain"
  94. fi
  95. lists="`listlists "$maildomain"`"
  96. if [ -z "$lists" ]; then
  97. echo "No mailinglists found."
  98. fi
  99. for list in $lists; do
  100. echo -n "Subscribe to mailinglist $list (y/N)? "
  101. read subscribe
  102. case $subscribe in
  103. y|Y)
  104. add2list "$subscriber" "$list";;
  105. esac
  106. done
  107. esac
  108. fi
  109. if [ -z "$profile_aux" ]; then
  110. if [ -n "$USERS_GROUPNAME" ]; then
  111. addgroup $NEWUSERNAME $USERS_GROUPNAME
  112. fi
  113. if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$REALUSERS_GROUPNAME" ]; then
  114. echo "This system has both dummy and real users:"
  115. echo " Dummy users have read access to specific files."
  116. echo " Real users have read/write access to personal files."
  117. echo -n "Is this a dummy user (Y/n)? "
  118. read realuser
  119. case $realuser in
  120. y|Y|"")
  121. ;;
  122. *)
  123. addgroup $NEWUSERNAME $REALUSERS_GROUPNAME
  124. ;;
  125. esac
  126. fi
  127. fi
  128. #if [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -n "$REALUSERS_GROUPNAME" ]; then
  129. # cat <<+
  130. #Is this a remote or local user (with need for physical
  131. #access to devices like CD-ROM, soundcard and modem needed)?
  132. #
  133. #+
  134. if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ]; then
  135. echo -n "Grant this user access to local utilities (y/N)?"
  136. read localuser
  137. case $localuser in
  138. y|Y)
  139. for group in floppy dialout cdrom audio video games; do
  140. addgroup $NEWUSERNAME $group
  141. done
  142. ;;
  143. *)
  144. ;;
  145. esac
  146. fi
  147. if [ -z "$profile_aux" ] && [ -z "$profile_web" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -d /var/www ]; then
  148. echo -n "Setup web hosting for this user (y/N)?"
  149. read webuser
  150. case $webuser in
  151. y|Y)
  152. profile_web=1
  153. ;;
  154. *)
  155. ;;
  156. esac
  157. fi
  158. if [ -n "$profile_web" ] && [ -d /var/www ]; then
  159. webroot="$NEWHOMEDIR/public_websites"
  160. cgiroot="$NEWHOMEDIR/public_cgi"
  161. dataroot="$NEWHOMEDIR/private_webdata"
  162. webmount="/var/www/vhosts/$NEWUSERNAME"
  163. cgimount="/var/www/cgi-vhosts/$NEWUSERNAME"
  164. echo >&2 "Adding private and public subdirs in homedir ..."
  165. install -d -o "$NEWUID" -g "$NEWGID" "$webroot" "$cgiroot"
  166. install -d -o "$NEWUID" -g "$NEWGID" -m 0750 "$dataroot"
  167. [ ! -r /etc/local/webusers.conf ] || . /etc/local/webusers.conf
  168. if [ -n "$WEBUSERS_BINDMOUNT" ]; then
  169. echo >&2 "Adding subdirs below /var/www ..."
  170. install -d "$webmount" "$cgimount"
  171. echo >&2 "Adding bind mount entries to /etc/fstab ..."
  172. webroot="$webroot" cgiroot="$cgiroot" webmount="$webmount" cgimount="$cgimount" perl -w -p -0 -i.old \
  173. -e 'my $webroot = $ENV{"webroot"};' \
  174. -e 'my $cgiroot = $ENV{"cgiroot"};' \
  175. -e 'my $webmount = $ENV{"webmount"};' \
  176. -e 'my $cgimount = $ENV{"cgimount"};' \
  177. -e 'if (s/\n[# ]*($webroot[ \t]+$webmount[ \t]+[^\n]+)/\n$1/) {' \
  178. -e '$web_seen++;' \
  179. -e 'print STDERR "Using existing web entry in fstab\n";' \
  180. -e '};' \
  181. -e 'if (s/\n[# ]*($cgiroot[ \t]+$cgimount[ \t]+[^\n]+)/\n$1/) {' \
  182. -e '$cgi_seen++;' \
  183. -e 'print STDERR "Using existing cgi entry in fstab\n";' \
  184. -e '};' \
  185. -e 's/$/\n$webroot\t$webmount\tauto\tbind\n/ unless $web_seen;' \
  186. -e 's/\n[# ]*($webroot[ \t]+$webmount[ \t]+[^\n]+)/\n$1\n$cgiroot\t$cgimount\tauto\tbind/ unless $cgi_seen;' \
  187. /etc/fstab
  188. echo >&2 "Mount web and cgi subdirs ..."
  189. mount "$webmount"
  190. mount "$cgimount"
  191. fi
  192. fi
  193. if [ -z "$profile_aux" ] && [ -x /usr/local/sbin/user-init ]; then
  194. /usr/local/sbin/user-init $NEWUSERNAME
  195. fi