set -e
+while [ $# -gt 0 ]; do
+ opt="$1"
+ shift
+ case "$opt" in
+ -h | --help )
+ cat <<EOF
+
+Usage:
+ scripts/setup [OPTIONS]
+
+Options:
+ --root ROOT Add a root (can be used multiple times)
+ --encoding ENCODING Filename encoding
+ --port PORT TCP port to listen on or 'none'
+ --smtp-server HOSTNAME SMTP server
+ --email ADDRESS Origin email address
+ --register y|n Enable/disable online registration
+ --play local|network Choose local or network play
+ --mcast ADDRESS PORT Set multicast address and port for --play network
+ -h, --help Display this message
+
+Sets up a basic DisOrder installation. You must have run 'make install'
+first. Use scripts/teardown to stop the server and deconfigure.
+
+EOF
+ exit 0
+ ;;
+ --version | -V )
+ echo "DisOrder scripts/setup _version_"
+ exit 0
+ ;;
+ --root )
+ roots="$roots $1"
+ shift
+ ;;
+ --encoding )
+ encoding="$1"
+ shift
+ ;;
+ --port )
+ port="$1"
+ shift
+ ;;
+ --smtp-server )
+ smtp_server="$1"
+ shift
+ ;;
+ --email )
+ mail_sender="$1"
+ shift
+ ;;
+ --register )
+ register="$1"
+ shift
+ ;;
+ --play )
+ play="$1"
+ shift
+ ;;
+ --mcast )
+ play=network
+ mcast_address="$1"
+ shift
+ mcast_port="$1"
+ shift
+ ;;
+ * )
+ echo >&2 "ERROR: unknown option '$opt'"
+ exit 1
+ ;;
+ esac
+done
+
echo
echo ------------------------------------------------------------------------
echo "DisOrder setup script"
echo "If this is not what you want, press ^C."
echo ------------------------------------------------------------------------
-while :; do
- echo
- echo "What directory or directories contain your music files:"
- echo "(enter one or more directories separated by spaces)"
- read -r roots
- ok=true
- for root in $roots; do
- if [ ! -d $root ]; then
- echo "'$root' does not exist"
- ok=false
+if [ -z "$roots" ]; then
+ while :; do
+ echo
+ echo "What directory or directories contain your music files:"
+ echo "(enter one or more directories separated by spaces)"
+ read -r roots
+ ok=true
+ for root in $roots; do
+ if [ ! -d $root ]; then
+ echo "'$root' does not exist"
+ ok=false
+ fi
+ done
+ if $ok; then
+ break
fi
done
- if $ok; then
- break
- fi
-done
+fi
if [ -z "$encoding" ]; then
echo
read -r encoding
fi
-while :; do
- echo
- echo "What TCP port should DisOrder listen on?"
- echo "(enter 'none' for none)"
- read -r port
- case $port in
- none )
- break
- ;;
- [^0-9] )
- echo "'$port' is not a valid port number"
- continue
- ;;
- * )
- break
- ;;
- esac
-done
+if [ -z "$port" ]; then
+ while :; do
+ echo
+ echo "What TCP port should DisOrder listen on?"
+ echo "(enter 'none' for none)"
+ read -r port
+ case $port in
+ none )
+ break
+ ;;
+ [^0-9] )
+ echo "'$port' is not a valid port number"
+ continue
+ ;;
+ * )
+ break
+ ;;
+ esac
+ done
+fi
-echo
-echo "What host should DisOrder use as an SMTP server?"
-read -r smtp_server
+if [ -z "$play" ]; then
+ while :; do
+ echo
+ echo "How do you want to play sound? Enter 'local' to use a local sound"
+ echo "device or 'network' to multicast sound across your network."
+ read -r play
+ case $play in
+ 'local' | network )
+ break
+ ;;
+ * )
+ echo "Enter 'local' or 'network'"
+ continue
+ ;;
+ esac
+ done
+fi
-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
+if [ "x$play" = xnetwork ]; then
+ if [ -z "$mcast_address" ]; then
+ echo
+ echo "Enter destination address for network transmission"
+ echo "(e.g. a multicast address)"
+ read -r mcast_address
+ fi
+ if [ -z "$mcast_port" ]; then
+ while :; do
+ echo
+ echo "Enter destination port for network transmission"
+ read -r mcast_port
+ case $mcast_port in
+ none )
+ break
+ ;;
+ [^0-9] )
+ echo "'$mcast_port' is not a valid port number"
+ continue
+ ;;
+ * )
+ break
+ ;;
+ esac
+ done
+ fi
+fi
+
+if [ -z "$mail_sender" ]; then
+ 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
+fi
+
+if [ -z "$register" ]; then
+ while :; do
+ echo
+ echo "Do you want to enable online registration? (Enter 'y' or 'n')"
+ read -r register
+ case $register in
+ y | n )
+ break
+ ;;
+ esac
+ done
+fi
echo
echo "Proposed DisOrder setup:"
else
echo " TCP port to listen on: $port"
fi
-echo " SMTP Server: $smtp_server"
+if [ ! -z "$smtp_server" ]; then
+ echo " SMTP Server: $smtp_server"
+fi
echo " Sender address: $mail_sender"
+echo " Online registration: $register"
+if [ $play = network ]; then
+ echo " Send sound to: $mcast_address port $mcast_port"
+fi
echo "Is this OK? (Enter 'y' or 'n')"
read -r ok
if [ $port != none ]; then
echo "listen 0.0.0.0 $port" >> pkgconfdir/config.new
fi
-echo "smtp_server $smtp_server" >> pkgconfdir/config.new
+if [ $play = network ]; then
+ echo "broadcast $mcast_address $mcast_port" >> pkgconfdir/config.new
+fi
+if [ ! -z "$smtp_server" ]; then
+ echo "smtp_server $smtp_server" >> pkgconfdir/config.new
+fi
echo "mail_sender $mail_sender" >> pkgconfdir/config.new
echo
launchctl load /Library/LaunchDaemons
echo "Starting DisOrder server"
launchctl start uk.org.greenend.rjk.disorder
- CGIBIN=/Library/WebServer/CGI-Executables
- DOCROOT=/Library/WebServer/Documents
- sever_running=true
+ server_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 "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
;;
* )
;;
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
sleep 5
while ! disorder version >/dev/null 2>&1; do
fi
sleep 1
done
- if [ $reg = y ]; then
+ if [ $register = y ]; then
echo "Creating guest user with 'register' right"
disorder setup-guest
else