5 Commits

Author SHA1 Message Date
MangoPig
0be5782d9e fix: make setup.ps1 fully non-interactive for automated deployment
- Add -NonInteractive switch parameter
- Auto-accept detected BenjaminTeam folder in non-interactive mode
- Fix SSH test to use StrictHostKeyChecking=no and ConnectTimeout
- Add try/catch for better error handling during SSH test
2026-02-13 12:03:46 +00:00
fea6996041 Merge pull request 'feat: add Windows setup and sync scripts' (#4) from opencode-agent/JingTian-Rclone:feature/windows-setup into main
Reviewed-on: http://git.mangopig.tech/Goko/JingTian-Rclone/pulls/4
2026-02-13 11:48:23 +00:00
1101f188e8 Merge pull request 'feat: fix permissions + add SSH key for Windows clients' (#3) from opencode-agent/JingTian-Rclone:feature/fix-permissions-add-key into main
Reviewed-on: http://git.mangopig.tech/Goko/JingTian-Rclone/pulls/3
2026-02-13 10:01:19 +00:00
f79712e8bd feat: add SSH private key for rclone SFTP connection
This key is generated by the Ubuntu setup script and allows
Windows clients to authenticate via SFTP to the sync server.
2026-02-13 10:00:43 +00:00
a145e82ffa 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
2026-02-13 10:00:28 +00:00
3 changed files with 97 additions and 46 deletions

View File

@@ -3,7 +3,10 @@
# JingTian rclone Server Setup Script # JingTian rclone Server Setup Script
# Run this on the Ubuntu VM that will receive synced files # 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 set -e
@@ -13,6 +16,7 @@ DATA_DIR="/data/jingtian/BenjaminTeam"
RCLONE_USER="rclone-sync" RCLONE_USER="rclone-sync"
SSH_KEY_NAME="jingtian_rclone" SSH_KEY_NAME="jingtian_rclone"
SSH_KEY_DIR="/home/$RCLONE_USER/.ssh" SSH_KEY_DIR="/home/$RCLONE_USER/.ssh"
PUBLIC_IP="${1:-}"
echo "==========================================" echo "=========================================="
echo "JingTian rclone Server Setup" echo "JingTian rclone Server Setup"
@@ -24,37 +28,9 @@ if [ "$EUID" -ne 0 ]; then
exit 1 exit 1
fi fi
# Step 1: Create data directory # Step 1: Create dedicated user for rclone sync (FIRST, so we can set ownership correctly)
echo "" echo ""
echo "[1/5] Creating data directory..." echo "[1/5] Creating dedicated sync user: $RCLONE_USER..."
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..."
if id "$RCLONE_USER" &>/dev/null; then if id "$RCLONE_USER" &>/dev/null; then
echo " User $RCLONE_USER already exists, skipping..." echo " User $RCLONE_USER already exists, skipping..."
else else
@@ -62,10 +38,44 @@ else
echo " Created user: $RCLONE_USER" echo " Created user: $RCLONE_USER"
fi fi
# Set ownership of data directory # Step 2: Create data directory structure with correct ownership from the start
chown -R "$RCLONE_USER:$RCLONE_USER" "$DATA_DIR" echo ""
chmod -R 755 "$DATA_DIR" echo "[2/5] Creating data directory..."
echo " Set ownership of $DATA_DIR to $RCLONE_USER"
# 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 # Step 3: Generate SSH key pair for rclone
echo "" echo ""
@@ -111,6 +121,12 @@ else
echo " Installed: $(rclone version | head -1)" echo " Installed: $(rclone version | head -1)"
fi 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 # Print summary
echo "" echo ""
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 "It will be used by Windows clients to connect."
echo "" echo ""
echo "Connection details for Windows rclone config:" echo "Connection details for Windows rclone config:"
echo " Host: $(hostname -I | awk '{print $1}')" echo " Host: $PUBLIC_IP"
echo " User: $RCLONE_USER" echo " User: $RCLONE_USER"
echo " Path: $DATA_DIR" echo " Path: $DATA_DIR"
echo "" echo ""

7
windows/rclone-key Normal file
View File

@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACBhGez4Yaqdq5kS2nLWDMje+Ay48G9pkTUgVHByrVrHOAAAAJjg45Xm4OOV
5gAAAAtzc2gtZWQyNTUxOQAAACBhGez4Yaqdq5kS2nLWDMje+Ay48G9pkTUgVHByrVrHOA
AAAEAw5C+98JLaNZakWuw88val82lV8ZgLzNLXcbh35aAVCWEZ7Phhqp2rmRLactYMyN74
DLjwb2mRNSBUcHKtWsc4AAAAFGppbmd0aWFuLXJjbG9uZS1zeW5jAQ==
-----END OPENSSH PRIVATE KEY-----

View File

@@ -27,6 +27,10 @@
Sync interval in minutes for the scheduled task. Sync interval in minutes for the scheduled task.
Default: 5 Default: 5
.PARAMETER NonInteractive
Run without prompts. Auto-accepts detected BenjaminTeam folder.
Use this when running from scripts or scheduled tasks.
.EXAMPLE .EXAMPLE
.\setup.ps1 .\setup.ps1
@@ -39,7 +43,8 @@ param(
[string]$ServerUser = "rclone-sync", [string]$ServerUser = "rclone-sync",
[string]$ServerPath = "/data/jingtian/BenjaminTeam", [string]$ServerPath = "/data/jingtian/BenjaminTeam",
[string]$LocalPath = "", [string]$LocalPath = "",
[int]$SyncInterval = 5 [int]$SyncInterval = 5,
[switch]$NonInteractive
) )
# Configuration # Configuration
@@ -202,13 +207,22 @@ if ($LocalPath -and (Test-Path $LocalPath)) {
if ($foundPath) { if ($foundPath) {
Write-Info "Found BenjaminTeam folder at: $foundPath" Write-Info "Found BenjaminTeam folder at: $foundPath"
if ($NonInteractive) {
# Auto-accept in non-interactive mode
$LocalPath = $foundPath
} else {
$confirm = Read-Host " Use this path? (Y/n)" $confirm = Read-Host " Use this path? (Y/n)"
if ($confirm -eq "" -or $confirm -match "^[Yy]") { if ($confirm -eq "" -or $confirm -match "^[Yy]") {
$LocalPath = $foundPath $LocalPath = $foundPath
} }
} }
}
if (-not $LocalPath -or -not (Test-Path $LocalPath)) { if (-not $LocalPath -or -not (Test-Path $LocalPath)) {
if ($NonInteractive) {
Write-ErrorMsg "Could not auto-detect BenjaminTeam folder. Use -LocalPath parameter."
exit 1
}
Write-Info "Could not auto-detect BenjaminTeam folder." Write-Info "Could not auto-detect BenjaminTeam folder."
$LocalPath = Read-Host " Enter the full path to your BenjaminTeam folder" $LocalPath = Read-Host " Enter the full path to your BenjaminTeam folder"
@@ -249,16 +263,30 @@ if (-not (Test-Path $RcloneKeySource)) {
Copy-Item -Path $RcloneKeySource -Destination $RcloneKeyDest -Force Copy-Item -Path $RcloneKeySource -Destination $RcloneKeyDest -Force
Write-Success "SSH key copied to $RcloneKeyDest" Write-Success "SSH key copied to $RcloneKeyDest"
# Test SSH connection # Test SSH connection (fully non-interactive)
Write-Info "Testing SSH connection to $ServerHost..." Write-Info "Testing SSH connection to $ServerHost..."
$sshTest = & ssh -o StrictHostKeyChecking=accept-new -o BatchMode=yes -i $RcloneKeyDest "$ServerUser@$ServerHost" "echo 'SSH_OK'" 2>&1 $sshArgs = @(
"-o", "StrictHostKeyChecking=no",
"-o", "BatchMode=yes",
"-o", "ConnectTimeout=10",
"-o", "UserKnownHostsFile=$env:USERPROFILE\.ssh\known_hosts",
"-i", $RcloneKeyDest,
"$ServerUser@$ServerHost",
"echo 'SSH_OK'"
)
if ($sshTest -match "SSH_OK") { try {
$sshTest = & ssh @sshArgs 2>&1
if ($sshTest -match "SSH_OK") {
Write-Success "SSH connection successful" Write-Success "SSH connection successful"
} else { } else {
Write-ErrorMsg "SSH connection failed: $sshTest" Write-ErrorMsg "SSH connection failed: $sshTest"
Write-Info "Please check the server is running and the key is correct." Write-Info "Please check the server is running and the key is correct."
exit 1 exit 1
}
} catch {
Write-ErrorMsg "SSH test error: $_"
exit 1
} }
# ------------------------------------------------------------ # ------------------------------------------------------------