flnxi-Wu/scripts/tools/transfer-to-nas.ps1
WuYongJie d1c6efc79d
Some checks failed
CI Check / check (push) Has been cancelled
feat: NAS 部署与 Harbor 推送流程
2025-12-03 14:39:06 +08:00

124 lines
4.1 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================================
# 传输安装文件到 NAS 设备
# ============================================
param(
[Parameter(Mandatory=$true)]
[string]$NasIp,
[Parameter(Mandatory=$true)]
[string]$NasUser,
[Parameter(Mandatory=$false)]
[string]$NasPath = "/volume1/docker/flnxi",
[Parameter(Mandatory=$false)]
[string]$NasPassword = "",
[Parameter(Mandatory=$false)]
[switch]$UseSftp
)
$ErrorActionPreference = "Stop"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " 传输 FLNXI 安装文件到 NAS" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 检查必要文件
$installScript = "scripts/tools/install.sh"
$dockerCompose = "docker-compose.prod.yml"
if (-not (Test-Path $installScript)) {
Write-Host "错误: 找不到 $installScript" -ForegroundColor Red
exit 1
}
if (-not (Test-Path $dockerCompose)) {
Write-Host "错误: 找不到 $dockerCompose" -ForegroundColor Red
exit 1
}
Write-Host "✓ 找到安装文件" -ForegroundColor Green
Write-Host ""
# 检查 SSH/SCP 工具
$scpAvailable = $false
if (Get-Command scp -ErrorAction SilentlyContinue) {
$scpAvailable = $true
Write-Host "✓ 检测到 SCP 工具" -ForegroundColor Green
} else {
Write-Host "⚠ 未检测到 SCP,将使用其他方法" -ForegroundColor Yellow
}
# 方法 1: 使用 SCP(如果可用)
if ($scpAvailable) {
Write-Host ""
Write-Host "正在传输文件到 NAS..." -ForegroundColor Blue
if ($NasPassword) {
# 使用 sshpass(如果可用)或 expect
Write-Host "提示: 如果提示输入密码,请输入: $NasPassword" -ForegroundColor Yellow
# 尝试使用 sshpass(Linux/WSL)
if (Get-Command sshpass -ErrorAction SilentlyContinue) {
$env:SSHPASS = $NasPassword
sshpass -e scp $installScript "${NasUser}@${NasIp}:${NasPath}/"
sshpass -e scp $dockerCompose "${NasUser}@${NasIp}:${NasPath}/"
} else {
# 使用 SCP(需要手动输入密码)
Write-Host "请手动输入 NAS 密码..." -ForegroundColor Yellow
scp $installScript "${NasUser}@${NasIp}:${NasPath}/"
scp $dockerCompose "${NasUser}@${NasIp}:${NasPath}/"
}
} else {
# 无密码传输(使用 SSH 密钥)
scp $installScript "${NasUser}@${NasIp}:${NasPath}/"
scp $dockerCompose "${NasUser}@${NasIp}:${NasPath}/"
}
Write-Host "✓ 文件传输完成" -ForegroundColor Green
Write-Host ""
Write-Host "下一步操作:" -ForegroundColor Cyan
Write-Host "1. SSH 登录 NAS: ssh ${NasUser}@${NasIp}" -ForegroundColor White
Write-Host "2. 进入目录: cd ${NasPath}" -ForegroundColor White
Write-Host "3. 给脚本执行权限: chmod +x install.sh" -ForegroundColor White
Write-Host "4. 运行安装: ./install.sh" -ForegroundColor White
}
# 方法 2: 使用 SFTP(如果 SCP 不可用)
elseif ($UseSftp) {
Write-Host ""
Write-Host "使用 SFTP 传输..." -ForegroundColor Blue
$sftpScript = @"
cd $NasPath
put $installScript
put $dockerCompose
quit
"@
$sftpScript | sftp "${NasUser}@${NasIp}"
Write-Host "✓ 文件传输完成" -ForegroundColor Green
}
# 方法 3: 提供手动传输说明
else {
Write-Host ""
Write-Host "请手动传输以下文件到 NAS:" -ForegroundColor Yellow
Write-Host " 源文件: $installScript" -ForegroundColor White
Write-Host " 源文件: $dockerCompose" -ForegroundColor White
Write-Host " 目标: ${NasUser}@${NasIp}:${NasPath}/" -ForegroundColor White
Write-Host ""
Write-Host "传输方法:" -ForegroundColor Cyan
Write-Host " 1. 使用 NAS Web 界面的文件管理器上传" -ForegroundColor White
Write-Host " 2. 使用 WinSCP 或其他 FTP/SFTP 工具" -ForegroundColor White
Write-Host " 3. 使用 SCP 命令: scp <file> ${NasUser}@${NasIp}:${NasPath}/" -ForegroundColor White
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan