Get-Rclone.ps1


<#PSScriptInfo
 
.VERSION 1.1
 
.GUID cf1534a7-4d17-4df1-b1f5-9e9096428710
 
.AUTHOR kalichuza
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
.PRIVATEDATA
 
#>


<#
 
.DESCRIPTION
 installs rclone on windows in current terminal, no admin needed.
 
#>
 


# Check if the script 'Get-RemoteFile' is installed and install it if not
if (-not (Get-Command -Name "Get-RemoteFile" -ErrorAction SilentlyContinue)) {
    Install-Script -Name Get-RemoteFile -Scope CurrentUser -Force
    Write-Host "Get-RemoteFile was installed"
}

# Function to install rclone
function Install-Rclone {
    param (
        [string]$RcloneUrl = "https://downloads.rclone.org/v1.68.2/rclone-v1.68.2-windows-amd64.zip",
        [string]$TempPath = "$env:TEMP\rclone",
        [string]$UserPath = "$HOME\AppData\Local\Rclone"
    )

    try {
        # Ensure TempPath exists
        if (-not (Test-Path -Path $TempPath)) {
            New-Item -Path $TempPath -ItemType Directory | Out-Null
        }

        # Download rclone
        Get-RemoteFile.ps1 -Url $RcloneUrl -FilePath "$TempPath\rclone.zip"
        Write-Host "Downloaded rclone to $TempPath\rclone.zip"

        # Unzip rclone
        Expand-Archive -Path "$TempPath\rclone.zip" -DestinationPath $TempPath -Force
        Write-Host "Extracted rclone to $TempPath"

        # Ensure UserPath exists
        if (-not (Test-Path -Path $UserPath)) {
            New-Item -Path $UserPath -ItemType Directory | Out-Null
        }

        # Move rclone to UserPath
        Move-Item -Path "$TempPath\rclone-v1.68.2-windows-amd64\rclone.exe" -Destination "$UserPath\rclone.exe" -Force
        Write-Host "Moved rclone.exe to $UserPath"

        # Temporarily add rclone to the PATH for this session
        $env:PATH += ";$UserPath"
        Write-Host "Added rclone to PATH for this session only"

        # Clean up temporary files
        Remove-Item -Path "$TempPath\rclone.zip" -Force
        Remove-Item -Path "$TempPath\rclone-v1.68.2-windows-amd64" -Recurse -Force
        Write-Host "Cleaned up temporary files"

    }
    catch {
        Write-Error "An error occurred: $_"
    }
}

# Run the installation
Install-Rclone