2012-06-01 17:27:20 +00:00
|
|
|
#!/bin/bash
|
2014-09-11 23:55:07 +00:00
|
|
|
#
|
2014-09-12 13:24:06 +00:00
|
|
|
# This script allows you to serve different TiddlyWiki editions.
|
|
|
|
#
|
2014-09-12 15:37:37 +00:00
|
|
|
# It respects a TW_SERVE_EDITION_PATH environment variable.
|
|
|
|
# If this variable is set it will be used. A command line parameter will overwrite it.
|
2014-09-11 23:55:07 +00:00
|
|
|
#
|
2014-09-12 13:24:06 +00:00
|
|
|
# Ensure your server tiddlywiki.info configuration contains
|
|
|
|
# these plugins, otherwise saving is not possible:
|
|
|
|
# - "tiddlywiki/tiddlyweb"
|
|
|
|
# - "tiddlywiki/filesystem"
|
2012-06-01 17:27:20 +00:00
|
|
|
|
2014-09-12 13:24:06 +00:00
|
|
|
# Global settings
|
2014-09-11 23:55:07 +00:00
|
|
|
# set -o nounset #exit if a variable is not set
|
|
|
|
set -o errexit #exit on error
|
2012-06-01 17:27:20 +00:00
|
|
|
|
2014-09-12 13:24:06 +00:00
|
|
|
# Get command name and path info needed for help text
|
2014-09-11 23:55:07 +00:00
|
|
|
ARG0=$(basename $0)
|
|
|
|
#ARG0DIR=$(dirname $0)
|
|
|
|
#[ $ARG0DIR == "." ] && ARG0DIR=$PWD
|
|
|
|
|
|
|
|
# ---- helper functions ----
|
|
|
|
version () {
|
2014-09-12 15:37:37 +00:00
|
|
|
echo "$ARG0, TiddlyWiki serve script version 0.0.2"
|
2014-09-11 23:55:07 +00:00
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
version
|
|
|
|
echo Usage:$'\t'$ARG0 [edition dir] [username] [password] [host] [port]
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
help() {
|
|
|
|
usage
|
|
|
|
|
|
|
|
echo Optional parameters
|
|
|
|
echo
|
2014-09-12 13:24:06 +00:00
|
|
|
echo $'\t'\$1 .. edition directory .. full or relative path to edition directory
|
2014-09-12 10:47:09 +00:00
|
|
|
echo $'\t'\$2 .. username for signing edits - can be empty like this: \"\"
|
|
|
|
echo $'\t'\$3 .. password - can be empty like this: \"\"
|
|
|
|
echo $'\t'\$4 .. IP address or HOST name .. defaults to: localhost
|
|
|
|
echo $'\t'\$5 .. PORT .. defaults to: 8080
|
2014-09-11 23:55:07 +00:00
|
|
|
echo
|
|
|
|
echo $'\t'-v .. Version
|
|
|
|
echo $'\t'-h .. Help
|
|
|
|
echo
|
2014-10-12 15:57:01 +00:00
|
|
|
echo Example 1 ./serve ./editions/tw5.com-server username
|
|
|
|
echo Example 2 ./serve ./editions/tw5.com-server \"\" \"\" localhost 9090
|
2014-09-11 23:55:07 +00:00
|
|
|
echo .. Example 2 defines: empty username, empty password
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2014-09-12 09:46:49 +00:00
|
|
|
_log () {
|
|
|
|
echo
|
|
|
|
echo "---> $1"
|
|
|
|
}
|
|
|
|
|
2014-09-12 09:50:55 +00:00
|
|
|
# error handling for wrong parameters
|
2014-09-11 23:55:07 +00:00
|
|
|
error() {
|
|
|
|
echo "$ARG0: $*" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# start the server
|
|
|
|
serve () {
|
|
|
|
#echo 1:$1 2:$2 3:$3 4:$4 5:$5
|
|
|
|
|
|
|
|
node ./tiddlywiki.js \
|
|
|
|
"$1" \
|
|
|
|
--verbose \
|
|
|
|
--server "$5" $:/core/save/all text/plain text/html "$2" "$3" "$4" \
|
|
|
|
|| exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
check_edition_directory () {
|
2014-09-12 09:46:49 +00:00
|
|
|
# The editions directory must exist and should contain a tiddlywiki.info file
|
2014-09-12 15:37:37 +00:00
|
|
|
if [ ! -d $TW_SERVE_EDITION_PATH ]; then
|
|
|
|
_log "Edition directory: '$TW_SERVE_EDITION_PATH' does not exist"
|
2014-09-11 23:55:07 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
|
# command line parameter handler
|
|
|
|
while getopts vh flag
|
|
|
|
do
|
|
|
|
case "$flag" in
|
|
|
|
(h) help; exit 0;;
|
|
|
|
(v) version; exit 0;;
|
|
|
|
(*) help
|
|
|
|
error
|
|
|
|
exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(expr $OPTIND - 1)
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
|
2014-09-12 09:46:49 +00:00
|
|
|
# If no edition parameter is provided, use Jeremy's defaults
|
2014-09-11 23:55:07 +00:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
# check if the edition path environment variable is set. If yes use it.
|
2014-09-12 15:37:37 +00:00
|
|
|
[ -z $TW_SERVE_EDITION_PATH ] && TW_SERVE_EDITION_PATH="./editions/tw5.com-server"
|
2014-09-11 23:55:07 +00:00
|
|
|
|
2014-09-12 13:24:06 +00:00
|
|
|
# directory must exist
|
2014-09-11 23:55:07 +00:00
|
|
|
check_edition_directory
|
|
|
|
|
|
|
|
# serve the default settings.
|
2014-09-12 15:37:37 +00:00
|
|
|
serve "$TW_SERVE_EDITION_PATH" "" "" localhost 8080
|
2014-09-11 23:55:07 +00:00
|
|
|
else
|
|
|
|
if [ -z "$5" ]; then
|
|
|
|
PORT=8080
|
|
|
|
else
|
|
|
|
PORT=$5
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If the 1st parameter (edition) is set, it has priority.
|
2014-09-12 15:37:37 +00:00
|
|
|
TW_SERVE_EDITION_PATH=$1
|
2014-09-11 23:55:07 +00:00
|
|
|
|
2014-09-12 13:24:06 +00:00
|
|
|
# directory must exist
|
2014-09-11 23:55:07 +00:00
|
|
|
check_edition_directory
|
|
|
|
|
2014-09-12 15:37:37 +00:00
|
|
|
serve "$TW_SERVE_EDITION_PATH" "$2" "$3" "$4" $PORT
|
2014-09-11 23:55:07 +00:00
|
|
|
fi
|