mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
chore: refactor install scripts to be actual scripts and simplify approach
This commit is contained in:
+61
-6
@@ -1,8 +1,63 @@
|
||||
$binaryUrl = "https://github.com/Slug-Boi/cocommit/blob/main/installer/bin/install-win"
|
||||
$outputPath = "install-win.exe"
|
||||
# Determine the OS and architecture
|
||||
|
||||
# Download the binary
|
||||
Invoke-WebRequest -Uri $binaryUrl -OutFile $outputPath
|
||||
# Set up a cleanup function to be triggered upon script exit
|
||||
function Cleanup {
|
||||
Remove-Item -ErrorAction SilentlyContinue "cocommit.tar.gz"
|
||||
Remove-Item -ErrorAction SilentlyContinue "author.txt"
|
||||
if ($file) {
|
||||
Remove-Item -ErrorAction SilentlyContinue $file
|
||||
}
|
||||
}
|
||||
|
||||
# Run the binary
|
||||
& .\$outputPath
|
||||
trap { Cleanup } EXIT
|
||||
|
||||
$OS = (Get-CimInstance Win32_OperatingSystem).Caption
|
||||
$ARCH = (Get-CimInstance Win32_Processor).Architecture
|
||||
|
||||
$file = ""
|
||||
|
||||
$url = "https://github.com/Slug-Boi/cocommit/releases/latest/download/"
|
||||
|
||||
# Set the download URL based on the OS and architecture
|
||||
if ($OS -match "Windows") {
|
||||
$URL = "${url}cocommit-win.tar.gz"
|
||||
$file = "cocommit.exe"
|
||||
} else {
|
||||
Write-Host "Unsupported OS: $OS"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Download and run the script
|
||||
Invoke-WebRequest -Uri $URL -OutFile "cocommit.tar.gz"
|
||||
if ($?) {
|
||||
tar -xvzf "cocommit.tar.gz"
|
||||
Remove-Item "cocommit.tar.gz"
|
||||
Remove-Item "author.txt"
|
||||
if ($file) {
|
||||
& .\$file -v
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Failed to extract the binary"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-Host "Failed to download the file"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Move the binary to the specified directory
|
||||
$target_dir = Read-Host "Enter the directory to move the binary to (default: C:\Program Files\cocommit)"
|
||||
$target_dir = if ($target_dir) { $target_dir } else { "C:\Program Files\cocommit" }
|
||||
|
||||
if (-Not (Test-Path (Split-Path $target_dir))) {
|
||||
Write-Host "Directory does not exist: $(Split-Path $target_dir)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Move-Item -Path $file -Destination $target_dir
|
||||
if ($?) {
|
||||
Write-Host "Binary moved to $target_dir successfully"
|
||||
} else {
|
||||
Write-Host "Failed to move the binary to $target_dir"
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user