]> git.sesse.net Git - bcachefs-tools-debian/blob - initramfs/script
Initramfs script improvements
[bcachefs-tools-debian] / initramfs / script
1 #!/bin/sh
2
3 PREREQ=""
4
5 prereqs()
6 {
7     echo "$PREREQ"
8 }
9
10 case $1 in
11 # get pre-requisites
12 prereqs)
13     prereqs
14     exit 0
15     ;;
16 esac
17
18 # Nothing to do if ROOTFSTYPE is set to something other than bcachefs
19 if [ -n "$ROOTFSTYPE" -a "$ROOTFSTYPE" != bcachefs ]; then
20     exit 0
21 fi
22
23 # source for resolve_device() and panic() functions
24 . /scripts/functions
25
26 # Resolve the root device (e.g. if root is specified by UUID)
27 DEV=$(resolve_device "$ROOT")
28
29 # Check if the root device needs unlocking:
30 if bcachefs unlock -c $DEV >/dev/null 2>&1; then
31     if [ "$DEV" == "$ROOT" ]; then
32         echo "Please unlock $DEV:"
33     else
34         echo "Please unlock $DEV ($ROOT):"
35     fi
36
37     count=0
38     tries=3
39     while [ $tries -le 0 -o $count -lt $tries ]; do
40         if bcachefs unlock "$DEV"; then
41             echo "Bcachefs: $DEV successfully unlocked"
42             break
43         fi
44
45         let count++
46     done
47
48     if [ $tries -gt 0 -a $count -ge $tries ]; then
49         panic "Bcachefs: maximum number of tries exceeded for $DEV"
50         exit 1
51     fi
52 fi
53
54 exit 0