chiark / gitweb /
Finish off Mac support in scripts/setup.
[disorder] / scripts / setup.in
index 8348724c8b25293b9ef737b87cb987d10792b85e..370013eba9f30fe7d7b378a3a1a7256b04b85a27 100755 (executable)
@@ -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"
@@ -191,11 +190,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,19 +281,51 @@ 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"
+  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."
   ;;
+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"
+  echo "Installing CGI"
+  install -m 555 server/disorder.cgi $web/cgi-bin/disorder
+  echo "Setting up link to CGI's dependencies"
+  rm -f $web/data/disorder
+  ln -s pkgdatadir/static $web/data/disorder
+  echo
+  echo "You must sudo disorder setup-guest [--no-online-registration] next."
+  ;;
 * )
   echo "Sorry, I don't know how to install the server on this platform."
   echo "You will have to do that by hand."