diff --git a/scripts/l2-explorer/l2-blockscout-set-env.sh b/scripts/l2-explorer/l2-blockscout-set-env.sh index 8fe83d1..8793554 100755 --- a/scripts/l2-explorer/l2-blockscout-set-env.sh +++ b/scripts/l2-explorer/l2-blockscout-set-env.sh @@ -23,6 +23,19 @@ L1_SYSTEM_CONFIG_ADDRESS=$(jq -r '.l1_system_config_address' "$ROLLUP_JSON") OUTPUT_ORACLE_ADDRESS=$(jq -r '.L2OutputOracleProxy' "$OP_DEPLOYMENTS_JSON_PATH") # Update .explorer.env file -sed -i "s/^L1_SYSTEM_CONFIG_CONTRACT=.*/L1_SYSTEM_CONFIG_CONTRACT=$L1_SYSTEM_CONFIG_ADDRESS/" "$ENV_FILE" -sed -i "s/^L1_OUTPUT_ORACLE_CONTRACT=.*/L1_OUTPUT_ORACLE_CONTRACT=$OUTPUT_ORACLE_ADDRESS/" "$ENV_FILE" +update_env_var() { + local key="$1" + local value="$2" + local file="$3" + if grep -q "^$key=" "$file"; then + # If the key exists, replace the line + sed -i.bak "s|^$key=.*|$key=$value|" "$file" && rm "${file}.bak" + else + # If the key doesn't exist, append it + echo "$key=$value" >> "$file" + fi +} +update_env_var "L1_SYSTEM_CONFIG_CONTRACT" "$L1_SYSTEM_CONFIG_ADDRESS" "$ENV_FILE" +update_env_var "L1_OUTPUT_ORACLE_CONTRACT" "$OUTPUT_ORACLE_ADDRESS" "$ENV_FILE" + echo "Updated .explorer.env file for Blockscout" \ No newline at end of file