$ErrorActionPreference='Stop' [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12 function P($s){Write-Host $s -ForegroundColor Green} function RcloneExe { $c=Get-Command rclone -ErrorAction SilentlyContinue if($c){return $c.Source} $a=@((Join-Path $env:LOCALAPPDATA 'Programs\rclone\rclone.exe'),(Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links\rclone.exe')) foreach($p in $a){if(Test-Path -LiteralPath $p){return $p}} return $null } $r=RcloneExe if(-not $r){ P 'Instaluję rclone. Najpierw próbuję WinGet.' $w=Get-Command winget -ErrorAction SilentlyContinue if($w){& $w.Source install --id Rclone.Rclone --exact --scope user --accept-package-agreements --accept-source-agreements; $exit=$LASTEXITCODE; if($exit -ne 0){P "WinGet: kod $exit. Spróbuję instalacji przenośnej."}} $r=RcloneExe if(-not $r){ P 'Pobieram przenośne rclone z oficjalnej witryny (HTTPS).' $arch=if($env:PROCESSOR_ARCHITECTURE -eq 'ARM64'){'arm64'}elseif([Environment]::Is64BitOperatingSystem){'amd64'}else{'386'} $tmp=Join-Path $env:TEMP ('rclone-'+[guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $tmp -Force | Out-Null try{ $zip=Join-Path $tmp 'rclone.zip' Invoke-WebRequest -Uri "https://downloads.rclone.org/rclone-current-windows-$arch.zip" -OutFile $zip -UseBasicParsing Expand-Archive -LiteralPath $zip -DestinationPath (Join-Path $tmp 'unzip') -Force $exe=Get-ChildItem -LiteralPath (Join-Path $tmp 'unzip') -Recurse -Filter rclone.exe -File | Select-Object -First 1 if(-not $exe){throw 'Archiwum nie zawiera rclone.exe'} $dest=Join-Path $env:LOCALAPPDATA 'Programs\rclone' New-Item -ItemType Directory -Force -Path $dest | Out-Null Copy-Item -LiteralPath $exe.FullName -Destination (Join-Path $dest 'rclone.exe') -Force $r=Join-Path $dest 'rclone.exe' $old=[Environment]::GetEnvironmentVariable('Path','User') if(-not (($old -split ';') -contains $dest)){[Environment]::SetEnvironmentVariable('Path',(($old.TrimEnd(';')+';'+$dest).TrimStart(';')),'User')} $env:Path += ';'+$dest }finally{Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue} } } if(-not $r){throw 'Nie udało się zainstalować rclone.'} P 'rclone gotowe:' & $r version | Select-Object -First 1 $answer=Read-Host 'Pobrać zaszyfrowany profil rclone z tej witryny? T/N' if($answer -notmatch '^[TtYy]'){P 'Konfigurację możesz odtworzyć później.';return} $url=if($env:SKRYPTY_PROFILE_URL){$env:SKRYPTY_PROFILE_URL}else{'https://cycki.neocities.org/powershell/profil/rclone-profil.txt'} $override=Read-Host "Adres profilu [Enter: $url]" if($override.Trim()){$url=$override.Trim()} if($url -notmatch '^https://'){throw 'Wymagany URL HTTPS.'} $tmp=Join-Path $env:TEMP ('rclone-profile-'+[guid]::NewGuid().ToString('N')+'.txt') try{ Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $tmp $head=[IO.File]::ReadAllText($tmp) if(-not $head.StartsWith('RCLONE_ENCRYPT_V0:')){throw 'Plik nie ma nagłówka zaszyfrowanej konfiguracji rclone. Odmawiam instalacji.'} $dst=Join-Path $env:APPDATA 'rclone\rclone.conf' New-Item -ItemType Directory -Path (Split-Path $dst -Parent) -Force | Out-Null if(Test-Path -LiteralPath $dst){ P "Konfiguracja już istnieje: $dst" if((Read-Host 'Nadpisać po zachowaniu kopii? wpisz TAK') -cne 'TAK'){return} Copy-Item -LiteralPath $dst -Destination ($dst+'.kopia-'+(Get-Date -Format 'yyyyMMdd-HHmmss')) -ErrorAction Stop } Copy-Item -LiteralPath $tmp -Destination $dst -Force P "Zapisano zaszyfrowany profil: $dst" P 'Hasło będzie potrzebne przy poleceniach rclone. Sprawdzam profil (może zapytać o hasło):' & $r listremotes }finally{Remove-Item -LiteralPath $tmp -Force -ErrorAction SilentlyContinue}