Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit ac924f7

Browse files
committed
feat: add go version comparison to rollkit install script
1 parent 0ea3d02 commit ac924f7

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

public/install.sh

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,68 @@
11
#!/bin/bash
22

3+
# Function to compare versions
4+
compare_versions() {
5+
if [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]; then
6+
if [ "$1" = "$2" ]; then
7+
return 0 # Equal
8+
else
9+
return 1 # First is less
10+
fi
11+
else
12+
return 2 # First is greater
13+
fi
14+
}
15+
16+
# Step 1: Download Rollkit source code
317
echo "Downloading Rollkit source code..."
418
git clone https://github.com/rollkit/rollkit.git
519

20+
# Navigate into the Rollkit repository
21+
cd rollkit || { echo "Failed to find the downloaded repository."; exit 1; }
22+
23+
# Step 2: Extract the Go version from the go.mod file in the Rollkit repo
24+
go_mod_version=$(grep "^go " go.mod | cut -d' ' -f2)
25+
26+
# Check if go.mod version was found
27+
if [ -z "$go_mod_version" ]; then
28+
echo "Error: Could not find a Go version in go.mod."
29+
exit 1
30+
fi
31+
32+
# Format Go version for installation (e.g., "1.22.2" -> "go1.22.2")
33+
formatted_go_version="go${go_mod_version}"
34+
35+
# Step 3: Check if Go is installed
636
if ! which go > /dev/null; then
7-
echo "Go is not installed. Attempting to install Go..."
8-
curl -sL "https://rollkit.dev/install-go.sh" | sh -s "go1.22.2"
37+
echo "Go is not installed. Attempting to install Go..."
38+
curl -sL "https://rollkit.dev/install-go.sh" | sh -s "$formatted_go_version"
939
fi
1040

11-
cd rollkit || { echo "Failed to find the downloaded repository."; exit 1; }
12-
git fetch && git checkout $1
41+
# Get the installed Go version
42+
installed_version=$(go version | awk '{print $3}' | sed 's/go//')
43+
44+
# Step 4: Validate installed version
45+
compare_versions "$installed_version" "$go_mod_version"
46+
comparison_result=$?
47+
48+
if [ $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."
51+
exit 1
52+
elif [ $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."
55+
fi
56+
57+
# Step 5: Continue with the installation of Rollkit
58+
echo "Fetching and checking out the specified branch or tag..."
59+
git fetch && git checkout "$1"
60+
1361
echo "Building and installing Rollkit..."
1462
make install
63+
1564
cd ..
1665
echo "Installation completed successfully."
66+
echo "Cleaning up downloads..."
67+
rm -rf rollkit
1768

0 commit comments

Comments
 (0)