| #!/bin/bash |
|
|
| set -e |
|
|
| |
| log() { |
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] [WebDAV] $*" |
| } |
|
|
| log "Initializing WebDAV service..." |
|
|
| |
| user_home="${HOME:-/home/user}" |
| config_file="$user_home/config/webdav.conf" |
|
|
| |
| 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}" |
|
|
| |
| 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 |
|
|
| |
| mkdir -p "$user_home/webdav/data" "$user_home/webdav/config" "$WEBDAV_ROOT_DIR" |
|
|
| |
| webdav_config_file="$user_home/webdav/config/flydav.toml" |
| log "Creating FlyDAV configuration file: $webdav_config_file" |
|
|
| |
| password_hash=$(echo -n "$WEBDAV_PASSWORD" | sha256sum | cut -d' ' -f1) |
|
|
| |
| 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 |
|
|
| |
| 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" |
|
|
| |
| 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 |
|
|
| |
| log "Starting WebDAV server..." |
|
|
| |
| 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" |
|
|
| |
| exec flydav -c "$webdav_config_file" $UI_FLAG |