max-boehm / qnap-utils

Utilities to unpack QNAP firmware images and QPKG files
64 stars 24 forks source link

running script on osx #2

Open drheiser opened 4 years ago

drheiser commented 4 years ago

Error on running on osx.

extracting '/Users/dietmar/Desktop/yt/header_script' ... 1870 bytes. dd: no value specified for bs error in line 52. Exiting.

max-boehm commented 4 years ago

yes, it does only work on Linux

QuantumLibet commented 1 year ago

That happens for two reasons. And would be an easy fix.

Reason 1:

SKIP=`wc -c < $DEST/header_script`

The ancient version of wc on macOS adds a leading tab. The solution would be:

SKIP=$(sed -n 's/script_len=\(.*\)/\1/p' $DEST/header_script)

Reason 2:

od -t x1 -w4 -Ad -v $DEST/payload | grep '1f 8b 08 00' | awk '{print $1}'

The ancient version of od on macOS does not support the parameter -w (--width). A solution would be:

printf "%d\n" $(hexdump -C $DEST/payload | grep '1f 8b 08 00' | awk '{print "0x"$1}')

Explanation:

hexdump displays the position of the grep'ped string in hex, but without leading 0x. print "0x"$1 will output the position with a leading 0x signalling a hex number to printf. printf "%d" will then convert a hexadecimal to decimal number.

Maybe this helps.

beltzak commented 4 months ago

I have not tested @QuantumLibet solution since I started to edit the script myself instead of checking the issues first. My fix solution, as I already have Coreutils from Homebrew installed was replacing all the commands and put a 'g' in front of some of them: dd, od and wc were replaced by gdd, god and gwc. (grep and awk I have them installed also in Homebrew but need no editing as they are replaced by alias, env or somehow).

So this were my changes made at the end.

SKIP=`gwc -c < $DEST/header_script`
gdd if=$SRC bs=$SKIP skip=1 of=$DEST/payload status=none
for a in `god -t x1 -w4 -Ad -v $DEST/payload | grep '1f 8b 08 00' | awk '{print $1}'`; do
gdd if=$DEST/payload bs=$a skip=1 of=$PART.tar.gz status=none