more powershell
[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 # TODO SetStrictMode
30 # TODO Test-Path variable:global:Env:WEBI_HOST ???
31 IF(!$Env:WEBI_HOST)
32 {
33     $Env:WEBI_HOST = "https://webinstall.dev"
34 }
35
36 if (!(Test-Path -Path .local\bin\pathman.exe))
37 {
38     & curl.exe -fsSL -A "$Env:WEBI_UA" "$Env:WEBI_HOST/packages/pathman/install.ps1" -o .\.local\tmp\pathman-setup.ps1
39     powershell .\.local\tmp\pathman-setup.ps1
40     # TODO del .\.local\tmp\pathman-setup.bat
41 }
42
43 # {{ baseurl }}
44 # {{ version }}
45
46 # Fetch <whatever>.ps1
47 echo "$Env:WEBI_HOST/packages/$exename/install.ps1"
48 echo "$exename.install.ps1"
49
50 # TODO detect formats
51 # Invoke-WebRequest -UserAgent "Windows amd64" "$Env:WEBI_HOST/api/installers/$exename.ps1?formats=zip,tar" -OutFile ".\.local\tmp\$exename.install.ps1"
52 & curl.exe -fsSL -A "$Env:WEBI_UA" "$Env:WEBI_HOST/api/installers/$exename.ps1?formats=zip,tar" -o .\.local\tmp\$exename.install.ps1
53
54 # Run <whatever>.ps1
55 powershell .\.local\tmp\$exename.install.ps1
56
57 # Done
58 popd