| #!/usr/bin/env bash | |
| # Copyright 2018 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| #### CATEGORY=Other | |
| ### register Zircon tools at MacOS Application Firewall | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? | |
| fx-config-read | |
| FIREWALL_CMD="/usr/libexec/ApplicationFirewall/socketfilterfw" | |
| function list_tools() { | |
| TOOL_LIST="$(${FIREWALL_CMD} --listapps | grep "${FUCHSIA_DIR}" | awk '{print $3}')" | |
| for f in "${TOOL_LIST[@]}"; do | |
| echo "${f}" | |
| done | |
| } | |
| function clear_tools() { | |
| TOOL_LIST="$(${FIREWALL_CMD} --listapps | grep "${FUCHSIA_DIR}" | awk '{print $3}')" | |
| for f in ${TOOL_LIST}; do | |
| sudo ${FIREWALL_CMD} --remove "${f}" &> /dev/null | |
| done | |
| } | |
| function allow_tools() { | |
| for f in ${ZIRCON_TOOLS_DIR}/*; do | |
| sudo ${FIREWALL_CMD} --add "$f" --unblockapp "$f" &> /dev/null | |
| done | |
| for f in ${FUCHSIA_BUILD_DIR}/host-tools/*; do | |
| sudo ${FIREWALL_CMD} --add "$f" --unblockapp "$f" &> /dev/null | |
| done | |
| } | |
| function main() { | |
| echo " clearing firewall rules.." | |
| clear_tools | |
| echo " adding firewall rules.." | |
| allow_tools | |
| # Activate the changes | |
| sudo ${FIREWALL_CMD} --setglobalstate off &> /dev/null | |
| sudo ${FIREWALL_CMD} --setglobalstate on &> /dev/null | |
| echo "..done" | |
| echo " following tools are registered in the firewall rules:" | |
| echo " " | |
| list_tools | |
| echo " " | |
| } | |
| main |