From 6954cf10b82e7bf1f3a8cc243796ab9e30b3be4c Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 24 Oct 2010 16:21:40 +0200 Subject: Add web extension, asked for human accounts, and auto-added for www-* aux accounts. --- adduser.local | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'adduser.local') diff --git a/adduser.local b/adduser.local index a526ab2..1c35450 100755 --- a/adduser.local +++ b/adduser.local @@ -44,6 +44,10 @@ add2list() { /bin/echo "$1" | /usr/sbin/add_members -w y -a y -r - "$2"; } # resolve account profiles case "$NEWUSERNAME" in + www-*) + profile_aux=1 + profile_web=1 + ;; *-*) profile_aux=1 ;; @@ -157,6 +161,55 @@ if [ -z "$profile_aux" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ]; then esac fi +if [ -z "$profile_aux" ] && [ -z "$profile_web" ] && [ -n "$VERBOSE" ] && [ "$VERBOSE" -gt 0 ] && [ -d /var/www ]; then + echo -n "Setup web hosting for this user (y/N)?" + read webuser + case $webuser in + y|Y) + profile_web=1 + ;; + *) + ;; + esac +fi + +if [ -n "$profile_aux" ] && [ -d /var/www ]; then + webroot="$NEWHOMEDIR/public_websites" + cgiroot="$NEWHOMEDIR/public_cgi" + dataroot="$NEWHOMEDIR/private_webdata" + webmount="/var/www/vhosts/$NEWUSERNAME" + cgimount="/var/www/cgi-vhosts/$NEWUSERNAME" + + echo >&2 "Adding private and public subdirs in homedir ..." + install -d -o "$NEWUID" -g "$NEWGID" "$webroot" "$cgiroot" + install -d -o "$NEWUID" -g "$NEWGID" -m 0750 "$dataroot" + + echo >&2 "Adding subdirs below /var/www ..." + install -d "$webmount" "$cgimount" + + echo >&2 "Adding bind mount entries to /etc/fstab ..." + webroot="$webroot" cgiroot="$cgiroot" webmount="$webmount" cgimount="$cgimount" perl -w -p -0 -i.old \ + -e 'my $webroot = $ENV{"webroot"};' \ + -e 'my $cgiroot = $ENV{"cgiroot"};' \ + -e 'my $webmount = $ENV{"webmount"};' \ + -e 'my $cgimount = $ENV{"cgimount"};' \ + -e 'if (s/\n[# ]*($webroot[ \t]+$webmount[ \t]+[^\n]+)/\n$1/) {' \ + -e '$web_seen++;' \ + -e 'print STDERR "Using existing web entry in fstab\n";' \ + -e '};' \ + -e 'if (s/\n[# ]*($cgiroot[ \t]+$cgimount[ \t]+[^\n]+)/\n$1/) {' \ + -e '$cgi_seen++;' \ + -e 'print STDERR "Using existing cgi entry in fstab\n";' \ + -e '};' \ + -e 's/$/\n$webroot\t$webmount\tauto\tbind\n/ unless $web_seen;' \ + -e 's/\n[# ]*($webroot[ \t]+$webmount[ \t]+[^\n]+)/\n$1\n$cgiroot\t$cgimount\tauto\tbind/ unless $cgi_seen;' \ + /etc/fstab + + echo >&2 "Mount web and cgi subdirs ..." + mount "$webmount" + mount "$cgimount" +fi + if [ -z "$profile_aux" ] && [ -x /usr/local/sbin/user-init ]; then /usr/local/sbin/user-init $NEWUSERNAME fi -- cgit v1.2.3