-
Notifications
You must be signed in to change notification settings - Fork 0
/
xyz
executable file
·54 lines (46 loc) · 1.16 KB
/
xyz
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
#!/bin/sh
SCRIPTDIR=$(dirname "$0")
XYZ_HOME=$(cd "$SCRIPTDIR" && pwd)
getPid() {
echo $(ps | grep "php -S $1" | grep -v "grep" | cut -d' ' -f1)
}
if [ "$1" = "stop" ]; then
pid=$(getPid "");
if [ -z "$pid" ]; then
echo "No server to stop"
else
echo "Killing sever at pid $pid"
kill $pid
fi
elif [ "$1" = "-S" ] || [ "$1" = "start" ]; then
if [ -z "$2" ]; then
hostName="localhost:8000"
else
hostName="$2"
fi
pid=$(getPid "$hostName");
if [ -z "$pid" ]; then
echo "Starting server on $hostName"
php -S "$hostName" "$XYZ_HOME/index.php"
else
echo "Server already running under pid $pid."
echo "Use 'xyz stop' to stop."
fi
elif [ "$1" = "test" ]; then
sh "$XYZ_HOME/factory/test.sh"
elif [ "$1" = "build" ]; then
sh "$XYZ_HOME/factory/build.sh"
else
prefix=$( echo "$1" |cut -c1 );
if [ -z "$1" ] || [ "$prefix" = "-" ] || [ "$prefix" = "/" ]; then
php -f "$XYZ_HOME/index.php" -- $@
elif [ -e "$XYZ_HOME/engine/cli/commands/$1.sh" ]; then
file="$XYZ_HOME/engine/cli/commands/$1.sh"
shift;
sh "$file" $@
else
#TODO did you mean?
echo "[!] Unknown command: '$1'."
exit 1
fi
fi