3d60325f576c2f2fd9187e65430278ebedf2da99
[live-boot-grml.git] / debian / patches / 12_uuid_support.dpatch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 12_uuid_support.dpatch by Michael Prokop <prokop@grml-forensic.org>
3 ##
4 ## DP: This patch enables support for verifying the ISO through bootid=.... bootoption.
5 ## DP: Logic behind bootoptions and possible combinations:
6 ## DP: * bootid.txt + wrong bootid=...                    => fails to boot
7 ## DP: * bootid.txt + right bootid=...                    => boots
8 ## DP: * bootid.txt + ignore_bootid                       => boots
9 ## DP: * bootid.txt + no bootid=... + no ignore_bootid    => fails to boot
10 ## DP: * no bootid.txt + no bootid=... + no ignore_bootid => boots
11 ## DP: * no bootid.txt + bootid=...                       => fails to boot
12 ## DP: * no bootid.txt + ignore_bootid=...                => boots
13
14 @DPATCH@
15 diff --git a/scripts/live b/scripts/live
16 index abce3cd..851796c 100755
17 --- a/scripts/live
18 +++ b/scripts/live
19 @@ -63,6 +63,11 @@ Arguments ()
20                                 export ACCESS
21                                 ;;
22  
23 +                       bootid=*)
24 +                               BOOTID="${ARGUMENT#bootid=}"
25 +                               export BOOTID
26 +                               ;;
27 +
28                         console=*)
29                                 DEFCONSOLE="${ARGUMENT#*=}"
30                                 export DEFCONSOLE
31 @@ -140,6 +145,11 @@ Arguments ()
32                                 export FROMISO
33                                 ;;
34  
35 +                       ignore_bootid)
36 +                               IGNORE_BOOTID="Yes"
37 +                               export IGNORE_BOOTID
38 +                               ;;
39 +
40                         ignore_uuid)
41                                 IGNORE_UUID="Yes"
42                                 export IGNORE_UUID
43 @@ -392,6 +402,42 @@ is_live_path ()
44         return 1
45  }
46  
47 +grml_match_bootid()
48 +{
49 +       path="$1"
50 +
51 +       if [ -n "$IGNORE_BOOTID" ] ; then
52 +               echo " * Ignoring verification of bootid.txt as requested via ignore_bootid.">>/live.log
53 +               return 0
54 +       fi
55 +
56 +       if [ -n "$BOOTID" ] && ! [ -r "${path}/conf/bootid.txt" ] ; then
57 +               echo "  * Warning: bootid=... specified but no bootid.txt found on currently requested device.">>/live-boot.log
58 +               return 1
59 +       fi
60 +
61 +       [ -r "${path}/conf/bootid.txt" ] || return 0
62 +
63 +       bootid_conf=$(cat "${path}/conf/bootid.txt")
64 +
65 +       if [ -z "$BOOTID" -a -z "$IGNORE_BOOTID" ]
66 +       then
67 +               echo " * Warning: bootid.txt found but ignore_bootid / bootid=.. bootoption missing...">>/live-boot.log
68 +               return 1
69 +       fi
70 +
71 +       if [ "$BOOTID" = "$bootid_conf" ]
72 +       then
73 +               echo " * Successfully verified /conf/bootid.txt from ISO, continuing... ">>/live-boot.log
74 +       else
75 +               echo " * Warning: BOOTID of ISO does not match. Retrying and continuing search...">>/live-boot.log
76 +               return 1
77 +       fi
78 +
79 +       return 0
80 +}
81 +
82 +
83  matches_uuid ()
84  {
85         if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
86 @@ -1550,7 +1596,7 @@ check_dev ()
87                 fi
88  
89                 if is_live_path ${mountpoint} && \
90 -                       ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
91 +                       ([ "${skip_uuid_check}" ] || grml_match_bootid ${mountpoint})
92                 then
93                         echo ${mountpoint}
94                         return 0
95 @@ -1665,19 +1711,6 @@ find_livefs ()
96                                         return 0
97                                 fi
98                         done
99 -               elif [ "${fstype}" = "squashfs" -o \
100 -                       "${fstype}" = "btrfs" -o \
101 -                       "${fstype}" = "ext2" -o \
102 -                       "${fstype}" = "ext3" -o \
103 -                       "${fstype}" = "ext4" -o \
104 -                       "${fstype}" = "jffs2" ]
105 -               then
106 -                       # This is an ugly hack situation, the block device has
107 -                       # an image directly on it.  It's hopefully
108 -                       # live-boot, so take it and run with it.
109 -                       ln -s "${devname}" "${devname}.${fstype}"
110 -                       echo "${devname}.${fstype}"
111 -                       return 0
112                 fi
113         done
114