Overview
Comment:Mise à jour script debian en bash plutôt qu'en PHP
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7a2f564518a50e752c4e9ef710aa929c28db5782
User & Date: bohwaz on 2014-01-08 16:32:50
Other Links: manifest | tags
Context
2014-01-08
17:21
Mise à jour manpage check-in: 6f04a43a5d user: bohwaz tags: trunk
16:32
Mise à jour script debian en bash plutôt qu'en PHP check-in: 7a2f564518 user: bohwaz tags: trunk
2013-12-19
03:27
Date un poil plus lisible + nom en français + message informant de la création d'une sauvegarde check-in: c87e9ecc9e user: bohwaz tags: trunk
Changes

Modified debian/garradin from [1ece109feb] to [08944ac4a2].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16



17
18
19
20
21
22
23
24
25
26
27
28
29
30



31
32
33
34
35
36


37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88


89





90


91

























#!/usr/bin/php
<?php

# Fixme: utiliser un routeur (path du script routeur à passer en argument à PHP)
# Fixme: faire passer le fait qu'on est en mode CLI et l'user via la directive ini : -d cli_server.color="$USER"
# Fixme: implémenter le fichier de config
# Fixme: faire en sorte qu'en mode UI le serveur web et le navigateur soient fermés tous les deux avec un Ctrl-C
# Fixme: loguer la sortie du serveur web

$config = [
	'browser'	=>	'/usr/bin/www-browser',
	'x-browser'	=>	'/usr/bin/x-www-browser',
	'port'		=>	8000,
	'root'		=>	'/usr/share/garradin/www',
];




if (isset($_SERVER['HOME']))
{
	$home = $_SERVER['HOME'];

	if (file_exists($home . '/.config/garradin/config.ini'))
	{
		$config = array_merge($config, parse_ini_file($home . '/.config/garradin/config.ini'));
	}
}

$options = getopt('p::v', ['port::', 'verbose']);

// Remove options from $argv array
foreach ($argv as $k=>$v)



{
	if (($v[0] == '-' && ($opt == substr($v, 1)) && array_key_exists($opt, $options))
		|| (substr($v, 0, 2) == '--' && ($opt == substr($v, 2)) && array_key_exists($opt, $options)))
	{
		if ($options[$opt] !== false)
		{


			unset($argv[$k+1]);
		}

		unset($argv[$k])

	}
}

$command = isset($argv[1]) ? $argv[1] : false;
$verbose = isset($options['v']) || isset($options['verbose']);
$port = isset($options['p']) ? (int) $options['p'] : (isset($options['port']) ? (int) $options['port'] : (int)$config['port']);

switch ($command)
{
	case 'server':
		system('php -S localhost:' . $port . ' -t ' . escapeshellarg($config['root']));
		break;
	case 'ui':
		$browser = !empty($_SERVER['DISPLAY']) ? $config['x-browser'] : $config['browser'];
		system('php -S localhost:' . $port . ' -t ' . escapeshellarg($config['root']) . ' > /dev/null &');
		system($browser . ' ' . escapeshellarg('http://localhost:' . $port));
		break;
	default:
		echo <<<EOF
Usage : $argv[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.

Configuration dans ~/.config/garradin/config.ini


EOF;





		break;


}

























|
<

<
<
<
<
<
<
<
<
<
<
|
<
|
>
>
>
|
|
<
|
|
|
<
<
<
|
<
|
<
<
>
>
>
|
|
|
|
|
<
>
>
|
<
|
|
>
|
<
|
|
<
<
|
<
|
<
<
|
<
<
<
<
<
<
|
|



|
|
|

|
|
|
|




|
|
|



|
|

|
|

<
>
>
|
>
>
>
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1

2










3

4
5
6
7
8
9

10
11
12



13

14


15
16
17
18
19
20
21
22

23
24
25

26
27
28
29

30
31


32

33


34






35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh












ROOT=/usr/share/garradin/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

[ $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
}