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:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,127 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var cmd *exec.Cmd
|
||||
// Check which os being run
|
||||
if runtime.GOOS == "windows" {
|
||||
cmd = exec.Command("where", "cocommit")
|
||||
} else {
|
||||
cmd = exec.Command("which", "cocommit")
|
||||
}
|
||||
|
||||
_, err := cmd.Output()
|
||||
if err != nil {
|
||||
download()
|
||||
} else {
|
||||
download()
|
||||
//update()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func cleanup() {
|
||||
fmt.Println("Removing cocommit.tar.gz")
|
||||
os.Remove("cocommit.tar.gz")
|
||||
}
|
||||
|
||||
func download() {
|
||||
var resp *http.Response
|
||||
var err error
|
||||
var cmd *exec.Cmd
|
||||
|
||||
// Download the latest release
|
||||
filename := "cocommit.tar.gz"
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
fmt.Println("Downloading mac version")
|
||||
if runtime.GOARCH == "amd64" {
|
||||
resp, err = http.Get("https://github.com/Slug-Boi/cocommit/releases/latest/download/cocommit-darwin-x86_64.tar.gz")
|
||||
} else {
|
||||
resp, err = http.Get("https://github.com/Slug-Boi/cocommit/releases/latest/download/cocommit-darwin-aarch64.tar.gz")
|
||||
}
|
||||
cmd = exec.Command("tar", "-xvf", filename)
|
||||
case "windows":
|
||||
fmt.Println("Downloading windows version")
|
||||
resp, err = http.Get("https://github.com/Slug-Boi/cocommit/releases/latest/download/cocommit-win.tar.gz")
|
||||
cmd = exec.Command("tar", "-xvf", filename)
|
||||
default:
|
||||
fmt.Println("Downloading linux version")
|
||||
resp, err = http.Get("https://github.com/Slug-Boi/cocommit/releases/latest/download/cocommit-linux.tar.gz")
|
||||
cmd = exec.Command("tar", "-xvf", filename)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("Error downloading file")
|
||||
}
|
||||
|
||||
// Create the file
|
||||
file, err := os.Create("cocommit.tar.gz")
|
||||
if err != nil {
|
||||
fmt.Println("Error creating file")
|
||||
}
|
||||
|
||||
defer cleanup()
|
||||
defer file.Close()
|
||||
|
||||
defer resp.Body.Close()
|
||||
_, err = io.Copy(file, resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println("Error copying file")
|
||||
}
|
||||
|
||||
// Extract the file
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
panic("Error extracting file")
|
||||
}
|
||||
|
||||
regExp := regexp.MustCompile("cocommit-.+")
|
||||
|
||||
// Find the correct binary
|
||||
var new_binary string
|
||||
|
||||
err = filepath.Walk("./", func(path string, info os.FileInfo, err error) error {
|
||||
if err == nil && regExp.MatchString(info.Name()) {
|
||||
new_binary = info.Name()
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Move the file to the correct path
|
||||
var input string
|
||||
fmt.Println("Cocommit default install location (/usr/local/bin/cocommit?):")
|
||||
fmt.Scanln(&input)
|
||||
if input == "" {
|
||||
input = "/usr/local/bin/cocommit"
|
||||
}
|
||||
|
||||
if new_binary != "" {
|
||||
err = os.Rename(new_binary, input)
|
||||
}
|
||||
fmt.Println("Cocommit cli tool installed successfully")
|
||||
// Cleanup
|
||||
cleanup()
|
||||
|
||||
}
|
||||
|
||||
func update() {
|
||||
cmd := exec.Command("cocommit", "update")
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println("Error updating")
|
||||
}
|
||||
}
|
||||
+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
|
||||
}
|
||||
+46
-9
@@ -1,23 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# Determine the OS and architecture
|
||||
|
||||
# Set up a cleanup function to be triggered upon script exit
|
||||
__cleanup ()
|
||||
{
|
||||
rm "cocommit.tar.gz" 2>/dev/null
|
||||
rm author.txt 2>/dev/null
|
||||
if [ -n "$file" ]; then
|
||||
rm $file 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
trap __cleanup EXIT
|
||||
|
||||
OS=$(uname -s)
|
||||
ARCH=$(uname -m)
|
||||
|
||||
file=""
|
||||
|
||||
url="https://github.com/Slug-Boi/cocommit/raw/refs/heads/chore_install_script/installer/bin/"
|
||||
url="https://github.com/Slug-Boi/cocommit/releases/latest/download/"
|
||||
|
||||
# Set the download URL based on the OS and architecture
|
||||
if [ "$OS" == "Linux" ]; then
|
||||
URL="${url}install-linux"
|
||||
file="install-linux"
|
||||
URL="${url}cocommit-linux.tar.gz"
|
||||
file="cocommit-linux"
|
||||
elif [ "$OS" == "Darwin" ]; then
|
||||
if [ "$ARCH" == "x86_64" ]; then
|
||||
URL="${url}install-darwin-x86_64"
|
||||
file="install-darwin-x86_64"
|
||||
URL="${url}cocommit-darwin-x86_64.tar.gz"
|
||||
file="cocommit-darwin"
|
||||
else
|
||||
URL="${url}install-darwin-aarch64"
|
||||
file="install-darwin-aarch64"
|
||||
URL="${url}cocommit-darwin-aarch64.tar.gz"
|
||||
file="cocommit-darwin-aarch64"
|
||||
fi
|
||||
else
|
||||
echo "Unsupported OS: $OS"
|
||||
@@ -26,5 +39,29 @@ fi
|
||||
|
||||
# Download and run the script
|
||||
|
||||
echo $file
|
||||
curl -LJO $URL && chmod +x $file && ./$file
|
||||
curl -L -o cocommit.tar.gz $URL && \
|
||||
tar -xvzf cocommit.tar.gz && \
|
||||
rm cocommit.tar.gz && rm author.txt && \
|
||||
chmod +x $file && ./$file -v
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to extract the binary"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Move the binary to the current directory
|
||||
read -p "Enter the directory to move the binary to (default: /usr/local/bin/cocommit): " target_dir
|
||||
target_dir=${target_dir:-/usr/local/bin/cocommit}
|
||||
|
||||
if [ ! -d "$(dirname "$target_dir")" ]; then
|
||||
echo "Directory does not exist: $(dirname "$target_dir")"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv $file "$target_dir"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to move the binary to $target_dir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Binary moved to $target_dir successfully"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user