From a145e82ffa63d2121de59c8c9217d057d1c955b3 Mon Sep 17 00:00:00 2001 From: opencode-agent Date: Fri, 13 Feb 2026 10:00:28 +0000 Subject: [PATCH] fix: improve permission handling for pre-existing directories - Create rclone-sync user BEFORE creating directories - Use chown -R to handle pre-existing directories from repo clone - Add ownership verification output - Support optional PUBLIC_IP argument for connection details --- ubuntu/setup.sh | 88 +++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/ubuntu/setup.sh b/ubuntu/setup.sh index 3929b0b..b2a1b3a 100644 --- a/ubuntu/setup.sh +++ b/ubuntu/setup.sh @@ -3,7 +3,10 @@ # JingTian rclone Server Setup Script # Run this on the Ubuntu VM that will receive synced files # -# Usage: sudo bash setup.sh +# Usage: sudo bash setup.sh [PUBLIC_IP] +# +# If PUBLIC_IP is provided, it will be shown in the connection details. +# Otherwise, the script will try to detect it or use the first local IP. # set -e @@ -13,6 +16,7 @@ DATA_DIR="/data/jingtian/BenjaminTeam" RCLONE_USER="rclone-sync" SSH_KEY_NAME="jingtian_rclone" SSH_KEY_DIR="/home/$RCLONE_USER/.ssh" +PUBLIC_IP="${1:-}" echo "==========================================" echo "JingTian rclone Server Setup" @@ -24,37 +28,9 @@ if [ "$EUID" -ne 0 ]; then exit 1 fi -# Step 1: Create data directory +# Step 1: Create dedicated user for rclone sync (FIRST, so we can set ownership correctly) echo "" -echo "[1/5] Creating data directory..." -mkdir -p "$DATA_DIR" -mkdir -p "$DATA_DIR/_LLM_Sync" - -# Create the same folder structure as client -mkdir -p "$DATA_DIR/Admin/E-Signature" -mkdir -p "$DATA_DIR/Admin/General Matter" -mkdir -p "$DATA_DIR/Admin/IPD e-filing" -mkdir -p "$DATA_DIR/Admin/JT Logo" -mkdir -p "$DATA_DIR/Admin/Letterhead" -mkdir -p "$DATA_DIR/Admin/Matter Open" -mkdir -p "$DATA_DIR/Admin/Template" -mkdir -p "$DATA_DIR/BD&M/2025 GCP" -mkdir -p "$DATA_DIR/BD&M/HKPC" -mkdir -p "$DATA_DIR/BD&M/WKCDA WKProcure" -mkdir -p "$DATA_DIR/Billing/Draft Bills" -mkdir -p "$DATA_DIR/Billing/Invoice Templates" -mkdir -p "$DATA_DIR/Billing/Issued Bills" -mkdir -p "$DATA_DIR/Client" -mkdir -p "$DATA_DIR/Free Schedules/Price List" -mkdir -p "$DATA_DIR/Free Schedules/Emails" -mkdir -p "$DATA_DIR/IP" -mkdir -p "$DATA_DIR/Precedent" - -echo " Created: $DATA_DIR" - -# Step 2: Create dedicated user for rclone sync -echo "" -echo "[2/5] Creating dedicated sync user: $RCLONE_USER..." +echo "[1/5] Creating dedicated sync user: $RCLONE_USER..." if id "$RCLONE_USER" &>/dev/null; then echo " User $RCLONE_USER already exists, skipping..." else @@ -62,10 +38,44 @@ else echo " Created user: $RCLONE_USER" fi -# Set ownership of data directory -chown -R "$RCLONE_USER:$RCLONE_USER" "$DATA_DIR" -chmod -R 755 "$DATA_DIR" -echo " Set ownership of $DATA_DIR to $RCLONE_USER" +# Step 2: Create data directory structure with correct ownership from the start +echo "" +echo "[2/5] Creating data directory..." + +# Create parent directories with root, then hand off to rclone-sync +mkdir -p /data/jingtian +chown root:root /data +chown -R "$RCLONE_USER:$RCLONE_USER" /data/jingtian + +# Create BenjaminTeam structure as rclone-sync user +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/_LLM_Sync" + +# Create the same folder structure as client +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Admin/E-Signature" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Admin/General Matter" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Admin/IPD e-filing" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Admin/JT Logo" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Admin/Letterhead" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Admin/Matter Open" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Admin/Template" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/BD&M/2025 GCP" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/BD&M/HKPC" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/BD&M/WKCDA WKProcure" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Billing/Draft Bills" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Billing/Invoice Templates" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Billing/Issued Bills" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Client" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Free Schedules/Price List" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Free Schedules/Emails" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/IP" +sudo -u "$RCLONE_USER" mkdir -p "$DATA_DIR/Precedent" + +echo " Created: $DATA_DIR" + +# Verify ownership +echo " Verifying ownership..." +ls -la /data/jingtian/ | head -5 # Step 3: Generate SSH key pair for rclone echo "" @@ -111,6 +121,12 @@ else echo " Installed: $(rclone version | head -1)" fi +# Determine the IP to show +if [ -z "$PUBLIC_IP" ]; then + # Try to get public IP, fall back to first local IP + PUBLIC_IP=$(curl -s --max-time 5 ifconfig.me 2>/dev/null || hostname -I | awk '{print $1}') +fi + # Print summary echo "" echo "==========================================" @@ -134,7 +150,7 @@ echo "Save this key to: windows/rclone-key" echo "It will be used by Windows clients to connect." echo "" echo "Connection details for Windows rclone config:" -echo " Host: $(hostname -I | awk '{print $1}')" +echo " Host: $PUBLIC_IP" echo " User: $RCLONE_USER" echo " Path: $DATA_DIR" echo ""