Skip to content

Commit 983206f

Browse files
author
Andrew Lorente
committed
Make an effort to install and use GNU-style utils [EFForg#1504]
The BSD versions of readlink and mktemp have totally different behavior from their GNU counterparts. It's possible that, at every site where we use them, there's a way to get what we need from the BSD version, but it seems more straightforward to install & use the GNU versions (especially since install-dev-dependencies.sh already installs gnu-sed).
1 parent 645eba2 commit 983206f

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

install-dev-dependencies.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if type apt-get >/dev/null ; then
77
firefox chromium-browser zip sqlite3 python-pip libcurl4-openssl-dev
88
elif type brew >/dev/null ; then
99
brew list python &>/dev/null || brew install python
10+
brew list coreutils &>/dev/null || brew install coreutils
1011
brew install libxml2 gnu-sed
1112
if ! echo $PATH | grep -ql /usr/local/bin ; then
1213
echo '/usr/local/bin not found in $PATH, please add it.'

locate-gnu-utils.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash -ex
2+
3+
# BSD readlink and mktemp have different APIs from their GNU counterparts. On
4+
# OSX systems we'll have g-prefixed GNU versions installed by Homebrew. Real
5+
# BSD systems are still left in the cold.
6+
7+
READLINK=$(which readlink 2>/dev/null)
8+
GREADLINK=$(which greadlink 2>/dev/null)
9+
if [ -x "$GREADLINK" ]; then
10+
READLINK="$GREADLINK"
11+
fi
12+
13+
MKTEMP=$(which mktemp 2>/dev/null)
14+
GMKTEMP=$(which gmktemp 2>/dev/null)
15+
if [ -x "$GMKTEMP" ]; then
16+
MKTEMP="$GMKTEMP"
17+
fi
18+
19+
check_for_gnu_version() {
20+
gnu_available=$("$1" --version 2>&1 | grep GNU)
21+
if [ ! "$gnu_available" ]; then
22+
echo "Could not locate a GNU version of ${2}. This may mean you're using "\
23+
"a non-OSX BSD system, which these scripts don't know how to handle. "
24+
echo "If you are indeed using OSX, something may have gone wrong running "\
25+
"install-dev-dependencies.sh. Look for errors related to coreutils."
26+
exit 1
27+
fi
28+
}
29+
30+
check_for_gnu_version "$MKTEMP" "mktemp"
31+
check_for_gnu_version "$READLINK" "readlink"

run-chromium.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# Build the extension and run a chromium extension with it installed.
44
#
55
set -o errexit -o xtrace
6+
67
cd $(dirname $0)
8+
source locate-gnu-utils.sh
79
source makecrx.sh
8-
PROFILE_DIRECTORY="$(mktemp -d)"
10+
PROFILE_DIRECTORY="$("$MKTEMP" -d)"
911
trap 'rm -r "$PROFILE_DIRECTORY"' EXIT
1012
chromium-browser \
1113
--user-data-dir="$PROFILE_DIRECTORY" \

test-ruleset-coverage.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# Test that all rulesets modified after a certain date have sufficient test
44
# coverage, according to the ruleset checker.
55
#
6+
67
cd $(dirname $0)
7-
TMP=`mktemp`
8+
source locate-gnu-utils.sh
9+
TMP=`"$MKTEMP"`
810
trap 'rm "$TMP"' EXIT
911
if ! [ -d https-everywhere-checker ] ; then
1012
echo "Submodule https-everywhere-checker is missing. Run"

test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#!/bin/bash -ex
22
# Run tests for HTTPS Everywhere
33

4+
source locate-gnu-utils.sh
5+
46
# We have to change to the right directory because this is sometimes invoked
57
# through a symlink in .git/hooks/pre-push.
6-
cd $(dirname $(readlink -f $0))
8+
cd $(dirname $("$READLINK" -f $0))
79

810
# dummy Jetpack addon that contains tests
911
TEST_ADDON_PATH=./https-everywhere-tests/
1012

1113
# We'll create a Firefox profile here and install HTTPS Everywhere into it.
12-
PROFILE_DIRECTORY="$(mktemp -d)"
14+
PROFILE_DIRECTORY="$("$MKTEMP" -d)"
1315
trap 'rm -r "$PROFILE_DIRECTORY"' EXIT
1416
HTTPSE_INSTALL_DIRECTORY=$PROFILE_DIRECTORY/extensions/https-everywhere@eff.org
1517

0 commit comments

Comments
 (0)