3 # this allows us to call ps1 files, which allows us to have spaces in filenames
4 # ('powershell "$Env:USERPROFILE\test.ps1" foo' will fail if it has a space in
5 # the path but '& "$Env:USERPROFILE\test.ps1" foo' will work even with a space)
6 Set-ExecutionPolicy -Scope Process Bypass
8 # If a command returns an error, halt the script.
9 $ErrorActionPreference = 'Stop'
11 # Ignore progress events from cmdlets so Invoke-WebRequest is not painfully slow
12 $ProgressPreference = 'SilentlyContinue'
14 # This is the canonical CPU arch when the process is emulated
15 $my_arch = "$Env:PROCESSOR_ARCHITEW6432"
16 IF ($my_arch -eq $null -or $my_arch -eq "") {
17 # This is the canonical CPU arch when the process is native
18 $my_arch = "$Env:PROCESSOR_ARCHITECTURE"
20 # TODO API should know to prefer x86 for windows when arm binary is not available
21 $Env:WEBI_UA = "Windows/10 $my_arch"
24 # Switch to userprofile
25 pushd $Env:USERPROFILE
27 # Make paths if needed
28 New-Item -Path .local\bin -ItemType Directory -Force | out-null
29 # TODO replace all xbin with opt\bin\
30 New-Item -Path .local\xbin -ItemType Directory -Force | out-null
32 # See note on Set-ExecutionPolicy above
33 Set-Content -Path .local\bin\webi.bat -Value "@echo off`r`npushd %USERPROFILE%`r`npowershell -ExecutionPolicy Bypass .local\bin\webi-pwsh.ps1 %1`r`npopd"
34 # Backwards-compat bugfix: remove old webi-pwsh.ps1 location
35 Remove-Item -Path .local\bin\webi.ps1 -Recurse -ErrorAction Ignore
36 if (!(Test-Path -Path .local\opt))
38 New-Item -Path .local\opt -ItemType Directory -Force | out-null
40 # TODO windows version of mktemp -d
41 if (!(Test-Path -Path .local\tmp))
43 New-Item -Path .local\tmp -ItemType Directory -Force | out-null
47 # TODO Test-Path variable:global:Env:WEBI_HOST ???
48 IF($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "")
50 $Env:WEBI_HOST = "https://webinstall.dev"
53 if (!(Test-Path -Path .local\bin\pathman.exe))
55 & curl.exe -fsSL -A "$Env:WEBI_UA" "$Env:WEBI_HOST/packages/pathman/install.ps1" -o .\.local\tmp\pathman-setup.ps1
56 powershell .\.local\tmp\pathman-setup.ps1
57 # TODO del .\.local\tmp\pathman-setup.bat
60 # Run pathman to set up the folder
61 # (using unix style path because... cmd vs powershell vs whatever)
62 $has_local_bin = echo "$Env:PATH" | Select-String -Pattern '\.local.bin'
66 Write-Host '**********************************' -ForegroundColor red -BackgroundColor white
67 Write-Host '* IMPORTANT -- READ ME *' -ForegroundColor red -BackgroundColor white
68 Write-Host '* (run the PATH command below) *' -ForegroundColor red -BackgroundColor white
69 Write-Host '**********************************' -ForegroundColor red -BackgroundColor white
71 & "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
77 # Fetch <whatever>.ps1
79 $PKG_URL = "$Env:WEBI_HOST/api/installers/$exename.ps1?formats=zip,exe,tar"
80 echo "Downloading $PKG_URL"
81 # Invoke-WebRequest -UserAgent "Windows amd64" "$PKG_URL" -OutFile ".\.local\tmp\$exename.install.ps1"
82 & curl.exe -fsSL -A "$Env:WEBI_UA" "$PKG_URL" -o .\.local\tmp\$exename.install.ps1
85 powershell .\.local\tmp\$exename.install.ps1