summaryrefslogtreecommitdiffstats
path: root/meta-iot/recipes-web/the-thing-system/steward-init/steward-init-settings.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta-iot/recipes-web/the-thing-system/steward-init/steward-init-settings.sh')
-rwxr-xr-xmeta-iot/recipes-web/the-thing-system/steward-init/steward-init-settings.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/meta-iot/recipes-web/the-thing-system/steward-init/steward-init-settings.sh b/meta-iot/recipes-web/the-thing-system/steward-init/steward-init-settings.sh
new file mode 100755
index 0000000..40f75ee
--- /dev/null
+++ b/meta-iot/recipes-web/the-thing-system/steward-init/steward-init-settings.sh
@@ -0,0 +1,62 @@
1#!/bin/sh
2
3if [ -z "$THE_THING_SYSTEM" ]; then
4 THE_THING_SYSTEM=/opt/TheThingSystem
5 export THE_THING_SYSTEM
6fi
7
8STEWARD_DIR=${THE_THING_SYSTEM}/steward
9STEWARD_SETTINGS=$STEWARD_DIR/db/server.key
10
11RET=0
12
13if [ -s $STEWARD_SETTINGS ]; then
14 exit 0
15fi
16
17# Change the port of the eca-web so that steward web-ui can live in
18# port 80. Eca-web will be moved to HTTP port 8080.
19sed -i 's/PORT=80$/PORT=8080/' /etc/eca-web/config
20
21if [ ! -d $STEWARD_DIR/sandbox ]; then
22 mkdir -p $STEWARD_DIR/sandbox
23fi
24if [ ! -d $STEWARD_DIR/db ]; then
25 mkdir -p $STEWARD_DIR/db
26fi
27
28if [ -z "$NODE_PATH" ]; then
29 NODE_PATH=${THE_THING_SYSTEM}/steward
30 export NODE_PATH
31fi
32
33cd $THE_THING_SYSTEM/steward
34
35echo -n "Creating server key..."
36rm -f ${STEWARD_DIR}/sandbox/server.crt ${STEWARD_DIR}/sandbox/server.sha1
37
38node <<EOF
39require('x509-keygen').x509_keygen({ subject : '/CN=steward'
40 , keyfile : '${STEWARD_DIR}/db/server.key'
41 , certfile : '${STEWARD_DIR}/sandbox/server.crt'
42 , sha1file : '${STEWARD_DIR}/sandbox/server.sha1'
43 , alternates : [ 'DNS:' + require('os').hostname(), 'DNS:eca.local' ]
44 , destroy : false }, function(err, data) {
45 if (err) return console.log('keypair generation error: ' + err.message);
46
47 console.log('keypair generated.');
48});
49EOF
50
51if [ -f ${STEWARD_DIR}/db/server.key ]; then
52 chmod 400 ${STEWARD_DIR}/db/server.key
53 chmod 444 ${STEWARD_DIR}/sandbox/server.crt
54 chmod 444 ${STEWARD_DIR}/sandbox/server.sha1
55else
56 rm -f ${STEWARD_DIR}/db/server.key ${STEWARD_DIR}/sandbox/server.crt \
57 ${STEWARD_DIR}/sandbox/server.sha1
58 echo "unable to create self-signed server certificate" 1>&2
59 RET=1
60fi
61
62exit $RET