-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuninstall_abkEnv.ps1
80 lines (67 loc) · 3.22 KB
/
uninstall_abkEnv.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
#Requires -Version 5.0
$ErrorActionPreference = "Stop"
# Requires -Modules ".\winBin\Modules\abk-lib"
Import-Module ".\winBin\Modules\abk-lib" -Force
# -----------------------------------------------------------------------------
# variables definitions
# -----------------------------------------------------------------------------
$EXPECTED_NUMBER_OF_PARAMETERS=0
$EXIT_CODE=$ERROR_CODE_SUCCESS
# -----------------------------------------------------------------------------
# functions
# -----------------------------------------------------------------------------
PrintUsageAndExitWithCode ($scriptName, $exitErrorCode) {
Write-Host "->" $MyInvocation.MyCommand.Name ($scriptName, $exitErrorCode) -ForegroundColor Yellow
Write-Host " $scriptName will uninstall ABK Environment and deleting links in $HOME_BIN_DIR"
Write-Host " Usage: $scriptName"
Write-Host " $scriptName --help - display this info"
Write-Host "<-" $MyInvocation.MyCommand.Name "($exitErrorCode)" -ForegroundColor Yellow
exit $exitErrorCode
}
# -----------------------------------------------------------------------------
# main
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "->" $MyInvocation.MyCommand.Name "($args)" -ForeGroundColor Green
Write-Host " [args.Count =" $args.Count "]"
Write-Host " [BIN_DIR = $BIN_DIR]"
Write-Host " [HOME_BIN_DIR = $HOME_BIN_DIR]"
Write-Host " [SH_BIN_DIR = $SH_BIN_DIR]"
Write-Host " [SH_PACKAGES_DIR = $SH_PACKAGES_DIR]"
Write-Host " [ABK_ENV_FILE = $ABK_ENV_FILE]"
Write-Host " [HOME = $HOME]"
Write-Host " [env:Home = $env:Home]"
Write-Host
# if logged in on a computer through a different user, the $env:Home is not the same as $HOME
# which will cause some problems. So the $env:Home needs to be set to $HOME
if ( $HOME -ne $env:Home ) {
Write-Host " [setting env:Home to $HOME] ..."
$env:Home=$HOME
}
# Is parameter --help?
if (Confirm-ParameterIsHelp $args.Count $args[0]) {
PrintUsageAndExitWithCode $MyInvocation.MyCommand.Name $EXIT_CODE_SUCCESS
}
# Is number of parameters ok
if (-not (Confirm-CorrectNumberOfParameters $EXPECTED_NUMBER_OF_PARAMETERS $args.Count)) {
Write-Host "ERROR: Incorrect number of parameters" -ForegroundColor Red
Write-Host "Expected: $EXPECTED_NUMBER_OF_PARAMETERS" -ForegroundColor Red
Write-Host "Actual:" $args.Count -ForegroundColor Red
PrintUsageAndExitWithCode $MyInvocation.MyCommand.Name $EXIT_CODE_INVALID_NUMBER_OF_PARAMETERS
}
# Figure out what directory this script is executed from
$CURRENT_DIR=$(Split-Path -Parent $PSCommandPath)
Write-Host " [CURRENT_DIR = $CURRENT_DIR]"
# delete abk env from user powershell profile
if (Confirm-FileExist $profile) {
Write-Host " [deleting abk environment from user profile: $profile ...]"
Remove-AbkEnvironmentSettings $profile
}
# if $HOME\bin junction directory exist -> delete it
if (Confirm-DirectoryExist $HOME_BIN_DIR) {
Write-Host " [Deleting $HOME_BIN_DIR junction to $CURRENT_DIR\$SH_BIN_DIR ...]"
Remove-Item -Path "$HOME_BIN_DIR" -Recurse -Force
}
& $profile
Write-Host "<-" $MyInvocation.MyCommand.Name "($EXIT_CODE)" -ForeGroundColor Green
exit $EXIT_CODE