-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
39 lines (35 loc) · 1.08 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
#!/bin/sh
jsonfile=/data/appdata/cred.json
line=70
file=/usr/src/node-red/node_modules/node-red/settings.js
if [ -e "$jsonfile" ]; then
key=$(sed -n "s/\"credentialSecret\": //p" $jsonfile)
trimedkey="$(echo "${key}" | sed -e 's/^[[:space:]]*//')"
text='\ \ \ \ credentialSecret:\ '${trimedkey}','
sed -i "${line} d" $file
sed -i "${line} i ${text}" $file
else
linetext=$(sed "${line}!d" $file)
trimedline="$(echo "${linetext}" | sed -e 's/^[[:space:]]*//')"
echo $trimedline
text='\ \ \ \ credentialSecret:\ "cisco",'
if [ "$(echo "$trimedline" | cut -c 1-4)" = 'cred' ]; then
sed -i "${line} d" $file
sed -i "${line} i ${text}" $file
else
sed -i "${line} i ${text}" $file
fi
fi
flowfile=/data/appdata/flows.json
flowcredfile=/data/appdata/flowscred.json
noderedDir=/.node-red
if [ -e "$flowfile" ] && [ -e "$flowcredfile" ]; then
if [ ! -e "$noderedDir" ]; then
mkdir /.node-red
fi
cp $flowfile /.node-red/flows_$(hostname).json
cp $flowcredfile /.node-red/flows_$(hostname)_cred.json
else
echo 'No flows.json or flowscred.json'
fi
/usr/src/node-red/node_modules/.bin/node-red