Merge branch 'master' into wip v0.3.0-rc1
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Fri, 20 Oct 2017 12:30:33 +0000 (14:30 +0200)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Fri, 20 Oct 2017 12:36:43 +0000 (14:36 +0200)
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Makefile
conf.d/etc/default/xds-agent [new file with mode: 0644]
conf.d/etc/profile.d/xds-agent.sh [new file with mode: 0644]
conf.d/etc/xds-agent/config.json [moved from agent-config.json.in with 86% similarity]
conf.d/usr/lib/systemd/user/xds-agent.service [moved from xds-agent.service with 74% similarity]
lib/syncthing/st.go
lib/xdsconfig/configfile.go
scripts/get-syncthing.sh
scripts/install.sh [new file with mode: 0755]

index 3329ead..db4d874 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -81,7 +81,7 @@ build: vendor xds webapp
 
 xds: scripts tools/syncthing/copytobin
        @echo "### Build XDS agent (version $(VERSION), subversion $(SUB_VERSION)) - $(BUILD_MODE)";
-       @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-agent$(EXT) -ldflags "$(GORELEASE) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" -gcflags "$(GO_GCFLAGS)" .
+       @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-agent$(EXT) -ldflags "$(GO_LDFLAGS) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" -gcflags "$(GO_GCFLAGS)" .
 
 test: tools/glide
        go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
@@ -117,14 +117,19 @@ webapp/install:
        @if [ -d ${DESTDIR}/usr/local/etc ]; then rm -rf ${DESTDIR}/usr; fi
 
 .PHONY: install
