forked from Goko/JingTian-Rclone
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
This commit is contained in:
@@ -27,6 +27,10 @@
|
||||
Sync interval in minutes for the scheduled task.
|
||||
Default: 5
|
||||
|
||||
.PARAMETER NonInteractive
|
||||
Run without prompts. Auto-accepts detected BenjaminTeam folder.
|
||||
Use this when running from scripts or scheduled tasks.
|
||||
|
||||
.EXAMPLE
|
||||
.\setup.ps1
|
||||
|
||||
@@ -39,7 +43,8 @@ param(
|
||||
[string]$ServerUser = "rclone-sync",
|
||||
[string]$ServerPath = "/data/jingtian/BenjaminTeam",
|
||||
[string]$LocalPath = "",
|
||||
[int]$SyncInterval = 5
|
||||
[int]$SyncInterval = 5,
|
||||
[switch]$NonInteractive
|
||||
)
|
||||
|
||||
# Configuration
|
||||
@@ -202,13 +207,22 @@ if ($LocalPath -and (Test-Path $LocalPath)) {
|
||||
|
||||
if ($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)"
|
||||
if ($confirm -eq "" -or $confirm -match "^[Yy]") {
|
||||
$LocalPath = $foundPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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."
|
||||
$LocalPath = Read-Host " Enter the full path to your BenjaminTeam folder"
|
||||
|
||||
@@ -249,10 +263,20 @@ if (-not (Test-Path $RcloneKeySource)) {
|
||||
Copy-Item -Path $RcloneKeySource -Destination $RcloneKeyDest -Force
|
||||
Write-Success "SSH key copied to $RcloneKeyDest"
|
||||
|
||||
# Test SSH connection
|
||||
# Test SSH connection (fully non-interactive)
|
||||
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'"
|
||||
)
|
||||
|
||||
try {
|
||||
$sshTest = & ssh @sshArgs 2>&1
|
||||
if ($sshTest -match "SSH_OK") {
|
||||
Write-Success "SSH connection successful"
|
||||
} else {
|
||||
@@ -260,6 +284,10 @@ if ($sshTest -match "SSH_OK") {
|
||||
Write-Info "Please check the server is running and the key is correct."
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
Write-ErrorMsg "SSH test error: $_"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Step 5: Configure rclone
|
||||
|
||||
Reference in New Issue
Block a user