Ajout : ./garradin
[garradin.git] / garradin
1 #!/bin/sh
2
3 #ROOT=/usr/share/garradin/www
4 ROOT=${0%/*}/www
5 #ROOT=~/fossil/garradin/src/www
6 ROUTER=${ROOT}/_route.php
7 PORT=8088
8 ADDRESS=localhost
9 VERBOSE=0
10
11 # Execute getopt
12 ARGS=`getopt -o "p:vh" -l "port:,verbose,help" -n "garradin" -- "$@"`
13
14 # Bad arguments
15 if [ $? -ne 0 ];
16 then
17 exit 1
18 fi
19
20 # A little magic
21 eval set -- "$ARGS"
22
23 # Now go through all the options
24 while true;
25 do
26 case "$1" in
27 -p|--port)
28 PORT=$2
29 shift;;
30
31 -v|--verbose)
32 VERBOSE=1
33 shift;;
34
35 -h|--help)
36 cat <<EOF
37 Usage : $0 [COMMANDE] [PROJET]
38
39 Où COMMANDE peut être :
40
41 server [-p|--port PORT]
42 Démarre un serveur web Garradin sur le port spécifié
43 (ou sur le port 8000 par défaut)
44
45 ui [-p|--port PORT]
46 Idem que 'server' mais démarre ensuite le navigateur web par défaut
47 et connecte automatiquement avec le premier administrateur
48 de l'association.
49
50 Si aucune COMMANDE n'est donnée, Garradin utilisera 'ui' par défaut.
51
52 PROJET est le chemin menant à un projet Garradin précis
53 (fichier .garradin.sqlite). Si aucun projet n'est indiqué, le
54 dernier projet ouvert sera rouvert. Si aucun projet n'a jamais été
55 ouvert un nouveau projet sera créé.
56
57 Options :
58
59 -p|--port PORT
60 Spécifie le port pour le mode ui ou le mode serveur.
61
62 -v|--verbose
63 Affiche les requêtes reçues sur le serveur web.
64
65 -h|--help
66 Affiche ce message.
67 EOF
68 exit
69 shift;;
70
71 --)
72 shift
73 break;;
74 esac
75 done
76
77 CMD="$1"
78
79 [ "$CMD" = "" ] && {
80 CMD="ui"
81 }
82
83 PROJECT="$2"
84
85 [ "$PROJECT" = "" ] && PROJECT="1"
86
87 export GARRADIN_STANDALONE="$PROJECT"
88
89 [ $VERBOSE = 1 ] && {
90 php -S ${ADDRESS}:${PORT} -t ${ROOT} -d variables_order=EGPCS ${ROUTER} &
91 } || {
92 php -S ${ADDRESS}:${PORT} -t ${ROOT} -d variables_order=EGPCS ${ROUTER} > /dev/null 2>&1 &
93 }
94
95 php_pid=$!
96 sleep .5
97
98 [ "$CMD" = "ui" ] && {
99 URL="http://${ADDRESS}:${PORT}/"
100 [ "$DISPLAY" != "" ] && {
101 x-www-browser ${URL} &
102 } || {
103 www-browser ${URL} &
104 }
105
106 wait $!
107 kill $php_pid
108 } || {
109 wait $php_pid
110 }