1
0
mirror of synced 2024-12-23 05:10:24 +01:00
bobwya a4d1ce1386 Bug fixes to ebuilds & systemd setup script
ebuilds: correct btsync user setup & correct PID storage location
ebuilds: correct information about user configuration storage location
btsync_setup: correct location for PID storage for system wide systemd service unit
btsync_setup: automatically strip trailing / from HOME env path
update Manifest file
2014-06-25 16:34:56 +01:00

44 lines
1.8 KiB
Bash
Executable File

#!/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="/run/${PN}/${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