3

I would like to get the sha1 checksums of all files inside a simple tar archive as a list.

This should be done on a busybox machine where only a minimal tar binary is avalable, see http://linux.die.net/man/1/busybox for the available commands.

Without using the disk space to unpack the big tar file. Something with piping and calculating the sha1 on the fly, directing the output to /dev/null

This would make it possible to verify backups without copying the file over the network or extracting it which is both resource consuming.

This is basically the same question as How to create sha1 checksums of files inside a tar archive without using much disk space which has a great answer, but I realized only later that the busybox tar binary is a minimal version which does not have the --to-command=sha1sum option.

1

Here are some major problems with this solution :

tar tf test.tar|while read file;do echo $file $(tar xOf test.tar $file|sha1sum);done

1-The tar of busybox cannot show differently filenames with newlines.

2-The "read" from shells does not handle backslash properly. ("\" characters are eaten or "\n" is replaced by a new line character)

3-Shell variables without double quotes eat repeated space characters.

I cannot fix the problem 1.

Any way, I can fix 2 and 3.

Create this shell script : "tarsha1.sh" (don't forget "chmod 755 tarsha1.sh")

#!/bin/sh
tarname="$1"
shift
for filename in "$@"
do tar xOf "$tarname" "$filename" | sha1sum | head -c -3
   printf '%s\n' "$filename"
done

Then use this command :

tar tf test.tar | tr '\n' '\0' | xargs -0 -r ./tarsha1.sh test.tar

With that you should be able to handle filenames with any characters but new lines ("\n").

Note : "-0" option for xargs must be activated in busybox compilation options.

2
tar tf test.tar|while read file;do echo $file $(tar xOf test.tar $file|sha1sum);done 
  • Consider using "$file" instead of $file. – Vouze Aug 23 '16 at 9:26
  • Please note that backslash characters are removed by "read". – Vouze Aug 23 '16 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.