aboutsummaryrefslogtreecommitdiffstats
path: root/INSTALL/tasks.d/80_xds
blob: 1a62d8be6baf5f00f3135e0963c2e5044a737bc3 (plain)
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
#!/bin/bash

# install required tools for XDS

XDS_BINDIR=/usr/local/bin
XDS_WWWDIR=/var/www/xds-server
XDS_CONFDIR=${DEVUSER_HOME}/.xds

curdir=`pwd`

## Install Go to build xds
apt-get install -y golang-1.6
export GOPATH=/tmp/go
export PATH=${PATH}:/usr/lib/go-1.6/bin:${GOPATH}/bin
mkdir -p ${GOPATH}/{src,bin,pkg}


## Build and install XDS server and XDS tools (eg. Syncthing)
url="https://github.com/iotbzh/xds-server" \
    && mkdir -p /tmp/src/github.com/iotbzh && cd /tmp/src/github.com/iotbzh \
    && git clone "${url}" \
    && cd xds-server \
    && INSTALL_DIR="${XDS_BINDIR}" INSTALL_WEBAPP_DIR="${XDS_WWWDIR}" make all install \
    && mkdir -p ${XDS_CONFDIR} \
    && cat <<EOF >${XDS_CONFDIR}/config.json
{
    "webAppDir": "${XDS_WWWDIR}",
    "shareRootDir": "${XDS_CONFDIR}/projects",
    "sdkRootDir": "${SDK_INSTALL_DIR}",
    "syncthing": {
        "home": "${XDS_CONFDIR}/syncthing-config",
        "gui-address": "http://localhost:8384"
    }
}
EOF

# Change owner of created files
chown -R ${DEVUSER}:${DEVUSER_UID} ${XDS_CONFDIR}
# Change owner of webapp assets files (allow dynamic download of xds-agent tarballs)
chown -R ${DEVUSER}:${DEVUSER_UID} ${XDS_WWWDIR}/assets

# generate service file for startup
SERVFILE=/lib/systemd/system/xds-server.service
cat <<EOF >$SERVFILE
[Unit]
Description=XDS Server

[Service]
User=${DEVUSER}
Type=forking
EnvironmentFile=-/etc/default/xds-server
ExecStart=/usr/local/bin/xds-server-start.sh

[Install]
WantedBy=multi-user.target
EOF

# config file
cat <<EOF >/etc/default/xds-server
# defaults file for XDS Server
# this file is used for service environment in $SERVFILE

# no variable defined yet
EOF

# install service
ln -s $SERVFILE /etc/systemd/system/multi-user.target.wants/

# cleanup (remove build tools)
cd $curdir
rm -rf /tmp/*

apt-get remove -y golang-1.6
npm cache clean