forked from pierky/arouteserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·225 lines (180 loc) · 6.67 KB
/
run.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
set -e
function bold {
echo -e "\e[1m${1}\e[0m"
}
function error {
bold "ERROR: $1"
exit 1
}
function error_envvar_not_set {
# $1 missing variable
# $2 optional reason
error "environment variable not set: ${1}\n
${2}\n
Please run the container passing the '-e ${1}=value' argument."
}
DAEMON="${DAEMON}"
VERSION="${VERSION}"
RS_ASN="${RS_ASN}"
PLACEHOLDER_16BIT_ASN="${PLACEHOLDER_16BIT_ASN}"
ROUTER_ID="${ROUTER_ID}"
LOCAL_PREFIXES="${LOCAL_PREFIXES}"
IP_VER="${IP_VER}"
LOCAL_FILES="${LOCAL_FILES}"
LOCAL_FILES_DIR="${LOCAL_FILES_DIR}"
TEMPLATES_DIR="${TEMPLATES_DIR}"
EURO_IX_URL="${EURO_IX_URL}"
EURO_IX_IXP_ID="${EURO_IX_IXP_ID}"
CLIENTS_FILE_PATH="/root/clients.yml"
OUTPUT_DIR="/root/arouteserver_configs"
OUTPUT_DIR_HTML="/root/arouteserver_html"
if [[ ! -e "${OUTPUT_DIR}" && ! -d "${OUTPUT_DIR}" ]]; then
error "The output directory ${OUTPUT_DIR} can't be found.
This is the directory where the configurations generated by ARouteServer will be saved.
Please be sure to mount the desired directory of the host to the ${OUTPUT_DIR} directory on the container.
You can run the container passing the '-v PATH_OF_DIRECTORY_ON_THE_HOST:${OUTPUT_DIR}' argument."
fi
if [[ -n "${TEMPLATES_DIR}" ]]; then
if [[ ! -e "${TEMPLATES_DIR}" ]]; then
error "Couldn't find the directory ${TEMPLATES_DIR} on the container.\n
Please mount the local directory where the templates are stored using '-v PATH_OF_TEMPLATES_DIR_ON_THE_HOST:${TEMPLATES_DIR}:ro' argument."
fi
fi
TEST_WRITABLE_FILE="${OUTPUT_DIR}/.test_dir_is_writable"
set +e
touch ${TEST_WRITABLE_FILE} &>/dev/null
EXIT_CODE=$?
set -e
if [[ ${EXIT_CODE} -ne 0 ]]; then
error "It seems that the output directory ${OUTPUT_DIR} is not writable.
This is the directory where the configurations generated by ARouteServer will be saved.
Please be sure to mount the desired directory of the host to the ${OUTPUT_DIR} directory on the container.
You can run the container passing the '-v PATH_OF_DIRECTORY_ON_THE_HOST:${OUTPUT_DIR}' argument."
fi
rm ${TEST_WRITABLE_FILE} &>/dev/null
if [[ -e "${OUTPUT_DIR_HTML}" && -d "${OUTPUT_DIR_HTML}" ]]; then
TEST_WRITABLE_FILE="${OUTPUT_DIR_HTML}/.test_dir_is_writable"
set +e
touch ${TEST_WRITABLE_FILE} &>/dev/null
EXIT_CODE=$?
set -e
if [[ ${EXIT_CODE} -ne 0 ]]; then
error "It seems that the HTML output directory ${OUTPUT_DIR_HTML} is not writable.
This is the directory where the textual representation of route server policy generated by ARouteServer will be saved.
Please be sure to mount the desired directory of the host to the ${OUTPUT_DIR_HTML} directory on the container.
You can run the container passing the '-v PATH_OF_DIRECTORY_ON_THE_HOST:${OUTPUT_DIR_HTML}' argument."
fi
rm ${TEST_WRITABLE_FILE} &>/dev/null
fi
if [[ -z "${DAEMON}" ]]; then
error_envvar_not_set "DAEMON"
fi
if [[ -z "${VERSION}" ]]; then
error_envvar_not_set "VERSION"
fi
if [[ -n "${EURO_IX_URL}" ]]; then
echo ""
echo "Generating clients.yaml from EURO IX-F"
echo ""
arouteserver clients-from-euroix -o "${CLIENTS_FILE_PATH}" --url "${EURO_IX_URL}" "${EURO_IX_IXP_ID}"
fi
if [[ ! -e "${CLIENTS_FILE_PATH}" ]]; then
error "Couldn't find the file ${CLIENTS_FILE_PATH} on the container.\n
Please mount the local file where the list of clients is defined using '-v PATH_OF_CLIENTS_FILE_ON_THE_HOST:${CLIENTS_FILE_PATH}:ro' argument."
fi
IP_VER_ARG=""
OUTPUT_FILE="${DAEMON}.cfg"
if [[ "${DAEMON}" == "bird" ]]; then
set +e
egrep "^1\." <<< "${VERSION}" &>/dev/null
IP_VER_REQUIRED=$? # 0 = IP_VER is required
set -e
if [[ ${IP_VER_REQUIRED} -eq 0 ]]; then
if [[ -z "${IP_VER}" ]]; then
error_envvar_not_set "IP_VER" "When BIRD 1.x is used, IP_VER must be set."
else
IP_VER_ARG="--ip-ver ${IP_VER}"
OUTPUT_FILE="${DAEMON}${IP_VER}.cfg"
fi
fi
fi
if [[ ! -e /etc/arouteserver/general.yml ]]; then
if [[ -z "${RS_ASN}" ]]; then
error_envvar_not_set "RS_ASN"
fi
if [[ ${RS_ASN} -gt 65535 ]]; then
if [[ -z "${PLACEHOLDER_16BIT_ASN}" ]]; then
error_envvar_not_set "PLACEHOLDER_16BIT_ASN"
else
comms_asn_optional_arg="comms_asn=${PLACEHOLDER_16BIT_ASN}"
fi
else
comms_asn_optional_arg=""
fi
if [[ -z "${ROUTER_ID}" ]]; then
error_envvar_not_set "ROUTER_ID"
fi
if [[ -z "${LOCAL_PREFIXES}" ]]; then
error_envvar_not_set "LOCAL_PREFIXES"
fi
echo ""
bold "Configuring ARouteServer for ${DAEMON} ${VERSION}..."
echo ""
arouteserver \
configure --preset-answer \
daemon=${DAEMON} \
version=${VERSION} \
asn=${RS_ASN} \
${comms_asn_optional_arg} \
router_id=${ROUTER_ID} \
black_list=${LOCAL_PREFIXES}
else
echo ""
bold "The user-provided configuration from general.yml will be used."
echo ""
fi
if [[ -e "${OUTPUT_DIR_HTML}" && -d "${OUTPUT_DIR_HTML}" ]]; then
OUTPUT_FILE_HTML="${DAEMON}.html"
echo ""
echo "Generating HTML textual representation of route server's options and policies"
echo ""
OUTPUT_PATH_HTML="${OUTPUT_DIR_HTML}/${OUTPUT_FILE_HTML}"
arouteserver \
html \
--clients "${CLIENTS_FILE_PATH}" \
-o "${OUTPUT_PATH_HTML}"
echo ""
bold "Textual representation of route server policy for ${DAEMON} saved to ${OUTPUT_PATH_HTML} (path on the container)."
echo "You will find the textual representation file in your host system, inside the directory that you mounted at run-time."
echo ""
fi
echo ""
bold "Generating route server configuration for ${DAEMON} ${VERSION}..."
echo ""
LOCAL_FILES_ARG=""
LOCAL_FILES_DIR_ARG=""
if [[ -n "${LOCAL_FILES}" ]]; then
LOCAL_FILES_ARG="--use-local-files ${LOCAL_FILES}"
if [[ -n "${LOCAL_FILES_DIR}" ]]; then
LOCAL_FILES_DIR_ARG="--local-files-dir ${LOCAL_FILES_DIR}"
fi
fi
TEMPLATES_DIR_ARG=""
if [[ -n "${TEMPLATES_DIR}" ]]; then
TEMPLATES_DIR_ARG="--templates-dir ${TEMPLATES_DIR}"
fi
OUTPUT_PATH="${OUTPUT_DIR}/${OUTPUT_FILE}"
arouteserver \
"${DAEMON}" \
${TEMPLATES_DIR_ARG} \
--target-version "${VERSION}" \
${IP_VER_ARG} \
--clients "${CLIENTS_FILE_PATH}" \
${LOCAL_FILES_ARG} \
${LOCAL_FILES_DIR_ARG} \
-o "${OUTPUT_PATH}"
echo ""
bold "Route server configuration for ${DAEMON} ${VERSION} saved to ${OUTPUT_PATH} (path on the container)."
echo "You will find the configuration file in your host system, inside the directory that you mounted at run-time."
echo ""