|
|
#!/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" |
|
|
|
|
|
|
|
|
WEBDAV_HOST="${WEBDAV_HOST:-0.0.0.0}" |
|
|
WEBDAV_PORT="${WEBDAV_PORT:-8081}" |
|
|
WEBDAV_USERNAME="${WEBDAV_USERNAME:-webdav}" |
|
|
WEBDAV_PASSWORD="${WEBDAV_PASSWORD:-webdav123}" |
|
|
WEBDAV_ROOT_DIR="${WEBDAV_ROOT_DIR:-$user_home/webdav}" |
|
|
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) |
|
|
|
|
|
cat > "$webdav_config_file" << EOF |
|
|
[server] |
|
|
host = "$WEBDAV_HOST" |
|
|
port = $WEBDAV_PORT |
|
|
path = "/webdav" |
|
|
fs_dir = "$WEBDAV_ROOT_DIR" |
|
|
|
|
|
[auth] |
|
|
[[auth.user]] |
|
|
username = "$WEBDAV_USERNAME" |
|
|
sub_fs_dir = "" |
|
|
sub_path = "" |
|
|
password_hash = "$password_hash" |
|
|
password_crypt = "sha256" |
|
|
|
|
|
[log] |
|
|
level = "info" |
|
|
|
|
|
[[log.stdout]] |
|
|
format = "text" |
|
|
output = "stdout" |
|
|
EOF |
|
|
|
|
|
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 |