From ac924f7d743be4ccbcc4bcfadb48a4c23b00e89b Mon Sep 17 00:00:00 2001 From: Matthew Sevey <15232757+MSevey@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:57:36 -0500 Subject: [PATCH 1/2] feat: add go version comparison to rollkit install script --- public/install.sh | 59 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/public/install.sh b/public/install.sh index b459fbbb1..1eee7c76a 100755 --- a/public/install.sh +++ b/public/install.sh @@ -1,17 +1,68 @@ #!/bin/bash +# Function to compare versions +compare_versions() { + if [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]; then + if [ "$1" = "$2" ]; then + return 0 # Equal + else + return 1 # First is less + fi + else + return 2 # First is greater + fi +} + +# Step 1: Download Rollkit source code echo "Downloading Rollkit source code..." git clone https://github.com/rollkit/rollkit.git +# Navigate into the Rollkit repository +cd rollkit || { echo "Failed to find the downloaded repository."; exit 1; } + +# Step 2: Extract the Go version from the go.mod file in the Rollkit repo +go_mod_version=$(grep "^go " go.mod | cut -d' ' -f2) + +# Check if go.mod version was found +if [ -z "$go_mod_version" ]; then + echo "Error: Could not find a Go version in go.mod." + exit 1 +fi + +# Format Go version for installation (e.g., "1.22.2" -> "go1.22.2") +formatted_go_version="go${go_mod_version}" + +# Step 3: Check if Go is installed if ! which go > /dev/null; then - echo "Go is not installed. Attempting to install Go..." - curl -sL "https://rollkit.dev/install-go.sh" | sh -s "go1.22.2" + echo "Go is not installed. Attempting to install Go..." + curl -sL "https://rollkit.dev/install-go.sh" | sh -s "$formatted_go_version" fi -cd rollkit || { echo "Failed to find the downloaded repository."; exit 1; } -git fetch && git checkout $1 +# Get the installed Go version +installed_version=$(go version | awk '{print $3}' | sed 's/go//') + +# Step 4: Validate installed version +compare_versions "$installed_version" "$go_mod_version" +comparison_result=$? + +if [ $comparison_result -eq 1 ]; then + echo "ERROR: The installed Go version ($installed_version) is less than the required version ($go_mod_version)." + echo " Please upgrade your version of go." + exit 1 +elif [ $comparison_result -eq 2 ]; then + echo "INFO: The installed Go version ($installed_version) is greater than the required version ($go_mod_version)." + echo " If you run into issues try downgrading your version of go." +fi + +# Step 5: Continue with the installation of Rollkit +echo "Fetching and checking out the specified branch or tag..." +git fetch && git checkout "$1" + echo "Building and installing Rollkit..." make install + cd .. echo "Installation completed successfully." +echo "Cleaning up downloads..." +rm -rf rollkit From 9ca90c8914d77efc8e7d70d9521d58d916738999 Mon Sep 17 00:00:00 2001 From: MSevey <15232757+MSevey@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:18:43 -0500 Subject: [PATCH 2/2] chore: update formatting of print outs --- public/install.sh | 71 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/public/install.sh b/public/install.sh index 1eee7c76a..fa6fe850a 100755 --- a/public/install.sh +++ b/public/install.sh @@ -1,5 +1,33 @@ #!/bin/bash +# Define colors for output +RED="\033[31m" +GREEN="\033[32m" +YELLOW="\033[33m" +CYAN="\033[36m" +BOLD="\033[1m" +RESET="\033[0m" + +# Function to print headers +print_header() { + echo -e "${CYAN}${BOLD}--> $1${RESET}" +} + +# Function to print success messages +print_success() { + echo -e "${GREEN}${BOLD}$1${RESET}" +} + +# Function to print warnings +print_warning() { + echo -e "${YELLOW}${BOLD}$1${RESET}" +} + +# Function to print errors +print_error() { + echo -e "${RED}${BOLD}$1${RESET}" +} + # Function to compare versions compare_versions() { if [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]; then @@ -13,56 +41,55 @@ compare_versions() { fi } -# Step 1: Download Rollkit source code -echo "Downloading Rollkit source code..." +print_header "Downloading Rollkit source code..." git clone https://github.com/rollkit/rollkit.git +echo "" -# Navigate into the Rollkit repository -cd rollkit || { echo "Failed to find the downloaded repository."; exit 1; } +cd rollkit || { print_error "Failed to find the downloaded repository."; exit 1; } -# Step 2: Extract the Go version from the go.mod file in the Rollkit repo +print_header "Extracting Go version from go.mod..." go_mod_version=$(grep "^go " go.mod | cut -d' ' -f2) -# Check if go.mod version was found if [ -z "$go_mod_version" ]; then - echo "Error: Could not find a Go version in go.mod." + print_error "Error: Could not find a Go version in go.mod." exit 1 fi - -# Format Go version for installation (e.g., "1.22.2" -> "go1.22.2") formatted_go_version="go${go_mod_version}" +echo -e " Required Go version: ${BOLD}${formatted_go_version}${RESET}\n" -# Step 3: Check if Go is installed +print_header "Checking if Go is installed..." if ! which go > /dev/null; then - echo "Go is not installed. Attempting to install Go..." + print_warning "Go is not installed. Attempting to install Go..." curl -sL "https://rollkit.dev/install-go.sh" | sh -s "$formatted_go_version" fi -# Get the installed Go version installed_version=$(go version | awk '{print $3}' | sed 's/go//') +echo -e " Installed Go version: ${BOLD}${installed_version}${RESET}\n" -# Step 4: Validate installed version +print_header "Validating installed Go version..." compare_versions "$installed_version" "$go_mod_version" comparison_result=$? if [ $comparison_result -eq 1 ]; then - echo "ERROR: The installed Go version ($installed_version) is less than the required version ($go_mod_version)." - echo " Please upgrade your version of go." + print_error "ERROR: The installed Go version ($installed_version) is less than the required version ($go_mod_version)." + echo " Please upgrade your version of Go." exit 1 elif [ $comparison_result -eq 2 ]; then - echo "INFO: The installed Go version ($installed_version) is greater than the required version ($go_mod_version)." - echo " If you run into issues try downgrading your version of go." + print_warning "INFO: The installed Go version ($installed_version) is greater than the required version ($go_mod_version)." + echo " If you run into issues, try downgrading your version of Go." fi +echo "" -# Step 5: Continue with the installation of Rollkit -echo "Fetching and checking out the specified branch or tag..." +print_header "Fetching and checking out the specified branch or tag..." git fetch && git checkout "$1" +echo "" -echo "Building and installing Rollkit..." +print_header "Building and installing Rollkit..." make install +print_success "Rollkit CLI installed successfully!" cd .. -echo "Installation completed successfully." -echo "Cleaning up downloads..." +print_header "Cleaning up downloads..." rm -rf rollkit +print_success "Installation completed successfully."