#!/bin/bash set -e # Function for logging log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] [WEBDAV] $*" } # Function for cleanup cleanup() { log "Performing WebDAV installation cleanup..." rm -rf /tmp/flydav* /tmp/webdav* /tmp/*.zip } # Trap to ensure cleanup on exit trap cleanup EXIT log "Starting WebDAV (FlyDAV) installation..." # Detect architecture ARCH=$(uname -m) case $ARCH in x86_64) BINARY_ARCH="amd64" ;; aarch64|arm64) BINARY_ARCH="arm64" ;; armv7l) BINARY_ARCH="arm" ;; *) log "ERROR: Unsupported architecture: $ARCH" exit 1 ;; esac log "Installing for architecture: $ARCH (binary: $BINARY_ARCH)" # Download FlyDAV binary FLYDAV_VERSION="v0.2.56" DOWNLOAD_URL="https://github.com/pluveto/flydav/releases/download/${FLYDAV_VERSION}/flydav-app-linux-${BINARY_ARCH}.zip" log "Downloading FlyDAV $FLYDAV_VERSION for $BINARY_ARCH..." cd /tmp curl -L -o "flydav.zip" "$DOWNLOAD_URL" # Extract and install log "Extracting FlyDAV..." unzip -q flydav.zip chmod +x flydav # Install to system path accessible by non-root user log "Installing FlyDAV binary..." mkdir -p /usr/local/bin mv flydav /usr/local/bin/flydav # Verify installation log "Verifying FlyDAV installation..." if command -v flydav >/dev/null 2>&1; then FLYDAV_VERSION_CHECK=$(flydav --version 2>&1 || echo "FlyDAV installed") log "FlyDAV installed successfully: ${FLYDAV_VERSION_CHECK}" else log "ERROR: FlyDAV installation failed" exit 1 fi # Create directories that will be owned by user 1000 log "Creating WebDAV directories..." mkdir -p /home/user/webdav /home/user/webdav/data /home/user/webdav/config chown -R 1000:1000 /home/user/webdav log "WebDAV (FlyDAV) installation completed successfully" log "Version: $FLYDAV_VERSION" log "Architecture: $BINARY_ARCH"