11#! /bin/bash
22
3+ # Define colors for output
4+ RED=" \033[31m"
5+ GREEN=" \033[32m"
6+ YELLOW=" \033[33m"
7+ CYAN=" \033[36m"
8+ BOLD=" \033[1m"
9+ RESET=" \033[0m"
10+
11+ # Function to print headers
12+ print_header () {
13+ echo -e " ${CYAN}${BOLD} --> $1 ${RESET} "
14+ }
15+
16+ # Function to print success messages
17+ print_success () {
18+ echo -e " ${GREEN}${BOLD} $1 ${RESET} "
19+ }
20+
21+ # Function to print warnings
22+ print_warning () {
23+ echo -e " ${YELLOW}${BOLD} $1 ${RESET} "
24+ }
25+
26+ # Function to print errors
27+ print_error () {
28+ echo -e " ${RED}${BOLD} $1 ${RESET} "
29+ }
30+
331# Function to compare versions
432compare_versions () {
533 if [ " $( printf ' %s\n' " $1 " " $2 " | sort -V | head -n1) " = " $1 " ]; then
@@ -13,56 +41,55 @@ compare_versions() {
1341 fi
1442}
1543
16- # Step 1: Download Rollkit source code
17- echo " Downloading Rollkit source code..."
44+ print_header " Downloading Rollkit source code..."
1845git clone https://github.com/rollkit/rollkit.git
46+ echo " "
1947
20- # Navigate into the Rollkit repository
21- cd rollkit || { echo " Failed to find the downloaded repository." ; exit 1; }
48+ cd rollkit || { print_error " Failed to find the downloaded repository." ; exit 1; }
2249
23- # Step 2: Extract the Go version from the go.mod file in the Rollkit repo
50+ print_header " Extracting Go version from go.mod... "
2451go_mod_version=$( grep " ^go " go.mod | cut -d' ' -f2)
2552
26- # Check if go.mod version was found
2753if [ -z " $go_mod_version " ]; then
28- echo " Error: Could not find a Go version in go.mod."
54+ print_error " Error: Could not find a Go version in go.mod."
2955 exit 1
3056fi
31-
32- # Format Go version for installation (e.g., "1.22.2" -> "go1.22.2")
3357formatted_go_version=" go${go_mod_version} "
58+ echo -e " Required Go version: ${BOLD}${formatted_go_version}${RESET} \n"
3459
35- # Step 3: Check if Go is installed
60+ print_header " Checking if Go is installed... "
3661if ! which go > /dev/null; then
37- echo " Go is not installed. Attempting to install Go..."
62+ print_warning " Go is not installed. Attempting to install Go..."
3863 curl -sL " https://rollkit.dev/install-go.sh" | sh -s " $formatted_go_version "
3964fi
4065
41- # Get the installed Go version
4266installed_version=$( go version | awk ' {print $3}' | sed ' s/go//' )
67+ echo -e " Installed Go version: ${BOLD}${installed_version}${RESET} \n"
4368
44- # Step 4: Validate installed version
69+ print_header " Validating installed Go version... "
4570compare_versions " $installed_version " " $go_mod_version "
4671comparison_result=$?
4772
4873if [ $comparison_result -eq 1 ]; then
49- echo " ERROR: The installed Go version ($installed_version ) is less than the required version ($go_mod_version )."
50- echo " Please upgrade your version of go ."
74+ print_error " ERROR: The installed Go version ($installed_version ) is less than the required version ($go_mod_version )."
75+ echo " Please upgrade your version of Go ."
5176 exit 1
5277elif [ $comparison_result -eq 2 ]; then
53- echo " INFO: The installed Go version ($installed_version ) is greater than the required version ($go_mod_version )."
54- echo " If you run into issues try downgrading your version of go ."
78+ print_warning " INFO: The installed Go version ($installed_version ) is greater than the required version ($go_mod_version )."
79+ echo " If you run into issues, try downgrading your version of Go ."
5580fi
81+ echo " "
5682
57- # Step 5: Continue with the installation of Rollkit
58- echo " Fetching and checking out the specified branch or tag..."
83+ print_header " Fetching and checking out the specified branch or tag..."
5984git fetch && git checkout " $1 "
85+ echo " "
6086
61- echo " Building and installing Rollkit..."
87+ print_header " Building and installing Rollkit..."
6288make install
89+ print_success " Rollkit CLI installed successfully!"
6390
6491cd ..
65- echo " Installation completed successfully."
66- echo " Cleaning up downloads..."
92+ print_header " Cleaning up downloads..."
6793rm -rf rollkit
6894
95+ print_success " Installation completed successfully."
0 commit comments