-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.ps1
180 lines (158 loc) · 4.49 KB
/
setup.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env pwsh
#Requires -Version 7
[CmdletBinding()]
Param(
[String]$GitHubRepo = "ryuuganime/animeDb"
)
# set Write-Information to always show messages
$InformationPreference = 'Continue'
# ==============================================================================
# FUNCTIONS
# ==============================================================================
Function Show-SudoWarning {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True)]
[string]$Package
)
Write-Information @"
`e[31mWARNING: This script will attempt to use sudo to install packages.`e[0m
If you do not want to use sudo (or gsudo is not installed for Windows), please exit this script and install the following package manually:
$package
"@
}
Function Install-PackageFromDistro {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True)]
[string]$Package
)
$sudo = $True
$installParam = "install"
If ($IsLinux) {
# Check currently available package managers
If (Get-Command apx -ErrorAction SilentlyContinue) {
$PackageManager = "apx"
$sudo = $False
}
ElseIf (Get-Command apt -ErrorAction SilentlyContinue) {
$PackageManager = "apt"
}
ElseIf (Get-Command dnf -ErrorAction SilentlyContinue) {
$PackageManager = "dnf"
}
ElseIf (Get-Command yum -ErrorAction SilentlyContinue) {
$PackageManager = "yum"
}
ElseIf (Get-Command pacman -ErrorAction SilentlyContinue) {
$PackageManager = "pacman"
$installParam = "-Syu"
}
# Confirm if apk is available AND if it's Alpine
ElseIf (Get-Command apk -ErrorAction SilentlyContinue) {
If (Test-Path -Path "/etc/alpine-release") {
$PackageManager = "apk"
$installParam = "add"
}
Else {
Write-Error "apk: Not Alpine, unsupported OS" -ErrorAction Break
}
}
Else {
# Raise an error
Write-Error "Unsupported package manager" -ErrorAction Break
}
}
ElseIf ($IsMacOS) {
If (Test-Path -Path "/usr/local/bin/brew") {
$PackageManager = "brew"
}
Else {
Write-Error "Unsupported package manager" -ErrorAction Break
}
}
ElseIf ($IsWindows) {
If (Get-Command choco -ErrorAction SilentlyContinue) {
$PackageManager = "choco"
}
ElseIf (Get-Command winget -ErrorAction SilentlyContinue) {
$PackageManager = "winget"
$installParam = "install -e"
}
ElseIf (Get-Command scoop -ErrorAction SilentlyContinue) {
$PackageManager = "scoop"
$Sudo = $False
}
Else {
Write-Error "Unsupported package manager" -ErrorAction Break
}
}
Else {
Write-Error "Unsupported operating system" -ErrorAction Break
}
# Install the package
If ($sudo) {
Show-SudoWarning -Package $Package
Start-Process -FilePath "sudo" -ArgumentList "$PackageManager $installParam $Package" -Wait
}
Else {
Start-Process -FilePath "$PackageManager" -ArgumentList "$installParam $Package" -Wait
}
}
# ==============================================================================
# PREQS
# ==============================================================================
# Check for binaries
$binaries = @(
'python3',
'git'
)
$binaries | ForEach-Object {
If (-not (Get-Command $_ -ErrorAction SilentlyContinue)) {
# If $_ is python3, check for python
If ($_ -eq 'python3') {
If (-not (Get-Command 'python' -ErrorAction SilentlyContinue)) {
Write-Error "$_ is not installed" -ErrorAction Continue
Install-PackageFromDistro -Package 'python3'
}
Else {
Write-Information "$_ is already installed"
}
}
Else {
Write-Error "$_ is not installed" -ErrorAction Continue
Install-PackageFromDistro -Package $_
}
}
Else {
Write-Information "$_ is already installed"
}
}
# Check required PowerShell Modules
$Modules = @(
'Set-PsEnv',
'PSGraphQL',
'PowerHTML'
)
$Modules | ForEach-Object {
If (-not (Get-Package -Name $_ -ErrorAction SilentlyContinue)) {
Write-Information "Installing module $_"
Install-Module -Name $_ -Force
}
Else {
Write-Information "Module $_ is already installed"
}
}
git clone "https://github.com/${GitHubRepo}.git" '.\Database\animeDb'
# Run Env Generator before running the rest of the script
If (-not (Test-Path -Path ".\.env" -ErrorAction SilentlyContinue)) {
Write-Information "Generating env.ps1"
.\Modules\Set-WorkplaceEnv.ps1
}
# ==============================================================================
# RUN THE REST OF THE SCRIPT
# ==============================================================================
# Load the environment variables
Set-PsEnv
# Grab python, run pip
Invoke-Expression -Command "${Env:PYTHON_PATH} -m pip install -r requirements.txt"