[Windows] Add managed restic bin to PATH for direct user use
The backrest installer should add the path to the managed restic bin to the user's environment variable to allow restic to be used from the command line from any current path.
Is your feature request related to a problem? Please describe.
It's very inconvenient to have to go to the C:\Users\[user]\AppData\Local\Programs\Backrest folder just to run a restic command in the terminal.
Describe the solution you'd like
Add $env:LOCALAPPDATA\Programs\Backrest to the user PATH variable environment.
Additional context
For those who want to do it with PowerShell, here's how to do it:
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
$newPath = "$env:LOCALAPPDATA\Programs\Backrest"
if (-not ($currentPath -split ';' | ForEach-Object { $_.Trim() } | Where-Object { $_ -eq $newPath }))
{
[Environment]::SetEnvironmentVariable("PATH", "$currentPath;$newPath", "User")
}
At the moment the windows installer isn't actually the thing installing restic-- it's backrest on first launch using https://github.com/garethgeorge/backrest/tree/main/internal/resticinstaller which includes key signature verification.
It's a simple sounding ask, but I believe updating the PATH env requires administrator privileges so I'd really need to bundle that whole flow into the windows installer.
Backrest's preferred approach if you want a global install is that you should go ahead and download it directly from https://github.com/restic/restic and add it to the path manually, that done backrest will pickup and use your install if it is an up to date version.
No, there are user environment variables that can be modified by the user without administrator rights.
In fact, the PowerShell code above modifies user variables, not global/system variables. Note the user parameter in [Environment]::SetEnvironmentVariable("PATH", "$currentPath;$newPath", "User").
Modifying user variables is consistent insofar as backrest itself is installed in the user's programs (C:\Users\[user_name]\AppData\Local\Programs\Backrest) and not in Program Files.
In short, adding the path to the managed restic binary in the user's PATH environment variable could be done by backrest without user rights, at runtime (and not at install-time) when no restic installation is found on the system and backrest takes care of downloading/installing it (managed).
This feature has been added with #867. Works for both install modes and also removes the directory from PATH when the corresponding checkbox is unchecked during upgrade or reinstall. Uninstallation will also remove it.
Although it's not the installer that installs restic, I think modifying PATH is best suited for the installer rather than application itself.