forked from NGRP/node-red-viseo-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.sh
executable file
·98 lines (81 loc) · 1.84 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
#!/bin/bash
initArgs() {
START="pm2"
for arg in "$@"; do
shift
case "$arg" in
"--") shift ; break ;;
"--env") set -- "$@" "-e" ;;
"--url") set -- "$@" "-h" ;;
"--credential-secret") set -- "$@" "-s" ;;
"--docker") set -- "$@" "-d" ;;
"--log-path") set -- "$@" "-l" ;;
"--node-red-route") set -- "$@" "-r" ;;
*) set -- "$@" "$arg" ;;
esac
done
local OPTIND=1
PORT=1880
SOURCE="$(dirname "${BASH_SOURCE[0]}")"
CUR_DIR="`pwd`"
cd "$SOURCE"
SOURCE="`pwd`"
cd "$CUR_DIR"
while getopts p:e:r:l:h:s:d option
do
case "$option" in
p) PORT="${OPTARG}";;
e) ENV="${OPTARG}";;
h) HOST="${OPTARG}";;
s) CREDENTIAL_SECRET="${OPTARG}";;
d) START="pm2-docker";;
l) LOG_PATH="${OPTARG}";;
r) NODE_RED_ROUTE="${OPTARG}";;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $(($OPTIND - 1))
APP="$1"
NAME=""
if [ $START == "pm2" ]
then
NAME="--name $APP"
fi
}
checkArgs() {
if [ -z "$APP" ] || [ -z "$ENV" ]
then
bold=$(tput bold)
normal=$(tput sgr0)
echo $bold"usage : bash start.sh [ -p port ] [ --url http://url ] [ --docker ] --env [ dev|quali|prod ] [ --log-path pathtologs ] [ --credential-secret passphrase ] app"$normal
exit 1
fi
}
initArgs "$@"
checkArgs
bot_content=`ls -A "$CUR_DIR"`
if [ -z "$bot_content" ]
then
bash "$SOURCE"/create_template.sh "$CUR_DIR"
fi
if [ -z "$LOG_PATH" ]
then
LOG_PATH=""
else
LOG_PATH="-o $LOG_PATH/$APP.out.log -e $LOG_PATH/$APP.err.log"
fi
NODE_ENV=$ENV \
NODE_TLS_REJECT_UNAUTHORIZED=0 \
NODE_RED_ROUTE="$NODE_RED_ROUTE" \
CONFIG_PATH="$CUR_DIR/conf/config.js" \
FRAMEWORK_ROOT="$SOURCE" \
HOST="$HOST" \
PORT=$PORT \
BOT_ROOT=$CUR_DIR \
CREDENTIAL_SECRET=$CREDENTIAL_SECRET \
$START \
start \
"$SOURCE"/node_modules/node-red/red.js $LOG_PATH $NAME -- -s "$SOURCE"/conf/node-red-config.js