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 if (!(Test-Path -Path .local\bin))
30 New-Item -Path .local\bin -ItemType Directory
32 if (!(Test-Path -Path .local\xbin))
34 New-Item -Path .local\xbin -ItemType Directory
36 # See note on Set-ExecutionPolicy above
37 Set-Content -Path .local\bin\webi.bat -Value "@echo off`r`npushd %USERPROFILE%`r`npowershell -ExecutionPolicy Bypass .local\bin\webi.ps1 %1`r`npopd"
38 if (!(Test-Path -Path .local\opt))
40 New-Item -Path .local\opt -ItemType Directory
42 # TODO windows version of mktemp -d
43 if (!(Test-Path -Path .local\tmp))
45 New-Item -Path .local\tmp -ItemType Directory
49 # TODO Test-Path variable:global:Env:WEBI_HOST ???
50 IF($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "")
52 $Env:WEBI_HOST = "https://webinstall.dev"
55 if (!(Test-Path -Path .local\bin\pathman.exe))
57 & curl.exe -fsSL -A "$Env:WEBI_UA" "$Env:WEBI_HOST/packages/pathman/install.ps1" -o .\.local\tmp\pathman-setup.ps1
58 powershell .\.local\tmp\pathman-setup.ps1
59 # TODO del .\.local\tmp\pathman-setup.bat
62 # Run pathman to set up the folder
63 # (using unix style path because... cmd vs powershell vs whatever)
64 & "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
69 # Fetch <whatever>.ps1
71 $PKG_URL = "$Env:WEBI_HOST/api/installers/$exename.ps1?formats=zip,exe,tar"
72 echo "Downloading $PKG_URL"
73 # Invoke-WebRequest -UserAgent "Windows amd64" "$PKG_URL" -OutFile ".\.local\tmp\$exename.install.ps1"
74 & curl.exe -fsSL -A "$Env:WEBI_UA" "$PKG_URL" -o .\.local\tmp\$exename.install.ps1
77 powershell .\.local\tmp\$exename.install.ps1