Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- make_tar_member() {
- local name=$1
- local content=$2
- local mode=644
- local uid=1000
- local gid=1000
- local size=${#content}
- local mtime=$(date +%s)
- local type=0
- local link=""
- local username="jow"
- local groupname="jow"
- printf '%-100s%07d\0%07o\0%07o\0%011o\0%011o\0 %1d%-100sustar \0%-32s%-32s%183s' \
- "$name" $mode $uid $gid $size $mtime $type \
- "$link" "$username" "$groupname" | tr ' ' '\0' > /tmp/header
- local checksum=$((8 * 32))
- for byte in $(hexdump -ve '1/1 "%u "' /tmp/header); do
- checksum=$((checksum + $byte))
- done
- printf '%06o\0 ' $checksum | dd bs=1 seek=148 count=8 conv=notrunc of=/tmp/header
- cat /tmp/header
- printf "%s" "$content"
- local pad=$((512 - (size % 512) ))
- [ $pad -eq 0 ] || dd if=/dev/zero bs=$pad count=1
- }
- {
- make_tar_member "example.txt" "Hello there"
- make_tar_member "example-2.txt" "Blah blah"
- # alternatively, instead of the dd, run a `tar -c ...` here
- dd if=/dev/zero bs=1024 count=1
- } | gzip > /tmp/test.tar.gz
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement