mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-02-14 17:49:53 +00:00
ref!: replace pathman with PowerShell [Environment]::SetEnvironmentVariable
This commit is contained in:
@@ -42,27 +42,87 @@ New-Item -Path .local\opt -ItemType Directory -Force | out-null
|
||||
# {{ baseurl }}
|
||||
# {{ version }}
|
||||
|
||||
function webi_add_path
|
||||
function webi_path_add($pathname)
|
||||
{
|
||||
Write-Host ''
|
||||
Write-Host '*****************************' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host '* IMPORTANT - READ ME *' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host '*****************************' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host ''
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add "$args[0]"
|
||||
# Note: not all of these work as expected, so we use the unix-style, which is most consistent
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add "$Env:USERPROFILE\.local\bin"
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add %USERPROFILE%\.local\bin
|
||||
# C:\Users\me => C:/Users/me
|
||||
$my_home = $Env:UserProfile
|
||||
$my_home = $my_home.replace('\\', '/')
|
||||
$my_home_re = [regex]::escape($my_home)
|
||||
|
||||
# ~/bin => %USERPROFILE%/bin
|
||||
$pathname = $pathname.replace('~/', "$Env:UserProfile/")
|
||||
|
||||
# C:\Users\me\bin => %USERPROFILE%/bin
|
||||
$my_pathname = $pathname.replace('\\', '/')
|
||||
$my_pathname = $my_pathname -ireplace $my_home_re, "%USERPROFILE%"
|
||||
|
||||
$all_user_paths = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||
$user_paths = $all_user_paths -Split(';')
|
||||
$exists_in_path = $false
|
||||
foreach ($user_path in $user_paths)
|
||||
{
|
||||
# C:\Users\me\bin => %USERPROFILE%/bin
|
||||
$my_user_path = $user_path.replace('\\', '/')
|
||||
$my_user_path = $my_user_path -ireplace $my_home_re, "%USERPROFILE%"
|
||||
|
||||
if ($my_user_path -ieq $my_pathname)
|
||||
{
|
||||
$exists_in_path = $true
|
||||
}
|
||||
}
|
||||
if (-Not $exists_in_path)
|
||||
{
|
||||
$all_user_paths = $pathname + ";" + $all_user_paths
|
||||
[Environment]::SetEnvironmentVariable("Path", $all_user_paths, "User")
|
||||
}
|
||||
|
||||
$session_paths = $Env:Path -Split(';')
|
||||
$in_session_path = $false
|
||||
foreach ($session_path in $session_paths)
|
||||
{
|
||||
# C:\Users\me\bin => %USERPROFILE%/bin
|
||||
$my_session_path = $session_path.replace('\\', '/')
|
||||
$my_session_path = $my_session_path -ireplace $my_home_re, "%USERPROFILE%"
|
||||
|
||||
if ($my_session_path -ieq $my_pathname)
|
||||
{
|
||||
$in_session_path = $true
|
||||
}
|
||||
}
|
||||
|
||||
if (-Not $in_session_path)
|
||||
{
|
||||
$my_cmd = 'PATH ' + "$pathname" + ';%PATH%'
|
||||
$my_pwsh = '$Env:Path = "' + "$pathname" + ';$Env:Path"'
|
||||
|
||||
Write-Host ''
|
||||
Write-Host '**********************************' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host '* IMPORTANT -- READ ME *' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host '* (run the PATH command below) *' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host '**********************************' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host ''
|
||||
echo ""
|
||||
echo "Copy, paste, and run the appropriate command to update your PATH:"
|
||||
echo "(or close and reopen the terminal, or reboot)"
|
||||
echo ""
|
||||
echo "cmd.exe:"
|
||||
echo " $my_cmd"
|
||||
echo ""
|
||||
echo "PowerShell:"
|
||||
echo " $my_pwsh"
|
||||
echo ""
|
||||
}
|
||||
}
|
||||
|
||||
# Run pathman to set up the folder
|
||||
if (Test-Path -Path "$Env:USERPROFILE.local\bin\pathman.exe")
|
||||
{
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
|
||||
}
|
||||
#$has_local_bin = echo "$Env:PATH" | Select-String -Pattern '\.local.bin'
|
||||
#if (!$has_local_bin)
|
||||
#{
|
||||
webi_path_add ~/.local/bin
|
||||
#}
|
||||
|
||||
{{ installer }}
|
||||
|
||||
webi_path_add ~/.local/bin
|
||||
|
||||
# Done
|
||||
popd
|
||||
|
||||
@@ -50,28 +50,6 @@ IF($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "")
|
||||
$Env:WEBI_HOST = "https://webinstall.dev"
|
||||
}
|
||||
|
||||
if (!(Test-Path -Path .local\bin\pathman.exe))
|
||||
{
|
||||
$PATHMAN_URL = "$Env:WEBI_HOST/api/installers/pathman.ps1?formats=zip,exe,tar"
|
||||
# Invoke-WebRequest -UserAgent "Windows amd64" "$PATHMAN_URL" -OutFile ".\.local\tmp\pathman.install.ps1"
|
||||
& curl.exe -fsSL -A "$Env:WEBI_UA" "$PATHMAN_URL" -o .\.local\tmp\pathman.install.ps1
|
||||
powershell .\.local\tmp\pathman.install.ps1
|
||||
}
|
||||
|
||||
# Run pathman to set up the folder
|
||||
# (using unix style path because... cmd vs powershell vs whatever)
|
||||
$has_local_bin = echo "$Env:PATH" | Select-String -Pattern '\.local.bin'
|
||||
if (!$has_local_bin)
|
||||
{
|
||||
Write-Host ''
|
||||
Write-Host '**********************************' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host '* IMPORTANT -- READ ME *' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host '* (run the PATH command below) *' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host '**********************************' -ForegroundColor red -BackgroundColor white
|
||||
Write-Host ''
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
|
||||
}
|
||||
|
||||
# {{ baseurl }}
|
||||
# {{ version }}
|
||||
|
||||
|
||||
@@ -10,18 +10,7 @@ pushd "%userprofile%" || goto :error
|
||||
mkdir .local\opt || goto :error
|
||||
)
|
||||
|
||||
pushd .local\bin || goto :error
|
||||
if NOT EXIST pathman.exe (
|
||||
echo updating PATH management
|
||||
powershell $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest https://webinstall.dev/packages/pathman/install.bat -OutFile pathman-setup.bat || goto :error
|
||||
call .\pathman-setup.bat || goto :error
|
||||
del pathman-setup.bat || goto :error
|
||||
rem TODO there's rumor of a windows tool called 'pathman' that does the same thing?
|
||||
)
|
||||
popd || goto :error
|
||||
.\.local\bin\pathman add ".local\bin" || goto :error
|
||||
|
||||
echo downloading and installing %1
|
||||
echo Downloading and installing %1
|
||||
powershell $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest https://webinstall.dev/packages/%1/install.ps1 -OutFile %1-webinstall.bat || goto :error
|
||||
|
||||
rem TODO only add if it's not in there already
|
||||
|
||||
@@ -38,6 +38,3 @@ IF (!(Test-Path -Path "$Env:USERPROFILE\.local\opt\$Env:PKG_NAME-v$Env:WEBI_VERS
|
||||
echo "Copying into '$Env:USERPROFILE\.local\bin\$Env:PKG_NAME.exe' from '$Env:USERPROFILE\.local\opt\$Env:PKG_NAME-v$Env:WEBI_VERSION.exe'"
|
||||
Remove-Item -Path "$Env:USERPROFILE\.local\bin\$Env:PKG_NAME.exe" -Recurse -ErrorAction Ignore
|
||||
Copy-Item -Path "$Env:USERPROFILE\.local\opt\$Env:PKG_NAME-v$Env:WEBI_VERSION.exe" -Destination "$Env:USERPROFILE\.local\bin\$Env:PKG_NAME.exe" -Recurse
|
||||
|
||||
# Add to path
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
|
||||
|
||||
@@ -53,6 +53,4 @@ Remove-Item -Path "$pkg_dst" -Recurse -ErrorAction Ignore
|
||||
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
|
||||
|
||||
# Add to path
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/opt/git/cmd
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add "$Env:USERPROFILE\.local\opt\git\cmd"
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add %USERPROFILE%\.local\opt\git\cmd
|
||||
webi_path_add ~/.local/opt/git/cmd
|
||||
|
||||
@@ -85,11 +85,7 @@ echo stringer
|
||||
& "$pkg_dst_cmd" install golang.org/x/tools/cmd/stringer
|
||||
|
||||
# Add to path
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/opt/go/bin
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add "$Env:USERPROFILE\.local\opt\go\bin"
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add %USERPROFILE%\.local\opt\go\bin
|
||||
webi_path_add ~/.local/opt/go/bin
|
||||
|
||||
# Special to go: add default GOBIN to PATH
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/go/bin
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add "$Env:USERPROFILE\go\bin"
|
||||
#& "$Env:USERPROFILE\.local\bin\pathman.exe" add %USERPROFILE%\go\bin
|
||||
webi_path_add ~/go/bin
|
||||
|
||||
@@ -41,4 +41,4 @@ Remove-Item -Path "$Env:USERPROFILE\.local\opt\$Env:PKG_NAME" -Recurse -ErrorAct
|
||||
Copy-Item -Path "$Env:USERPROFILE\.local\opt\$Env:PKG_NAME-v$Env:WEBI_VERSION" -Destination "$Env:USERPROFILE\.local\opt\$Env:PKG_NAME" -Recurse
|
||||
|
||||
# Add to path
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/opt/node
|
||||
webi_path_add ~/.local/opt/node
|
||||
|
||||
@@ -55,6 +55,3 @@ IF (!(Test-Path -Path "$pkg_src_cmd"))
|
||||
echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
|
||||
Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | out-null
|
||||
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
|
||||
|
||||
# for the special case of pathman bootstrapping itself
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
|
||||
|
||||
@@ -52,4 +52,4 @@ echo "Linking '$pkg_dst_dir' from '$pkg_src_dir'"
|
||||
New-Item -ItemType Junction -Path "$pkg_dst_dir" -Target "$pkg_src_dir" > $null
|
||||
|
||||
# Add to path
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/opt/dart-sass
|
||||
webi_path_add ~/.local/opt/dart-sass
|
||||
|
||||
@@ -5,8 +5,5 @@ echo "Installing sudo.cmd..."
|
||||
# Couldn't figure out how to get this to work with "here strings", so forgive the ugly, but at least it works
|
||||
Set-Content -Path .local\bin\sudo.cmd -Value "@echo off`r`npowershell -Command ""Start-Process cmd -Verb RunAs -ArgumentList '/c cd /d %CD% && %*'""`r`n@echo on"
|
||||
|
||||
# Add to path
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
|
||||
|
||||
echo "Installed to '$Env:USERPROFILE\.local\bin\sudo.cmd'"
|
||||
echo ""
|
||||
|
||||
@@ -62,10 +62,8 @@ These are the files that are installed when you use [webinstall.dev](/):
|
||||
~/.local/opt/pathman-*
|
||||
|
||||
# Windows
|
||||
~/.local/bin/webi.cmd
|
||||
~/.local/bin/webi.bat
|
||||
~/.local/bin/webi-pwsh.ps1
|
||||
~/.local/bin/pathman.exe
|
||||
~/.local/opt/pathman-*
|
||||
```
|
||||
|
||||
Assuming that you don't use `pathman` for anything else, you can safely remove
|
||||
|
||||
@@ -57,4 +57,4 @@ Remove-Item -Path "$pkg_dst" -Recurse -ErrorAction Ignore | out-null
|
||||
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
|
||||
|
||||
# Add to Windows PATH
|
||||
& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/opt/zig
|
||||
webi_path_add ~/.local/opt/zig
|
||||
|
||||
Reference in New Issue
Block a user