diff options
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | conf.d/etc/default/xds-agent | 5 | ||||
-rw-r--r-- | conf.d/etc/profile.d/xds-agent.sh | 4 | ||||
-rw-r--r-- | conf.d/etc/xds-agent/config.json (renamed from agent-config.json.in) | 0 | ||||
-rw-r--r-- | conf.d/usr/lib/systemd/user/xds-agent.service (renamed from xds-agent.service) | 2 | ||||
-rw-r--r-- | lib/xdsconfig/fileconfig.go | 19 | ||||
-rwxr-xr-x | scripts/get-syncthing.sh | 4 | ||||
-rwxr-xr-x | scripts/install.sh | 42 |
8 files changed, 65 insertions, 26 deletions
@@ -27,9 +27,9 @@ endif # for backward compatibility DESTDIR := $(INSTALL_DIR) -# Configurable variables for installation (default /usr/local/...) +# Configurable variables for installation (default /opt/AGL/xds/agent) ifeq ($(origin DESTDIR), undefined) - DESTDIR := /usr/local/bin + DESTDIR := /opt/AGL/xds/agent endif HOST_GOOS=$(shell go env GOOS) @@ -82,9 +82,10 @@ build: tools/syncthing/copytobin @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)" . 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 $(PACKAGE_DIR)/xds-agent + cp -r $(ROOT_SRCDIR)/scripts $(PACKAGE_DIR)/scripts cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-agent .PHONY: package-all @@ -121,8 +122,10 @@ distclean: clean rm -rf $(LOCAL_BINDIR) tools glide.lock vendor $(ROOT_SRCDIR)/*.zip .PHONY: install -install: all - mkdir -p $(DESTDIR) && cp $(LOCAL_BINDIR)/* $(DESTDIR) +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) && $(ROOT_SRCDIR)/scripts/install.sh vendor: tools/glide glide.yaml $(LOCAL_TOOLSDIR)/glide install --strip-vendor diff --git a/conf.d/etc/default/xds-agent b/conf.d/etc/default/xds-agent new file mode 100644 index 0000000..93d56cb --- /dev/null +++ b/conf.d/etc/default/xds-agent @@ -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 index 0000000..78eff4f --- /dev/null +++ b/conf.d/etc/profile.d/xds-agent.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +#---------- AGL xds-agent tool options Start ---------" +[ ":${PATH}:" != *":%%XDS_INSTALL_BIN_DIR%%:"* ] && export PATH=%%XDS_INSTALL_BIN_DIR%%:${PATH} diff --git a/agent-config.json.in b/conf.d/etc/xds-agent/config.json index 35d702d..35d702d 100644 --- a/agent-config.json.in +++ b/conf.d/etc/xds-agent/config.json diff --git a/xds-agent.service b/conf.d/usr/lib/systemd/user/xds-agent.service index 66788dc..1fd038b 100644 --- a/xds-agent.service +++ b/conf.d/usr/lib/systemd/user/xds-agent.service @@ -2,7 +2,7 @@ Description=XDS Agent [Service] -User=claneys +EnvironmentFile=-/etc/default/xds-agent ExecStart=/opt/AGL/xds/agent/xds-agent & [Install] diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go index efe94bf..d936bbe 100644 --- a/lib/xdsconfig/fileconfig.go +++ b/lib/xdsconfig/fileconfig.go @@ -5,7 +5,6 @@ import ( "os" "os/user" "path" - "path/filepath" common "github.com/iotbzh/xds-common/golib" ) @@ -28,8 +27,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 updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) { @@ -41,20 +39,7 @@ func updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) { searchIn = append(searchIn, path.Join(usr.HomeDir, ".xds", "agent", "agent-config.json")) } - searchIn = append(searchIn, "/etc/xds-agent/agent-config.json") - - exePath := os.Args[0] - ee, _ := os.Executable() - exeAbsPath, err := filepath.Abs(ee) - if err == nil { - exePath, err = filepath.EvalSymlinks(exeAbsPath) - if err == nil { - exePath = filepath.Dir(ee) - } else { - exePath = filepath.Dir(exeAbsPath) - } - } - searchIn = append(searchIn, path.Join(exePath, "agent-config.json")) + searchIn = append(searchIn, "/etc/xds-agent/config.json") var cFile *string for _, p := range searchIn { diff --git a/scripts/get-syncthing.sh b/scripts/get-syncthing.sh index 3455122..772c09a 100755 --- a/scripts/get-syncthing.sh +++ b/scripts/get-syncthing.sh @@ -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 index 0000000..6f93f2b --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Install XDS agent as a user systemd service + +DESTDIR=${DESTDIR:-/opt/AGL/xds/agent} + +ROOT_SRCDIR=$(cd $(dirname "$0")/.. && pwd) + +install() { + mkdir -p ${DESTDIR} && cp ${ROOT_SRCDIR}/bin/* ${DESTDIR} || 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 |