Skip to content

Commit 7c3f064

Browse files
author
Intra2net AG
authored
Merge pull request #4 from tuxlifan/upyx-b2sum
Include the b2sum for the original data in the generated PDF file.
2 parents 5ec6531 + 534cd74 commit 7c3f064

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

paperbackup-verify.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/bash
2+
3+
# USAGE: paperbackup-verify.sh backup.pdf
4+
# where backup.pdf should be the pdf created with paperbackup.py
5+
6+
RESTOREPROG=$(dirname $0)/paperrestore.sh
7+
8+
bPDF=$( $RESTOREPROG $1 | sha256sum | cut -d ' ' -f 1)
9+
bEmbedded=$(pdftotext $1 - | grep sha256sum -A1 | tail -1 | tr -d '\n')
10+
11+
if [ "x$bPDF" == "x$bEmbedded" ]; then
12+
echo "sha256sums MATCH :-)"
13+
echo
14+
exit 0
15+
else
16+
echo "Creating diff:"
17+
$RESTOREPROG $1 | diff ${1%.*} -
18+
diffret=$?
19+
echo
20+
if [ $diffret -ne 0 ]; then
21+
echo "diff and sha256sums do NOT match!"
22+
echo "restored sha256sum from PDF: " $bPDF
23+
echo "original sha256sum embedded: " $bEmbedded
24+
echo
25+
exit 11
26+
else
27+
echo "diff matches but sha256sum is missing."
28+
echo "restored sha256sum from PDF: " $bPDF
29+
echo "original sha256sum embedded: " $bEmbedded
30+
echo
31+
exit 1
32+
fi
33+
fi

paperbackup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ def finish_page(pdf, canv, pageno):
171171

172172
chksumlines.append(line)
173173

174+
# we also want a checksum which the restored file should match
175+
checksum = hashlib.sha256(bytes(ascdata, 'utf8')).hexdigest()
176+
174177
# add some documentation around the plaintest
175178
outlines=[]
176179
coldoc=" "*splitat
@@ -179,6 +182,9 @@ def finish_page(pdf, canv, pageno):
179182
outlines.extend(chksumlines)
180183
outlines.append("")
181184
outlines.append("")
185+
outlines.append("sha256sum of input file:")
186+
outlines.append("%s"%checksum)
187+
outlines.append("")
182188
outlines.append("")
183189
outlines.append("--")
184190
outlines.append("Created with paperbackup.py")
@@ -216,3 +222,6 @@ def finish_page(pdf, canv, pageno):
216222

217223
os.remove(temp_text_path)
218224
os.remove(temp_barcode_path)
225+
226+
print("Please now verify that the output can be restored by calling:")
227+
print("paperbackup-verify.sh {}.pdf".format(just_filename))

0 commit comments

Comments
 (0)