X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/dda7681934e228545aae11623fbd253fe7b8928f..08874c0649d7377f09c698bc84b885dd3b62b217:/scripts/setup.in diff --git a/scripts/setup.in b/scripts/setup.in index 8348724..dc8ca9b 100755 --- a/scripts/setup.in +++ b/scripts/setup.in @@ -29,9 +29,8 @@ case $(uname -s) in Darwin ) echo "Mac OS X detected" os=Mac - # TODO we should use jukebox and create it if necessary; see below - user=daemon - group=daemon + user=jukebox + group=jukebox ;; FreeBSD ) echo "FreeBSD detected" @@ -42,11 +41,10 @@ FreeBSD ) Linux ) if grep Debian /etc/issue >/dev/null 2>&1; then echo "You appear to be running Debian - please use .debs instead" - exit 1 - fi - if grep Ubuntu /etc/issue >/dev/null 2>&1; then + echo + elif grep Ubuntu /etc/issue >/dev/null 2>&1; then echo "You appear to be running Ubuntu - please use .debs instead" - exit 1 + echo fi echo "Linux detected" os=Linux @@ -66,12 +64,9 @@ esac echo echo "This script will:" echo " - overwrite any existing configuration" -case $os in -Mac ) - echo " - set the server up to be run at boot time" - echo " - start the server" - ;; -esac +echo " - set the server up to be run at boot time" +echo " - start the server" +echo " - set up the web interface" echo echo "If this is not what you want, press ^C." echo ------------------------------------------------------------------------ @@ -122,10 +117,20 @@ done echo echo "What host should DisOrder use as an SMTP server?" read -r smtp_server - -echo -echo "What address should mail from DisOrder come from?" -read -r mail_sender + +while :; do + echo + echo "What address should mail from DisOrder come from?" + read -r mail_sender + case "$mail_sender" in + *@* ) + break + ;; + * ) + echo "Email address must contain an '@' sign" + ;; + esac +done echo echo "Proposed DisOrder setup:" @@ -191,11 +196,60 @@ if [ ! -f pkgconfdir/options.user ]; then touch pkgconfdir/options.user fi +# pick ID1 ID2 ... IDn +# Echoes an ID matching none of ID1..IDn +pick() { + local n + n=250 # better not choose 0! + while :; do + ok=true + for k in "$@"; do + if [ $n = $k ]; then + ok=false + break + fi + done + if $ok; then + echo $n + return + fi + n=$((1+$n)) + done +} + case $os in Mac ) - # TODO niutil? + # Apple don't seem to believe in creating a user as a discrete operation + if dscl . -read /Groups/$group >/dev/null 2>&1; then + echo "$group group already exists" + else + echo "Creating $group group" + gids=$(dscl . -list /Groups PrimaryGroupID|awk '{print $2}') + gid=$(pick $gids) + echo "(picked gid $gid)" + dscl . -create /Groups/$group + dscl . -create /Groups/$group PrimaryGroupID $gid + dscl . -create /Groups/$group Password \* + fi + if dscl . -read /Users/$user >/dev/null 2>&1; then + echo "$user user already exists" + else + echo "Creating $user user" + uids=$(dscl . -list /Users UniqueID|awk '{print $2}') + uid=$(pick $uids) + echo "(picked uid $uid)" + gid=$(dscl . -read /Groups/$group PrimaryGroupID | awk '{print $2}') + dscl . -create /Users/$user + dscl . -create /Users/$user UniqueID $uid + dscl . -create /Users/$user UserShell /usr/bin/false + dscl . -create /Users/$user RealName 'DisOrder server' + dscl . -create /Users/$user NFSHomeDirectory pkgstatedir + dscl . -create /Users/$user PrimaryGroupID $gid + dscl . -create /Users/$user Password \* + fi ;; FreeBSD ) + # FreeBSD has a simple well-documented interface if pw groupshow $group >/dev/null 2>&1; then echo "$group group already exists" else @@ -233,22 +287,139 @@ chmod 2755 pkgstatedir case $os in Mac ) echo "Installing the plist into /Library/LaunchDaemons" - cp server/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/. + cp examples/uk.org.greenend.rjk.disorder.plist /Library/LaunchDaemons/. echo "Reloading launchd" launchctl load /Library/LaunchDaemons echo "Starting DisOrder server" launchctl start uk.org.greenend.rjk.disorder - echo "Installing CGI" - install -m 555 server/disorder.cgi /Library/WebServer/CGI-Executables/disorder - echo "Setting up link to CGI;'s dependencies" - rm -f /Library/WebServer/Documents/disorder - ln -s pkgdatadir/static /Library/WebServer/Documents/disorder - echo - echo "You must sudo disorder setup-guest [--no-online-registration] next." + CGIBIN=/Library/WebServer/CGI-Executables + DOCROOT=/Library/WebServer/Documents + sever_running=true + ;; +FreeBSD ) + echo "Installing startup script into /etc/rc.d" + install -m 555 examples/disorder.rc /etc/rc.d/disorder + echo "Starting DisOrder server" + /etc/rc.d/disorder start + echo "Identifying web server" + set /usr/local/www/* + case $# in + 0 ) + echo + echo "Could not find a web server" + exit 1 + ;; + 1 ) + ;; + * ) + echo + echo "Yikes! There seems to be more than one web server here." + echo "Guessing that you want $1." + echo + ;; + esac + web=$1 + echo "Found $web" + CGIBIN=$web/cgi-bin + DOCROOT=$web/data + server_running=true + ;; +Linux ) + echo "Looking for init scripts directory" + for d in /etc/rc.d /etc; do + if [ -d $d/init.d ]; then + RC_D=$d + break + fi + done + if [ -z "$RC_D" ]; then + echo "Cannot find your init scripts directory" + else + echo "Installing init script into $RC_D/init.d" + install -m 755 examples/disorder.init $RC_D/init.d/disorder + echo "Linking init script into $RC_D/rc*.d" + for n in 2 3 4 5; do + echo " $RC_D/rc$n.d/S99disorder -> $RC_D/init.d/disorder" + rm -f $RC_D/rc$n.d/S99disorder + ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/S99disorder + done + for n in 0 1 6; do + echo " $RC_D/rc$n.d/K01disorder -> $RC_D/init.d/disorder" + rm -f $RC_D/rc$n.d/K01disorder + ln -s $RC_D/init.d/disorder $RC_D/rc$n.d/K01disorder + done + echo "Starting DisOrder server" + $RC_D/init.d/disorder start + fi + echo "Looking for web server document root" + for d in /var/www/html /var/www; do + if [ -d $d ]; then + DOCROOT=$d + break + fi + done + echo "Looking for cgi-bin directory" + for d in /var/www/cgi-bin /usr/lib/cgi-bin; do + if [ -d $d ]; then + CGIBIN=$d + break + fi + done + server_running=true ;; * ) + echo echo "Sorry, I don't know how to install the server on this platform." echo "You will have to do that by hand." - exit 1 + server_running=false ;; esac + +echo +if [ -z "$DOCROOT" ]; then + echo "Cannot find your web server's document root" +else + echo "Setting up link to CGI's dependencies in $DOCROOT" + rm -f $DOCROOT/disorder + ln -s pkgdatadir/static $DOCROOT/disorder +fi + +echo +if [ -z "$CGIBIN" ]; then + echo "Cannot find your web server's cgi-bin directory" +else + echo "Installing CGI in $CGIBIN" + install -m 555 server/disorder.cgi $CGIBIN/disorder +fi + +if $server_running; then + while :; do + echo + echo "Do you want to enable online registration? (Enter 'y' or 'n')" + read -r reg + case $reg in + y | n ) + break + ;; + esac + done + echo + first=true + while ! disorder version >/dev/null 2>&1; do + if $first; then + echo "Waiting for server startup to complete..." + first=false + fi + sleep 1 + done + if [ $reg = y ]; then + echo "Creating guest user with 'register' right" + disorder setup-guest + else + echo "Creating guest user without 'register' right" + disorder setup-guest --no-online-registration + fi +fi + +echo +echo Done