-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_trema_satellite
executable file
·126 lines (99 loc) · 2.13 KB
/
start_trema_satellite
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
121
122
123
124
125
126
#!/bin/bash
usage() {
cat << EOF
usage: trema_satellite [options] <trema_app>
This script runs trema with trema-satellite. The <app> of last argument specifies an application file path of Trema. This is same of the first argument of "trema run" command.
OPTIONS:
-h Show this message
-f Specifies Trema-Satellite configuration
-c Specifies emulated network configuration (Trema Option)
-s Enables Trema wireshark plugin (Trema Option)
-d Runs as a daemon (Trema Option)
EOF
}
parse_options() {
while getopts hf:c:sd OPTION
do
case $OPTION in
h)
usage
exit 1
;;
f)
TSAT_CONFIG=${OPTARG}
;;
c)
TREMA_CONFIG="-c ${OPTARG}"
;;
s)
TREMA_FLAG_SHARK="-s"
;;
d)
TREMA_FLAG_DAEMON="-d"
;;
?)
usage
exit
;;
esac
done
}
check_file_existence() {
if [ ! -e $1 ]
then
echo "(error) trema-satellite: $1: file not found"
echo "Please check command-line optios with -h parameter."
exit 1
fi
}
check_command_existence() {
if [ ! -n $(which $1) ]
then
echo "(error) trema-satellite: $1: command not found"
echo "Please check command-line optios with -h parameter."
exit 1
fi
}
init_default_params() {
TSAT_CONFIG="$(dirname ${0})/conf/default.conf"
}
init_tsat() {
tmpdir="${TOPDIR}/tmp"
db_path="${tmpdir}/.stored_data.db"
if [ ! -d ${tmpdir} ]
then
mkdir ${tmpdir}
fi
init_default_params
}
start_web_server() {
ruby graph/command/web-runner.rb ${TSAT_CONFIG} &
WEB_SERVER_PID=$!
}
stop_web_server() {
ps ${WEB_SERVER_PID} &> /dev/null
if [ $? == 0 ]
then
kill ${WEB_SERVER_PID}
fi
}
trema_run() {
trema run ${APP_FILEPATH} ${TREMA_CONFIG} ${TREMA_FLAG_SHARK} ${TREMA_FLAG_DAEMON}
}
### main processing ###
ARGS=("$@")
if [ $# -lt 1 ]
then
usage
exit 1
fi
TOPDIR=`dirname $0`
APP_FILEPATH=${ARGS[((${#ARGS[@]}-1))]}
init_tsat
parse_options $*
check_command_existence "trema"
check_file_existence ${TSAT_CONFIG}
check_file_existence ${APP_FILEPATH}
start_web_server
trema_run
stop_web_server