summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-01-04 15:42:12 +0100
committerFlorian Pritz <bluewind@xinu.at>2012-01-04 15:43:41 +0100
commitbcb55411af16c89a633c2e7c8e04769766a9fec7 (patch)
tree4566beeeaa32d4b76c8be464b09856ab6e24147a
parenta604f22b6c5afd3204d2e99d78f863736a795202 (diff)
fix stat calls on non-gnu systems
Reported-by: Moritz Wilhelmy <moritz+git@wzff.de> Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--Makefile3
-rw-r--r--fb-helper.sh.in6
-rw-r--r--fb.in6
-rw-r--r--functions9
4 files changed, 20 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 74dfb37..f91b94e 100644
--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,7 @@ clean:
install: all
install -Dm755 fb $(DESTDIR)$(BINDIR)/fb
install -Dm755 fb-helper $(DESTDIR)$(MY_LIBDIR)/fb-helper
+ install -Dm755 functions $(DESTDIR)$(MY_LIBDIR)/functions
install -Dm644 fb.1 $(DESTDIR)$(MANDIR)/man1/fb.1
uninstall:
@@ -45,7 +46,7 @@ uninstall:
dist: all
@[ -n "$(VERSION)" ] || (echo "Error: version detection failed"; exit 1)
mkdir -p dist/fb-$(VERSION)
- cp -a fb-helper.c fb{,.in} fb.pod fb.1 COPYING Makefile dist/fb-$(VERSION)
+ cp -a fb-helper.c fb{,.in} fb.pod fb.1 functions COPYING Makefile dist/fb-$(VERSION)
sed -i 's/^VERSION:=.*$$/VERSION:='$(VERSION)'/' dist/fb-$(VERSION)/Makefile
cd dist; tar -czf fb-$(VERSION).tar.gz fb-$(VERSION)
diff --git a/fb-helper.sh.in b/fb-helper.sh.in
index 3a4e3b2..e6868f6 100644
--- a/fb-helper.sh.in
+++ b/fb-helper.sh.in
@@ -4,12 +4,16 @@ mode=$1
url=$2
file=$3
+LIBDIR="@LIBDIR@"
+
+source "$LIBDIR/functions"
+
USERAGENT="fb-client/shell-@VERSION@"
CURLOPTS="-n -L -A $USERAGENT"
if [ "$mode" = "u" ]; then
basefilename=`basename -- "$file"`
- if [ `stat -c %s -- "$file"` -eq "0" ] || echo "$basefilename" | grep -F -q ","; then
+ if [ `$STAT -- "$file"` -eq "0" ] || echo "$basefilename" | grep -F -q ","; then
basefilename=`echo "$basefilename" | tr -d ,`
curl $CURLOPTS -F "file=@-;filename=$basefilename" "$url" < "$file" -o /dev/stdout
else
diff --git a/fb.in b/fb.in
index 2d9df34..2a67f83 100644
--- a/fb.in
+++ b/fb.in
@@ -24,6 +24,8 @@ CLIPBOARD=""
EXITCODE=0
LIBDIR="@LIBDIR@"
+source "$LIBDIR/functions"
+
require_executable() {
if ! type $1 >/dev/null; then
echo "Error: $1 not found. Please install." >&2
@@ -87,9 +89,9 @@ do_upload() {
fi
TMPFILE=`mktemp "$TMPDIR/data.XXXXXX"`
- if [ `stat -c %s -- "$file"` -gt "$WARNSIZE" ]; then
+ if [ `$STAT -- "$file"` -gt "$WARNSIZE" ]; then
WARNSIZE=`$LIBDIR/fb-helper d "$PASTEBIN/file/get_max_size"`
- if [ `stat -c %s -- "$file"` -gt "$WARNSIZE" ]; then
+ if [ `$STAT -- "$file"` -gt "$WARNSIZE" ]; then
echo "Warning: Your upload is too big and would be rejected. Maximum size is: $WARNSIZE bytes. Skipping..." >&2
return 1
fi
diff --git a/functions b/functions
new file mode 100644
index 0000000..1dc76d3
--- /dev/null
+++ b/functions
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# the calling conventions for stat(1) are highly system dependent
+STAT='stat -c %s' # GNU stat(1) is the default since most people have it
+case "`uname -s`" in
+ *BSD) STAT='stat -f %z';;
+ Minix) STAT='stat -size';;
+esac
+