Debian Codegraph @

hooks/fsck

raw
1 #!/bin/sh
2
3 PREREQ=""
4
5 prereqs()
6 {
7 echo "$PREREQ"
8 }
9
10 # Find a specific fstab entry
11 # $1=mountpoint
12 # $2=fstype (optional)
13 _read_fstab_entry () {
14 # Not found by default.
15 echo "MNT_FSNAME="
16 echo "MNT_DIR="
17 echo "MNT_TYPE="
18
19 for file in /etc/fstab /etc/fstab.d/*.fstab; do
20 if [ -f "$file" ]; then
21 # shellcheck disable=SC2034
22 while read -r MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MNT_PASS MNT_JUNK; do
23 case "$MNT_FSNAME" in
24 ""|\#*)
25 continue;
26 ;;
27 esac
28 if [ "$MNT_DIR" = "$1" ]; then
29 if [ -n "$2" ]; then
30 [ "$MNT_TYPE" = "$2" ] || continue;
31 fi
32 echo "MNT_FSNAME=$MNT_FSNAME"
33 echo "MNT_DIR=$MNT_DIR"
34 echo "MNT_TYPE=$MNT_TYPE"
35 echo "MNT_PASS=$MNT_PASS"
36 break 2
37 fi
38 MNT_DIR=""
39 done < "$file"
40 fi
41 done
42 }
43
44 # Find a specific fstab entry and print its type (if found, and pass != 0)
45 # $1=mountpoint
46 get_fsck_type_fstab () {
47 local device
48 eval "$(_read_fstab_entry "$1")"
49
50 # Not found by default.
51 if [ "$1" = "$MNT_DIR" ]; then
52 # Ignore filesystem type for /, as it is not available and
53 # therefore never used at boot time
54 if [ "${MNT_DIR}" = "/" ] || [ "${MNT_TYPE}" = "auto" ]; then
55 device="$(resolve_device "${MNT_FSNAME}")"
56 # shellcheck disable=SC2317,SC2329
57 fstype() { "/usr/lib/klibc/bin/fstype" "$@"; }
58 if ! get_fstype "${device}"; then
59 echo "W: Couldn't identify type of $2 file system '$MNT_FSNAME' for fsck hook" >&2
60 fi
61 unset -f fstype
62 else
63 echo "${MNT_TYPE}"
64 fi
65 fi
66 }
67
68 get_fsck_types() {
69 if [ "${FSTYPE:-auto}" = auto ]; then
70 get_fsck_type_fstab / root
71 get_fsck_type_fstab /usr usr
72 else
73 local IFS=,
74 local fstype
75 set -f
76 for fstype in $FSTYPE; do
77 echo "$fstype"
78 done
79 set +f
80 fi
81 }
82
83 case $1 in
84 prereqs)
85 prereqs
86 exit 0
87 ;;
88 esac
89
90 if [ ! -x /sbin/fsck ]; then
91 exit 0
92 fi
93
94 . /usr/share/initramfs-tools/scripts/functions
95 . /usr/share/initramfs-tools/hook-functions
96
97 fsck_types="$(get_fsck_types | sort | uniq)"
98
99 if [ -z "$fsck_types" ]; then
100 exit 0
101 fi
102
103 copy_exec /sbin/fsck
104 copy_exec /sbin/logsave
105
106 for type in $fsck_types; do
107 if prog="$(command -v "fsck.${type}")"; then
108 copy_exec "$prog"
109 else
110 echo "W: /sbin/fsck.${type} doesn't exist, can't install to initramfs" >&2
111 fi
112 done