2798e29d / scripts /start /webdav-start.sh
autoface's picture
Add aria2 and webdav configuration template files and update the associated startup scripts to generate configurations from the templates. Modify restic startup scripts to use project configuration templates to simplify configuration management.
a225f5b
#!/bin/bash
set -e
# Logging function
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [WebDAV] $*"
}
log "Initializing WebDAV service..."
# Load configuration
user_home="${HOME:-/home/user}"
config_file="$user_home/config/webdav.conf"
# Default configuration values
export WEBDAV_HOST="${WEBDAV_HOST:-0.0.0.0}"
export WEBDAV_PORT="${WEBDAV_PORT:-8081}"
export WEBDAV_USERNAME="${WEBDAV_USERNAME:-webdav}"
export WEBDAV_PASSWORD="${WEBDAV_PASSWORD:-webdav123}"
export WEBDAV_ROOT_DIR="${WEBDAV_ROOT_DIR:-$user_home/webdav}"
export WEBDAV_ENABLE_UI="${WEBDAV_ENABLE_UI:-true}"
# Load config file if exists
if [[ -f "$config_file" ]]; then
log "Loading WebDAV configuration from: $config_file"
source "$config_file"
else
log "No WebDAV configuration file found, using defaults"
fi
# Ensure directories exist
mkdir -p "$user_home/webdav/data" "$user_home/webdav/config" "$WEBDAV_ROOT_DIR"
# Create FlyDAV configuration file
webdav_config_file="$user_home/webdav/config/flydav.toml"
log "Creating FlyDAV configuration file: $webdav_config_file"
# Generate SHA256 hash of the password
password_hash=$(echo -n "$WEBDAV_PASSWORD" | sha256sum | cut -d' ' -f1)
# Determine template path
TEMPLATE_PATH="/etc/hf_docker_template/configs/templates/webdav.toml.template"
if [ ! -f "$TEMPLATE_PATH" ]; then
TEMPLATE_PATH="$(dirname "$(dirname "$(dirname "$0")")")/configs/templates/webdav.toml.template"
fi
# Generate WebDAV configuration
log "Generating WebDAV configuration from template..."
if [ -f "$TEMPLATE_PATH" ]; then
envsubst < "$TEMPLATE_PATH" > "$webdav_config_file"
log "Using template from: $TEMPLATE_PATH"
else
log "ERROR: Template file not found at $TEMPLATE_PATH"
exit 1
fi
log "WebDAV configuration created successfully"
log "Server: $WEBDAV_HOST:$WEBDAV_PORT"
log "Root directory: $WEBDAV_ROOT_DIR"
log "Username: $WEBDAV_USERNAME"
log "WebDAV URL: http://$WEBDAV_HOST:$WEBDAV_PORT/webdav"
# Check if FlyDAV is available
if ! command -v flydav >/dev/null 2>&1; then
log "ERROR: FlyDAV command not found!"
log "Please ensure WebDAV installation completed successfully"
exit 1
fi
# Start WebDAV server
log "Starting WebDAV server..."
# Add UI flag if enabled
UI_FLAG=""
if [[ "${WEBDAV_ENABLE_UI}" == "true" ]]; then
UI_FLAG="--with-ui"
log "WebDAV Web UI enabled"
log "Web UI URL: http://$WEBDAV_HOST:$WEBDAV_PORT/"
fi
log "Executing: flydav -c \"$webdav_config_file\" $UI_FLAG"
# Start the service with proper signal handling
exec flydav -c "$webdav_config_file" $UI_FLAG