1
0
mirror of synced 2024-12-22 12:50:33 +01:00

Add btsync systemd setup script

This commit is contained in:
bobwya 2014-06-23 22:09:10 +01:00
parent 9e9bf81c45
commit 6015de186c

View File

@ -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