]> Sergey Matveev's repositories - godlighty.git/commitdiff
Simple bsdiff-based updater
authorSergey Matveev <stargrave@stargrave.org>
Wed, 6 Oct 2021 14:19:34 +0000 (17:19 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 6 Oct 2021 14:19:34 +0000 (17:19 +0300)
make-update.sh [new file with mode: 0755]

diff --git a/make-update.sh b/make-update.sh
new file mode 100755 (executable)
index 0000000..5cf764a
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh -ex
+
+w=$1
+[ -n "$w" ]
+[ -d rc/$w.cfg ]
+redo $w
+mkdir -p updates
+[ -s updates/$w.old ] || {
+    echo This is first run
+    mv $w updates/$w.old
+    exit
+}
+bsdiff updates/$w.old $w updates/$w.bsdiff
+mv updates/$w.old updates/$w.older
+mv $w updates/$w.old
+cat > updates/$w-update.sh <<EOF
+#!/bin/sh -ex
+w=\$1
+[ -n "\$w" ]
+their_hash=\`sha512 < \$w\`
+our_hash=`sha512 < updates/$w.older`
+[ "\$their_hash" = "\$our_hash" ]
+b64decode -o \$w.bsdiff < \$0
+bspatch \$w \$w.new \$w.bsdiff
+their_hash=\`sha512 < \$w.new\`
+our_hash=`sha512 < updates/$w.old`
+[ "\$their_hash" = "\$our_hash" ]
+chown \`stat -f %u:%g \$w\` \$w.new
+chmod \`stat -f %Mp%Lp \$w\` \$w.new
+mv -f \$w.new \$w
+exit
+EOF
+b64encode updates/$w.bsdiff < updates/$w.bsdiff >> updates/$w-update.sh
+chmod +x updates/$w-update.sh