Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
642 changes: 642 additions & 0 deletions CONTRIBUTE.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions bin/installer/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module goblitz-installer

go 1.22.3
14 changes: 14 additions & 0 deletions bin/installer/go/helper/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package helper

import "os"

func CheckIfPathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
39 changes: 39 additions & 0 deletions bin/installer/go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"flag"
"goblitz-installer/src"
"log"
"os"
"runtime"
)

var version string
var install bool
var update bool

func init() {
flag.StringVar(&version, "version", "", "Specify the version to install or update.")
flag.BoolVar(&install, "install", false, "Install GoBlitz.")
flag.BoolVar(&update, "update", false, "Update GoBlitz.")
flag.Parse()
}

func main() {
if version == "" {
log.Println("No version specified. Please specify the version to install or update.")
log.Println("Available versions can be tag or branch name. Example: v1.0.0 or master")
os.Exit(1)
}

switch {
case install && runtime.GOOS == "darwin":
src.InstallMacOSUtilities()
src.InstallGoBlitz(version)
case update && runtime.GOOS == "darwin":
// Implement the update functionality here
default:
log.Println("Invalid option. Please use --install or --update.")
os.Exit(1)
}
}
42 changes: 42 additions & 0 deletions bin/installer/go/src/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package src

import (
"goblitz-installer/helper"
"io"
"log"
"net/http"
"os"
)

func InstallGoBlitz(version string) {
checkFile, err := helper.CheckIfPathExists("GoBlitz")
if err != nil {
log.Fatalf("Failed to check if GoBlitz directory exists: %s", err)
}

if !checkFile {
log.Println("GoBlitz directory does not exist. Pulling GoBlitz...")
releaseUri := "https://github.com/LookinLabs/GoBlitz/archive/refs/tags/" + version + ".zip"

uriResponse, err := http.Get(releaseUri)
if err != nil {
log.Fatalf("Failed to download the zip file: %s", err)
}

defer uriResponse.Body.Close()

fileOutput, err := os.Create("/tmp/GoBlitz.zip")
if err != nil {
log.Fatalf("Failed to create the zip file: %s", err)
}

defer fileOutput.Close()

_, err = io.Copy(fileOutput, uriResponse.Body)
if err != nil {
log.Fatalf("Failed to write the zip file: %s", err)
}

}

}
75 changes: 75 additions & 0 deletions bin/installer/go/src/macos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package src

import (
"io"
"log"
"os/exec"
)

func InstallMacOSUtilities() {
// List of utilities to install
commonUtils := []string{"curl", "git", "go"}
linterUtils := []string{"golangci-lint", "gosec"}
migrationUtils := []string{"goose"}
log.Println("Checking MacOS utilities...")
// Check if Homebrew is installed
if !isCommandAvailable("brew") {
log.Println("Homebrew is not installed. Installing Homebrew...")
runCommand("/bin/bash", "-c", `$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)`)
}

// Install common utilities
for _, util := range commonUtils {
if !isCommandAvailable(util) {
log.Printf("%s is not installed. Installing %s...\n", util, util)
runCommand("brew", "install", util)
}
}

// Install linter utilities
for _, util := range linterUtils {
if !isCommandAvailable(util) {
log.Printf("%s is not installed. Installing %s...\n", util, util)
runCommand("brew", "install", util)
}
}

// Install migration utilities
for _, util := range migrationUtils {
if !isCommandAvailable(util) {
log.Printf("%s is not installed. Installing %s...\n", util, util)
runCommand("brew", "install", util)
}
}

// Install air
if !isCommandAvailable("air") {
log.Println("air is not installed. Installing air...")
runCommand("/bin/bash", "-c", `$(curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh)`)
}

// Check if Docker is installed
if !isCommandAvailable("docker") {
log.Println("Docker is not installed. Please install Docker Desktop.")
// Open the Docker Desktop download page
runCommand("open", "https://hub.docker.com/editions/community/docker-ce-desktop-mac/")
}
log.Println("MacOS utilities installed successfully.")
}

func isCommandAvailable(name string) bool {
cmd := exec.Command("/bin/sh", "-c", "command -v "+name)
if err := cmd.Run(); err != nil {
return false
}
return true
}

func runCommand(name string, arg ...string) {
cmd := exec.Command(name, arg...)
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
if err := cmd.Run(); err != nil {
log.Fatalf("Failed to execute command: %s", err)
}
}
33 changes: 33 additions & 0 deletions bin/installer/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

for i in $(pwd)/bin/installer/src/*.sh; do
source $i
done

OS=$(uname -s)
OPTION=$1
VERSION=$2

if [[ -z $VERSION ]]; then
echo "No version specified. Please specify the version to install or update."
echo "Available versions can be tag or branch name. Example: v1.0.0 or master"
exit 1
fi

case $OPTION in
--install)
if [[ $OS == "Darwin" ]]; then
install_macos_utilities $VERSION
install_goblitz $VERSION
fi
;;
--update)
if [[ $OS == "Darwin" ]]; then
update_goblitz $VERSION
fi
;;
*)
echo "Invalid option. Please use --install or --update."
exit 1
;;
esac
23 changes: 23 additions & 0 deletions bin/installer/src/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

function install_goblitz() {
if ! [ -d "$(pwd)/GoBlitz" ]; then
echo "GoBlitz directory does not exist. Pulling GoBlitz..."
git config --global advice.detachedHead false
git clone git@github.com:LookinLabs/GoBlitz.git --branch $VERSION
rm -rf GoBlitz/.git
fi
}

function update_goblitz() {
if `pwd | grep -q "GoBlitz"` && [ "$VERSION" == "master" ]; then
echo "GoBlitz directory found. Pulling updates..."
git merge origin/master
fi

if `pwd | grep -q "GoBlitz"` && [ "$VERSION" != "master" ]; then
echo "GoBlitz directory found. Checking out $VERSION..."
git fetch
git merge $VERSION
fi
}
42 changes: 42 additions & 0 deletions bin/installer/src/macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

function install_macos_utilities() {

if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

for common_utils in curl git go; do
if ! command -v $common_utils &> /dev/null; then
echo "$common_utils is not installed. Installing $common_utils..."
brew install $common_utils
fi
done

for linter_utils in golangci-lint gosec; do
if ! command -v $linter_utils &> /dev/null; then
echo "$linter_utils is not installed. Installing $linter_utils..."
brew install $linter_utils
fi
done

for migration_utils in goose; do
if ! command -v $migration_utils &> /dev/null; then
echo "$migration_utils is not installed. Installing $migration_utils..."
brew install $migration_utils
fi
done

if ! command -v air &> /dev/null; then
echo "air is not installed. Installing air..."
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s
fi


if ! command -v docker &> /dev/null; then
echo "Docker is not installed. Please install Docker Desktop."
# Open the Docker Desktop download page
open https://hub.docker.com/editions/community/docker-ce-desktop-mac/
fi
}