From 6408b622bfa3d76923d99e52e75a645ceb4d20fd Mon Sep 17 00:00:00 2001 From: Travis Paul Date: Thu, 29 Nov 2018 12:47:37 +0800 Subject: [PATCH 1/7] Add NetBSD and SunOS support to md5sum_file. --- bin/_blackbox_common.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index de5e1ab..2786781 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -411,6 +411,12 @@ function md5sum_file() { Darwin | FreeBSD ) md5 -r "$1" | awk '{ print $1 }' ;; + NetBSD ) + md5 -q "$1" + ;; + SunOS ) + digest -a md5 "$1" + ;; Linux | CYGWIN* | MINGW* ) md5sum "$1" | awk '{ print $1 }' ;; From b3b0604be7a4913186a324a6dbbb1e9a40c09da5 Mon Sep 17 00:00:00 2001 From: Travis Paul Date: Thu, 29 Nov 2018 13:27:06 +0800 Subject: [PATCH 2/7] Add NetBSD and SunOS support to cp_permissions. Note that this likely won't work on Solaris without Coreutils as Solaris lacks stat(1). SmartOS has stat from Coreutils in base and the chmod(1) from it's OpenSolaris heritage. Using the chmod from either Coreutils or Solaris will work the same (in this case) on SmartOS. --- bin/_blackbox_common.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/_blackbox_common.sh b/bin/_blackbox_common.sh index 2786781..8125af6 100755 --- a/bin/_blackbox_common.sh +++ b/bin/_blackbox_common.sh @@ -433,10 +433,13 @@ function cp_permissions() { Darwin ) chmod $( stat -f '%p' "$1" ) "${@:2}" ;; - FreeBSD ) + FreeBSD | NetBSD ) chmod $( stat -f '%p' "$1" | sed -e "s/^100//" ) "${@:2}" ;; - Linux | CYGWIN* | MINGW* ) + SunOS ) + chmod $( stat -c '%a' "$1" ) "${@:2}" + ;; + Linux | CYGWIN* | MINGW* | SunOS ) if [[ -e /etc/alpine-release ]]; then chmod $( stat -c '%a' "$1" ) "${@:2}" else From 3a491aad01548e3a6373bd39a64d0cfa90460e56 Mon Sep 17 00:00:00 2001 From: Travis Paul Date: Thu, 29 Nov 2018 14:01:54 +0800 Subject: [PATCH 3/7] Add NetBSD and SunOS (SmartOS) support to _stack_lib.sh. --- bin/_stack_lib.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/_stack_lib.sh b/bin/_stack_lib.sh index 8ca801a..6543c55 100755 --- a/bin/_stack_lib.sh +++ b/bin/_stack_lib.sh @@ -57,7 +57,7 @@ function create_self_deleting_tempfile() { : "${TMPDIR:=/tmp}" ; filename=$(mktemp -t _stacklib_.XXXXXXXX ) ;; - Linux | CYGWIN* | MINGW* ) + Linux | CYGWIN* | MINGW* | NetBSD | SunOS ) filename=$(mktemp) ;; * ) @@ -78,7 +78,7 @@ function create_self_deleting_tempdir() { : "${TMPDIR:=/tmp}" ; filename=$(mktemp -d -t _stacklib_.XXXXXXXX ) ;; - Linux | CYGWIN* | MINGW* ) + Linux | CYGWIN* | MINGW* | NetBSD | SunOS ) filename=$(mktemp -d) ;; * ) @@ -102,7 +102,7 @@ function make_self_deleting_tempfile() { : "${TMPDIR:=/tmp}" ; name=$(mktemp -t _stacklib_.XXXXXXXX ) ;; - Linux | CYGWIN* | MINGW* ) + Linux | CYGWIN* | MINGW* | NetBSD | SunOS ) name=$(mktemp) ;; * ) @@ -127,7 +127,7 @@ function make_tempdir() { # which needs to fit within sockaddr_un.sun_path (see unix(7)). name=$(mktemp -d -t SO ) ;; - Linux | CYGWIN* | MINGW* ) + Linux | CYGWIN* | MINGW* | NetBSD | SunOS ) name=$(mktemp -d) ;; * ) @@ -160,14 +160,14 @@ function fail_if_not_running_as_root() { function fail_if_in_root_directory() { # Verify nobody has tricked us into being in "/". case $(uname -s) in - Darwin | FreeBSD ) + Darwin | FreeBSD | NetBSD ) if [[ $(stat -f'%i' / ) == $(stat -f'%i' . ) ]] ; then echo 'SECURITY ALERT: The current directory is the root directory.' echo 'Exiting...' exit 1 fi ;; - Linux | CYGWIN* | MINGW* ) + Linux | CYGWIN* | MINGW* | SunOS ) if [[ $(stat -c'%i' / ) == $(stat -c'%i' . ) ]] ; then echo 'SECURITY ALERT: The current directory is the root directory.' echo 'Exiting...' From fd3ad2fcea5e1b1f99e20eabbc5ddf49de20aaa7 Mon Sep 17 00:00:00 2001 From: Travis Paul Date: Fri, 30 Nov 2018 10:59:21 +0800 Subject: [PATCH 4/7] Add better support for NetBSD and SunOS in test scripts. --- tools/confidence_test.sh | 2 +- tools/test_functions.sh | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/confidence_test.sh b/tools/confidence_test.sh index 0a69fbb..c71d2d3 100755 --- a/tools/confidence_test.sh +++ b/tools/confidence_test.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../bin -export PATH="${blackbox_home}:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/local/bin:${blackbox_home}" +export PATH="${blackbox_home}:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/local/bin:/usr/pkg/bin:/usr/pkg/gnu/bin:${blackbox_home}" export LANG=C.UTF-8 # Required ro "gpg --export" to work properly. diff --git a/tools/test_functions.sh b/tools/test_functions.sh index 68786fa..2f34800 100755 --- a/tools/test_functions.sh +++ b/tools/test_functions.sh @@ -24,6 +24,12 @@ function md5sum_file() { Darwin | FreeBSD ) md5 -r "$1" | awk '{ print $1 }' ;; + NetBSD ) + md5 -q "$1" + ;; + SunOS ) + digest -a md5 "$1" + ;; Linux ) md5sum "$1" | awk '{ print $1 }' ;; @@ -72,10 +78,10 @@ function assert_file_group() { assert_file_exists "$file" case $(uname -s) in - Darwin|FreeBSD ) + Darwin | FreeBSD | NetBSD ) found=$(stat -f '%Dg' "$file") ;; - Linux ) + Linux | SunOS ) found=$(stat -c '%g' "$file") ;; CYGWIN* ) @@ -102,11 +108,11 @@ function assert_file_perm() { assert_file_exists "$file" case $(uname -s) in - Darwin|FreeBSD ) + Darwin | FreeBSD | NetBSD ) found=$(stat -f '%Sp' "$file") ;; # NB(tlim): CYGWIN hasn't been tested. It might be more like Darwin. - Linux | CYGWIN* ) + Linux | CYGWIN* | SunOS ) found=$(stat -c '%A' "$file") ;; * ) From 3594a3124e30172c92eb21666fab325d40f8327b Mon Sep 17 00:00:00 2001 From: Travis Paul Date: Fri, 30 Nov 2018 13:24:56 +0800 Subject: [PATCH 5/7] Bash from pkgsrc has a flag to disable importing functions unless explicitly enabled. The patch was created in response to ShellShock and still remains: https://www.mail-archive.com/smartos-discuss@lists.smartos.org/msg01247.html https://github.com/NetBSD/pkgsrc/blob/trunk/shells/bash/patches/patch-shell.c --- bin/blackbox_shred_all_files | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/blackbox_shred_all_files b/bin/blackbox_shred_all_files index 668c657..87ac1f6 100755 --- a/bin/blackbox_shred_all_files +++ b/bin/blackbox_shred_all_files @@ -39,7 +39,12 @@ export -f exported_internal_shred_file DEREFERENCED_BIN_DIR="${0%/*}" MAX_PARALLEL_SHRED=10 +bash_args= +if bash --help | grep import-functions >/dev/null 2>/dev/null; then + bash_args=--import-functions +fi + export IFS= -tr '\n' '\0' <"$BB_FILES" | xargs -0 -I{} -n 1 -P $MAX_PARALLEL_SHRED bash -c "exported_internal_shred_file $DEREFERENCED_BIN_DIR \"{}\"" $DEREFERENCED_BIN_DIR/fake +tr '\n' '\0' <"$BB_FILES" | xargs -0 -I{} -n 1 -P $MAX_PARALLEL_SHRED bash $bash_args -c "exported_internal_shred_file $DEREFERENCED_BIN_DIR \"{}\"" $DEREFERENCED_BIN_DIR/fake echo '========== DONE.' From f681872c4d8c211344b8145f8f1757945a517673 Mon Sep 17 00:00:00 2001 From: Travis Paul Date: Fri, 30 Nov 2018 13:51:01 +0800 Subject: [PATCH 6/7] Remove `-n 1` argument from the xargs invocation in blackbox_shred_all_files. The -I and -n options are mutually-exclusive, don't work as expected with xargs from SunOS, and appear to be unecessary anyway. --- bin/blackbox_shred_all_files | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/blackbox_shred_all_files b/bin/blackbox_shred_all_files index 87ac1f6..7b640bc 100755 --- a/bin/blackbox_shred_all_files +++ b/bin/blackbox_shred_all_files @@ -45,6 +45,6 @@ if bash --help | grep import-functions >/dev/null 2>/dev/null; then fi export IFS= -tr '\n' '\0' <"$BB_FILES" | xargs -0 -I{} -n 1 -P $MAX_PARALLEL_SHRED bash $bash_args -c "exported_internal_shred_file $DEREFERENCED_BIN_DIR \"{}\"" $DEREFERENCED_BIN_DIR/fake +tr '\n' '\0' <"$BB_FILES" | xargs -0 -I{} -P $MAX_PARALLEL_SHRED bash $bash_args -c "exported_internal_shred_file $DEREFERENCED_BIN_DIR \"{}\"" $DEREFERENCED_BIN_DIR/fake echo '========== DONE.' From e17c44aa61cf6136f85940a5e27c163420ccffea Mon Sep 17 00:00:00 2001 From: Travis Paul Date: Mon, 3 Dec 2018 09:19:27 -0600 Subject: [PATCH 7/7] Add NetBSD and SmartOS to list of supported OSes. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4d59e41..08490af 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,8 @@ BlackBox automatically determines which VCS you are using and does the right thi - MacOS X - Cygwin (Thanks, Ben Drasin!) **See Note Below** - MinGW (git bash on windows) **See Note Below** + - NetBSD + - SmartOS To add or fix support for a VCS system, look for code at the end of `bin/_blackbox_common.sh`