Skip to content

Commit

Permalink
Merge pull request #44 from WDCommunity/syncthing
Browse files Browse the repository at this point in the history
Bump and harden syncthing
  • Loading branch information
stefaang authored Oct 3, 2019
2 parents 44b0927 + 041fe89 commit 8195f24
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 27 deletions.
8 changes: 7 additions & 1 deletion build_and_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ cssh=ssh

echo
echo "Install the app"
$cssh $TARGET "PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin /usr/sbin/upload_apkg -rapp.bin -d -f1 -g1 && echo 'SUCCESS!'"
ALREADY_INSTALLED=$($cssh $TARGET "del_apkg whatever | grep ${PACKAGE}")
if [ -n "${ALREADY_INSTALLED}" ]; then
$cssh $TARGET "PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin /usr/sbin/upload_apkg -rapp.bin -d -f1 -g1 && echo 'SUCCESS!'"
else
echo "Warning: this usually doesn't work!"
$cssh $TARGET "PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin /usr/sbin/upload_apkg -papp.bin -t2 -d -f0 -g1 && echo 'SUCCESS!'"
fi


TEST=tests/$PACKAGE/test.sh
Expand Down
24 changes: 24 additions & 0 deletions tests/syncthing/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

source wdpk/$PACKAGE/env

serverReachable() {
return $(nc -z $TARGET $PORT)
}

count=0
until serverReachable
do
if [ $count -le 50 ]
then
echo "Waiting for server..."
sleep 1
count=$(( $count + 1 ))
else
echo "Server not reachable"
break
exit 1
fi
done
echo "Server reachable!"

4 changes: 2 additions & 2 deletions tests/tautulli/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ serverReachable() {
}

count=0
until serverReachable
until serverReachable
do
if [ $count -le 50 ]
then
Expand All @@ -17,7 +17,7 @@ do
else
echo "Server not reachable"
break
#exit 1
exit 1
fi
done
echo "Server reachable!"
Expand Down
2 changes: 1 addition & 1 deletion wdpk/syncthing/apkg.rc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: syncthing
Version: 1.1.0
Version: 1.3.0
Packager: TFL
Email:
Homepage: https://www.syncthing.net
Expand Down
2 changes: 2 additions & 0 deletions wdpk/syncthing/env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ BINARY="syncthing"

WEBGUI_ADDR=$(grep -m1 Require /usr/local/apache2/conf/httpd.conf | awk '{print $NF}' | cut -d/ -f1)
PORT=8384

export ST_HOME=/shares/Volume_1/Nas_Prog/syncthing_home
25 changes: 12 additions & 13 deletions wdpk/syncthing/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

[ -f /tmp/debug_apkg ] && echo "APKG_DEBUG: $0 $@" >> /tmp/debug_apkg
log=/tmp/debug_apkg

echo "APKG_DEBUG: $0 $@" >> $log

INSTALL_DIR=$(readlink -f $1)
. ${INSTALL_DIR}/env
Expand All @@ -11,8 +13,8 @@ log=/tmp/debug_apkg

APKG_PATH="${NAS_PROG}/${APKG_NAME}"

# move package data
mv ${INSTALL_DIR} ${NAS_PROG}
echo "move package data" >> $log
mv ${INSTALL_DIR} ${NAS_PROG} 2>&1 >> $log

# setup secure downloads
if [ ! -e /etc/ssl/cert.pem ]; then
Expand All @@ -23,25 +25,22 @@ fi
PLATFORM=$(uname -m)
if [ "${PLATFORM}" = "x86_64" ]; then
PLATFORM="amd64"
else
else
PLATFORM="arm"
fi
VERSION="v1.1.0"
VERSION="v1.3.0"

MAINDIR="syncthing-linux-${PLATFORM}-${VERSION}"
PACKAGE="${MAINDIR}.tar.gz"
URL="https://github.com/syncthing/syncthing/releases/download/${VERSION}/${PACKAGE}"

/usr/bin/wget ${URL}

[[ ! $? -eq 0 ]] && exit 1

tar xf ${PACKAGE} -C ${APKG_PATH}
curl -L -s ${URL} | tar zx -C ${APKG_PATH} 2>&1 >> $log

[[ ! $? -eq 0 ]] && exit 2

rm ${PACKAGE}

# strip the version from the app dir
mv ${APKG_PATH}/${MAINDIR} ${APKG_PATH}/${APKG_NAME}

# TODO: restore config
# create syncthing home dir
mkdir -p ${ST_HOME}

5 changes: 3 additions & 2 deletions wdpk/syncthing/remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

[ -f /tmp/debug_apkg ] && echo "APKG_DEBUG: $0 $@" >> /tmp/debug_apkg

[ -n "$(pidof syncthing)" ] && pkill syncthing

APKG_PATH=$(readlink -f $1)
. ${APKG_PATH}/env

# remove app
rm -rf ${APKG_PATH}

# remove lib

# remove web
rm -rf /var/www/${APKG_NAME}
7 changes: 3 additions & 4 deletions wdpk/syncthing/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

log=/tmp/debug_apkg

APKG_PATH=$1
. ${APKG_PATH}/env

Expand All @@ -8,9 +10,6 @@ ADDRESS=$(grep -m1 'Require ip' /usr/local/apache2/conf/httpd.conf | awk '{print
# disable creation of default folder
export STNODEFAULTFOLDER=0

# keep all persistent data in the syncthing home dir
ST_HOME=${APKG_PATH}/var

# start the binary
${APKG_PATH}/syncthing/syncthing -no-browser -home=${ST_HOME} -gui-address="http://${ADDRESS}:${PORT}"
${APKG_PATH}/syncthing/syncthing -no-browser -home=${ST_HOME} -gui-address="http://${ADDRESS}:${PORT}" 2>&1 >> $log

14 changes: 10 additions & 4 deletions wdpk/syncthing/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

# stop daemon
APKG_DIR=$(readlink -f $1)
. ${APKG_DIR}/env
. ${APKG_DIR}/env

if pidof ${BINARY} > /dev/null ; then
pkill ${BINARY}

p=$(pidof ${BINARY} > /dev/null)
while [ -n "$p" ] ; do
echo "Stopping ${APKG_NAME}"
kill $(pidof ${BINARY})
fi
kill $p
sleep 1
p=$(pidof ${BINARY} > /dev/null)
do

0 comments on commit 8195f24

Please sign in to comment.