install-foundry 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # This script install foundry and the solidity compiler required to build the
  3. # ethereum contracts. Foundry itself provides a mechanism to install solc, but
  4. # it doesn't work with certain firewall configurations.
  5. set -euo pipefail
  6. # check if foundry.toml exists
  7. if [ ! -f foundry.toml ]; then
  8. echo "foundry.toml not found. Please call from the ethereum directory." >& 2
  9. exit 1
  10. fi
  11. # Read compiler version from foundry.toml
  12. SOLC_VERSION=$(grep solc_version foundry.toml | cut -d'=' -f2 | tr -d '" ') || true
  13. if [ -z "$SOLC_VERSION" ]; then
  14. echo "solc_version not found in foundry.toml." >& 2
  15. exit 1
  16. fi
  17. main() {
  18. OS=$(uname -s)
  19. case "$OS" in
  20. Darwin)
  21. install_mac
  22. ;;
  23. Linux)
  24. install_linux
  25. ;;
  26. *)
  27. echo "Unsupported OS: $OS"
  28. exit 1
  29. ;;
  30. esac
  31. }
  32. function install_mac() {
  33. if ! command -v brew > /dev/null; then
  34. echo "brew is unavailable. Please install: https://brew.sh"
  35. fi
  36. if ! brew list libusb > /dev/null 2>&1; then
  37. echo "Installing libusb"
  38. brew install libusb
  39. fi
  40. if ! command -v foundryup > /dev/null; then
  41. curl -L https://foundry.paradigm.xyz --silent | bash
  42. "$HOME/.foundry/bin/foundryup"
  43. fi
  44. INSTALL_DIR="$HOME/.svm/$SOLC_VERSION"
  45. mkdir -p "$INSTALL_DIR"
  46. SOLC_PATH="$INSTALL_DIR/solc-$SOLC_VERSION"
  47. if [ ! -f "$SOLC_PATH" ]; then
  48. echo "Installing solc-$SOLC_VERSION"
  49. curl -L --silent "https://github.com/ethereum/solidity/releases/download/v$SOLC_VERSION/solc-macos" > "$SOLC_PATH"
  50. chmod +x "$SOLC_PATH"
  51. echo "Installed $SOLC_PATH"
  52. else
  53. echo "Solidity compiler found: $SOLC_PATH"
  54. fi
  55. }
  56. function install_linux() {
  57. if ! command -v foundryup > /dev/null; then
  58. curl -L https://foundry.paradigm.xyz --silent | bash
  59. "$HOME/.foundry/bin/foundryup"
  60. fi
  61. INSTALL_DIR="$HOME/.svm/$SOLC_VERSION"
  62. mkdir -p "$INSTALL_DIR"
  63. SOLC_PATH="$INSTALL_DIR/solc-$SOLC_VERSION"
  64. if [ ! -f "$SOLC_PATH" ]; then
  65. echo "Installing solc-$SOLC_VERSION"
  66. curl -L --silent "https://github.com/ethereum/solidity/releases/download/v$SOLC_VERSION/solc-static-linux" > "$SOLC_PATH"
  67. chmod +x "$SOLC_PATH"
  68. echo "Installed $SOLC_PATH"
  69. else
  70. echo "Solidity compiler found: $SOLC_PATH"
  71. fi
  72. }
  73. main "$@"; exit