-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·183 lines (148 loc) · 3.27 KB
/
generate.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/sh
PROJECT_DIR=`pwd`
SRC_DIR=${PROJECT_DIR}/src
RIOT_DIR=${SRC_DIR}/RIOT
BIN_DIR=${SRC_DIR}/bin
TAPSETUP_CMD=${RIOT_DIR}/dist/tools/tapsetup/tapsetup
TAP0_CLASS_FOLDER=/sys/class/net/tap0/
BINARY_FILE=${SRC_DIR}/bin/native/echo_server.elf
prepare () {
echo ">>> Preparing environment..."
USER=`id -u`
if [ "${USER}" -ne 0 ]; then
echo "! This preparation needs to run as root"
SUDO=sudo
fi
echo "This preparation will install the following packages and its dependencies:"
echo "- git"
echo "- gcc-multilib"
echo -n "Do you agree? (Y/n) "
read opt
echo
if [ "${opt}" != "n" ]; then
${SUDO} apt-get -y install git \
gcc-multilib
fi
}
gitclone () {
echo ">>> Cloning environment..."
if [ -d ${RIOT_DIR} ]; then
echo "RIOT directory already exist"
return
fi
git clone https://github.com/RIOT-OS/RIOT ${RIOT_DIR}
}
interface () {
echo ">>> Creating interface tap0 and tap1..."
if [ -d "${TAP0_CLASS_FOLDER}" ]; then
echo "tap0 interface already exist"
return
fi
if [ ! -f "${TAPSETUP_CMD}" ]; then
echo "RIOT not cloned. Run: $0 -g"
return
fi
${TAPSETUP_CMD} -c
}
build () {
echo ">>> Building..."
if [ ! -d ${RIOT_DIR} ]; then
echo "! RIOT dir does not exist."
echo "Run: $0 -g"
return
fi
make RIOT_DIR=${RIOT_DIR}
}
run () {
echo ">>> Running sample..."
if [ ! -d "${TAP0_CLASS_FOLDER}" ]; then
echo "Tap0 interface not exist. Run: $0 -i"
return
fi
if [ ! -f "${BINARY_FILE}" ]; then
echo "Project not compiled. Run: $0 -b"
return
fi
${BINARY_FILE} tap0
}
clean () {
echo ">>> Cleaning..."
make clean RIOT_DIR=${RIOT_DIR}
if [ -d ${BIN_DIR} ]; then
rm -rf ${BIN_DIR}
fi
}
deepclean () {
echo ">>> Erasing..."
clean
if [ ! -d ${RIOT_DIR} ]; then
echo "! RIOT dir does not exist."
return
fi
${TAPSETUP_CMD} -d
rm -rf ${RIOT_DIR} 2> /dev/null
}
invalid() {
echo "Invalid option: -$1"
}
param() {
echo "Option -$1 requires an argument"
}
check() {
if [ $1 != 0 ]; then
echo "! Error running last command =("
exit 1
fi
}
usage() {
echo "Usage: $1 [OPTIONS]"
echo ""
echo " -p \t\tPrepare environment (requires sudo)"
echo " -g \t\tClone RIOT repository"
echo " -i \t\tCreate ethernet interface (requires sudo)"
echo " -b \t\tBuild"
echo " -r \t\tRun application"
echo " -c \t\tClean"
echo " -d \t\tClean all temporary files and remove ethernet interface (requires sudo)"
echo ""
}
RUN=0
while getopts ":p :g :i :b :r :c :d" opt; do
RUN=1
case $opt in
p)
prepare
;;
g)
gitclone
;;
i)
interface
;;
b)
build
;;
c)
clean
;;
r)
run
;;
d)
deepclean
;;
:)
param $OPTARG
RUN=0
;;
\?)
invalid $OPTARG
RUN=0
;;
esac
check $?
done
if [ "$RUN" != "1" ]; then
usage $0
exit 1
fi