Skip to content

Instantly share code, notes, and snippets.

@samjessup
Created June 25, 2020 06:35
Show Gist options
  • Save samjessup/a7fd5c15e3fe442fc49f300a016989dd to your computer and use it in GitHub Desktop.
Save samjessup/a7fd5c15e3fe442fc49f300a016989dd to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script originally from https://blog.arrogantrabbit.com/backup/Duplicacy-Web-on-Synology-Diskstation/
# Duplicacy version. Modify and re-run the script when new version is released
DUPLICACY_WEB_VERSION=1.3.0
# Username for the daemon to run on behalf of. Give this user permission to read stuff that needs to be backed up.
USERNAME=duplicacy
GROUPNAME=users
if [[ $(id -u) != 0 ]]; then
sudo -p 'Restarting as root, password: ' bash $0 "$@"
exit $?
fi
# Figuring out correct download suffix
MACHINE_ARCH=$(uname -m)
case ${MACHINE_ARCH} in
"x86_64")
ARCH=x64
;;
"arm")
ARCH=arm
;;
*)
echo Unknown or unsupported architecture ${MACHINE_ARCH}
exit 2
;;
esac
SERVICENAME=duplicacy_web
echo "Using duplicacy_web version ${DUPLICACY_WEB_VERSION} arch ${ARCH}"
echo "Service ${SERVICENAME} will run as a user ${USERNAME}:${GROUPNAME}"
# Target application filename.
APPFILE=duplicacy_web_linux_${ARCH}_${DUPLICACY_WEB_VERSION}
# Download URL
URL=https://acrosync.com/duplicacy-web/${APPFILE}
echo "Stopping the service ${SERVICENAME}"
stop ${SERVICENAME}
# Check if specified user exists
if [[ 0 != $(id -u ${USERNAME} > /dev/null 2>&1; echo $?) ]] ; then
echo "User ${USERNAME} does not exist. Create the user and enable user home service (Control Panel, User, Advanced)"
exit 3
fi
# Check if user has home folder
HOMEDIR="$(eval echo ~"${USERNAME}")"
if [ ! -d ${HOMEDIR} ] ; then
echo "Home directory for the user ${USERNAME} does not exist. Make sure Homes service is running"
exit 4
fi
# If application executable hasn't been downloaded yet -- do it now
APPFILEPATH=${HOMEDIR}/${APPFILE}
if [ ! -f ${APPFILEPATH} ]; then
echo "Downloading executable from ${URL}"
wget -O ${APPFILEPATH} ${URL}
if [[ $? != 0 ]]; then
echo "Download failed"
rm -f ${APPFILEPATH}
exit 5
fi
chmod +x ${APPFILEPATH} || exit 6
fi
# Write out upstart daemon configuration
echo "Creating upstart daemon ${SERVICENAME} in /etc/init"
cat > /etc/init/${SERVICENAME}.conf << EOF
description "${SERVICENAME} daemon"
author "Arrogant Rabbit"
start on syno.network.ready and syno.share.ready
stop on runlevel [06]
env HOME=${HOMEDIR}
env DUPLICACY_ATTRIBUTE_THRESHOLD=1
setuid ${USERNAME}
setgid ${GROUPNAME}
respawn
respawn limit 5 10
oom score -999
console log
exec ${APPFILEPATH}
EOF
echo "Launching service ${SERVICENAME}"
start ${SERVICENAME} || exit 7
echo "Duplicacy has been installed and started successfully"
echo "By default duplicacy_web is listening on port 3875 on a loopback interface for security."
echo "To establish connection start TCP tunnel first: ssh -L 3875:127.0.0.1:3875 $(hostname)"
echo "Then navigate to http://localhost:3875"
# Enable SSH TcpForwarding
sed -i "s/.*AllowTcpForwarding.*/AllowTcpForwarding yes/g" /etc/ssh/sshd_config
restart sshd
ssh -L 3875:127.0.0.1:3875 $(hostname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment