-
Notifications
You must be signed in to change notification settings - Fork 29
/
start.sh
executable file
·122 lines (113 loc) · 2.67 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
121
122
#!/usr/bin/env bash
set -eu
usage() {
echo "Usage: $0 [ --d ] [ --s ] [ --h ] [ --v[1|2] ] [--stdin] <filename>
--d - development mode, uses nodemon instead of node
--s - silent mode, no output at all
--v - verbosity, shows debug output on application level
--v1 - enhanced verbosity, shows debug output on application and http-server level
--v2 - full verbosity, shows all debug output
--stdin - uses stdin to read JavaScript
--keyStore - json string. Array of objects with keys: id, key, cert. Where id is the cpName, key the filename to the key file, cert the filename to the cert file. All PEM encoded.
--keyStoreRoot - path where newly created keys/certs are being stored
--ca - path to PEM encoded CA certificate file
--cadir - path to PEM encoded CA certificate dir
--o - path to a options file which will be sourced
--h - shows this help
" 1>&2
}
exit_abnormal() {
usage
exit 1
}
if ! npm --version >/dev/null 2>&1; then
echo "npm not installed. Abort."
exit 1
fi
if [ ! -d "node_modules" ]; then
npm i
fi
DEV=
STDIN=
while [[ "${1:-}" =~ ^- ]] ; do
case "${1}" in
-h)
usage
exit 0
;;
--h)
usage
exit 0
;;
-help)
usage
exit 0
;;
--help)
usage
exit 0
;;
--d)
DEV=TRUE
;;
--v)
export DEBUG=ocpp-chargepoint-simulator:simulator:*
;;
--v1)
export DEBUG=ocpp-chargepoint-simulator:*
;;
--v2)
export DEBUG=*
;;
--vv)
export DEBUG=$2
shift
;;
--s)
export DEBUG=.
;;
--keyStore)
export SSL_CLIENT_KEYSTORE=$2
shift
;;
--keyStoreRoot)
export SSL_CLIENT_KEYSTORE_ROOT=$2
shift
;;
--ca)
export SSL_CERT_FILE=$2
shift
;;
--cadir)
export SSL_CERT_DIR=$2
shift
;;
--o)
SIMULATOR_OPTS=$2
shift
;;
--stdin)
STDIN=--stdin
;;
*)
exit_abnormal
esac
shift
done
if [ -n "${SIMULATOR_OPTS:-}" ]; then
. ${SIMULATOR_OPTS}
fi
if [ -z "${DEBUG:-}" ]; then
echo "No debug output configured."
fi
if [ -n "$DEV" ]; then
[ -n "$STDIN" ] && echo "You cannot combine dev and stdin" && exit 1
npm run dev "$@"
else
if [ -n "${SSL_CERT_FILE:-}" ] || [ -n "${SSL_CERT_DIR:-}" ]; then
# nasty special case, but the environment variable SSL_CERT_FILE or SSL_CERT_DIR requires to also set --use-openssl-ca on node (not ts-node)
node --use-openssl-ca ./node_modules/.bin/ts-node --project ./tsconfig.release.json ./src/main.ts $STDIN "$@"
else
./node_modules/.bin/ts-node --project ./tsconfig.release.json ./src/main.ts $STDIN "$@"
fi
fi