-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.sh
executable file
·120 lines (105 loc) · 2.25 KB
/
start.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
# Function to show help
function show_help () {
echo -e "Usage: \e[1m./start.sh \e[33m[OPTIONS]\e[0m"
echo ""
echo -e "Starts \e[1mtestrpc\e[0m and creates a betfunding contract with truffle"
echo ""
echo "Possible arguments:"
echo ""
echo -e " \e[1m-v\e[0m be verbose"
echo -e " \e[1m-s\e[0m starts the server and creates a Betfunding instance"
echo -e " \e[1m-k\e[0m kills the server"
echo -e " \e[1m-i\e[0m print server info"
echo ""
}
# Function to set the PID of testrpc process
function set_pid () {
echo "TESTRPCPID=$1" > env.vars
TESTRPCPID=$1
}
function print_server_ifo () {
if [ $TESTRPCPID = 0 ]
then
echo "Server is not running, use -s option to start the server"
else
echo "Server running with PID=$TESTRPCPID"
fi
}
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
output_file=""
verbose=0
exec=0
TESTRPCPID=$(cat ./env.vars | grep TESTRPCPID | sed 's/TESTRPCPID\=//g')
if [ -z "$TESTRPCPID" ]
then
set_pid 0
fi
while getopts "h?viskf:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
v)
verbose=1
;;
i)
print_server_ifo
exit 0
;;
s)
exec=1
;;
k)
exec=2
;;
f)
output_file=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
#echo "verbose=$verbose, output_file='$output_file', Leftovers: $@"
case "$exec" in
1)
if [ $TESTRPCPID = 0 ]
then
testrpc &
pid="$!"
set_pid "$pid"
echo "Starting testrpc server with pid=$pid"
truffle compile
truffle migrate
truffle exec ./createProject.js
else
echo "Already running..."
fi
exit 0
;;
2)
if [ $TESTRPCPID != 0 ]
then
echo "Ending testrpcserver"
kill $TESTRPCPID
set_pid 0
else
echo "No server detected"
fi
exit 0
;;
9)
testrpc &
echo "$!"
;;
esac
case "$@" in
"")
show_help
;;
*)
exit 0
;;
esac