From 6015de186c6c0142a5e82f283fd7c50aee48a591 Mon Sep 17 00:00:00 2001 From: bobwya Date: Mon, 23 Jun 2014 22:09:10 +0100 Subject: [PATCH] Add btsync systemd setup script --- net-p2p/btsync/files/btsync_setup | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 net-p2p/btsync/files/btsync_setup diff --git a/net-p2p/btsync/files/btsync_setup b/net-p2p/btsync/files/btsync_setup new file mode 100755 index 0000000..8a2f968 --- /dev/null +++ b/net-p2p/btsync/files/btsync_setup @@ -0,0 +1,43 @@ +#!/bin/sh +# +# Prestart script run before "/opt/btsync/bin/btsync" that generates a +# suitable default configuration if it's not present already. +# +# For the root user, it is put at "/etc/btsync.conf" and uses system-wide paths +# (working folder "/var/lib/btsync" and PID storage in "/run/btsync/"). +# +# Non-root users get a "$HOME/.btsync/btsync.conf" file and uses a user local path +# (working folder "$HOME/.btsync" including PID storage). +# + +# Absolute path to this script. +script_path=$(readlink -f $0) +# Absolute path this script is in. +script_folder=$( dirname "${script_path}" ) +script_name=$( basename "${script_path}" ) + +PN="btsync" +BTSYNC_PATH="/opt/${PN}" + +if [[ $EUID -eq 0 ]]; then + STORAGE_PATH="/var/lib/${PN}" + CONF_FILE="/etc/${PN}.conf" + PID_FILE="/var/run/${PN}.pid" +else + STORAGE_PATH="$HOME.${PN}" + CONF_FILE="${STORAGE_PATH}/${PN}.conf" + PID_FILE="${STORAGE_PATH}/${PN}.pid" + mkdir -p "${STORAGE_PATH}" +fi + +if [ ! -f "${CONF_FILE}" ] ; then + "${BTSYNC_PATH}/bin/${PN}" --dump-sample-config > "${CONF_FILE}" || exit 1 + sed -i \ + -e "s|\"password\" : \"password\"|\"password\" : \"$(date +%s | sha256sum | base64 | head -c 32)\"|" \ + -e "s|\"device_name\": \"My Sync Device\"|\"device_name\": \"$(hostname -f 2>/dev/null||hostname)\"|" \ + -e "s|\"login\" : \"admin\"|\"login\" : \"$USER\"|" \ + -e "s|\"listen\" : \"0.0.0.0:8888\"|\"listen\" : \"127.0.0.1:$(expr 8888 + $EUID)\"|" \ + -e "s|\"storage_path\" : \"/home/user/.sync\"|\"storage_path\" : \"${STORAGE_PATH}\"|" \ + -e "/\/\/ uncomment next line if you want to set location of pid file/d" \ + -e "s|\/\/ \"pid_file\" : \"/var/run/${PN}/${PN}.pid\"| \"pid_file\" : \"${PID_FILE}\"|" "${CONF_FILE}" +fi