93 lines
2.7 KiB
PowerShell
93 lines
2.7 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$RemoteHost,
|
|
[int]$Port = 22,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$User,
|
|
[string]$RootDir = "/volume4/Music_Cloud"
|
|
)
|
|
|
|
function Quote-RemotePathForPosixShell {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Path
|
|
)
|
|
|
|
$EscapedPath = $Path.Replace("'", "'\''")
|
|
return "'$EscapedPath'"
|
|
}
|
|
|
|
function New-ScpRemoteTarget {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Remote,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Path
|
|
)
|
|
|
|
return "${Remote}:$(Quote-RemotePathForPosixShell -Path $Path)"
|
|
}
|
|
|
|
$AppHome = "$RootDir/catalogsync"
|
|
$RemoteDirs = @(
|
|
$RootDir,
|
|
"$RootDir/library",
|
|
"$AppHome/app",
|
|
"$AppHome/bin",
|
|
"$AppHome/config",
|
|
"$AppHome/data",
|
|
"$AppHome/inputs",
|
|
"$AppHome/logs"
|
|
)
|
|
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$ProjectRoot = Resolve-Path (Join-Path $ScriptDir "..\..")
|
|
$Remote = "$User@$RemoteHost"
|
|
|
|
$QuotedDirs = $RemoteDirs | ForEach-Object { Quote-RemotePathForPosixShell -Path $_ }
|
|
$RemoteMkdirCommand = "mkdir -p " + ($QuotedDirs -join " ")
|
|
ssh -p $Port $Remote $RemoteMkdirCommand
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Failed to create remote directories."
|
|
}
|
|
|
|
$AppSources = @(
|
|
(Join-Path $ProjectRoot "musicdl"),
|
|
(Join-Path $ProjectRoot "setup.py"),
|
|
(Join-Path $ProjectRoot "README.md"),
|
|
(Join-Path $ProjectRoot "LICENSE"),
|
|
(Join-Path $ProjectRoot "requirements.txt"),
|
|
(Join-Path $ProjectRoot "requirements-optional.txt")
|
|
)
|
|
$RemoteAppDirTarget = New-ScpRemoteTarget -Remote $Remote -Path "$AppHome/app/"
|
|
foreach ($Source in $AppSources) {
|
|
scp -P $Port -r $Source $RemoteAppDirTarget
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Failed to copy app source: $Source"
|
|
}
|
|
}
|
|
|
|
$BinTemplates = @(
|
|
(Join-Path $ScriptDir "templates\download_all.sh"),
|
|
(Join-Path $ScriptDir "templates\download_from_file.sh"),
|
|
(Join-Path $ScriptDir "templates\upload_all.sh"),
|
|
(Join-Path $ScriptDir "templates\install_runtime.sh"),
|
|
(Join-Path $ScriptDir "templates\serve_console.sh"),
|
|
(Join-Path $ScriptDir "templates\deploy_and_restart.sh")
|
|
)
|
|
$RemoteBinDirTarget = New-ScpRemoteTarget -Remote $Remote -Path "$AppHome/bin/"
|
|
foreach ($Template in $BinTemplates) {
|
|
scp -P $Port $Template $RemoteBinDirTarget
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Failed to copy bin template: $Template"
|
|
}
|
|
}
|
|
|
|
$RemoteEnvExample = "$AppHome/config/catalogsync.env.example"
|
|
$LocalEnvExample = Join-Path $ScriptDir "templates\catalogsync.env.example"
|
|
$RemoteEnvExampleTarget = New-ScpRemoteTarget -Remote $Remote -Path $RemoteEnvExample
|
|
scp -P $Port $LocalEnvExample $RemoteEnvExampleTarget
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Failed to copy catalogsync.env.example."
|
|
}
|