|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 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 |
3 | 17 | echo "Downloading Rollkit source code..." |
4 | 18 | git clone https://github.com/rollkit/rollkit.git |
5 | 19 |
|
| 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 |
6 | 36 | 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" |
9 | 39 | fi |
10 | 40 |
|
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 | + |
13 | 61 | echo "Building and installing Rollkit..." |
14 | 62 | make install |
| 63 | + |
15 | 64 | cd .. |
16 | 65 | echo "Installation completed successfully." |
| 66 | +echo "Cleaning up downloads..." |
| 67 | +rm -rf rollkit |
17 | 68 |
|
0 commit comments