Skip to content

Commit

Permalink
fix: Fixed install script
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrovian4 committed Nov 11, 2024
1 parent 47f04dd commit f293564
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 79 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ventana.com

go 1.23.1
go 1.22

require (
github.com/chzyer/readline v1.5.1 // indirect
Expand Down
111 changes: 33 additions & 78 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,30 @@ echo_error() {
echo -e "\033[1;31m[ERROR]\033[0m $1" >&2
}

OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case "$OS" in
linux*) OS="linux";;
darwin*) OS="darwin";;
*) echo_error "Unsupported operating system: $OS"; exit 1;;
esac

case "$ARCH" in
x86_64|amd64) ARCH="amd64";;
arm64|aarch64) ARCH="arm64";;
*) echo_error "Unsupported architecture: $ARCH"; exit 1;;
esac

REQUIRED_GO_VERSION="go1.23.1"
MIN_GO_VERSION="1.22"

version_greater_equal() {
local IFS=.
local i ver1=($1) ver2=($2)
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++)); do
if [[ -z ${ver2[i]} ]]; then
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]})); then
return 0
elif ((10#${ver1[i]} < 10#${ver2[i]})); then
return 1
fi
done
return 0
}

compare_go_version() {
INSTALLED_VERSION=$(go version 2>/dev/null | awk '{print $3}')
if [[ "$INSTALLED_VERSION" == "$REQUIRED_GO_VERSION" ]]; then
INSTALLED_VERSION=$(go version 2>/dev/null | awk '{print $3}' | sed 's/go//')
if version_greater_equal "$INSTALLED_VERSION" "$MIN_GO_VERSION"; then
return 0
else
return 1
Expand All @@ -42,89 +46,40 @@ compare_go_version() {

if command -v go >/dev/null 2>&1; then
if compare_go_version; then
echo_info "Go $REQUIRED_GO_VERSION is already installed."
USE_SYSTEM_GO=true
else
echo_warning "Installed Go version ($(go version | awk '{print $3}')) is not the required version ($REQUIRED_GO_VERSION)."
USE_SYSTEM_GO=false
fi
else
echo_warning "Go is not installed on the system."
USE_SYSTEM_GO=false
fi

if [ "$USE_SYSTEM_GO" = false ]; then
if [[ "$OS" == "linux" ]]; then
GO_URL="https://go.dev/dl/${REQUIRED_GO_VERSION}.linux-${ARCH}.tar.gz"
elif [[ "$OS" == "darwin" ]]; then
if [[ "$ARCH" == "amd64" ]]; then
GO_URL="https://go.dev/dl/${REQUIRED_GO_VERSION}.darwin-amd64.pkg"
else
GO_URL="https://go.dev/dl/${REQUIRED_GO_VERSION}.darwin-arm64.pkg"
fi
echo_info "A versão do Go ($(go version | awk '{print $3}')) é suficiente."
else
echo_error "Unsupported operating system for Go installation: $OS"
echo_error "A versão do Go instalada ($(go version | awk '{print $3}')) é mais antiga que a versão mínima requerida (go$MIN_GO_VERSION)."
exit 1
fi

GO_INSTALL_DIR="$HOME/go${REQUIRED_GO_VERSION}"
mkdir -p "$GO_INSTALL_DIR"

echo_info "Downloading Go $REQUIRED_GO_VERSION from $GO_URL..."
cd "$HOME"

if [[ "$OS" == "linux" ]]; then
curl -L -o "go.tar.gz" "$GO_URL"
tar -C "$GO_INSTALL_DIR" -xzf "go.tar.gz" --strip-components=1
rm "go.tar.gz"
elif [[ "$OS" == "darwin" ]]; then
curl -L -o "go.pkg" "$GO_URL"
pkgutil --expand-full "go.pkg" "go_pkg"
mkdir -p "$GO_INSTALL_DIR"
tar -C "$GO_INSTALL_DIR" -xzf "go_pkg/Payload~" --strip-components=3
rm -rf "go.pkg" "go_pkg"
fi

export GOROOT="$GO_INSTALL_DIR"
export PATH="$GOROOT/bin:$PATH"

echo_info "Go $REQUIRED_GO_VERSION installed at $GOROOT"

go version

else
echo_info "Using Go $REQUIRED_GO_VERSION installed on the system."
echo_error "O Go não está instalado no sistema."
exit 1
fi

VENTANA_DIR="$HOME/ventana"
if [[ -d "$VENTANA_DIR" ]]; then
echo_info "Directory $VENTANA_DIR already exists. Updating repository..."
echo_info "O diretório $VENTANA_DIR já existe. Atualizando o repositório..."
cd "$VENTANA_DIR"
git pull
else
echo_info "Cloning Ventana repository..."
echo_info "Clonando o repositório Ventana..."
git clone https://github.com/pedrovian4/Ventana.git "$VENTANA_DIR"
fi

cd "$VENTANA_DIR"

echo_info "Building Ventana..."
echo_info "Compilando o Ventana..."
go build -o ventana ./cmd/ventana

echo_info "Installing Ventana to /usr/local/bin..."
echo_info "Instalando o Ventana em /usr/local/bin..."
sudo mv ventana /usr/local/bin/

CONFIG_DIR="$HOME/.config/ventana"
mkdir -p "$CONFIG_DIR"

echo_info "Copying messages directory to $CONFIG_DIR..."
echo_info "Copiando o diretório de mensagens para $CONFIG_DIR..."
cp -r "$VENTANA_DIR/messages" "$CONFIG_DIR/"

if [ "$USE_SYSTEM_GO" = false ]; then
echo_info "Cleaning up local Go installation..."
rm -rf "$GO_INSTALL_DIR"
fi

echo_info "Installation complete! Check by running 'ventana'"
echo_info "Instalação concluída! Verifique executando 'ventana'"

echo_info "Installation finished."
echo_info "Instalação finalizada."

0 comments on commit f293564

Please sign in to comment.