1#!/bin/bash
2# Script that adds rules to Mac OS X Socket Firewall to avoid
3# popups asking to accept incoming network connections when
4# running tests.
5SFW="/usr/libexec/ApplicationFirewall/socketfilterfw"
6TOOLSDIR="`dirname \"$0\"`"
7TOOLSDIR="`( cd \"$TOOLSDIR\" && pwd) `"
8ROOTDIR="`( cd \"$TOOLSDIR/..\" && pwd) `"
9OUTDIR="$TOOLSDIR/../out"
10# Using cd and pwd here so that the path used for socketfilterfw does not
11# contain a '..', which seems to cause the rules to be incorrectly added
12# and they are not removed when this script is re-run. Instead the new
13# rules are simply appended. By using pwd we can get the full path
14# without '..' and things work as expected.
15OUTDIR="`( cd \"$OUTDIR\" && pwd) `"
16NODE_RELEASE="$OUTDIR/Release/node"
17NODE_DEBUG="$OUTDIR/Debug/node"
18NODE_LINK="$ROOTDIR/node"
19CCTEST_RELEASE="$OUTDIR/Release/cctest"
20CCTEST_DEBUG="$OUTDIR/Debug/cctest"
21OPENSSL_CLI_RELEASE="$OUTDIR/Release/openssl-cli"
22OPENSSL_CLI_DEBUG="$OUTDIR/Debug/openssl-cli"
23
24if [ -f $SFW ];
25then
26  # Duplicating these commands on purpose as the symbolic link node might be
27  # linked to either out/Debug/node or out/Release/node depending on the
28  # BUILDTYPE.
29  $SFW --remove "$NODE_DEBUG"
30  $SFW --remove "$NODE_DEBUG"
31  $SFW --remove "$NODE_RELEASE"
32  $SFW --remove "$NODE_RELEASE"
33  $SFW --remove "$NODE_LINK"
34  $SFW --remove "$CCTEST_DEBUG"
35  $SFW --remove "$CCTEST_RELEASE"
36  $SFW --remove "$OPENSSL_CLI_DEBUG"
37  $SFW --remove "$OPENSSL_CLI_RELEASE"
38
39  $SFW --add "$NODE_DEBUG"
40  $SFW --add "$NODE_RELEASE"
41  $SFW --add "$NODE_LINK"
42  $SFW --add "$CCTEST_DEBUG"
43  $SFW --add "$CCTEST_RELEASE"
44  $SFW --add "$OPENSSL_CLI_DEBUG"
45  $SFW --add "$OPENSSL_CLI_RELEASE"
46
47  $SFW --unblock "$NODE_DEBUG"
48  $SFW --unblock "$NODE_RELEASE"
49  $SFW --unblock "$NODE_LINK"
50  $SFW --unblock "$CCTEST_DEBUG"
51  $SFW --unblock "$CCTEST_RELEASE"
52  $SFW --unblock "$OPENSSL_CLI_DEBUG"
53  $SFW --unblock "$OPENSSL_CLI_RELEASE"
54else
55  echo "SocketFirewall not found in location: $SFW"
56fi
57