block-mount: add a delay between sto pand start in fstab init restart action, fixes...
[openwrt.git] / package / block-mount / files / 55_determine_extroot_sysupgrade
1 #!/bin/sh
2 # Copyright (C) 2010 Daniel Dickinson
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
5
6
7 check_set_md5sum() {
8         local er_md5sum_file
9         er_md5sum_file="${ER_OVERLAY_PREFIX}/.extroot.md5sum"
10         local er_disabled
11         if [ "${ER_OVERLAY_ROM}" = "/rom" ]; then
12                 er_disabled=/tmp/whole_root-disabled
13         else
14                 er_disabled=/tmp${ER_OVERLAY_ROM}-disabled
15         fi
16
17         local er_extroot_md5sum
18         if [ -f $md5sum_file ]; then
19                 er_extroot_md5sum="$(cat $er_md5sum_file)"
20         fi
21
22         local er_overlay_file="${ER_OVERLAY_ROM}/etc/extroot.md5sum"
23
24         local er_extroot_overlay_md5sum
25         if [ -f "$er_overlay_file" ]; then
26                 er_extroot_overlay_md5sum="$(cat $er_overlay_file)"
27         fi
28
29         if [ -z "$er_extroot_overlay_md5sum" ]; then
30                 cat $er_md5sum_file >$er_overlay_file
31         elif [ "$er_extroot_overlay_md5sum" != "$er_extroot_md5sum" ]; then
32                 pi_extroot_mount_success="false"
33                 mkdir -p $er_disabled
34                 mount --move ${ER_OVERLAY_ROM} $er_disabled
35         fi
36 }
37
38 set_jffs_md5sum() {
39         # We do this anytime block-extroot exists, even on the first boot with
40         # no extroot defined.
41
42         local er_md5sum_file
43         er_md5sum_file="${ER_OVERLAY_PREFIX}/.extroot.md5sum"
44
45         local er_extroot_md5sum
46         if [ -f $er_md5sum_file ]; then
47                 er_extroot_md5sum="$(cat $er_md5sum_file)"
48         fi
49         if [ -z "$er_extroot_md5sum" ]; then
50                 dd if=/dev/urandom count=32 bs=1k 2>/dev/null | md5sum | cut -f1 -d\  >$er_md5sum_file
51         fi
52 }
53
54 determine_extroot_sysupgrade() {
55         check_skip || set_jffs_md5sum
56
57         check_skip || [ "$pi_extroot_mount_success" != "true" ] || {
58                 check_set_md5sum
59         }
60 }
61
62 boot_hook_add preinit_mount_root determine_extroot_sysupgrade
63