3 # Configurable variables
4 [ -z "$SYNCTHING_VERSION" ] && SYNCTHING_VERSION=0.14.28
5 [ -z "$SYNCTHING_INOTIFY_VERSION" ] && SYNCTHING_INOTIFY_VERSION=0.8.6
7 # Used as temporary HACK while waiting merge of #165
8 #[ -z "$SYNCTHING_INOTIFY_VERSION" ] && { SYNCTHING_INOTIFY_VERSION=master; SYNCTHING_INOTIFY_CMID=af6fbf9d63f95a0; }
9 [ -z "$DESTDIR" ] && DESTDIR=/opt/AGL/xds/server
10 [ -z "$TMPDIR" ] && TMPDIR=/tmp
11 [ -z "$GOOS" ] && GOOS=$(go env GOOS)
12 [ -z "$GOARCH" ] && GOARCH=$(go env GOARCH)
13 [ -z "$CLEANUP" ] && CLEANUP=false
16 TEMPDIR=$TMPDIR/.get-syncthing.tmp
17 mkdir -p ${TEMPDIR} && cd ${TEMPDIR} || exit 1
18 trap "cleanExit" 0 1 2 15
21 if [ "$CLEANUP" = "true" ]; then
28 [[ "$GOOS" = "windows" ]] && { TB_EXT="zip"; EXT=".exe"; }
32 [[ "$GOOS" = "darwin" ]] && GOOS_ST="macosx"
34 echo "Get Syncthing..."
38 ## Install Syncthing + Syncthing-inotify
39 ## gpg: key 00654A3E: public key "Syncthing Release Management <release@syncthing.net>" imported
41 if [ "$?" != 0 ]; then
42 echo "You must install first gpg ( eg.: sudo apt install gpg )"
46 gpg -q --keyserver pool.sks-keyservers.net --recv-keys 37C84554E7E0A261E4F76E1ED26E6ED000654A3E || exit 1
48 tarball="syncthing-${GOOS_ST}-${GOARCH}-v${SYNCTHING_VERSION}.${TB_EXT}" \
49 && curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/${tarball}" -O \
50 && curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/sha1sum.txt.asc" -O \
51 && gpg -q --verify sha1sum.txt.asc \
52 && grep -E " ${tarball}\$" sha1sum.txt.asc | sha1sum -c - \
53 && rm -rf sha1sum.txt.asc syncthing-${GOOS_ST}-${GOARCH}-v${SYNCTHING_VERSION}
54 if [ "${TB_EXT}" = "tar.gz" ]; then
55 tar -xvf "$tarball" --strip-components=1 "$(basename "$tarball" .tar.gz)"/syncthing \
56 && mv syncthing ${DESTDIR}/syncthing || exit 1
58 unzip "$tarball" && mv syncthing-windows-*/syncthing.exe ${DESTDIR}/syncthing.exe || exit 1
61 echo "Get Syncthing-inotify..."
62 if [ "$SYNCTHING_INOTIFY_VERSION" = "master" ]; then
63 mkdir -p ${TEMPDIR}/syncthing-inotify-build/src/github.com/syncthing || exit 1
64 cd ${TEMPDIR}/syncthing-inotify-build/src/github.com/syncthing
65 [[ ! -d ./syncthing ]] && (git clone https://github.com/syncthing/syncthing || exit 1; )
66 [[ ! -d ./syncthing-inotify ]] && (git clone https://github.com/syncthing/syncthing-inotify || exit 1; )
69 version=$(git describe --tags --always | sed 's/^v//')__patch_165
70 if [ "$SYNCTHING_INOTIFY_CMID" != "" ]; then
71 git checkout -q $SYNCTHING_INOTIFY_CMID || exit 1
72 version=${version}__patch_165
75 # Workaround about "cannot find package "golang.org/x/sys/unix"
76 go get -u golang.org/x/sys/unix
78 # Workaround about "undefined: stream" error when cross-building MacOS
79 # https://github.com/rjeczalik/notify/issues/108
81 [[ "$GOOS_STI" = "darwin" ]] && OPTS="-tags kqueue"
83 export GOPATH=$(cd ../../../.. && pwd)
84 go build -v -i -ldflags "-w -X main.Version=$version" -o ${DESTDIR}/syncthing-inotify${EXT} || exit 1
87 tarball="syncthing-inotify-${GOOS_STI}-${GOARCH}-v${SYNCTHING_INOTIFY_VERSION}.${TB_EXT}"
88 curl -sfSL "https://github.com/syncthing/syncthing-inotify/releases/download/v${SYNCTHING_INOTIFY_VERSION}/${tarball}" -O || exit 1
89 rm -rf syncthing-inotify-${GOOS_STI}-${GOARCH}-v${SYNCTHING_INOTIFY_VERSION}
90 if [ "${TB_EXT}" = "tar.gz" ]; then
91 tar -xvf "${tarball}" syncthing-inotify && mv syncthing-inotify ${DESTDIR}/syncthing-inotify || exit 1
93 unzip "$tarball" && mv syncthing-inotify.exe ${DESTDIR}/syncthing-inotify.exe || exit 1
97 echo "DONE: syncthing and syncthing-inotify successfuly installed in ${DESTDIR}"