Bump to Syncthing 0.14.28
[src/xds/xds-server.git] / scripts / get-syncthing.sh
1 #!/bin/bash
2
3 # Configurable variables
4 [ -z "$SYNCTHING_VERSION" ] && SYNCTHING_VERSION=0.14.28
5
6 # FIXME: temporary HACK while waiting merge of #165
7 #[ -z "$SYNCTHING_INOTIFY_VERSION" ] && SYNCTHING_INOTIFY_VERSION=0.8.5
8 [ -z "$SYNCTHING_INOTIFY_VERSION" ] && { SYNCTHING_INOTIFY_VERSION=master; SYNCTHING_INOTIFY_CMID=af6fbf9d63f95a0; }
9 [ -z "$DESTDIR" ] && DESTDIR=/usr/local/bin
10 [ -z "$TMPDIR" ] && TMPDIR=/tmp
11
12
13 TEMPDIR=$TMPDIR/.get-st.$$
14 mkdir -p ${TEMPDIR} && cd ${TEMPDIR} || exit 1
15 trap "cleanExit" 0 1 2 15
16 cleanExit ()
17 {
18    rm -rf ${TEMPDIR}
19 }
20
21 echo "Get Syncthing..."
22
23 ## Install Syncthing + Syncthing-inotify
24 ## gpg: key 00654A3E: public key "Syncthing Release Management <release@syncthing.net>" imported
25 gpg -q --keyserver pool.sks-keyservers.net --recv-keys 37C84554E7E0A261E4F76E1ED26E6ED000654A3E || exit 1
26
27 tarball="syncthing-linux-amd64-v${SYNCTHING_VERSION}.tar.gz" \
28         && curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/${tarball}" -O \
29     && curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/sha1sum.txt.asc" -O \
30         && gpg -q --verify sha1sum.txt.asc \
31         && grep -E " ${tarball}\$" sha1sum.txt.asc | sha1sum -c - \
32         && rm sha1sum.txt.asc \
33         && tar -xvf "$tarball" --strip-components=1 "$(basename "$tarball" .tar.gz)"/syncthing \
34         && mv syncthing ${DESTDIR}/syncthing || exit 1
35
36 echo "Get Syncthing-inotify..."
37 if [ "$SYNCTHING_INOTIFY_VERSION" = "master" ]; then
38     mkdir -p ${TEMPDIR}/syncthing-inotify-build/src/github.com/syncthing || exit 1
39     cd ${TEMPDIR}/syncthing-inotify-build/src/github.com/syncthing
40     git clone https://github.com/syncthing/syncthing || exit 1
41     git clone https://github.com/syncthing/syncthing-inotify || exit 1
42     cd syncthing-inotify
43     if [ "$SYNCTHING_INOTIFY_CMID" != "" ]; then
44         git checkout -q $SYNCTHING_INOTIFY_CMID || exit 1
45     fi
46     git status
47     export GOPATH=$(realpath `pwd`/../../../..)
48     version=$(git describe --tags --always | sed 's/^v//')__patch_165
49     go build -v -i -ldflags "-w -X main.Version=$version" -o ${DESTDIR}/syncthing-inotify || exit 1
50 else
51
52 tarball="syncthing-inotify-linux-amd64-v${SYNCTHING_INOTIFY_VERSION}.tar.gz" \
53     && curl -sfSL "https://github.com/syncthing/syncthing-inotify/releases/download/v${SYNCTHING_INOTIFY_VERSION}/${tarball}" -O \
54     && tar -xvf "${tarball}" syncthing-inotify \
55         && mv syncthing-inotify ${DESTDIR}/syncthing-inotify
56 fi
57
58 echo "DONE: syncthing and syncthing-inotify successfuly installed in ${DESTDIR}"