github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/scripts/print-addresses.sh (about)

     1  #!/bin/bash
     2  
     3  # Get the directory of the script itself
     4  SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
     5  
     6  # Check if the first argument is provided
     7  if [ -z "$1" ]; then
     8      echo "Usage: $0 <directory-name>"
     9      exit 1
    10  fi
    11  
    12  # Check if jq is installed
    13  if ! command -v jq &> /dev/null; then
    14      echo "jq is not installed. Please install it to run this script."
    15      exit 1
    16  fi
    17  
    18  # Directory name from the argument
    19  DIR_NAME=$1
    20  
    21  # Check for the --sdk flag
    22  SDK_MODE=false
    23  if [[ "$2" == "--sdk" ]]; then
    24      SDK_MODE=true
    25  fi
    26  
    27  # Full directory path, relative from the script's location
    28  DIR="$SCRIPT_DIR/../deployments/$DIR_NAME"
    29  
    30  # Check if the directory exists
    31  if [ ! -d "$DIR" ]; then
    32      echo "Directory does not exist: $DIR"
    33      exit 1
    34  fi
    35  
    36  # Declare an array of filenames to check when in SDK mode
    37  declare -a SDK_FILES=("AddressManager" "L1CrossDomainMessengerProxy" "L1StandardBridgeProxy" "OptimismPortalProxy" "L2OutputOracleProxy")
    38  
    39  # Loop through each .json file in the directory
    40  for file in "$DIR"/*.json; do
    41      # Extract the filename without the directory and the .json extension
    42      filename=$(basename "$file" .json)
    43  
    44      # If SDK mode is on and the filename is not in the list, skip it
    45      # shellcheck disable=SC2199,SC2076
    46      if $SDK_MODE && [[ ! " ${SDK_FILES[@]} " =~ " ${filename} " ]]; then
    47          continue
    48      fi
    49  
    50      # Extract the 'address' field from the JSON file
    51      address=$(jq -r '.address' "$file")
    52  
    53      # Print the filename and the address
    54      echo "${filename}: ${address}"
    55  done