Extending verify-checksums parameters to allow specifying custom list of digests.
[debian-live-boot.git] / scripts / boot / 3010-verify-checksums
blob3649e04a433fa52adb24a60bf5032766c3dec82e
1 #!/bin/sh
3 #set -e
5 Verify_checksums ()
7 for _PARAMETER in ${_CMDLINE}
8 do
9 case "${_PARAMETER}" in
10 live-boot.verify-checksums=*|verify-checksums=*)
11 LIVE_VERIFY_CHECKSUMS="true"
12 LIVE_VERIFY_CHECKSUMS_DIGESTS="${_PARAMETER#*verify-checksums=}"
15 live-boot.verify-checksums|verify-checksums)
16 LIVE_VERIFY_CHECKSUMS="true"
18 esac
19 done
21 if [ "${LIVE_VERIFY_CHECKSUMS}" != "true" ]
22 then
23 return 0
26 _MOUNTPOINT="${1}"
28 LIVE_VERIFY_CHECKSUMS_DIGESTS="${LIVE_VERIFY_CHECKSUMS_DIGESTS:-sha512 sha384 sha256 sha224 sha1 md5}"
29 _TTY="/dev/tty8"
31 log_begin_msg "Verifying checksums"
33 cd "${_MOUNTPOINT}"
35 for _DIGEST in $(echo ${LIVE_VERIFY_CHECKSUMS_DIGESTS} | sed -e 's|,| |g')
37 _CHECKSUMS="$(echo ${_DIGEST} | tr [a-z] [A-Z])SUMS"
39 if [ -e "${_CHECKSUMS}" ]
40 then
41 echo "Found ${_CHECKSUMS}..." > "${_TTY}"
43 if [ -e "/bin/${_DIGEST}sum" ]
44 then
45 echo "Checking ${_CHECKSUMS}..." > "${_TTY}"
47 # Verify checksums
48 /bin/${_DIGEST}sum -c "${_CHECKSUMS}" < "${_TTY}" > "${_TTY}"
49 _RETURN="${?}"
51 # Stop after first verification
52 break
53 else
54 echo "Not found /bin/${_DIGEST}sum..." > "${_TTY}"
57 done
59 log_end_msg
61 case "${_RETURN}" in
63 log_success_msg "Verification successfull, rebooting in 10 seconds."
64 sleep 10
66 # Unmount live-media
67 cd /
68 umount -f ${_MOUNTPOINT} > /dev/null 2>&1
69 sync
71 # Attempt to remount all mounted filesystems read-only
72 echo u > /proc/sysrq-trigger
74 # Immediately reboot the system without syncing or unmounting filesystems
75 echo b > /proc/sysrq-trigger
79 panic "Verification failed, $(basename ${_TTY}) for more information."
81 esac