--- patches/gitapply.sh	2021-10-23 11:20:53.385792000 +0200
+++ patches/gitapply.sh	2021-10-23 11:21:40.952836000 +0200
@@ -22,6 +22,13 @@
 nogit=0
 tmpfile=""
 
+patch="patch"
+sha1sum="sha1sum"
+if [ `uname -s` = "FreeBSD" ]; then
+	patch="gpatch"
+	sha1sum="sha1"
+fi
+
 # Show usage information about gitapply script
 usage()
 {
@@ -57,7 +64,7 @@
 gitsha1()
 {
 	if [ -f "$1" ]; then
-		echo -en "blob $(du -b "$1" | cut -f1)\x00" | cat - "$1" | sha1sum | cut -d' ' -f1
+		echo -en "blob $(wc -c < "$1" | xargs | cut -d' ' -f1)\x00" | cat - "$1" | $sha1sum | cut -d' ' -f1
 	else
 		echo "0000000000000000000000000000000000000000"
 	fi
@@ -66,7 +73,7 @@
 # Determine size of a file (or zero, if it doesn't exist)
 filesize()
 {
-	local size=$(du -b "$1" | cut -f1)
+	local size=$(wc -c < "$1" | xargs | cut -d' ' -f1)
 	if [ -z "$size" ]; then
 		size="0"
 	fi
@@ -114,13 +121,6 @@
 	exit 1
 fi
 
-# Detect BSD - we check this first to error out as early as possible
-if gzip -V 2>&1 | grep -q "BSD"; then
-	echo "This script is not compatible with *BSD utilities. Please install git," >&2
-	echo "which provides the same functionality and will be used instead." >&2
-	exit 1
-fi
-
 # Check if GNU Awk is available
 if ! command -v gawk >/dev/null 2>&1; then
 	if ! awk -V 2>/dev/null | grep -q "GNU Awk"; then
@@ -135,7 +135,7 @@
 fi
 
 # Check for missing depdencies
-for dependency in gawk cut dd du grep gzip hexdump patch sha1sum; do
+for dependency in gawk cut dd grep gzip hexdump $patch $sha1sum; do
 	if ! command -v "$dependency" >/dev/null 2>&1; then
 		echo "Missing dependency: $dependency - please install this program and try again." >&2
 		exit 1
@@ -358,7 +358,7 @@
 
 		# Apply textual patch
 		tmpoffset=$((lastoffset - 1))
-		if ! sed -n "$offset,$tmpoffset p" "$tmpfile" | patch -p1 -s -f; then
+		if ! sed -n "$offset,$tmpoffset p" "$tmpfile" | $patch -p1 -s -f; then
 			abort "Textual patch did not apply, aborting."
 		fi
 
