support FreeBSD (#260)

* start FreeBSD support

* permissions change

* improve command to fetch permissions.

* note we use 'shasum' and not 'sha256sum' on osx and freebsd
pull/261/merge
Josh Rabinowitz 6 years ago committed by Nikita Sobolev
parent 168fe8cd9b
commit 6251fae396

@ -36,7 +36,7 @@ See the [installation section](http://git-secret.io/installation) for the detail
- `gawk` since `4.0.2`
- `git` since `1.8.3.1`
- `gpg` since `gnupg 1.4` to `gnupg 2.X`
- `sha256sum` since `8.21`
- `sha256sum` since `8.21` (on freebsd and OSX `shasum` is used instead)
## Contributing

@ -120,6 +120,10 @@ function _os_based {
"$1_linux" "${@:2}"
;;
FreeBSD)
"$1_freebsd" "${@:2}"
;;
# TODO: add MS Windows support.
# CYGWIN*|MINGW32*|MSYS*)
# $1_ms ${@:2}

@ -0,0 +1,37 @@
#!/usr/bin/env bash
# support for freebsd. Mostly the same as OSX.
# shellcheck disable=1117
function __replace_in_file_freebsd {
sed -i.bak "s/^\($1[[:space:]]*=[[:space:]]*\).*\$/\1$2/" "$3"
}
function __temp_file_freebsd {
: "${TMPDIR:=/tmp}"
local filename
filename=$(mktemp -t _gitsecrets_XXX )
echo "$filename";
}
function __sha256_freebsd {
# this is in a different location than osx
/usr/local/bin/shasum -a256 "$1"
}
function __get_octal_perms_freebsd {
local filename
filename=$1
local perms
perms=$(stat -f "%04OLp" "$filename")
# perms is a string like '0644'.
# In the "%04OLp':
# the '04' means 4 digits, 0 padded. So we get 0644, not 644.
# the 'O' means Octal.
# the 'Lp' means 'low subfield of file type and permissions (st_mode).'
# (without 'L' you get 6 digits like '100644'.)
echo "$perms"
}

@ -22,5 +22,6 @@ function __get_octal_perms_linux {
filename=$1
local perms
perms=$(stat --format '%a' "$filename")
# a string like '0644'
echo "$perms"
}

@ -18,10 +18,12 @@ function __temp_file_osx {
function __sha256_osx {
/usr/bin/shasum -a256 "$1"
}
function __get_octal_perms_osx {
local filename
filename=$1
local perms
perms=$(stat -f '%p' "$filename")
perms=$(stat -f "%04OLp" "$filename")
# see _git_secret_tools_freebsd.sh for more about stat's format string
echo "$perms"
}

Loading…
Cancel
Save