3 # If a command returns an error, halt the script.
4 $ErrorActionPreference = 'Stop'
6 # Ignore progress events from cmdlets so Invoke-WebRequest is not painfully slow
7 $ProgressPreference = 'SilentlyContinue'
9 # This is the canonical CPU arch when the process is emulated
10 $my_arch = "$Env:PROCESSOR_ARCHITEW6432"
11 IF ($my_arch -eq $null -or $my_arch -eq "") {
12 # This is the canonical CPU arch when the process is native
13 $my_arch = "$Env:PROCESSOR_ARCHITECTURE"
15 # TODO API should know to prefer x86 for windows when arm binary is not available
16 $Env:WEBI_UA = "Windows/10 $my_arch"
19 # Switch to userprofile
20 pushd $Env:USERPROFILE
22 # Make paths if needed
23 if (!(Test-Path -Path .local\bin))
25 New-Item -Path .local\bin -ItemType Directory
27 if (!(Test-Path -Path .local\xbin))
29 New-Item -Path .local\xbin -ItemType Directory
31 Set-Content -Path .local\bin\webi.bat -Value "@echo off`r`npushd %USERPROFILE%`r`npowershell -ExecutionPolicy Bypass .local\bin\webi.ps1 %1`r`npopd"
32 if (!(Test-Path -Path .local\opt))
34 New-Item -Path .local\opt -ItemType Directory
36 # TODO windows version of mktemp -d
37 if (!(Test-Path -Path .local\tmp))
39 New-Item -Path .local\tmp -ItemType Directory
43 # TODO Test-Path variable:global:Env:WEBI_HOST ???
44 IF($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "")
46 $Env:WEBI_HOST = "https://webinstall.dev"
49 if (!(Test-Path -Path .local\bin\pathman.exe))
51 & curl.exe -fsSL -A "$Env:WEBI_UA" "$Env:WEBI_HOST/packages/pathman/install.ps1" -o .\.local\tmp\pathman-setup.ps1
52 powershell .\.local\tmp\pathman-setup.ps1
53 # TODO del .\.local\tmp\pathman-setup.bat
56 # Run pathman to set up the folder
57 # (using unix style path because... cmd vs powershell vs whatever)
58 & "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin
63 # Fetch <whatever>.ps1
65 $PKG_URL = "$Env:WEBI_HOST/api/installers/$exename.ps1?formats=zip,exe,tar"
66 echo "Downloading $PKG_URL"
67 # Invoke-WebRequest -UserAgent "Windows amd64" "$PKG_URL" -OutFile ".\.local\tmp\$exename.install.ps1"
68 & curl.exe -fsSL -A "$Env:WEBI_UA" "$PKG_URL" -o .\.local\tmp\$exename.install.ps1
71 powershell .\.local\tmp\$exename.install.ps1