pixelb / fslint

Linux file system lint checker/cleaner
319 stars 72 forks source link

command-line portability to run on Mac OS X #88

Open pixelb opened 9 years ago

pixelb commented 9 years ago

Original issue 89 created by pixelb on 2013-11-18T02:18:28.000Z:

What steps will reproduce the problem?

  1. Run command line findup on Mac OS X 10.5 F/ex: ./findup --summary ~/ | ./fstool/dupwaste

What is the expected output? What do you see instead?

Expected: normal output Actual: various failures from lack of latest GNU tools

xargs: illegal option -- r

sed: 6: "\n # md5sum and sha1s ...": bad flag in substitute command: '}'

Error: uniq must have --all-repeated=prepend option. Get the latest version from GNU coreutils or textutils-2.0.21

md5sum: stat '--': No such file or directory

sha1sum: stat '--': No such file or directory

du: illegal option -- B usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m | -g] [-x] [-I mask] [file ...]

What version of the product are you using? On what operating system? fslint-2.42 ## release version Mac OS X 10.5.8 (Intel 32 bit on Core2 Duo, MacMini2,1) $ uname -a Darwin tiny 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386

Please provide any additional information below.

Yeah, I know, it's my own fault for not running GNU/Linux ;-) But this is a great tool and there is no reason that it shouldn't be portable to various UNIXen.

My recommended approach is to not hard-code path-less binary names throughout the script (du, xargs, sed). Instead use variables like $DU, $XARGS, etc Then the caller can provide paths to non-broken versions of the required commands F/ex: $ export MD5SUM=/sw/bin/md5sum $ export SHA1SUM="/opt/local/bin/shasum-5.12 -a 1" $ export DU=/opt/local/bin/gdu $ export SED=/opt/local/bin/gsed $ export FIND=/opt/local/bin/gfind $ export XARGS=/opt/local/bin/gxargs $ export UNIQ=/opt/local/bin/guniq Then at the top of the script: MD5SUM="${MD5SUM:-md5sum}" ## default to the plain commands... SHA1SUM="${SHA1SUM:-sha1sum}" ## ...while allowing user overrides DU="${DU:-du}"

To get really fancy, the ideal solution would source a common bash script fragment that would assign the variables, then test that the provided tools were compatible (ie check that $MD5SUM and $SHA1SUM can accept "--" and read from STDIN).

There are a couple of different UNIX package managers that run on Mac OS X that can provide proper command-line utilities:

Mixing and matching from both lets hard core command-line junkies like myself assemble a working system.

Attached is the quick hack that I used to get findup --summary | fstool/dupwaste running on my system.
(This does NOT use the better coding style environment variables that I suggested above.)

$ diff -Naur fslint-2.42.orig fslint-2.42 > mac-10.5-MacPorts,Fink.patch