forked from fauxpilot/fauxpilot
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
launch.ps1
88 lines (78 loc) · 2.28 KB
/
launch.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env -S pwsh -nop
#requires -version 5
<#PSScriptInfo
.VERSION 0.0.1
.GUID
.AUTHOR Rowe Wilson Frederisk Holme
.PROJECTURI https://github.com/Frederisk/fauxpilot-windows
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI https://github.com/Frederisk/fauxpilot-windows/blob/main/LICENSE.txt
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
#>
<#
.SYNOPSIS
fauxpilot-windows-launch - Start fauxpilot in Windows.
.DESCRIPTION
.PARAMETER Help
Display the full help message.
.INPUTS
System.String
.OUTPUTS
System.Object
.NOTES
#>
using namespace System;
using namespace System.Text.RegularExpressions;
using namespace System.Management.Automation;
using namespace System.IO;
[CmdletBinding()]
param (
[Switch][Alias('h')]$Help,
[Switch]$Daemon
)
if ($Help) {
Get-Help -Name ($MyInvocation.MyCommand.Definition) -Full | Out-Host;
exit 0;
}
# Read in .env file; error if not found
if (-not (Get-Item -Path '.env' -ErrorAction SilentlyContinue)) {
Write-Warning -Message '.env not found, running setup.ps1' | Out-Null;
& 'setup.ps1';
}
Write-Verbose -Message 'Read in .env file' | Out-Null;
Get-Content -Path '.env' -Encoding utf8NoBOM | ForEach-Object -Process {
$name, $value = $_.Split('=');
Write-Verbose -Message "Name: $name, Value: $value" | Out-Null;
# Set-Variable -Name $name -Value $value;
[Environment]::SetEnvironmentVariable($name, $value);
}
[ApplicationInfo]$docker = Get-Command -Name 'docker';
[String]$dockerVersionOutput = &$docker --version 2>&1;
[String]$versionString = [Regex]::Match($dockerVersionOutput, '(?<=version\s*)[0-9]*\.[0-9]*\.[0-9]*');
Write-Verbose -Message "docker version: $versionString" | Out-Null;
[Version]$version = [Version]::new($versionString);
if ($version -ge ([Version]::new('20.10.2'))) {
Write-Verbose -Message 'up with docker compose' | Out-Null;
if ($Daemon) {
&$docker compose up -d --remove-orphans;
}
else {
&$docker compose up --remove-orphans;
}
}
else {
[ApplicationInfo]$dockerCompose = Get-Command -Name 'docker-compose';
Write-Verbose -Message 'up with docker-compose' | Out-Null;
if ($Daemon) {
&$dockerCompose up -d --remove-orphans;
}
else {
&$dockerCompose up --remove-orphans;
}
}