Skip to content

Instantly share code, notes, and snippets.

@rwenz3l
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwenz3l/3391773882c1e8f6f9f3 to your computer and use it in GitHub Desktop.
Save rwenz3l/3391773882c1e8f6f9f3 to your computer and use it in GitHub Desktop.
#!/bin/bash
clear
cd /usr/src
wget -O btsync_x64.tar.gz http://download.getsyncapp.com/endpoint/btsync/os/linux-x64/track/stable
tar -xf btsync_x64.tar.gz -C /usr/local/sbin btsync
adduser --quiet --system --group --disabled-password
read -d '' config <<"EOF"
{
"device_name" : "server",
"listening_port" : 0,
"storage_path" : "/home/btsync",
"pid_file" : "/home/btsync/btsync.pid",
"check_for_updates" : false,
"use_upnp" : true,
"download_limit" : 0,
"upload_limit" : 0,
"webui" :
{
"listen" : "0.0.0.0:8888",
"login" : "admin",
"password" : "admin"
}
}
EOF
echo "${config}" > /etc/btsync.conf
read -d '' init <<"EOF"
#! /bin/sh
### BEGIN INIT INFO
# Provides: btsync daemon
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: BTSync server daemon
# Description: Daemon script to run a BTSync permanent peer
# Placed in /etc/init.d.
### END INIT INFO
# Author: Nicolas Bernaerts <nicolas.bernaerts@laposte.net>
# Version:
# V1.0, 06/09/2013 - Creation
# V1.1, 09/09/2013 - Use under-priviledged system user
# description variables
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="BTSync server"
NAME="btsync"
USER=$NAME
DAEMON=/usr/local/sbin/$NAME
ROOT=/home/$NAME
PIDFILE=$ROOT/$NAME.pid
# Exit if btsync program is not installed
if [ ! -x "$DAEMON" ] ; then
echo "Binary $DAEMON does not exist. Aborting"
exit 0
fi
# Exit if btsync user home directory doesn't exist
if [ ! -d "$ROOT" ]; then
echo "User $USER does not exist. Aborting"
exit 0
fi
# Function that starts the daemon/service
# 0 - daemon started
# 1 - daemon already running
# 2 - daemon could not be started
do_start()
{
# If needed, start the daemon
if [ -f "$PIDFILE" ]
then
echo "$NAME already running"
RETVAL="1"
else
start-stop-daemon --start --quiet --chuid $USER --name $NAME --exec $DAEMON -- --config /etc/btsync.conf
RETVAL="$?"
[ "$RETVAL" = "0" ] && echo "$NAME started"
fi
return "$RETVAL"
}
# Function that stops the daemon/service
# 0 - daemon stopped
# 1 - daemon already stopped
# 2 - daemon could not be stopped
do_stop()
{
# Stop the daemon
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = "0" ] && echo "$NAME stopped"
[ "$RETVAL" = "1" ] && echo "$NAME was not running"
# remove pid file
rm -f $PIDFILE
return "$RETVAL"
}
# deal with different parameters : start, stop & status
case "$1" in
# start service
start)
do_start
;;
# stop service
stop)
do_stop
;;
# restart service
restart)
do_stop
do_start
;;
# unknown command, display help message
*)
echo "Usage : $SCRIPTNAME {start|stop|restart}" >&2
exit 3
;;
esac
EOF
echo "${init}" > /etc/init.d/btsync
chmod +x /etc/init.d/btsync
update-rc.d btsync defaults
service btsync start
echo "User = admin"
echo "Pass = admin"
echo "Please change the login via the sync app"
echo "---------------------------------------------"
echo "credit goes to nicolas.bernaerts@laposte.net"
echo "---------------------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment