Ajout : ./garradin master
authorJulien Moutinho <julm@autogeree.net>
Mon, 13 Oct 2014 06:26:24 +0000 (08:26 +0200)
committerJulien Moutinho <julm@autogeree.net>
Mon, 13 Oct 2014 06:26:24 +0000 (08:26 +0200)
garradin [new file with mode: 0755]

diff --git a/garradin b/garradin
new file mode 100755 (executable)
index 0000000..95dceba
--- /dev/null
+++ b/garradin
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+#ROOT=/usr/share/garradin/www
+ROOT=${0%/*}/www
+#ROOT=~/fossil/garradin/src/www
+ROUTER=${ROOT}/_route.php
+PORT=8088
+ADDRESS=localhost
+VERBOSE=0
+
+# Execute getopt
+ARGS=`getopt -o "p:vh" -l "port:,verbose,help" -n "garradin" -- "$@"`
+# Bad arguments
+if [ $? -ne 0 ];
+then
+  exit 1
+fi
+# A little magic
+eval set -- "$ARGS"
+
+# Now go through all the options
+while true;
+do
+  case "$1" in
+    -p|--port)
+      PORT=$2
+      shift;;
+
+    -v|--verbose)
+      VERBOSE=1
+      shift;;
+
+    -h|--help)
+      cat <<EOF
+Usage : $0 [COMMANDE] [PROJET]
+
+Où COMMANDE peut être :
+
+        server [-p|--port PORT] 
+                Démarre un serveur web Garradin sur le port spécifié
+                (ou sur le port 8000 par défaut)
+
+        ui [-p|--port PORT]
+                Idem que 'server' mais démarre ensuite le navigateur web par défaut
+                et connecte automatiquement avec le premier administrateur
+                de l'association.
+
+Si aucune COMMANDE n'est donnée, Garradin utilisera 'ui' par défaut.
+
+PROJET est le chemin menant à un projet Garradin précis 
+        (fichier .garradin.sqlite). Si aucun projet n'est indiqué, le 
+        dernier projet ouvert sera rouvert. Si aucun projet n'a jamais été
+        ouvert un nouveau projet sera créé.
+
+Options :
+
+        -p|--port PORT
+                Spécifie le port pour le mode ui ou le mode serveur.
+
+        -v|--verbose
+                Affiche les requêtes reçues sur le serveur web.
+
+        -h|--help
+                Affiche ce message.
+EOF
+      exit
+      shift;;
+    --)
+      shift
+      break;;
+  esac
+done
+
+CMD="$1"
+
+[ "$CMD" = "" ] && {
+    CMD="ui"
+}
+
+PROJECT="$2"
+
+[ "$PROJECT" = "" ] && PROJECT="1"
+
+export GARRADIN_STANDALONE="$PROJECT"
+
+[ $VERBOSE = 1 ] && {
+    php -S ${ADDRESS}:${PORT} -t ${ROOT} -d variables_order=EGPCS ${ROUTER} &
+} || {
+    php -S ${ADDRESS}:${PORT} -t ${ROOT} -d variables_order=EGPCS ${ROUTER} > /dev/null 2>&1 &
+}
+
+php_pid=$!
+sleep .5
+
+[ "$CMD" = "ui" ] && {
+    URL="http://${ADDRESS}:${PORT}/"
+    [ "$DISPLAY" != "" ] && {
+        x-www-browser ${URL} &
+    } || {
+        www-browser ${URL} &
+    }
+
+    wait $!
+    kill $php_pid
+} || {
+    wait $php_pid
+}