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
29 # TODO replace all xbin with opt\bin\
30 New-Item -Path .local\xbin -ItemType Directory -Force
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 if (!(Test-Path -Path .local\opt))
36 New-Item -Path .local\opt -ItemType Directory -Force
38 # TODO windows version of mktemp -d
39 if (!(Test-Path -Path .local\tmp))
41 New-Item -Path .local\tmp -ItemType Directory -Force
45 # TODO Test-Path variable:global:Env:WEBI_HOST ???
46 IF($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "")
48 $Env:WEBI_HOST = "https://webinstall.dev"
51 if (!(Test-Path -Path .local\bin\pathman.exe))
53 & curl.exe -fsSL -A "$Env:WEBI_UA" "$Env:WEBI_HOST/packages/pathman/install.ps1" -o .\.local\tmp\pathman-setup.ps1
54 powershell .\.local\tmp\pathman-setup.ps1
55 # TODO del .\.local\tmp\pathman-setup.bat
58 # Run pathman to set up the folder
59 # (using unix style path because... cmd vs powershell vs whatever)
60 & "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
65 # Fetch <whatever>.ps1
67 $PKG_URL = "$Env:WEBI_HOST/api/installers/$exename.ps1?formats=zip,exe,tar"
68 echo "Downloading $PKG_URL"
69 # Invoke-WebRequest -UserAgent "Windows amd64" "$PKG_URL" -OutFile ".\.local\tmp\$exename.install.ps1"
70 & curl.exe -fsSL -A "$Env:WEBI_UA" "$PKG_URL" -o .\.local\tmp\$exename.install.ps1
73 powershell .\.local\tmp\$exename.install.ps1