summaryrefslogtreecommitdiff
path: root/user-init
blob: 7895d5f5389f62bd1251edda7ccc152f215257b4 (plain)
  1. #!/bin/sh
  2. set -e
  3. # reset flags
  4. apache_reload_needed=""
  5. runmode="normal"
  6. # subfolder name defaults (edit /etc/local/users.conf to override)
  7. mac="mac" # Optimized for sharing through AppleShare (netatalk)
  8. pc="pc" # Optimized for sharing though SMB/CIFS (Samba)
  9. xchange="xchange" # Readable by group
  10. # config (edit /etc/local/users.conf to override)
  11. # which are user accounts (adduser values are used if empty)
  12. first_uid=""
  13. last_uid=""
  14. do_quota="no" # Manage disk quota
  15. do_distrib="no" # Distributed shares (software archive)
  16. do_personal="no" # Personal shares (mac, pc, public_html)
  17. do_xchange="no" # Group-readable shares
  18. do_public="no" # Public share (web homepage)
  19. do_mac="no" # AppleShare-optimized share (netatalk)
  20. do_pc="no" # SMB-ptimized share (Samba)
  21. do_server="no" # Personal share on remote SMB server
  22. quota_roots="" # space-delimited list of disk devices
  23. quota_soft="100000"
  24. quota_hard="1000000"
  25. quota_newstyle="yes" # Woody used a different syntax...
  26. xchange_root="xchange"
  27. xchange_sharedroot="/home/XCHANGE"
  28. mac_root="mac"
  29. pc_root="pc"
  30. server_name="SERVER" # SMB name of remote server
  31. server_desc="remote server"
  32. server_root="server"
  33. server_conf="/etc/security/pam_mount.conf"
  34. server_userconf=".winpassword"
  35. QUOTASOFT="0"
  36. QUOTAHARD="0"
  37. # Relax permissions
  38. # Currently allows group write access to root of mac shares
  39. RELAXEDPERMS=''
  40. ### No servicable parts below this line! ###
  41. if [ -e /etc/adduser.conf ]; then
  42. . /etc/adduser.conf
  43. else
  44. echo "/etc/adduser.conf missing. Exiting..."
  45. exit 1
  46. fi
  47. [ -r /etc/local/users.conf ] && . /etc/local/users.conf
  48. #TODO: Add conversion like below, and change remaining script to new variable names
  49. #[ -n "$XDIR" ] && xchange_sharedroot="$XDIR"
  50. # exit silently if this system lacks required hints
  51. [ -r /etc/local/volumes ] && . /etc/local/volumes || exit 0
  52. XDIRREAL="$XDIR/users/root"
  53. if [ -n "$XCHANGE" ]; then
  54. if [ ! -d "$XDIR" ]; then
  55. echo "XDIR doesn't exist. Ignoring XCHANGE!"
  56. XCHANGE=""
  57. fi
  58. fi
  59. if [ $# -gt 0 ]; then
  60. USERS=$*
  61. else
  62. # USERS=`getent passwd | awk -F: '{print $1}'`
  63. echo "uid required!"
  64. exit 1
  65. fi
  66. [ -n "$NETATALK_HOME" ] && mac="$NETATALK_HOME"
  67. [ -n "$SAMBA_HOME" ] && pc="$SAMBA_HOME"
  68. [ -n "$XCHANGE_HOME" ] && xchange="$XCHANGE_HOME"
  69. echo "Setting up additional folders and permissions..."
  70. for user in $USERS; do
  71. uid="`getent passwd \"$user\" | awk -F: '{print $3}' | head -n 1`"
  72. HOME="`getent passwd \"$user\" | awk -F: '{print $6}' | head -n 1`"
  73. groups="`groups \"$user\"`"
  74. if [ -z "$HOME" ]; then
  75. echo "User $user doesn't exist. Ignoring..."
  76. continue
  77. fi
  78. # Ignore non-human accounts silently
  79. [ "$uid" -ge "$FIRST_UID" -a "$uid" -le "$LAST_UID" ] || continue
  80. [ -d "$HOME" ] || continue
  81. # [ -L "$HOME" ] && continue
  82. echo -n "$user"
  83. # if [ -x /etc/local/quota.sh ]; then
  84. # /etc/local/quota.sh "$user"
  85. # fi
  86. quotasoft_override=''
  87. quotahard_override=''
  88. for quotaoverride in $QUOTAOVERRIDES; do
  89. for group in $groups; do
  90. if [ "$quotaoverride" = "$group" ]; then
  91. eval quotasoft_override=\"\$QUOTASOFT_${quotaoverride}\"
  92. eval quotahard_override=\"\$QUOTAHARD_${quotaoverride}\"
  93. break 2
  94. fi
  95. done
  96. done
  97. quotasoft="${quotasoft_override:-$QUOTASOFT}"
  98. quotahard="${quotahard_override:-$QUOTAHARD}"
  99. for quotahome in $QUOTAHOMES; do
  100. if [ -n "$NEW_QUOTA" ]; then
  101. setquota "$user" "$quotasoft" "$quotahard" 0 0 "$quotahome"
  102. else
  103. setquota "$user" "$quotahome" "$quotasoft" "$quotahard" 0 0
  104. fi
  105. done
  106. if [ -n "$NETATALK" ]; then
  107. mkdir -p "$HOME/$mac"
  108. fi
  109. if [ -n "$SAMBA" ]; then
  110. mkdir -p "$HOME/$pc"
  111. fi
  112. if [ -n "$XCHANGE" ]; then
  113. mkdir -p "$XDIRREAL/$user"
  114. fi
  115. if [ -n "$PUBLIC" ]; then
  116. mkdir -p "$HOME/public_html"
  117. fi
  118. #TODO: Enable this only when option implemented to do it non-interactively
  119. # echo # dirty hack: better if being able to lower verbosity of localuserconfig
  120. # su -s /bin/bash -c localuserconfig "$user"
  121. if [ "$do_server" = "yes" ] && [ -r "$server_conf" ] && [ -f "$HOME/$server_userconf" ]; then
  122. server_username="$(grep '^username' \"$HOME/$server_userconf\" | awk -F= '{print $2}' | head -n 1 | awk '{print $1}')"
  123. if [ -n "$server_username" ]; then
  124. if grep -q "^volume $user " "$server_conf"; then
  125. perl -pi -e "s|^volume $user .*|volume $user smb $server_name $server_username $HOME/$server_root uid=$user,gid=$user - -|" "$server_conf"
  126. else
  127. echo "volume $user smb $server_name $server_username $HOME/$server_root uid=$user,gid=$user - -" >> "$server_conf"
  128. fi
  129. fi
  130. fi
  131. chown "$user": "$HOME"
  132. chmod u=rwX,go=rX "$HOME"
  133. # Mail handling
  134. maildir="$MAILDIR"
  135. if [ -f "$HOME/.procmailrc" ]; then
  136. # Drop simple maildir-enabling procmail file when default
  137. if [ -n "$MAILDIR" ] && [ "`md5sum \"$HOME/.procmailrc\" | awk '{print $1}'`" = "03ea802caaa5ce6f2a9be8d56eaf8ff5" ]; then
  138. rm "$HOME/.procmailrc"
  139. else
  140. chown "$user": "$HOME/.procmailrc"
  141. chmod 0640 "$HOME/.procmailrc"
  142. # Check if this one account exceptionally uses maildir
  143. if [ -z "$maildir" ] && egrep -q '^DEFAULT=\$HOME/Maildir/$' "$HOME/.procmailrc"; then
  144. maildir="yes"
  145. fi
  146. fi
  147. fi
  148. if [ -n "$maildir" ]; then
  149. mkdir -p "$HOME/Maildir/cur" "$HOME/Maildir/new" "$HOME/Maildir/tmp"
  150. chown -R "$user": "$HOME/Maildir"
  151. chmod -R u=rw,go=,u+X "$HOME/Maildir"
  152. else
  153. mkdir -p "$HOME/mail"
  154. if [ -n "$USE_MBOX" ]; then
  155. touch "$HOME/mail/mbox"
  156. elif [ -f "$HOME/mail/mbox" ] && [ ! -s "$HOME/mail/mbox" ]; then
  157. rm -f "$HOME/mail/mbox"
  158. fi
  159. chown -R "$user": "$HOME/mail"
  160. chmod -R u=rw,go=,u+X "$HOME/mail"
  161. if [ -f "$HOME/.mailboxlist" ]; then
  162. chown "$user": "$HOME/.mailboxlist"
  163. chmod 0640 "$HOME/.mailboxlist"
  164. fi
  165. fi
  166. mailspool="/var/spool/mail"
  167. if [ -d "/var/mail" ]; then
  168. mailspool="/var/mail"
  169. fi
  170. if [ -f "$mailspool/$user" ]; then
  171. if [ -n "$maildir" ] && [ ! -s "$mailspool/$user" ]; then
  172. rm "$mailspool/$user"
  173. else
  174. chown "$user":mail "$mailspool/$user"
  175. chmod ug=rw,o= "$mailspool/$user"
  176. fi
  177. fi
  178. if [ -f "$HOME/.forward" ]; then
  179. chown "$user": "$HOME/.forward"
  180. chmod 0640 "$HOME/.forward"
  181. fi
  182. # MySQL handling
  183. if [ -f "$HOME/.my.cnf" ]; then
  184. chown "$user": "$HOME/.my.cnf"
  185. chmod 0600 "$HOME/.my.cnf"
  186. fi
  187. # Mac dir permissions
  188. if [ -d "$HOME/$mac" ]; then
  189. chown -R "$user": "$HOME/$mac"
  190. chmod -R u=rw,g=r,o=,ug+X "$HOME/$mac"
  191. rm -rf "$HOME/$mac/Network Trash Folder"
  192. mkdir "$HOME/$mac/Network Trash Folder"
  193. chown nobody: "$HOME/$mac/Network Trash Folder"
  194. chmod a= "$HOME/$mac/Network Trash Folder"
  195. fi
  196. # PC dir permissions
  197. if [ -d "$HOME/$pc" ]; then
  198. chown -R "$user": "$HOME/$pc"
  199. chmod -R u=rw,g=r,o=,ug+X "$HOME/$pc"
  200. fi
  201. #FIXME: something is wrong with prefixing "x" here...
  202. # Exchange dir permissions
  203. if [ -d "$XDIRREAL/$user" ]; then
  204. chown -R "$user":users "$XDIRREAL/$user"
  205. chmod -R g=r,g+X "$XDIRREAL/$user"
  206. if [ -e "x$HOME/$xchange" ]; then
  207. if [ -L "x$HOME/$xchange" ]; then
  208. ln -sf "$XDIRREAL/$user $HOME/$xchange"
  209. else
  210. echo "ERROR: \"$HOME/$xchange\" exists already. Leaving it as is..."
  211. fi
  212. else
  213. ln -s "$XDIRREAL/$user" "$HOME/$xchange"
  214. fi
  215. fi
  216. # Public dir permissions
  217. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./public\(_.*\)?'`; do
  218. chown -R "$user": "$HOME/$dir"
  219. chmod -R u+rX,go=r,go+X "$HOME/$dir"
  220. if [ -n "$NETATALK" ]; then
  221. rm -rf "$HOME/$dir/Network Trash Folder"
  222. mkdir "$HOME/$dir/Network Trash Folder"
  223. chown nobody: "$HOME/$dir/Network Trash Folder"
  224. chmod a= "$HOME/$dir/Network Trash Folder"
  225. fi
  226. done
  227. # Shared dirs are writable by own primary group
  228. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./shared\(_.*\)?'`; do
  229. chgrp -R "$user" "$HOME/$dir"
  230. chmod -R ug=rw,o=,ug+X,g+s "$HOME/$dir"
  231. if [ -n "$NETATALK" ]; then
  232. rm -rf "$HOME/$dir/Network Trash Folder"
  233. mkdir "$HOME/$dir/Network Trash Folder"
  234. chown nobody: "$HOME/$dir/Network Trash Folder"
  235. chmod a= "$HOME/$dir/Network Trash Folder"
  236. fi
  237. done
  238. # Private dirs are readable by own primary group
  239. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./private\(_.*\)?$'`; do
  240. chown -R "$user": "$HOME/$dir"
  241. chmod -R u+rX,g=r,g+X,o= "$HOME/$dir"
  242. done
  243. # Secret dirs are accessible only by self
  244. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./secret\(_.*\)?$'`; do
  245. chown -R "$user": "$HOME/$dir"
  246. chmod -R u+rX,go= "$HOME/$dir"
  247. done
  248. # Fileshares: <home>/shares.<sharetype>/<rogroup>/<rwgroup>/<sharename>
  249. # <sharetype>: Either mac or win depending on which of netatalk and samba provides r/w access to the shares
  250. # <rwgroup>: Group with write access to the share (usually the default group of the owner)
  251. # <rogroup>: Either rwgroup or secondary group with read-only access to the share
  252. # owner and rwgroup members must be member of both groups
  253. #FIXME: Use the below instead, and replace occurrences of "$thisdir" with "$HOME/$dir".
  254. #for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./shares\..*'`; do
  255. find "$HOME" -mindepth 1 -maxdepth 1 -type d -print | egrep "^$HOME/shares\." | (while read thisdir; do
  256. sharetype="`basename \"$thisdir\" | awk -F. '{print $2}'`"
  257. # Define dir and file exceptions
  258. case "$sharetype" in
  259. mac)
  260. dirs_world_rw_create='.AppleDB'
  261. dirs_group_rw_create='.AppleDesktop/Temporary Items/TheFindByContentFolder'
  262. dirs_group_ro_create='TheVolumeSettingsFolder'
  263. if [ -n "$RELAXEDPERMS" ]; then
  264. dirs_group_rw_update='.AppleDouble'
  265. else
  266. dirs_group_ro_update='.AppleDouble'
  267. fi
  268. dirs_group_ro_update='.AppleDouble'
  269. files_group_ro_update=':2eDS_Store'
  270. dirs_no_access_purge='Network Trash Folder'
  271. ;;
  272. win)
  273. ;;
  274. *)
  275. continue
  276. ;;
  277. esac
  278. exceptions="$dirs_world_rw_create/$dirs_group_rw_create/$dirs_group_ro_create/$dirs_group_rw_update/$dirs_group_ro_update/$files_group_ro_update/$dirs_no_access_purge"
  279. exception_dirs_create="$dirs_world_rw_create/$dirs_group_rw_create/$dirs_group_ro_create"
  280. # <home>/shares.<sharetype>
  281. chown "$user": "$thisdir"
  282. chmod a=rX "$thisdir"
  283. find "$thisdir" -mindepth 1 -maxdepth 1 -type d -print | (while read thisdir; do
  284. # <home>/shares.<sharetype>/<rogroup>
  285. rogroup="`basename \"$thisdir\"`"
  286. chown "$user":"$rogroup" "$thisdir"
  287. chmod ug=rX,o= "$thisdir"
  288. find "$thisdir" -mindepth 1 -maxdepth 1 -type d -print | (while read thisdir; do
  289. # <home>/shares.<sharetype>/<rogroup>/<rwgroup>
  290. rwgroup="`basename \"$thisdir\"`"
  291. chown "$user":"$rwgroup" "$thisdir"
  292. chmod a=rX,g+s "$thisdir"
  293. find "$thisdir" -mindepth 1 -maxdepth 1 -type d -print | (while read thisdir; do
  294. # <home>/shares.<sharetype>/<rogroup>/<rwgroup>/<sharename>
  295. sharename="`basename \"$thisdir\"`"
  296. chown "$user":"$rwgroup" "$thisdir"
  297. if [ -n "$RELAXEDPERMS" ]; then
  298. chmod ug=rw,o=r,a+X,g+s "$thisdir"
  299. else
  300. chmod u=rw,go=r,a+X,g+s "$thisdir"
  301. fi
  302. ifs="$IFS"
  303. # Set default permissions
  304. find "$thisdir" -mindepth 1 -maxdepth 1 -print | (while read thisitem; do
  305. # <home>/shares.<sharetype>/<rogroup>/<rwgroup>/<sharename>/*
  306. thisparentdir="`basename \"$thisitem\"`"
  307. IFS="/"; for exception in $exceptions; do IFS="$ifs";
  308. if [ "$thisparentdir" = "$exception" ]; then
  309. continue 2
  310. fi
  311. done
  312. chgrp -R "$rwgroup" "$thisitem"
  313. chmod -R ug=rw,o=r,a+X,g+s "$thisitem"
  314. done)
  315. # Handle exception dirs to be created if not existing
  316. IFS="/"; for dir in $exception_dirs_create; do IFS="$ifs";
  317. if [ ! -d "$thisdir/$dir" ]; then
  318. rm -f "$thisdir/$dir"
  319. fi
  320. if [ ! -e "$thisdir/$dir" ]; then
  321. mkdir "$thisdir/$dir"
  322. fi
  323. chown "$user":"$rwgroup" "$thisdir/$dir"
  324. done
  325. IFS="/"; for dir in $dirs_world_rw_create; do IFS="$ifs";
  326. if [ "$rogroup" = "$rwgroup" ]; then
  327. chmod -R ug=rw,o=r,a+X,g+s "$thisdir/$dir"
  328. else
  329. chmod -R a=rw,a+X,g+s "$thisdir/$dir"
  330. fi
  331. done
  332. IFS="/"; for dir in $dirs_group_rw_create; do IFS="$ifs";
  333. chmod -R ug=rw,o=r,a+X,g+s "$thisdir/$dir"
  334. done
  335. IFS="/"; for dir in $dirs_group_ro_create; do IFS="$ifs";
  336. chmod -R u=rw,go=r,a+X,g+s "$thisdir/$dir"
  337. done
  338. # Handle exception dirs to be updated if already there
  339. IFS="/"; for dir in $dirs_group_rw_update; do IFS="$ifs";
  340. if [ -e "$thisdir/$dir" ]; then
  341. chmod ug=rw,o=r,a+X,g+s "$thisdir/$dir"
  342. fi
  343. done
  344. IFS="/"; for dir in $dirs_group_ro_update; do IFS="$ifs";
  345. if [ -e "$thisdir/$dir" ]; then
  346. chmod u=rw,go=r,a+X,g+s "$thisdir/$dir"
  347. fi
  348. done
  349. # Handle exception files to be updated if already there
  350. IFS="/"; for file in $files_group_ro_update; do IFS="$ifs";
  351. if [ -e "$thisdir/$file" ]; then
  352. chmod u=rw,go=r,g+s "$thisdir/$file"
  353. fi
  354. done
  355. # Handle exception dirs to be purged and recreated
  356. IFS="/"; for dir in $dirs_no_access_purge; do IFS="$ifs";
  357. rm -rf "$thisdir/$dir"
  358. mkdir -m a= "$thisdir/$dir"
  359. chown nobody: "$thisdir/$dir"
  360. done
  361. IFS="$ifs"
  362. done)
  363. done)
  364. done)
  365. done)
  366. # Ftp shares permissions
  367. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex "^\./ftp_$user$"`; do
  368. chgrp -R "$user" "$HOME/$dir"
  369. chmod -R ug=rw,o=r,a+X,g+s "$HOME/$dir"
  370. rm -rf "$HOME/$dir/Network Trash Folder"
  371. mkdir "$HOME/$dir/Network Trash Folder"
  372. chown nobody: "$HOME/$dir/Network Trash Folder"
  373. chmod a= "$HOME/$dir/Network Trash Folder"
  374. done
  375. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex "^\./ftp_${user}_ro$"`; do
  376. chown -R "$user": "$HOME/$dir"
  377. chmod -R u=rw,go=r,a+X "$HOME/$dir"
  378. rm -rf "$HOME/$dir/Network Trash Folder"
  379. mkdir "$HOME/$dir/Network Trash Folder"
  380. chown nobody: "$HOME/$dir/Network Trash Folder"
  381. chmod a= "$HOME/$dir/Network Trash Folder"
  382. done
  383. # Web shares permissions
  384. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./web_.*'`; do
  385. chown -R "$user": "$HOME/$dir"
  386. # chmod -R u=rw,go=r,a+X $webdir
  387. #TODO: Only cgi scripts (.cgi and .pl) should be executable
  388. chmod -R u+rw,go+r,a+X "$HOME/$dir"
  389. # leftover from ancient times with another policy
  390. if [ $NETATALK ]; then
  391. rm -rf "$HOME/$dir/Network Trash Folder"
  392. fi
  393. done
  394. # Web shares permissions
  395. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./websites$'`; do
  396. chown root: "$HOME/$dir"
  397. chmod a=r,u+w,a+X "$HOME/$dir"
  398. done
  399. for dir in `cd "$HOME" && find . -mindepth 2 -maxdepth 2 -type d -regex '^\./websites/.*'`; do
  400. chown -R "$user": "$HOME/$dir"
  401. # chmod -R u=rw,go=r,a+X $webdir
  402. #TODO: Only cgi scripts (.cgi and .pl) should be executable
  403. chmod -R u+rw,go+r,a+X "$HOME/$dir"
  404. # leftover from ancient times with another policy
  405. if [ $NETATALK ]; then
  406. rm -rf "$HOME/$dir/Network Trash Folder"
  407. fi
  408. done
  409. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./webscripts$'`; do
  410. chown root: "$HOME/$dir"
  411. chmod a=r,u+w,a+X "$HOME/$dir"
  412. done
  413. for dir in `cd "$HOME" && find . -mindepth 2 -maxdepth 2 -type d -regex '^\./webscripts/.*'`; do
  414. chown -R $user: "$HOME/$dir"
  415. # chmod -R u=rw,go=r,a+X $webdir
  416. #TODO: Only cgi scripts (.cgi and .pl) should be executable
  417. chmod -R u+rw,go+r,a+X "$HOME/$dir"
  418. done
  419. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./webdata$'`; do
  420. chown "$user": "$HOME/$dir"
  421. chmod a=r,u+w,a+X "$HOME/$dir"
  422. done
  423. for dir in `cd "$HOME" && find . -mindepth 2 -maxdepth 2 -type d -regex '^\./webdata/.*'`; do
  424. chown -R "$user": "$HOME/$dir"
  425. chmod -R u=rw,go=,u+X "$HOME/$dir"
  426. done
  427. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./webshareddata$'`; do
  428. chown "$user": "$HOME/$dir"
  429. chmod a=r,u+w,a+X "$HOME/$dir"
  430. done
  431. for dir in `cd "$HOME" && find . -mindepth 2 -maxdepth 2 -type d -regex '^\./webshareddata/.*'`; do
  432. chown -R "$user:" "$HOME/$dir"
  433. chmod -R u=rw,go=r,a+X "$HOME/$dir"
  434. done
  435. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./webphpsites$'`; do
  436. chown root: "$HOME/$dir"
  437. chmod u=rw,go=r,a+X "$HOME/$dir"
  438. done
  439. for dir in `cd "$HOME" && find . -mindepth 2 -maxdepth 2 -type d -regex '^\./webphpsites/.*'`; do
  440. chown -R "$user":www-data "$HOME/$dir"
  441. # chmod -R ug=rw,o=r,a+X $dir
  442. chmod -R ug=rw,o=,ug+X "$HOME/$dir"
  443. done
  444. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./webphpdata$'`; do
  445. chown root: "$HOME/$dir"
  446. chmod a=r,u+w,a+X "$HOME/$dir"
  447. done
  448. for dir in `cd "$HOME" && find . -mindepth 2 -maxdepth 2 -type d -regex '^\./webphpdata/.*'`; do
  449. chown -R "$user":www-data "$HOME/$dir"
  450. chmod -R ug=rw,o=,ug+X "$HOME/$dir"
  451. done
  452. for dir in `cd "$HOME" && find . -mindepth 1 -maxdepth 1 -type d -regex '^\./weblogs$'`; do
  453. chown -R "$user": "$HOME/$dir"
  454. chmod -R u=rw,g=r,o=,ug+X "$HOME/$dir"
  455. done
  456. # Dummy user restrictions
  457. if [ -n "$REALUSERS_GROUPNAME" -a -n "$DUMMYSHAREDIR" -a -n "$DUMMYSHAREOWNER" -a -n "$DUMMYSHARENAME" ]; then
  458. [ -e $DUMMYSHAREDIR/$user ] \
  459. || mkdir $DUMMYSHAREDIR/$user
  460. chown $DUMMYSHAREOWNER: $DUMMYSHAREDIR/$user
  461. chmod u=rw,go=r,a+X $DUMMYSHAREDIR/$user
  462. if [ -e $HOME/$DUMMYSHARENAME ]; then
  463. if [ -L $HOME/$DUMMYSHARENAME ]; then
  464. ln -sf $DUMMYSHAREDIR/$user $HOME/$DUMMYSHARENAME
  465. chown $user: $HOME/$DUMMYSHARENAME
  466. else
  467. echo "WARNING: $HOME/$DUMMYSHAREDIR exists already. Leaving it as is..."
  468. fi
  469. else
  470. ln -s $DUMMYSHAREDIR/$user $HOME/$DUMMYSHARENAME
  471. chown $user: $HOME/$DUMMYSHARENAME
  472. fi
  473. if [ -n "$DUMMYAPACHECFG" -a -n "$DUMMYAPACHESHAREDIR" ]; then
  474. if [ -f /etc/apache/include.d/$DUMMYAPACHECFG -a -x /etc/init.d/apache ]; then
  475. if [ -e /etc/apache/include.d/$DUMMYAPACHECFG-$user ]; then
  476. echo "/etc/apache/include.d/$DUMMYAPACHECFG-$user exists already. Ignoring..."
  477. else
  478. echo "# Created automatically by adduser.local
  479. <Location /$DUMMYAPACHESHAREDIR/$user>
  480. <Limit GET POST>
  481. require user $user
  482. </Limit>
  483. </Location>" \
  484. > /etc/apache/include.d/$DUMMYAPACHECFG-$user
  485. apache_reload_needed="1"
  486. fi
  487. fi
  488. fi
  489. fi
  490. echo "."
  491. done
  492. if [ $XCHANGE ]; then
  493. for USER in $(ls $XDIRREAL); do
  494. id $user >/dev/null 2>&1 || rm -rf $XDIRREAL/$user
  495. done
  496. fi
  497. if [ "$apache_reload_needed" ]; then
  498. apache_do_reload=""
  499. case runmode in
  500. interactive)
  501. echo -n "Apache config changed. Reload Apache now (Y/n)? "
  502. read apache_reload
  503. case $apache_reload in
  504. y|Y|"")
  505. apache_do_reload="1"
  506. ;;
  507. esac
  508. ;;
  509. force)
  510. apache_do_reload="1"
  511. ;;
  512. *)
  513. echo "Apache config has changed. Remember to reload Apache...!"
  514. ;;
  515. esac
  516. if "$apache_do_reload" ]; then
  517. /etc/init.d/apache force-reload
  518. fi
  519. fi