Skip to content

Commit

Permalink
Adds install and uninstall scripts for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
SaahilNotSahil committed Aug 30, 2023
1 parent c987523 commit eedf869
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,5 @@ archives:
- README.md
- autoproxy.config
- scripts/*
- install.ps1
- uninstall.ps1
37 changes: 37 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Ensure the script is run as Administrator
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "This script must be run as an Administrator. Restarting as administrator..."
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File $($MyInvocation.MyCommand.Path)" -Verb RunAs
exit
}

# Define directories
$binDir = "bin"
$configDir = "."
$installDir = "C:\Program Files\IITJ Autoproxy"
$configInstallDir = "C:\ProgramData\IITJ Autoproxy"

# Create installation directories if they don't exist
if (-Not (Test-Path $installDir)) {
New-Item -Path $installDir -ItemType Directory
}

if (-Not (Test-Path $configInstallDir)) {
New-Item -Path $configInstallDir -ItemType Directory
}

# Copy binaries
Copy-Item -Path "$binDir\*" -Destination $installDir -Force

# Copy example config, README, and LICENSE to config folder
Copy-Item -Path "$configDir\autoproxy.config" -Destination $configInstallDir -Force
Copy-Item -Path "$configDir\README.md" -Destination $configInstallDir -Force
Copy-Item -Path "$configDir\LICENSE" -Destination $configInstallDir -Force

# Add to PATH environment variable
$envPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine)
if (-Not ($envPath -like "*$installDir*")) {
[Environment]::SetEnvironmentVariable("Path", $envPath + ";$installDir", [EnvironmentVariableTarget]::Machine)
}

Write-Host "Installation completed successfully!"
29 changes: 29 additions & 0 deletions uninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Ensure the script is run as Administrator
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "This script must be run as an Administrator. Restarting as administrator..."
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File $($MyInvocation.MyCommand.Path)" -Verb RunAs
exit
}

# Define directories
$installDir = "C:\Program Files\IITJ Autoproxy"
$configInstallDir = "C:\ProgramData\IITJ Autoproxy"

# Remove binaries
if (Test-Path $installDir) {
Remove-Item -Path "$installDir\*" -Force
Remove-Item -Path $installDir -Force
}

# Remove config files, README, and LICENSE
if (Test-Path $configInstallDir) {
Remove-Item -Path "$configInstallDir\*" -Force
Remove-Item -Path $configInstallDir -Force
}

# Remove from PATH environment variable
$envPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine)
$newEnvPath = ($envPath.Split(';') | Where-Object { $_ -ne $installDir }) -join ';'
[Environment]::SetEnvironmentVariable("Path", $newEnvPath, [EnvironmentVariableTarget]::Machine)

Write-Host "Uninstallation completed successfully!"

0 comments on commit eedf869

Please sign in to comment.