Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: install script compiles all dependencies locally #211

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 94 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
VERSION="v0.0.0"

# The list of projects to be installed
PROJECTS=("dymension" "dymension-relayer" "roller" "dymension-rdk" "celestia-node")
REPOS=("" "" "" "" "https://github.com/celestiaorg/celestia-node")
VERSIONS=("" "" "" "" "v0.6.4")
BUILDCOMMANDS=("" "" "" "make install_evm" "make go-install install-key")
BINARYNAME=("dymd" "rly" "roller" "rollapp_evm" "celestia cel-key")

# Set the appropriate download URL
if [[ "$ARCH" == "x86_64" ]]; then
ARCH="amd64"
Expand All @@ -35,16 +42,95 @@ fi
sudo mkdir -p "$INTERNAL_DIR"
sudo mkdir -p "/tmp/roller_tmp"

# Function to display Go installation instructions
GO_REQUIRED_VERSION="1.19"
display_go_installation_instructions() {
echo "$EMOJI To install Go $GO_REQUIRED_VERSION, you can run the following commands:"
echo " wget https://go.dev/dl/go1.19.10.${OS}-${ARCH}.tar.gz"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shaolin-flow add wget as a requirement for the docs

echo " sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.19.10.${OS}-${ARCH}.tar.gz"
}

# Download and extract the tar file to a temporary directory
echo "$EMOJI Downloading roller..."
sudo curl -L "$TGZ_URL" --progress-bar | sudo tar -xz -C "/tmp/roller_tmp"

# Assuming that the tar file contains the lib folder and the roller and rollapp_evm binaries inside the roller_bins directory.
# Move binaries to their correct locations
echo "$EMOJI Installing roller..."
sudo mv "/tmp/roller_tmp/roller_bins/lib"/* "$INTERNAL_DIR"
sudo mv "/tmp/roller_tmp/roller_bins/roller" "$ROLLER_BIN_PATH"
sudo mv "/tmp/roller_tmp/roller_bins/rollapp_evm" "$ROLLAPP_EVM_PATH" # move the rollapp_evm binary
if sudo curl -L "$TGZ_URL" --progress-bar | sudo tar -xz -C "/tmp/roller_tmp"; then
# Assuming that the tar file contains the lib folder and the roller and rollapp_evm binaries inside the roller_bins directory.
# Move binaries to their correct locations
echo "$EMOJI Installing roller..."
sudo mv "/tmp/roller_tmp/roller_bins/lib"/* "$INTERNAL_DIR"
sudo mv "/tmp/roller_tmp/roller_bins/roller" "$ROLLER_BIN_PATH"
sudo mv "/tmp/roller_tmp/roller_bins/rollapp_evm" "$ROLLAPP_EVM_PATH" # move the rollapp_evm binary
else
# Curl failed. Fallback to clone and build.
echo "$EMOJI Download failed. Cloning and building manually..."
# Check prerequisites
command -v curl >/dev/null 2>&1 || { echo >&2 "$EMOJI curl is required but it's not installed. Aborting."; exit 1; }
command -v wget >/dev/null 2>&1 || { echo >&2 "$EMOJI wget is required but it's not installed. Aborting."; exit 1; }
command -v git >/dev/null 2>&1 || { echo >&2 "$EMOJI git is required but it's not installed. Aborting."; exit 1; }
if ! command -v go >/dev/null 2>&1; then
echo >&2 "$EMOJI Go is required but it's not installed. Aborting."
display_go_installation_instructions
exit 1;
fi

# Check go version
GO_VERSION=$(go version | awk -F' ' '{print substr($3, 3, 4)}') # Extract major.minor version number (remove the 'go' prefix)
if [ "$GO_VERSION" != "$GO_REQUIRED_VERSION" ]; then
echo "$EMOJI Go version $GO_REQUIRED_VERSION is required, but you have version $GO_VERSION. Aborting."
display_go_installation_instructions
exit 1
fi

for i in "${!PROJECTS[@]}"; do
echo "$EMOJI handling ${PROJECTS[i]}..."
cd /tmp

# Check if binaries already exist
IFS=' ' read -r -a binary_array <<< "${BINARYNAME[i]}" # convert string to array
binary=${binary_array[0]} # get the first element
echo "$EMOJI checking for $binary..."
if [ -x "$(command -v "$binary")" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for that - if the binary not exist in the roller path, we want to install it. this will cause versioning problems

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or verify the binary version as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if the binary does exist, I'm want to let the user know it's gonna be overridden

read -p "$binary already exists. Do you want to overwrite it? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
binary_path=$(which "$binary" 2> /dev/null) # Redirect error output to /dev/null
sudo cp "$binary_path" "$INTERNAL_DIR"
continue 1
else
rm -f "$binary_path"
fi
fi

REPO_URL=${REPOS[i]:-"https://github.com/dymensionxyz/${PROJECTS[i]}"}
if [ ! -d "/tmp/${PROJECTS[i]}" ]; then
git clone "$REPO_URL"
fi
cd "${PROJECTS[i]}"
if [ -n "${VERSIONS[i]}" ]; then
git checkout "${VERSIONS[i]}"
fi
if [ -n "${BUILDCOMMANDS[i]}" ]; then
${BUILDCOMMANDS[i]}
else
make install
fi

for binary in ${BINARYNAME[i]}; do
if [ ! -x "$(command -v "$binary")" ]; then
echo "$EMOJI Couldn't find $binary in PATH. Aborting."; exit 1;
fi
binary_path=$(which "$binary" 2> /dev/null) # Redirect error output to /dev/null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problematic again. the user may have both the standard and the dymension relayer on the same machine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case the user had the option to use the existing one or overwrite

sudo cp "$binary_path" "$INTERNAL_DIR"
done
done


# Move roller and rollapp_evm separately
sudo mv "$INTERNAL_DIR/roller" "$ROLLER_BIN_PATH"
sudo mv "$INTERNAL_DIR/rollapp_evm" "$ROLLAPP_EVM_PATH"

fi



# Make roller and rollapp_evm executables
sudo chmod +x "$ROLLER_BIN_PATH"
Expand Down