aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-16 04:15:05 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-16 04:25:42 +0200
commit4502350512f01ddaee8c4e6366bfbd0fedb994b3 (patch)
treec82536522169b8e2f461c7af262d844a040c3cf8 /src
parentwg-quick: darwin: restore DNS on down (diff)
downloadwireguard-tools-4502350512f01ddaee8c4e6366bfbd0fedb994b3.tar.xz
wireguard-tools-4502350512f01ddaee8c4e6366bfbd0fedb994b3.zip
wg-quick: darwin: use bash from environment and require bash 4+
For properly configured Homebrew installations /usr/local/bin should be before /bin, so this should still work. This allows the script to be used in more than one setting. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/wg-quick/darwin.bash26
-rwxr-xr-xsrc/wg-quick/linux.bash20
2 files changed, 23 insertions, 23 deletions
diff --git a/src/wg-quick/darwin.bash b/src/wg-quick/darwin.bash
index ba1e49b..4a3240c 100755
--- a/src/wg-quick/darwin.bash
+++ b/src/wg-quick/darwin.bash
@@ -1,11 +1,9 @@
-#!/usr/local/bin/bash
+#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
#
-# The shebang is in /usr/local because this requires bash 4.
-
set -e -o pipefail
shopt -s extglob
export LC_ALL=C
@@ -29,6 +27,18 @@ CONFIG_FILE=""
PROGRAM="${0##*/}"
ARGS=( "$@" )
+cmd() {
+ echo "[#] $*" >&2
+ "$@"
+}
+
+die() {
+ echo "$PROGRAM: $*" >&2
+ exit 1
+}
+
+[[ ${BASH_VERSINFO[0]} -ge 4 ]] || die "Version mismatch: bash ${BASH_VERSINFO[0]} detected, when bash 4+ required"
+
parse_options() {
local interface_section=0 line key value stripped
CONFIG_FILE="$1"
@@ -71,16 +81,6 @@ read_bool() {
esac
}
-cmd() {
- echo "[#] $*" >&2
- "$@"
-}
-
-die() {
- echo "$PROGRAM: $*" >&2
- exit 1
-}
-
auto_su() {
[[ $UID == 0 ]] || exec sudo -p "$PROGRAM must be run as root. Please enter the password for %u to continue: " "$SELF" "${ARGS[@]}"
}
diff --git a/src/wg-quick/linux.bash b/src/wg-quick/linux.bash
index cd66b4d..38ccad2 100755
--- a/src/wg-quick/linux.bash
+++ b/src/wg-quick/linux.bash
@@ -26,6 +26,16 @@ CONFIG_FILE=""
PROGRAM="${0##*/}"
ARGS=( "$@" )
+cmd() {
+ echo "[#] $*" >&2
+ "$@"
+}
+
+die() {
+ echo "$PROGRAM: $*" >&2
+ exit 1
+}
+
parse_options() {
local interface_section=0 line key value stripped
CONFIG_FILE="$1"
@@ -68,16 +78,6 @@ read_bool() {
esac
}
-cmd() {
- echo "[#] $*" >&2
- "$@"
-}
-
-die() {
- echo "$PROGRAM: $*" >&2
- exit 1
-}
-
auto_su() {
[[ $UID == 0 ]] || exec sudo -p "$PROGRAM must be run as root. Please enter the password for %u to continue: " "$SELF" "${ARGS[@]}"
}