forked from nullxception/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
50 lines (46 loc) · 1.79 KB
/
install.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
#
# nullxception's Dotfiles install script
# usage:
# ./install.ps1 <module-name>
#
param(
[Parameter(Mandatory=$True)]
[String] $Module
)
$DotfilesPath = Split-Path -parent $PSCommandPath
$ModuleData = ".module-data.ps1"
function Install-Mod($Name) {
$ModuleName = Split-Path $Name -Leaf
$ModulePath = $DotfilesPath + "\" + $ModuleName
if ([System.IO.File]::Exists("$ModulePath\$ModuleData")) {
. "$ModulePath\$ModuleData"
if (Get-Command 'PreInstall-Dotfiles' -errorAction SilentlyContinue) {
PreInstall-Dotfiles
}
if (Get-Command 'Install-Dotfiles' -errorAction SilentlyContinue) {
Install-Dotfiles
} else {
Write-Output "installing module $ModuleName to $Installtarget"
if (![System.IO.Directory]::Exists($Installtarget)) {
New-Item -ItemType Directory -Path $Installtarget
}
Get-ChildItem -Path $ModulePath -Exclude $ModuleData,.module-data.bash | Copy-Item -Destination $Installtarget -Recurse -Force
}
if (Get-Command 'PostInstall-Dotfiles' -errorAction SilentlyContinue) {
PostInstall-Dotfiles
}
# Unregister modules functions
if (Get-Command 'PreInstall-Dotfiles' -errorAction SilentlyContinue) {
Remove-Item -Path Function:\PreInstall-Dotfiles
}
if (Get-Command 'Install-Dotfiles' -errorAction SilentlyContinue) {
Remove-Item -Path Function:\Install-Dotfiles
}
if (Get-Command 'PostInstall-Dotfiles' -errorAction SilentlyContinue) {
Remove-Item -Path Function:\PostInstall-Dotfiles
}
} else {
"Module $ModuleName does not exists or has no $ModuleData"
}
}
Install-Mod $Module