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