aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile55
-rw-r--r--README.md12
-rwxr-xr-xscripts/get-syncthing.sh40
-rwxr-xr-xscripts/xds-start-server.sh50
4 files changed, 131 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 5fb3204..6f9f990 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,9 @@
# Makefile used to build XDS daemon Web Server
+# Syncthing version to install
+SYNCTHING_VERSION = 0.14.25
+SYNCTHING_INOTIFY_VERSION = 0.8.5
+
# Retrieve git tag/commit to set sub-version string
ifeq ($(origin VERSION), undefined)
VERSION := $(shell git describe --tags --always | sed 's/^v//')
@@ -13,7 +17,7 @@ ifeq ($(origin INSTALL_DIR), undefined)
INSTALL_DIR := /usr/local/bin
endif
ifeq ($(origin INSTALL_WEBAPP_DIR), undefined)
- INSTALL_WEBAPP_DIR := ${INSTALL_DIR}/xds-server-www
+ INSTALL_WEBAPP_DIR := $(INSTALL_DIR)/xds-server-www
endif
HOST_GOOS=$(shell go env GOOS)
@@ -23,6 +27,7 @@ REPOPATH=github.com/iotbzh/xds-server
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
+LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
export PATH := $(PATH):$(ROOT_SRCDIR)/tools
@@ -30,24 +35,16 @@ export PATH := $(PATH):$(ROOT_SRCDIR)/tools
VERBOSE_1 := -v
VERBOSE_2 := -v -x
-#WHAT := xds-make
all: build webapp
-#build: build/xds build/cmds
build: build/xds
xds: build/xds
-build/xds: vendor
+build/xds: vendor scripts
@echo "### Build XDS server (version $(VERSION))";
- @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o bin/xds-server -ldflags "-X main.AppVersionGitTag=$(VERSION)" .
-
-#build/cmds: vendor
-# @for target in $(WHAT); do \
-# echo "### Build $$target"; \
-# $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o bin/$$target -ldflags "-X main.AppVersionGitTag=$(VERSION)" ./cmd/$$target; \
-# done
+ @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-server -ldflags "-X main.AppVersionGitTag=$(VERSION)" .
test: tools/glide
go test --race $(shell ./tools/glide novendor)
@@ -58,17 +55,19 @@ vet: tools/glide
fmt: tools/glide
go fmt $(shell ./tools/glide novendor)
-run: build/xds
- ./bin/xds-server --log info -c config.json.in
+run: build/xds tools/syncthing
+ $(LOCAL_BINDIR)/xds-server --log info -c config.json.in
-debug: build/xds webapp/debug
- ./bin/xds-server --log debug -c config.json.in
+debug: build/xds webapp/debug tools/syncthing
+ $(LOCAL_BINDIR)/xds-server --log debug -c config.json.in
+.PHONY: clean
clean:
- rm -rf ./bin/* debug cmd/*/debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH)
+ rm -rf $(LOCAL_BINDIR)/* debug cmd/*/debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH)
+.PHONY: distclean
distclean: clean
- rm -rf bin tools glide.lock vendor cmd/*/vendor webapp/node_modules webapp/dist
+ rm -rf $(LOCAL_BINDIR) tools glide.lock vendor cmd/*/vendor webapp/node_modules webapp/dist
run3:
goreman start
@@ -82,10 +81,14 @@ webapp/debug:
webapp/install:
(cd webapp && npm install)
+.PHONY: scripts
+scripts:
+ @mkdir -p $(LOCAL_BINDIR) && cp -f scripts/xds-start-server.sh $(LOCAL_BINDIR)
-install: all
- mkdir -p ${INSTALL_DIR} && cp bin/xds-server ${INSTALL_DIR}
- mkdir -p ${INSTALL_WEBAPP_DIR} && cp -a webapp/dist/* ${INSTALL_WEBAPP_DIR}
+.PHONY: install
+install: all scripts tools/syncthing
+ mkdir -p $(INSTALL_DIR) && cp $(LOCAL_BINDIR)/* $(INSTALL_DIR)
+ mkdir -p $(INSTALL_WEBAPP_DIR) && cp -a webapp/dist/* $(INSTALL_WEBAPP_DIR)
vendor: tools/glide glide.yaml
./tools/glide install --strip-vendor
@@ -95,14 +98,19 @@ tools/glide:
mkdir -p tools
curl --silent -L https://glide.sh/get | GOBIN=./tools sh
-goenv:
- @go env
+.PHONY: tools/syncthing
+tools/syncthing:
+ @(test -s $(LOCAL_BINDIR)/syncthing || \
+ DESTDIR=$(LOCAL_BINDIR) \
+ SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
+ SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
+ ./scripts/get-syncthing.sh)
+.PHONY: help
help:
@echo "Main supported rules:"
@echo " build (default)"
@echo " build/xds"
- @echo " build/cmds"
@echo " release"
@echo " clean"
@echo " distclean"
@@ -110,4 +118,3 @@ help:
@echo "Influential make variables:"
@echo " V - Build verbosity {0,1,2}."
@echo " BUILD_ENV_FLAGS - Environment added to 'go build'."
-# @echo " WHAT - Command to build. (e.g. WHAT=xds-make)"
diff --git a/README.md b/README.md
index 16d0946..2f068cf 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,11 @@ Clone this repo into your `$GOPATH/src/github.com/iotbzh` and use delivered Make
make all
```
+And to install xds-server in /usr/local/bin:
+```bash
+make install
+```
+
## How to run
## Configuration
@@ -69,11 +74,14 @@ Supported fields in configuration file are:
## Start-up
+Use `xds-start-server.sh` script to start all requested tools
```bash
-./bin/xds-server -c config.json
+/usr/local/bin/xds-start-server.sh
```
-**TODO**: add notes about Syncthing setup and startup
+>**NOTE** you can define some environment variables to setup for example
+config file `XDS_CONFFILE` or change logs directory `LOGDIR`.
+See head section of `xds-start-server.sh` file to see all configurable variables.
## Debugging
diff --git a/scripts/get-syncthing.sh b/scripts/get-syncthing.sh
new file mode 100755
index 0000000..284c58e
--- /dev/null
+++ b/scripts/get-syncthing.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+# Configurable variables
+[ -z "$SYNCTHING_VERSION" ] && SYNCTHING_VERSION=0.14.25
+[ -z "$SYNCTHING_INOTIFY_VERSION" ] && SYNCTHING_INOTIFY_VERSION=0.8.5
+[ -z "$DESTDIR" ] && DESTDIR=/usr/local/bin
+[ -z "$TMPDIR" ] && TMPDIR=/tmp
+
+
+TEMPDIR=$TMPDIR/.get-st.$$
+mkdir -p ${TEMPDIR} && cd ${TEMPDIR} || exit 1
+trap "cleanExit" 0 1 2 15
+cleanExit ()
+{
+ rm -rf ${TEMPDIR}
+}
+
+echo "Get Syncthing..."
+
+## Install Syncthing + Syncthing-inotify
+## gpg: key 00654A3E: public key "Syncthing Release Management <release@syncthing.net>" imported
+gpg -q --keyserver pool.sks-keyservers.net --recv-keys 37C84554E7E0A261E4F76E1ED26E6ED000654A3E || exit 1
+
+tarball="syncthing-linux-amd64-v${SYNCTHING_VERSION}.tar.gz" \
+ && curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/${tarball}" -O \
+ && curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/sha1sum.txt.asc" -O \
+ && gpg -q --verify sha1sum.txt.asc \
+ && grep -E " ${tarball}\$" sha1sum.txt.asc | sha1sum -c - \
+ && rm sha1sum.txt.asc \
+ && tar -xvf "$tarball" --strip-components=1 "$(basename "$tarball" .tar.gz)"/syncthing \
+ && mv syncthing ${DESTDIR}/syncthing
+
+
+echo "Get Syncthing-inotify..."
+tarball="syncthing-inotify-linux-amd64-v${SYNCTHING_INOTIFY_VERSION}.tar.gz" \
+ && curl -sfSL "https://github.com/syncthing/syncthing-inotify/releases/download/v${SYNCTHING_INOTIFY_VERSION}/${tarball}" -O \
+ && tar -xvf "${tarball}" syncthing-inotify \
+ && mv syncthing-inotify ${DESTDIR}/syncthing-inotify
+
+echo "DONE: syncthing and syncthing-inotify successfuly installed in ${DESTDIR}" \ No newline at end of file
diff --git a/scripts/xds-start-server.sh b/scripts/xds-start-server.sh
new file mode 100755
index 0000000..5a3cba7
--- /dev/null
+++ b/scripts/xds-start-server.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+# Configurable variables
+[ -z "$BINDIR" ] && BINDIR=/usr/local/bin
+[ -z "$ST_CONFDIR" ] && ST_CONFDIR=$HOME/.xds/syncthing-config
+[ -z "$XDS_CONFFILE" ] && XDS_CONFFILE=$HOME/.xds/config.json
+[ -z "$LOGLEVEL" ] && LOGLEVEL=warn
+[ -z "$LOGDIR" ] && LOGDIR=/tmp/xds-logs
+[ -z "$PORT_GUI" ] && PORT_GUI=8384
+[ -z "$API_KEY" ] && API_KEY="1234abcezam"
+
+
+mkdir -p ${LOGDIR}
+LOG_XDS=${LOGDIR}/xds-server.log
+LOG_SYNC=${LOGDIR}/syncthing.log
+LOG_SYNCI=${LOGDIR}/syncthing-inotify.log
+
+echo "### Info"
+echo "XDS server config: $XDS_CONFFILE"
+echo "Syncthing GUI on port: $PORT_GUI"
+echo "Syncthing Config: $ST_CONFDIR"
+echo "XDS server output redirected in: $LOG_XDS"
+echo "Syncthing-inotify output redirected in: $LOG_SYNCI"
+echo "Syncthing output redirected in: $LOG_SYNC"
+echo ""
+
+pwd
+[[ -f $BINDIR/xds-server ]] || { BINDIR=$(cd `dirname $0` && pwd); }
+pwd
+[[ -f $BINDIR/xds-server ]] || { echo "Cannot find xds-server in BINDIR !"; exit 1; }
+
+echo "### Start syncthing-inotify:"
+$BINDIR/syncthing-inotify --home=$ST_CONFDIR -target=http://localhost:$PORT_GUI -verbosity=4 > $LOG_SYNCI 2>&1 &
+pid_synci=$(jobs -p)
+echo "pid=${pid_synci}"
+echo ""
+
+echo "### Start Syncthing:"
+STNODEFAULTFOLDER=1 $BINDIR/syncthing --home=$ST_CONFDIR -no-browser -verbose --gui-address=0.0.0.0:$PORT_GUI -gui-apikey=${API_KEY} > $LOG_SYNC 2>&1 &
+pid_sync=$(jobs -p)
+echo "pid=${pid_sync}"
+echo ""
+
+sleep 1
+
+echo "### Start XDS server"
+$BINDIR/xds-server --config $XDS_CONFFILE -log $LOGLEVEL > $LOG_XDS 2>&1 &
+pid_xds=$(jobs -p)
+echo "pid=${pid_xds}"
+echo ""