update
parent
86755130f9
commit
933349f595
|
@ -0,0 +1,67 @@
|
|||
function Get-Update {
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$user,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$source,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$destination,
|
||||
[String]$tempFolder,
|
||||
[String]$keyFile = "C:\Users\dmitr\.ssh\dmitry.kirdyashkin"
|
||||
)
|
||||
|
||||
if (!(Test-Path -Path $destination)){
|
||||
New-Item -Path $destination -ItemType Directory -Force
|
||||
}
|
||||
|
||||
Write-Host -ForegroundColor Cyan "`nDownloading packages..."
|
||||
scp -i "$($keyFile)" "$($user)@$($source)" "$($destination)"
|
||||
}
|
||||
|
||||
Get-Update -user owner -source "192.168.1.200:/mnt/data/foundryvtt-v10/Data/modules/shared-compendia/packs/*" -destination "C:\Users\dmitr\Documents\Repos\local\fvtt-shared-compendia\src\packs"
|
||||
|
||||
function update-archive {
|
||||
param (
|
||||
#$exclude = @(".gitignore","export","audio","temp",".git","create-archive.ps1"),
|
||||
$workFolder = "C:\Users\dmitr\Documents\Repos\local\fvtt-shared-compendia\src",
|
||||
$moduleName = "shared-compendia",
|
||||
$uploadPath = "https://nexus.kdiva.ru/repository/generic"
|
||||
)
|
||||
#изменение версии и пути скачивания
|
||||
Write-Host -ForegroundColor Cyan "`nModifying module.json..."
|
||||
$content = Get-Content "$workFolder\module.json" | ConvertFrom-Json
|
||||
$oldVersion = $content.version
|
||||
$oldIndex = $oldVersion.ToString().split(".")[2] -as [int]
|
||||
$newIndex = ($oldIndex + 1).ToString()
|
||||
$patch = $oldVersion.LastIndexOf(".")
|
||||
$newVersion = $oldVersion.Substring(0, $patch) + "." + $newIndex
|
||||
$content.version = $newVersion
|
||||
$archiveName = "$moduleName-$newVersion.zip"
|
||||
$content.download = "$uploadPath/$moduleName/$archiveName"
|
||||
$content | ConvertTo-Json | Set-Content "$workFolder\module.json"
|
||||
Write-Host "Version Changed $oldVersion -> $newVersion"
|
||||
|
||||
#создание архива
|
||||
Write-Host -ForegroundColor Cyan "`nCreating archive..."
|
||||
Get-ChildItem $workFolder\ -Recurse -Depth 0 |
|
||||
Where-Object {$_.Name -notin $exclude} |
|
||||
Compress-Archive -Force -DestinationPath "$workFolder\$archiveName"
|
||||
# Copy-Item -Path "$workFolder\src\module.json" -Destination "$workFolder\module.json" -Force
|
||||
|
||||
#загрузка архива
|
||||
Write-Host -ForegroundColor Cyan "`nUploading archive..."
|
||||
curl.exe --user owner:5ehfv3fbj8 --upload-file $workFolder\$archiveName $uploadPath/$moduleName/$archiveName --upload-file $workFolder\module.json $uploadPath/$moduleName/module.json
|
||||
|
||||
#проверка и удаление архива
|
||||
$response = Invoke-RestMethod -Method Get -Uri 'https://nexus.kdiva.ru/service/rest/v1/assets?repository=generic'
|
||||
# $response = curl.exe --user owner:5ehfv3fbj8 -X GET 'https://nexus.kdiva.ru/repository/service/rest/v1/assets?repository=generic' | ConvertFrom-Json
|
||||
if ($response.items.path -like "*$archiveName*"){
|
||||
Write-Host -ForegroundColor Cyan "`nUploaded successfully`nDeleting local archive..."
|
||||
Remove-Item -Path $workFolder/*.zip
|
||||
}
|
||||
else {
|
||||
Write-Host -ForegroundColor Red "Archive not found"
|
||||
}
|
||||
}
|
||||
|
||||
update-archive
|
Reference in New Issue