From 45f7b6cc45fa86d118af5b1f3166f126181d528e Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Fri, 12 Sep 2014 01:55:07 +0200 Subject: [PATCH 1/4] svere.sh first take, to make it more flexible --- bin/serve.sh | 125 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 118 insertions(+), 7 deletions(-) diff --git a/bin/serve.sh b/bin/serve.sh index bf6666c58..f84427f24 100755 --- a/bin/serve.sh +++ b/bin/serve.sh @@ -1,11 +1,122 @@ #!/bin/bash +# +# This script allows you to serve different TiddlyWiki editions. +# It respects the TIDDLYWIKI_EDITION_PATH variable described +# at: # http://tiddlywiki.com/#Environment%20Variables%20on%20Node.js +# +# Be sure your server tiddlywiki.info configuration contains the +# - "tiddlywiki/tiddlyweb" and the "tiddlywiki/filesystem" plugins. +# Otherwise saving is not possible. -# serve TiddlyWiki5 over HTTP +# global settings +# set -o nounset #exit if a variable is not set +set -o errexit #exit on error -# Optional parameter is the username for signing edits +# get command naem and path info needed for help text +ARG0=$(basename $0) +#ARG0DIR=$(dirname $0) +#[ $ARG0DIR == "." ] && ARG0DIR=$PWD + +# ---- helper functions ---- +_log () { + echo + echo "---> $1" +} + +version () { + echo "$ARG0, TiddlyWiki serve script version 0.0.1" + echo +} + +usage() { + version + echo Usage:$'\t'$ARG0 [edition dir] [username] [password] [host] [port] + echo +} + +help() { + usage + + echo Optional parameters + echo + echo $'\t'\$1 .. editions directory .. full path or relative to current directory + 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 + echo + echo $'\t'-v .. Version + echo $'\t'-h .. Help + echo + echo Example 1 ./serve ./edition/tw5.com-server username + echo Example 2 ./serve ./edition/tw5.com-server \"\" \"\" localhost 9090 + echo .. Example 2 defines: empty username, empty password + echo +} + +# error handling +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 () { + if [ ! -d $TIDDLYWIKI_EDITION_PATH ]; then + _log "Edition directory: '$TIDDLYWIKI_EDITION_PATH' doesn't exist. Create it!" + 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) + +#---------------------------------------------------- + +# If no edition parameter is provided, use defaults +if [ $# -eq 0 ]; then + # check if the edition path environment variable is set. If yes use it. + [ -z $TIDDLYWIKI_EDITION_PATH ] && TIDDLYWIKI_EDITION_PATH="./editions/tw5.com-server" + + # directory must exist! + check_edition_directory + + # serve the default settings. + serve "$TIDDLYWIKI_EDITION_PATH" "" "" localhost 8080 +else + if [ -z "$5" ]; then + PORT=8080 + else + PORT=$5 + fi + + # If the 1st parameter (edition) is set, it has priority. + TIDDLYWIKI_EDITION_PATH=$1 + + # directory must exist! + check_edition_directory + + serve "$TIDDLYWIKI_EDITION_PATH" "$2" "$3" "$4" $PORT +fi -node ./tiddlywiki.js \ - editions/tw5.com-server \ - --verbose \ - --server 8080 $:/core/save/all text/plain text/html "$1" "$2" "$3"\ - || exit 1 From fcf65433eabcb9daaff15ac2760f587635429f13 Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Fri, 12 Sep 2014 11:46:49 +0200 Subject: [PATCH 2/4] a bit more docs --- bin/serve.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/serve.sh b/bin/serve.sh index f84427f24..7fe064e97 100755 --- a/bin/serve.sh +++ b/bin/serve.sh @@ -4,25 +4,20 @@ # It respects the TIDDLYWIKI_EDITION_PATH variable described # at: # http://tiddlywiki.com/#Environment%20Variables%20on%20Node.js # -# Be sure your server tiddlywiki.info configuration contains the -# - "tiddlywiki/tiddlyweb" and the "tiddlywiki/filesystem" plugins. -# Otherwise saving is not possible. +# Be sure your server tiddlywiki.info configuration contains the plugins: +# - "tiddlywiki/tiddlyweb" and the "tiddlywiki/filesystem" +# - Otherwise saving is not possible. # global settings # set -o nounset #exit if a variable is not set set -o errexit #exit on error -# get command naem and path info needed for help text +# get command name and path info needed for help text ARG0=$(basename $0) #ARG0DIR=$(dirname $0) #[ $ARG0DIR == "." ] && ARG0DIR=$PWD # ---- helper functions ---- -_log () { - echo - echo "---> $1" -} - version () { echo "$ARG0, TiddlyWiki serve script version 0.0.1" echo @@ -54,6 +49,11 @@ help() { echo } +_log () { + echo + echo "---> $1" +} + # error handling error() { echo "$ARG0: $*" 1>&2 @@ -72,6 +72,7 @@ serve () { } check_edition_directory () { + # The editions directory must exist and should contain a tiddlywiki.info file if [ ! -d $TIDDLYWIKI_EDITION_PATH ]; then _log "Edition directory: '$TIDDLYWIKI_EDITION_PATH' doesn't exist. Create it!" exit 1 @@ -94,7 +95,7 @@ shift $(expr $OPTIND - 1) #---------------------------------------------------- -# If no edition parameter is provided, use defaults +# If no edition parameter is provided, use Jeremy's defaults if [ $# -eq 0 ]; then # check if the edition path environment variable is set. If yes use it. [ -z $TIDDLYWIKI_EDITION_PATH ] && TIDDLYWIKI_EDITION_PATH="./editions/tw5.com-server" @@ -119,4 +120,3 @@ else serve "$TIDDLYWIKI_EDITION_PATH" "$2" "$3" "$4" $PORT fi - From 9ca6b6bfb8c43ac43fb943776217e8acad693a79 Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Fri, 12 Sep 2014 11:50:55 +0200 Subject: [PATCH 3/4] prepare for PR --- bin/serve.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/serve.sh b/bin/serve.sh index 7fe064e97..fc50d8773 100755 --- a/bin/serve.sh +++ b/bin/serve.sh @@ -54,7 +54,7 @@ _log () { echo "---> $1" } -# error handling +# error handling for wrong parameters error() { echo "$ARG0: $*" 1>&2 exit 1 From fe83d289f4abaf3a82c419a40b57ffc7049377ea Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Fri, 12 Sep 2014 12:47:09 +0200 Subject: [PATCH 4/4] make empty strings visible --- bin/serve.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/serve.sh b/bin/serve.sh index fc50d8773..d9d034621 100755 --- a/bin/serve.sh +++ b/bin/serve.sh @@ -35,10 +35,10 @@ help() { echo Optional parameters echo echo $'\t'\$1 .. editions directory .. full path or relative to current directory - 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 + 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 echo echo $'\t'-v .. Version echo $'\t'-h .. Help