7dd5da3753c541ead973e92c45030566015d0735
[live-boot-grml.git] / scripts / boot / verify-checksums.sh
1 #!/bin/sh
2
3 #set -e
4
5 Verify_checksums ()
6 {
7         _MOUNTPOINT="${1}"
8
9         _DIGESTS="sha512 sha384 sha256 sha224 sha1 md5"
10         _TTY="/dev/tty8"
11
12         log_begin_msg "Verifying checksums"
13
14         cd "${_MOUNTPOINT}"
15
16         for _DIGEST in ${_DIGESTS}
17         do
18                 _CHECKSUMS="$(echo ${_DIGEST} | tr [a-z] [A-Z])SUMS"
19
20                 if [ -e "${_CHECKSUMS}" ]
21                 then
22                         echo "Found ${_CHECKSUMS}..." > "${_TTY}"
23
24                         if [ -e "/bin/${_DIGEST}sum" ]
25                         then
26                                 echo "Checking ${_CHECKSUMS}..." > "${_TTY}"
27
28                                 # Verify checksums
29                                 /bin/${_DIGEST}sum -c "${_CHECKSUMS}" < "${_TTY}" > "${_TTY}"
30                                 _RETURN="${?}"
31
32                                 # Stop after first verification
33                                 break
34                         else
35                                 echo "Not found /bin/${_DIGEST}sum..." > "${_TTY}"
36                         fi
37                 fi
38         done
39
40         log_end_msg
41
42         case "${_RETURN}" in
43                 0)
44                         log_success_msg "Verification successfull, rebooting in 10 seconds."
45                         sleep 10
46
47                         # Unmount live-media
48                         cd /
49                         umount -f ${_MOUNTPOINT} > /dev/null 2>&1
50                         sync
51
52                         # Attempt to remount all mounted filesystems read-only
53                         echo u > /proc/sysrq-trigger
54
55                         # Immediately reboot the system without syncing or unmounting filesystems
56                         echo b > /proc/sysrq-trigger
57                         ;;
58
59                 *)
60                         panic "Verification failed, $(basename ${_TTY}) for more information."
61                         ;;
62         esac
63 }