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