summaryrefslogtreecommitdiffstats
path: root/meta-iot/recipes-web/the-thing-system/steward-init
diff options
context:
space:
mode:
Diffstat (limited to 'meta-iot/recipes-web/the-thing-system/steward-init')
-rw-r--r--meta-iot/recipes-web/the-thing-system/steward-init/LICENSE.steward-init9
-rwxr-xr-xmeta-iot/recipes-web/the-thing-system/steward-init/steward-init-settings.sh62
-rw-r--r--meta-iot/recipes-web/the-thing-system/steward-init/steward-init.service.in14
3 files changed, 85 insertions, 0 deletions
diff --git a/meta-iot/recipes-web/the-thing-system/steward-init/LICENSE.steward-init b/meta-iot/recipes-web/the-thing-system/steward-init/LICENSE.steward-init
new file mode 100644
index 0000000..0388698
--- /dev/null
+++ b/meta-iot/recipes-web/the-thing-system/steward-init/LICENSE.steward-init
@@ -0,0 +1,9 @@
1# LICENSE
2
3[MIT](http://en.wikipedia.org/wiki/MIT_License) license. Freely have you received, freely give.
4
5Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
7The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
9THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
diff --git a/meta-iot/recipes-web/the-thing-system/steward-init/steward-init.service.in b/meta-iot/recipes-web/the-thing-system/steward-init/steward-init.service.in
new file mode 100644
index 0000000..feed7f5
--- /dev/null
+++ b/meta-iot/recipes-web/the-thing-system/steward-init/steward-init.service.in
@@ -0,0 +1,14 @@
1[Unit]
2Description=Initialize TheThingSystem steward settings
3After=syslog.target
4Before=eca-web.service
5ConditionFileNotEmpty=!@the_thing_system_dir@/steward/db/server.key
6
7[Service]
8Type=oneshot
9EnvironmentFile=-/etc/TheThingSystem/config
10ExecStart=-@the_thing_system_dir@/steward/steward-init-settings.sh
11StandardOutput=null
12
13[Install]
14WantedBy=steward.service