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

Added preinstall script #955

Merged
merged 7 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"hardhat/**/@ethereumjs/tx": "3.5.0"
},
"scripts": {
"preinstall": "bash preinstall.sh",
"postinstall": "patch-package",
"prepare": "yarn prepare:husky",
"prepare:husky": "husky install",
Expand Down
66 changes: 66 additions & 0 deletions preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

echo "Setting up the development environment..."

mirooon marked this conversation as resolved.
Show resolved Hide resolved
# Function to install a package if not already installed
install_package_linux() {
PACKAGE=$1
if ! command -v $PACKAGE &> /dev/null; then
echo "Installing $PACKAGE on Linux..."
sudo apt-get update -y
ezynda3 marked this conversation as resolved.
Show resolved Hide resolved
sudo apt-get install -y $PACKAGE
else
echo "$PACKAGE is already installed."
fi
}

install_package_mac() {
PACKAGE=$1
if ! command -v $PACKAGE &> /dev/null; then
mirooon marked this conversation as resolved.
Show resolved Hide resolved
echo "Installing $PACKAGE on macOS..."
brew install $PACKAGE
else
echo "$PACKAGE is already installed."
fi
}
mirooon marked this conversation as resolved.
Show resolved Hide resolved

# Detect the operating system
OS=$(uname -s)

if [[ "$OS" == "Linux" ]]; then
echo "Detected Linux. Using apt package manager."
install_package_linux jq
install_package_linux bc
elif [[ "$OS" == "Darwin" ]]; then
echo "Detected macOS. Using Homebrew package manager."

# Check if Homebrew is installed
if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed. Installing Homebrew..."
# Download script first to allow inspection
BREW_SCRIPT=$(mktemp)
if ! curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh -o "$BREW_SCRIPT"; then
echo "Failed to download Homebrew install script"
rm -f "$BREW_SCRIPT"
exit 1
fi
# Execute the downloaded script
if ! /bin/bash "$BREW_SCRIPT"; then
echo "Failed to install Homebrew"
rm -f "$BREW_SCRIPT"
exit 1
fi
rm -f "$BREW_SCRIPT"
# Add Homebrew to PATH for immediate use
eval "$("$(brew --prefix)/bin/brew" shellenv)"
fi

install_package_mac jq
install_package_mac bc
else
echo "Unsupported operating system: $OS"
echo "Please install jq and bc manually."
exit 1
fi

echo "All necessary packages are installed."
Loading