-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiggly.sh
executable file
·78 lines (69 loc) · 1.25 KB
/
piggly.sh
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
#!/usr/bin/env bash
set -e
set -x
DATABASE=
HOST=
PORT=5432
USER="postgres"
PASSWORD=
RESULT="/var/piggly/result"
COMMAND=
function usage() { echo "Usage: $0 -c [trace|report] -h host -d database -p port -u username -w password" 1>&2; exit 1; }
while getopts d:h:p:u:w:c: OPTION
do
case $OPTION in
d)
DATABASE=$OPTARG
;;
h)
HOST=$OPTARG
;;
p)
PORT=$OPTARG
;;
u)
USER=$OPTARG
;;
w)
PASSWORD=$OPTARG
;;
c)
COMMAND=$OPTARG
;;
*)
usage
;;
esac
done
if [[ -z $DATABASE ]] || [[ -z $HOST ]] || [[ -z $PORT ]] || [[ -z $USER ]]
then
usage
exit 1
fi
ROOT=/piggly
echo "
piggly:
adapter: postgresql
database: $DATABASE
username: $USER
password: $PASSWORD
host: $HOST" > "$ROOT/database.yml"
if [ "$COMMAND" = "trace" ]; then
"$ROOT/bin/piggly" trace \
-d "$ROOT/database.yml" \
-o "$RESULT/reports" \
-c "$RESULT/cache"
elif [ "$COMMAND" = "report" ]; then
"$ROOT/bin/piggly" report \
-o "$RESULT/reports" \
-c "$RESULT/cache" \
-f "$RESULT/trace.txt"
"$ROOT/bin/piggly" untrace \
-d "$ROOT/database.yml" \
-c "$RESULT/cache"
echo "OK, view $RESULT/reports/index.html"
else
usage
exit 1
fi;
chmod -R 777 $RESULT