shithub: rech

ref: f3cb4b36831e141994b9508139f6c2e4d69ebbe6
dir: /bin/pdfid/

View raw version
#!/bin/rc
# set the pdf ID to a given ID
# $1 is pdf file, $2 is the checksum
# assume ramfs in /tmp

rfork en

# get size of the file
size=`{du -n $1}
size=$size(1)

todump=`{echo $size - 160 | hoc}
# 160 characters should make sure that we actually have the ID, and that we skipped the binary part

# split file $1 into parts
dd -if $1 -bs 1 -count $todump -quiet 1 > /tmp/pdf_part1
dd -if $1 -bs 1 -count 160 -iseek $todump -quiet 1 > /tmp/pdf_part2

# replace ID
sed 's:^/ID \[<[A-Z0-9]+><[A-Z0-9]+>\]$:/ID [<'^$2^'><'^$2^'>]:g' /tmp/pdf_part2 > /tmp/pdf_part2_edited

# recombine file to stdout, and cleanup
cat /tmp/pdf_part1 /tmp/pdf_part2_edited
rm /tmp/pdf_part1 /tmp/pdf_part2 /tmp/pdf_part2_edited