3ad9ef6f545bc7b0402d52982a2e8395804eec5c
[live-boot-grml.git] / scripts / live-premount / 10driver_updates
1 #!/bin/sh
2
3 #set -e
4
5 # initramfs-tools header
6
7 PREREQ=""
8
9 prereqs()
10 {
11         echo "${PREREQ}"
12 }
13
14 case "${1}" in
15         prereqs)
16                 prereqs
17                 exit 0
18                 ;;
19 esac
20
21 # live-initramfs header
22
23 if [ -n "${NOUSER}" ]
24 then
25         exit 0
26 fi
27
28 . /scripts/live-functions
29 . /scripts/live-helpers
30
31 log_begin_msg "Adding live session user..."
32
33 # live-initramfs script
34
35 mountpoint=/cdrom
36
37 is_updates_path ()
38 {
39         # Driver packages are stored in ubuntu-drivers/<kver>/
40         # subdirectory. Each package contains a module for a specific
41         # kernel flavour.
42
43         path=${1}
44         abi="$(uname -r)"
45         kver="$(echo "$abi" | cut -d- -f1,2)"
46         kbase="$(echo "$abi" | cut -d- -f1)"
47         for leaf in "$abi" "$kver" "$kbase"; do
48                 update_dir="$path/ubuntu-drivers/$leaf"
49                 [ -d "$update_dir" ] || continue
50                 if [ "$(echo ${update_dir}/*_${DPKG_ARCH}.deb)" != \
51                         "${update_dir}/*_${DPKG_ARCH}.deb" ]
52                 then
53                         echo "${update_dir}"
54                         return 0
55                 fi
56         done
57
58         return 1;
59 }
60
61 is_nice_device ()
62 {
63         sysfs_path="${1#/sys}"
64
65         if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-(ide|scsi|usb))"
66         then
67                 return 0
68         fi
69
70         return 1
71 }
72
73 is_supported_fs ()
74 {
75         # FIXME: do something better like the scan of supported filesystems
76         fstype="${1}"
77
78         case ${fstype} in
79                 vfat|iso9660|udf|ext2|ext3|ntfs)
80                         return 0
81                         ;;
82         esac
83
84         return 1
85 }
86
87 check_dev_updates ()
88 {
89         sysdev="${1}"
90         devname="${2}"
91
92         if [ -z "${devname}" ]
93         then
94                 devname=$(sys2dev "${sysdev}")
95         fi
96
97         fstype=$(get_fstype "${devname}")
98
99         if is_supported_fs ${fstype}
100         then
101                 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
102
103                 if is_updates_path ${mountpoint}
104                 then
105                         return 0
106                 else
107                         umount ${mountpoint}
108                 fi
109         fi
110
111         return 1
112 }
113
114 find_driver_updates ()
115 {
116         for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram)
117         do
118                 devname=$(sys2dev "${sysblock}")
119                 fstype=$(get_fstype "${devname}")
120
121                 if /lib/udev/cdrom_id ${devname} > /dev/null
122                 then
123                         if check_dev_updates "null" "${devname}"
124                         then
125                                 return 0
126                         fi
127                 elif is_nice_device "${sysblock}"
128                 then
129                         for dev in $(subdevices "${sysblock}")
130                         do
131                                 if check_dev_updates "${dev}"
132                                 then
133                                         return 0
134                                 fi
135                         done
136                 fi
137         done
138
139         return 1
140 }
141
142 pulsate ()
143 {
144         if [ -x /sbin/usplash_write ]
145         then
146                 /sbin/usplash_write "PULSATE"
147         fi
148 }
149
150 updates="false"
151
152 for x in $(cat /proc/cmdline)
153 do
154         case ${x} in
155                 debian-installer/driver-update=*)
156                         updates=${x#debian-installer/driver-update=}
157                         ;;
158         esac
159 done
160
161 if [ "${updates}" != "true" ]
162 then
163         log_end_msg
164         exit 0
165 fi
166
167 # Not sure what to do for network installs. I assume there isn't even a CD
168 # for this anyway, so fail.
169 if [ -n "${NETBOOT}" ]
170 then
171         log_end_msg
172         exit 0;
173 fi
174
175 #if chroot /root [ -f /etc/gdm/gdm-cdd.conf ]
176 #then
177 #       GDMCONF=/etc/gdm/gdm-cdd.conf
178 #else
179 #       GDMCONF=/etc/gdm/gdm.conf
180 #fi
181
182 if [ -x /usr/bin/eject ]
183 then
184         eject
185 fi
186
187 log_wait_msg "Insert a driver CD and press ENTER (${DPKG_ARCH})"
188
189 log_begin_msg "Looking for driver update CD"
190
191 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
192 do
193         updates_root=$(find_driver_updates)
194
195         if [ "${updates_root}" ]
196         then
197                 break;
198         fi
199
200         sleep 1
201 done
202
203 log_end_msg
204
205 if [ -z "${updates_root}" ]
206 then
207         log_begin_msg "Could not find driver updates"
208         log_wait_msg "Re-insert install CD and press ENTER"
209         exit 0
210 fi
211
212 log_begin_msg "Copying driver updates to temporary location"
213
214 mkdir -p /tmp/driver-updates
215 cp ${updates_root}/*_${DPKG_ARCH}.deb /tmp/driver-updates/
216 umount ${mountpoint}
217
218 if [ -x /usr/bin/eject ]
219 then
220         eject
221 fi
222
223 log_end_msg
224
225 log_wait_msg "Re-insert install CD and press ENTER."