-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuninstall.ps1
More file actions
149 lines (124 loc) · 4.81 KB
/
uninstall.ps1
File metadata and controls
149 lines (124 loc) · 4.81 KB
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
# PowerShell script for uninstalling the project on Windows
# Define variables
$NODE_VERSION = "22.16.0"
$POSTGRES_VERSION = "17"
$PHP_VERSION = "8.4"
$LOG_FILE = "uninstall.log"
# Function to log messages
function Log-Message {
param([string]$message)
Write-Host $message
Add-Content -Path $LOG_FILE -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): $message"
}
# Function to run commands with logging
function Run-Command {
param([string]$command)
Log-Message "Running: $command"
try {
Invoke-Expression $command *>&1 | Tee-Object -Append -FilePath $LOG_FILE
if ($LASTEXITCODE -ne 0) {
throw "Command failed with exit code $LASTEXITCODE"
}
}
catch {
Log-Message "Error executing command: $_"
throw
}
}
# Function to check for admin permissions and confirm
function Check-Admin {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Log-Message "This script requires administrator permissions. Please run PowerShell as an administrator."
exit 1
}
Log-Message "This script requires administrator permissions to uninstall components. Note: you should probably not run random scripts from the Internet without checking the code first. Do you want to continue? (y/n)"
$response = Read-Host
if ($response -ne "y") {
Log-Message "Exiting..."
exit 1
}
Log-Message "Thank you. Proceeding with uninstallation..."
}
# Function to detect OS and verify Windows
function Check-SystemCompatibility {
$os = Get-WmiObject -Class Win32_OperatingSystem
if (-not $os.Caption.Contains("Windows")) {
Log-Message "This script is only compatible with Windows operating systems."
exit 1
}
Log-Message "Running on: $($os.Caption)"
}
# Function to uninstall PostgreSQL
function Uninstall-Postgres {
Log-Message "Uninstalling PostgreSQL ${POSTGRES_VERSION}..."
# Stop services first
Run-Command "net stop postgresql-x64-$POSTGRES_VERSION" -ErrorAction SilentlyContinue
# Uninstall PostgreSQL
Run-Command "choco uninstall postgresql$POSTGRES_VERSION -y"
Log-Message "Removing PostgreSQL data..."
Run-Command "Remove-Item -Path 'C:\Program Files\PostgreSQL' -Recurse -Force -ErrorAction SilentlyContinue"
Run-Command "Remove-Item -Path 'C:\ProgramData\PostgreSQL' -Recurse -Force -ErrorAction SilentlyContinue"
}
# Function to uninstall Node.js and related tools
function Uninstall-Node {
Log-Message "Uninstalling Node.js and related tools..."
# Remove Node.js
Run-Command "choco uninstall nodejs -y --version=$NODE_VERSION"
Run-Command "choco uninstall yarn -y"
# Remove related directories
Run-Command "Remove-Item -Path '$env:APPDATA\npm' -Recurse -Force -ErrorAction SilentlyContinue"
Run-Command "Remove-Item -Path '$env:APPDATA\npm-cache' -Recurse -Force -ErrorAction SilentlyContinue"
}
# Function to uninstall PHP
function Uninstall-PHP {
Log-Message "Uninstalling PHP ${PHP_VERSION} and extensions..."
# Uninstall PHP and extensions
$extensions = @(
"php",
"php-pgsql",
"php-curl",
"php-opcache",
"php-intl",
"php-xml",
"php-dom",
"php-zip",
"php-mbstring"
)
foreach ($ext in $extensions) {
Run-Command "choco uninstall $ext -y --version=$PHP_VERSION"
}
Log-Message "Uninstalling Composer..."
Run-Command "choco uninstall composer -y"
# Remove PHP related directories
Run-Command "Remove-Item -Path 'C:\tools\php' -Recurse -Force -ErrorAction SilentlyContinue"
Run-Command "Remove-Item -Path '$env:APPDATA\Composer' -Recurse -Force -ErrorAction SilentlyContinue"
}
# Function to clean up remaining packages
function Remove-UnusedPackages {
Log-Message "Cleaning up unused packages..."
Run-Command "choco cleanup" # Cleans up old versions
# NOTE: Manual cleanup for PostgreSQL databases and users might be required.
# This script does not handle dropping specific databases (mush, etwin.dev) or users (mysql, etwin.dev).
# This would require connecting to the PostgreSQL server with appropriate credentials and executing SQL commands.
}
# Main uninstallation process
function Main {
try {
Check-SystemCompatibility
Check-Admin
Log-Message "Starting uninstallation process..."
Uninstall-Postgres
Uninstall-Node
Uninstall-PHP
Remove-UnusedPackages
Log-Message "Uninstallation completed successfully."
}
catch {
Log-Message "Uninstallation failed: $_"
exit 1
}
}
# Run the main function
Main