#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
. /etc/conf.d/crond
USER=root # changeme...
HOME=$(egrep "^"$USER /etc/passwd | cut -d: -f6)
PIDFILE="$HOME"/.config/btsync/sync.pid
PID=$(cat $PIDFILE 2>/dev/null)
case $1 in
start)
stat_busy "Starting BitTorrent Sync service"
if su $USER -- /usr/bin/btsync-wrapper --config "$HOME"/.config/btsync/btsync.conf 1>/dev/null ; then
add_daemon btsync
stat_done
else
stat_fail
exit 1
fi
;;
stop)
stat_busy "Stopping BitTorrent Sync service"
if [[ ! -z $PID ]] && kill "$PID" &>/dev/null; then
rm_daemon btsync
stat_done
else
stat_fail
exit 1
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 1
esac