#!/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\"||g" \ -e "s|\"device_name\": \"caMy Sync Device\"|\"device_name\": \"$(hostname -f 2>/dev/null||hostname)\"|" \ -e "s|\"login\" : \"admin\",||g" \ -e "s|\"listen\" : \"0.0.0.0:8888\",|\"listen\" : \"127.0.0.1:$(expr 7888 + $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