switch from bat to ps1
[webi-installers/.git] / _webi / webi.ps1
1 # If a command returns an error, halt the script.
2 $ErrorActionPreference = 'Stop'
3
4 # Ignore progress events from cmdlets so Invoke-WebRequest is not painfully slow
5 $ProgressPreference = 'SilentlyContinue'
6
7 # TODO get arch
8 $Env:WEBI_UA = 'Windows/10 amd64'
9 $exename = $args[0]
10
11 # Switch to userprofile
12 pushd $Env:USERPROFILE
13
14 # Make paths if needed
15 if (!(Test-Path -Path .local\bin))
16 {
17     New-Item -Path .local\bin -ItemType Directory
18 }
19 if (!(Test-Path -Path .local\opt))
20 {
21     New-Item -Path .local\opt -ItemType Directory
22 }
23 # TODO windows version of mktemp -d
24 if (!(Test-Path -Path .local\tmp))
25 {
26     New-Item -Path .local\tmp -ItemType Directory
27 }
28
29 if (!(Test-Path -Path .local\bin\pathman.exe))
30 {
31     & curl.exe -fsSL -A "$Env:WEBI_UA" "$Env:WEBI_HOST/packages/pathman/install.ps1" -o .\.local\tmp\pathman-setup.ps1
32     powershell .\.local\tmp\pathman-setup.ps1
33     # TODO del .\.local\tmp\pathman-setup.bat
34 }
35
36 # {{ baseurl }}
37 # {{ version }}
38
39 # Fetch <whatever>.ps1
40 echo "$Env:WEBI_HOST/packages/$exename/install.ps1"
41 echo "$exename.install.ps1"
42
43 # TODO detect formats
44 # Invoke-WebRequest -UserAgent "Windows amd64" "$Env:WEBI_HOST/api/installers/$exename.ps1?formats=zip,tar" -OutFile ".\.local\tmp\$exename.install.ps1"
45 & curl.exe -fsSL -A "$Env:WEBI_UA" "$Env:WEBI_HOST/api/installers/$exename.ps1?formats=zip,tar" -o .\.local\tmp\$exename.install.ps1
46
47 # Run <whatever>.ps1
48 powershell .\.local\tmp\$exename.install.ps1
49
50 # Done
51 popd