Skip to content

Commit

Permalink
feat: ✨ add install script for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
OnCloud125252 committed May 4, 2024
1 parent 737e9d1 commit a028f78
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions install/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Colors
$GREEN = [ConsoleColor]::Green
$YELLOW = [ConsoleColor]::Yellow
$RED = [ConsoleColor]::Red

# Variables
$app_name = "cm"
$download_link = "https://github.com/lazco-studio/Component-Manager/releases/latest/download/cm-cli_windows_amd64.exe"
$install_path = "C:\Program Files\$app_name\"
$app_path = "C:\Program Files\$app_name\$app_name.exe"

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe " -NoExit -NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }

function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

if ((Test-Admin) -eq $false) {
if ($elevated) {
} else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}

function Add-To-Path {
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "Machine")

if ($currentPath -split ";" -notcontains $install_path) {
$newPath = $currentPath + ";" + $install_path
[Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine")
Write-Host "Directory added to PATH variable successfully." -ForegroundColor Green
} else {
Write-Host "Directory is already in PATH variable." -ForegroundColor Yellow
}
}

function Install-Tool {
if (!(Test-Path "$install_path")) {
New-Item -Path "$install_path" -ItemType Directory
}

Invoke-WebRequest $download_link -OutFile $app_path

Add-To-Path

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

Write-Host "Successfully installed $app_name." -ForegroundColor $GREEN
Write-Host "Please open a new PowerShell session to start using $app_name." -ForegroundColor $YELLOW
}


if (Test-Path "$app_path") {
Write-Host -NoNewline "Warning: App named $app_name already exists in $install_path. Do you want to overwrite it? (y/N): " -ForegroundColor $YELLOW
$response = Read-Host

if ($response -eq "Y" -or $response -eq "y") {
Write-Host "Updating $app_name ..." -ForegroundColor $GREEN
Install-Tool
} else {
Write-Host "Installation aborted." -ForegroundColor $RED
exit 1
}
} else {
Write-Host "Installing $app_name ..." -ForegroundColor $GREEN
Install-Tool
}
File renamed without changes.

0 comments on commit a028f78

Please sign in to comment.