-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScriptStartOSRM.sh
executable file
·147 lines (126 loc) · 3.73 KB
/
ScriptStartOSRM.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
#!/bin/bash -
# -*- coding: UTF8 -*-
#===============================================================================
#
# FILE: ScriptStartOSRM.sh
#
# USAGE: ./ScriptStartOSRM.sh
#
# DESCRIPTION: See README
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: https://github.com/JulioJu
# ORGANIZATION:
# CREATED: 01/29/2019 17:55
# REVISION: ---
#===============================================================================
trap 'kill' HUP
trap 'kill' INT
trap 'kill' QUIT
trap 'finishError "$LINENO"' ERR
trap 'finish' EXIT
# Cannot be trapped
# trap 'kill' KILL
trap 'kill' TERM
# set -euET
set -euET
# Note: `set +E' doesn't work
# set -x
close() {
# "_" is the throwaway variable
read -r -t 1 -n 10000 _ || echo ""
read -r -p "Press 'ENTER' to close"
}
kill() {
set +x
1>&2 echo -e "\\n\\n\\n""${URED}""Killed by user""${NC}""\\n\\n"
exit 130
}
finishError() {
set +x
1>&2 echo "In the script, error on line: '$1'"
exit 2
# Otherwise, all script it's executed
}
finish() {
returnCode=$?
while read -r i ; do
kill "$i" || echo "\`kill '$i'' is failed. Probably already terminated."
done < <(jobs -p)
set +x
if [[ "${returnCode}" -gt 0 ]] ; then
1>&2 echo -e "\\n\\n\\n${URED}ERROR" \
"with code '${returnCode}'${NC}\\n\\n"
close
else
echo -e "\\n\\n\\n""${URED}""SUCCESS""${NC}""\\n\\n"
close
fi
echo -e "\n\n\n"
}
error() {
set +x
1>&2 echo -e "\\n\\n\\n${URED}ERROR:" "${@:2}" "${NC}\\n\\n"
exit "${@:1:1}"
}
testWorkingFolder() {
local -i profileFileNameArrayIndex=0
while [[ ${profileFileNameArrayIndex} -lt "${#profileFileNameArray[*]}" ]]
do
local profileFile="*-${profileFileNameArray[profileFileNameArrayIndex]}/*.osrm"
local -i numberOfProfileFile=
numberOfProfileFile="$(wc -l < <(find . -path "${profileFile}"))"
if [[ "${numberOfProfileFile}" -eq 0 ]]
then
error 5 "The file '${profileFile}' not found."
fi
if [[ "${numberOfProfileFile}" -gt 1 ]]
then
error 5 "${numberOfProfileFile} files match the pattern" \
"'${profileFile}'. Only one match should be found."
fi
local -i port="500$((profileFileNameArrayIndex+5))"
if grep "\* ${port} " < <(ss -nap)
then
grep "${port}" < <(ss -nap)
error 6 "port '${port}' busy."
fi
profileFileNameArrayIndex=$((profileFileNameArrayIndex+1))
done
}
main() {
local -a profileFileNameArray=(bicycle foot car)
set +x
testWorkingFolder
set -x
local -i profileFileNameArrayIndex=0
while [[ ${profileFileNameArrayIndex} -lt "${#profileFileNameArray[*]}" ]]
do
local profileFile="*-${profileFileNameArray[profileFileNameArrayIndex]}/*.osrm"
fileOsrm="$(find . -path "${profileFile}")"
osrm-routed --algorithm=MLD "${fileOsrm}" \
-p 500$((profileFileNameArrayIndex+5)) &
profileFileNameArrayIndex=$((profileFileNameArrayIndex+1))
done
sleep 5
set +x
echo -e "\n\n${URED} Type <Ctrl-c> to kill \`osrm-route'" \
"or close the current Terminal${NC}\n\n"
wait
}
echo -e "\n\nStart of Script\n============\n"
# shellcheck disable=SC2154
export PS4='
${debian_chroot:+($debian_chroot)}'\
'\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] [\D{%T}] \$ '
# declare -g -r PS4Light="\n\n\\033[1;32m""$USER@""$HOSTNAME""\\033[0m"": "
declare -g -r URED="\\033[4;31m"
declare -g -r NC="\\033[0m"
declare -g DIR_WORKING
DIR_WORKING="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P)/../osrm"
cd -P "${DIR_WORKING}"
set -x
time main "${@}"