. "$BST_LIB" # makeself 2.5.0, part 5 of 5 — SELF-VERIFICATION. Creates one archive and then # only interrogates it: --check reads the payload through dd | md5sum without # unpacking, and a damaged archive is refused at the size comparison BEFORE it # decompresses anything. So this file spends no unpack at all, which is what # leaves both of the boot's two for parts 2 and 3 (see part 2's header). # # Being the only archive file that never decompresses is why it runs LAST: it is # the one that can most afford whatever budget is left by the time the runner # reaches it. Part 4 held this slot first and lost its `--list` to # "tar: Cannot allocate memory". # # The point of the file is that a self-extracting archive is only trustworthy if # it refuses a damaged one. One measured contract worth stating: a damaged # archive exits 2 -- not 1 -- and prints its diagnostic before unpacking, so the # startup script must not run. Truncation and an in-place overwrite land on the # same status, which is why rc 2 is asserted for each rather than a distinct code # per damage kind. require makeself.sh makeself/present MS=/usr/bin/makeself.sh LC_ALL=C; export LC_ALL W=${TMPDIR:-/tmp}/bst-makeself-verify.$$ rm -rf "$W"; mkdir -p "$W/p" || { bst_notok makeself/verify-setup "cannot create $W"; exit 0; } echo makeself-payload-marker > "$W/p/greeting.txt" printf '#!/bin/sh\necho MS-STARTUP-RAN\nexit 0\n' > "$W/p/startup.sh" chmod 755 "$W/p/startup.sh" cd "$W" || { bst_notok makeself/verify-setup "cannot cd $W"; exit 0; } A="$W/demo.run" "$MS" "$W/p" "$A" "BST Verify" ./startup.sh >/dev/null 2>&1 check makeself/verify-archive test -s "$A" # --- the archive verifies itself (no unpack) ------------------------------- MSCHK=$("$A" --noprogress --check 2>&1); MSCHKRC=$? if [ "$MSCHKRC" -eq 0 ]; then bst_ok makeself/check-rc else bst_notok makeself/check-rc "rc=$MSCHKRC $(_bst_1line "$MSCHK")"; fi case "$MSCHK" in *"MD5 checksums are OK"*) bst_ok makeself/check-ok ;; *) bst_notok makeself/check-ok "$(_bst_1line "$MSCHK")" ;; esac # Default archives carry a CRC and an MD5 but no SHA256, and --check says so. case "$MSCHK" in *"does not contain an embedded SHA256"*) bst_ok makeself/check-nosha ;; *) bst_notok makeself/check-nosha "$(_bst_1line "$MSCHK")" ;; esac # --- a truncated archive is refused, rc 2 ---------------------------------- MSSZ=$(wc -c < "$A" | tr -d ' ') head -c $((MSSZ - 500)) "$A" > "$W/trunc.run" 2>/dev/null chmod 755 "$W/trunc.run" 2>/dev/null check_rc makeself/truncated-rc 2 "$W/trunc.run" --noprogress --check MSTR=$("$W/trunc.run" --noprogress --check 2>&1) case "$MSTR" in *"Unexpected archive size"*) bst_ok makeself/truncated-msg ;; *) bst_notok makeself/truncated-msg "$(_bst_1line "$MSTR")" ;; esac # --- an overwritten archive is refused, and never reaches the startup ------ cp "$A" "$W/bad.run"; chmod 755 "$W/bad.run" dd if=/dev/zero of="$W/bad.run" bs=1 seek=$((MSSZ - 300)) count=64 conv=notrunc 2>/dev/null MSBAD=$("$W/bad.run" --noprogress 2>&1); MSBADRC=$? if [ "$MSBADRC" -eq 2 ]; then bst_ok makeself/corrupt-rc else bst_notok makeself/corrupt-rc "rc=$MSBADRC want=2 $(_bst_1line "$MSBAD")"; fi case "$MSBAD" in *MS-STARTUP-RAN*) bst_notok makeself/corrupt-no-startup "startup script ran from a damaged archive" ;; *) bst_ok makeself/corrupt-no-startup ;; esac cd / rm -rf "$W"