-install: all
-       mkdir -p $(DESTDIR) && cp $(LOCAL_BINDIR)/* $(DESTDIR)
-       mkdir -p $(DESTDIR_WWW) && cp -a webapp/dist/* $(DESTDIR_WWW)
+install:
+       @test -e $(LOCAL_BINDIR)/xds-agent$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
+       @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
+       export DESTDIR=$(DESTDIR) && export DESTDIR_WWW=$(DESTDIR_WWW) && $(ROOT_SRCDIR)/scripts/install.sh
+
+.PHONY: uninstall
+uninstall:
+       export DESTDIR=$(DESTDIR) && export DESTDIR_WWW=$(DESTDIR_WWW) && $(ROOT_SRCDIR)/scripts/install.sh uninstall
 
 package: clean tools/syncthing vendor build
-       @mkdir -p $(PACKAGE_DIR)/xds-agent
-       @cp agent-config.json.in $(PACKAGE_DIR)/xds-agent/agent-config.json
+       @mkdir -p $(PACKAGE_DIR)/xds-agent $(PACKAGE_DIR)/scripts
        @cp -a $(LOCAL_BINDIR)/* $(PACKAGE_DIR)/xds-agent
+       @cp -r $(ROOT_SRCDIR)/conf.d $(ROOT_SRCDIR)/scripts $(PACKAGE_DIR)/xds-agent
        cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-agent
 
 .PHONY: package-all
@@ -174,6 +179,7 @@ help:
        @echo "  build"
        @echo "  package"
        @echo "  install"
+       @echo "  uninstall"
        @echo "  clean"
        @echo "  distclean"
        @echo ""
diff --git a/conf.d/etc/default/xds-agent b/conf.d/etc/default/xds-agent
new file mode 100644 (file)
index 0000000..93d56cb
--- /dev/null
@@ -0,0 +1,5 @@
+# defaults file for XDS Agent
+# this file is used for service environment in /usr/lib/systemd/user/xds-agent.service
+
+# Logging level (supported levels: panic, fatal, error, warn, info, debug)
+LOG_LEVEL=info
diff --git a/conf.d/etc/profile.d/xds-agent.sh b/conf.d/etc/profile.d/xds-agent.sh
new file mode 100644 (file)
index 0000000..78eff4f
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+#----------  AGL xds-agent tool options Start ---------"
+[ ":${PATH}:" != *":%%XDS_INSTALL_BIN_DIR%%:"* ] && export PATH=%%XDS_INSTALL_BIN_DIR%%:${PATH}
similarity index 86%
rename from agent-config.json.in
rename to conf.d/etc/xds-agent/config.json
index e8599cb..7c7d7cb 100644 (file)
@@ -9,7 +9,7 @@
     ],
     "syncthing": {
         "home": "${HOME}/.xds/agent/syncthing-config",
-        "gui-address": "http://localhost:8384",
+        "gui-address": "http://localhost:8386",
         "gui-apikey": "1234abcezam"
     }
 }
similarity index 74%
rename from xds-agent.service
rename to conf.d/usr/lib/systemd/user/xds-agent.service
index 66788dc..1fd038b 100644 (file)
@@ -2,7 +2,7 @@
 Description=XDS Agent
 
 [Service]
-User=claneys
+EnvironmentFile=-/etc/default/xds-agent
 ExecStart=/opt/AGL/xds/agent/xds-agent &
 
 [Install]
index 924f407..031a2ac 100644 (file)
@@ -98,7 +98,7 @@ func NewSyncThing(conf *xdsconfig.Config, log *logrus.Logger) *SyncThing {
        }
 
        if url == "" {
-               url = "http://localhost:8384"
+               url = "http://localhost:8386"
        }
        if url[0:7] != "http://" {
                url = "http://" + url
index 6eaaf6a..e3737f4 100644 (file)
@@ -38,8 +38,7 @@ type FileConfig struct {
 // Order to determine which config file is used:
 //  1/ from command line option: "--config myConfig.json"
 //  2/ $HOME/.xds/agent/agent-config.json file
-//  3/ <current_dir>/agent-config.json file
-//  4/ <executable dir>/agent-config.json file
+//  3/ /etc/xds-agent/config.json file
 
 func readGlobalConfig(c *Config, confFile string) error {
 
@@ -53,8 +52,6 @@ func readGlobalConfig(c *Config, confFile string) error {
 
        searchIn = append(searchIn, "/etc/xds-agent/agent-config.json")
 
-       searchIn = append(searchIn, path.Join(common.GetExePath(), "agent-config.json"))
-
        var cFile *string
        for _, p := range searchIn {
                if _, err := os.Stat(p); err == nil {
index 3455122..772c09a 100755 (executable)
@@ -43,7 +43,7 @@ if [ "$?" != 0 ]; then
     exit 1
 fi
 
-gpg -q --keyserver pool.sks-keyservers.net --recv-keys 37C84554E7E0A261E4F76E1ED26E6ED000654A3E || exit 1
+${GPG} -q --keyserver pool.sks-keyservers.net --recv-keys 37C84554E7E0A261E4F76E1ED26E6ED000654A3E || exit 1
 
 tarball="syncthing-${GOOS_ST}-${GOARCH}-v${SYNCTHING_VERSION}.${TB_EXT}" \
        && curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/${tarball}" -O \
@@ -94,4 +94,4 @@ else
     fi
 fi
 
-echo "DONE: syncthing and syncthing-inotify successfuly installed in ${DESTDIR}"
\ No newline at end of file
+echo "DONE: syncthing and syncthing-inotify successfuly installed in ${DESTDIR}"
diff --git a/scripts/install.sh b/scripts/install.sh
new file mode 100755 (executable)
index 0000000..357c5e8
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# Install XDS agent as a user systemd service
+
+DESTDIR=${DESTDIR:-/opt/AGL/xds/agent}
+DESTDIR_WWW=${DESTDIR_WWW:-${DESTDIR}/www}
+
+ROOT_SRCDIR=$(cd $(dirname "$0")/.. && pwd)
+
+install() {
+    mkdir -p ${DESTDIR} && cp ${ROOT_SRCDIR}/bin/* ${DESTDIR} || exit 1
+    mkdir -p ${DESTDIR_WWW} && cp -a ${ROOT_SRCDIR}/webapp/dist/* ${DESTDIR_WWW} || exit 1
+
+    cp ${ROOT_SRCDIR}/conf.d/etc/xds-agent /etc/ || exit 1
+    cp ${ROOT_SRCDIR}/conf.d/etc/default/xds-agent /etc/default/ || exit 1
+
+    FILE=/etc/profile.d/xds-agent.sh
+    sed -e "s;%%XDS_INSTALL_BIN_DIR%%;${DESTDIR};g" ${ROOT_SRCDIR}/conf.d/${FILE} > ${FILE} || exit 1
+
+    FILE=/usr/lib/systemd/user/xds-agent.service
+    sed -e "s;/opt/AGL/xds/agent;${DESTDIR};g" ${ROOT_SRCDIR}/conf.d/${FILE} > ${FILE} || exit 1
+
+    echo ""
+    echo "To enable xds-agent service, execute:      systemctl --user enable xds-agent"
+    echo "and to start xds-agent service, execute:   systemctl --user start xds-agent"
+}
+
+uninstall() {
+    rm -rf "${DESTDIR}"
+    rm -f /etc/xds-agent /etc/profile.d/xds-agent.sh /usr/lib/systemd/user/xds-agent.service
+}
+
+if [ "$1" == "uninstall" ]; then
+    echo -n "Are-you sure you want to remove ${DESTDIR} [y/n]? "
+    read answer
+    if [ "${answer}" = "y" ]; then
+        uninstall
+        echo "xds-agent sucessfully uninstalled."
+    else
+        echo "Uninstall canceled."
+    fi
+else
+    install
+fi