-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
63 lines (52 loc) · 1.74 KB
/
build.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
<#
.SYNOPSIS
Quick build script that will clone the repo to a PSModulePath and install the module locally.
.EXAMPLE
./build.ps1
Clones, installs and imports the module.
.EXAMPLE
./build.ps1 -Force
ReInstall and imports the module.
#>
param(
[switch]$Force,
$ModulePathToInstall = $env:PSModulePath.Split(":")[0]
)
function Install-LinuxInfo {
try {
$GoBack = $pwd
Set-Location $env:PSModulePath.Split(":")[0]
if (Test-Path ./linuxinfo) {
Remove-Item ./linuxinfo -Recurse -Force
}
Write-Verbose "Cloning linuxinfo.." -Verbose
$null = git clone https://github.com/ehmiiz/linuxinfo.git
# Figure out module version
[string]$V = (Test-ModuleManifest -Path linuxinfo/src/linuxinfo/linuxinfo.psd1).Version
$null = New-Item -ItemType Directory -Name $V -Path ./linuxinfo/
Move-Item ./linuxinfo/src/linuxinfo/* -Destination ./linuxinfo/$V/
Import-Module linuxinfo -Force -ErrorAction SilentlyContinue
Set-Location $GoBack
Write-Verbose "Installed and Imported." -Verbose
Get-Module linuxinfo
}
catch {
Write-Error $error[0] -ErrorAction Stop
}
}
if ((Test-Path "$ModulePathToInstall/linuxinfo") -and ($Force)) {
# Remove since -Force was used
Write-Verbose "Module found, and -Force was used. Removing.." -Verbose
$null = Remove-Item $ModulePathToInstall/linuxinfo -Recurse -Force -Confirm:$false
# Install
Write-Verbose "Installing.." -Verbose
Install-LinuxInfo
}
elseif (Test-Path "$ModulePathToInstall/linuxinfo") {
Write-Warning 'Module already installed. Use -Force to reinstall.'
Break
}
else {
Install-LinuxInfo
Write-Verbose "Installed." -Verbose
}