Using linux keyword for linux kernel images to profit from syslinux' automagic (Close...
[syslinux-debian/hramrach.git] / debian / local / extlinux-update
blob69824182bf5ff10ada6a64cdd3d9d84d6f4ab464
1 #!/bin/sh
3 set -e
5 _EXTLINUX_DIRECTORY="/boot/extlinux"
7 Update ()
9 # Upate target file using source content
10 _TARGET="${1}"
11 _SOURCE="${2}"
13 _TMPFILE="${_TARGET}.tmp"
14 rm -f "${_TMPFILE}"
16 echo "${_SOURCE}" > "${_TMPFILE}"
18 if [ -e "${_TARGET}" ] && cmp -s "${_TARGET}" "${_TMPFILE}"
19 then
20 rm -f "${_TMPFILE}"
21 else
22 # FIXME: should use fsync here
23 echo "P: Updating ${_TARGET}..."
24 mv -f "${_TMPFILE}" "${_TARGET}"
28 # User is unprivileged
29 if [ "$(id -u)" -ne 0 ]
30 then
31 echo "E: need root privileges"
32 exit 1
35 # Redirect stdout to stderr due Debconf usage
36 exec 1>&2
38 # Reading the default file
39 if [ -e /etc/default/extlinux ]
40 then
41 . /etc/default/extlinux
44 EXTLINUX_UPDATE="${EXTLINUX_UPDATE:-true}"
46 if [ "${EXTLINUX_UPDATE}" != "true" ]
47 then
48 echo "P: extlinux-update is disabled in /etc/default/extlinux."
50 exit 0
53 # Checking extlinux directory
54 echo -n "P: Checking for EXTLINUX directory..."
56 # Creating extlinux directory
57 if [ ! -e "${_EXTLINUX_DIRECTORY}" ]
58 then
59 echo " not found."
61 echo -n "P: Creating EXTLINUX directory..."
62 mkdir -p "${_EXTLINUX_DIRECTORY}"
63 echo " done: ${_EXTLINUX_DIRECTORY}"
64 else
65 echo " found."
68 # Setting defaults
69 EXTLINUX_ALTERNATIVES="${EXTLINUX_ALTERNATIVES:-default recovery}"
70 EXTLINUX_DEFAULT="${EXTLINUX_DEFAULT:-l0}"
71 EXTLINUX_ENTRIES="${EXTLINUX_ENTRIES:-all}"
72 EXTLINUX_MEMDISK="${EXTLINUX_MEMDISK:-true}"
73 EXTLINUX_MEMDISK_DIRECTORY="${EXTLINXU_MEMDISK_DIRECTORY:-/boot}"
75 if [ -z "${EXTLINUX_MENU_LABEL}" ]
76 then
77 if [ -x "$(which lsb_release 2>/dev/null)" ]
78 then
79 EXTLINUX_MENU_LABEL="$(lsb_release -i -s) GNU/Linux, kernel"
80 else
81 EXTLINUX_MENU_LABEL="Debian GNU/Linux, kernel"
85 EXTLINUX_OS_PROBER="${EXTLINUX_OS_PROBER:-true}"
86 EXTLINUX_PARAMETERS="${EXTLINUX_PARAMETERS:-ro quiet}"
88 if [ -z "${EXTLINUX_ROOT}" ]
89 then
90 # Find root partition
91 while read _LINE
94 read _FS_SPEC _FS_FILE _FS_VFSTYPE _FS_MNTOPS _FS_FREQ _FS_PASSNO << EOF
95 ${_LINE}
96 EOF
98 if [ "${_FS_SPEC}" != "#" ] && [ "${_FS_FILE}" = "/" ]
99 then
100 EXTLINUX_ROOT="root=${_FS_SPEC}"
101 break
103 done < /etc/fstab
106 if [ -z "${EXTLINUX_THEME}" ]
107 then
108 # Using default menu if available
109 if [ -e /usr/share/syslinux/themes/debian/extlinux ]
110 then
111 EXTLINUX_THEME="debian"
112 else
113 EXTLINUX_THEME="none"
117 EXTLINUX_TIMEOUT="${EXTLINUX_TIMEOUT:-50}"
119 # Writing new default file
120 cat > "/etc/default/extlinux" << EOF
121 ## /etc/default/extlinux - configuration file for extlinux-update(8)
123 EXTLINUX_UPDATE="${EXTLINUX_UPDATE}"
125 EXTLINUX_ALTERNATIVES="${EXTLINUX_ALTERNATIVES}"
126 EXTLINUX_DEFAULT="${EXTLINUX_DEFAULT}"
127 EXTLINUX_ENTRIES="${EXTLINUX_ENTRIES}"
128 EXTLINUX_MEMDISK="${EXTLINUX_MEMDISK}"
129 EXTLINUX_MEMDISK_DIRECTORY="${EXTLINUX_MEMDISK_DIRECTORY}"
130 EXTLINUX_MENU_LABEL="${EXTLINUX_MENU_LABEL}"
131 EXTLINUX_OS_PROBER="${EXTLINUX_OS_PROBER}"
132 EXTLINUX_PARAMETERS="${EXTLINUX_PARAMETERS}"
133 EXTLINUX_ROOT="${EXTLINUX_ROOT}"
134 EXTLINUX_THEME="${EXTLINUX_THEME}"
135 EXTLINUX_TIMEOUT="${EXTLINUX_TIMEOUT}"
138 # Create linux.cfg
139 _CONFIG="\
140 ## ${_EXTLINUX_DIRECTORY}/linux.cfg
142 ## IMPORTANT WARNING
144 ## The configuration of this file is generated automatically.
145 ## Do not edit this file manually, use: extlinux-update
150 # Find linux versions
151 _VERSIONS="$(cd /boot && ls vmlinuz-* | grep -v .dpkg-tmp | sed -e 's|vmlinuz-||g' | sort -r)"
153 if [ "$(stat --printf %d /)" = "$(stat --printf %d /boot)" ]
154 then
155 # / and /boot are on the same filesystem
156 _BOOT_DIRECTORY="/boot"
157 else
158 # / and /boot are not on the same filesystem
159 _BOOT_DIRECTORY=""
163 for _VERSION in ${_VERSIONS}
165 echo "P: Writing config for /boot/vmlinuz-${_VERSION}..."
167 _NUMBER="${_NUMBER:-0}"
168 _ENTRY="${_ENTRY:-1}"
170 if [ -e /boot/initrd.img-${_VERSION} ]
171 then
172 _INITRD="initrd=${_BOOT_DIRECTORY}/initrd.img-${_VERSION}"
173 else
174 _INITRD=""
177 if echo ${EXTLINUX_ALTERNATIVES} | grep -q default
178 then
180 # Writing default entry
181 _CONFIG="${_CONFIG}
183 label l${_NUMBER}
184 menu label ${EXTLINUX_MENU_LABEL} ${_VERSION}
185 linux ${_BOOT_DIRECTORY}/vmlinuz-${_VERSION}
186 append ${_INITRD} ${EXTLINUX_ROOT} ${EXTLINUX_PARAMETERS}"
190 if echo ${EXTLINUX_ALTERNATIVES} | grep -q live
191 then
193 # Writing live entry
194 _CONFIG="${_CONFIG}
196 label l${_NUMBER}l
197 menu label ${EXTLINUX_MENU_LABEL} ${_VERSION} (live mode)
198 linux ${_BOOT_DIRECTORY}/vmlinuz-${_VERSION}
199 append ${_INITRD} ${EXTLINUX_ROOT} ${EXTLINUX_PARAMETERS} boot=live plainroot
200 text help
201 This option boots the system into live mode (non-persistent)
202 endtext"
206 if echo ${EXTLINUX_ALTERNATIVES} | grep -q recovery
207 then
209 # Writing recovery entry
210 _CONFIG="${_CONFIG}
212 label l${_NUMBER}r
213 menu label ${EXTLINUX_MENU_LABEL} ${_VERSION} (recovery mode)
214 linux ${_BOOT_DIRECTORY}/vmlinuz-${_VERSION}
215 append ${_INITRD} ${EXTLINUX_ROOT} $(echo ${EXTLINUX_PARAMETERS} | sed -e 's| quiet||') single
216 text help
217 This option boots the system into recovery mode (single-user)
218 endtext"
222 _NUMBER="$((${_NUMBER} + 1))"
224 if [ "${EXTLINUX_ENTRIES}" = "${_ENTRY}" ]
225 then
226 break
228 done
230 _NUMBER=""
232 Update "${_EXTLINUX_DIRECTORY}/linux.cfg" "${_CONFIG}"
235 if [ "${EXTLINUX_MEMDISK}" = "true" ]
236 then
237 if [ ! -e /usr/lib/extlinux/memdisk ]
238 then
239 echo "E: /usr/lib/extlinux/memdisk: No such file"
240 exit 1
243 cp -f /usr/lib/extlinux/memdisk "${_EXTLINUX_DIRECTORY}"
245 # Create memdisk.cfg
246 _CONFIG="\
247 ## ${_EXTLINUX_DIRECTORY}/memdisk.cfg
249 ## IMPORTANT WARNING
251 ## The configuration of this file is generated automatically.
252 ## Do not edit this file manually, use: extlinux-update
257 for _IMAGE in "${EXTLINUX_MEMDISK_DIRECTORY}"/*.iso "${EXTLINUX_MEMDISK_DIRECTORY}"/*.img
259 # Skip non-existing files and files matching '^initrd.*'
260 if [ ! -e "${_IMAGE}" ] || [ "$(basename ${_IMAGE} | cut -b 1-6)" = "initrd" ]
261 then
262 continue
265 _NUMBER="${_NUMBER:-0}"
267 echo "P: Writing config for ${_IMAGE}..."
269 case "${_IMAGE}" in
270 *.iso)
271 _IMAGE_APPEND="iso"
274 *.img)
275 _IMAGE_APPEND="raw"
277 esac
279 if [ -n "${_BOOT_DIRECTORY}" ]
280 then
281 # / and /boot are on the same filesystem
282 _MEMDISK_DIRECTORY="${_EXTLINUX_DIRECTORY}"
283 else
284 # / and /boot are not on the same filesystem
285 _MEMDISK_DIRECTORY="$(echo ${_EXTLINUX_DIRECTORY} | sed -e 's|^/boot||')"
286 _IMAGE="$(echo ${_IMAGE} | sed -e 's|^/boot||')"
289 # Writing image entry
290 _CONFIG="${_CONFIG}
292 label m${_NUMBER}
293 menu label Memdisk, image $(basename ${_IMAGE})
294 linux ${_MEMDISK_DIRECTORY}/memdisk
295 initrd ${_IMAGE}
296 append ${_IMAGE_APPEND}"
298 _NUMBER="$((${_NUMBER} + 1))"
299 done
301 _NUMBER=""
303 Update "${_EXTLINUX_DIRECTORY}/memdisk.cfg" "${_CONFIG}"
306 if [ "${EXTLINUX_OS_PROBER}" = "true" ] && [ -x "$(which os-prober 2>/dev/null)" ]
307 then
308 if [ ! -e /usr/lib/extlinux/chain.c32 ]
309 then
310 echo "E: /usr/lib/extlinux/chain.c32: No such file"
311 exit 1
314 cp -f /usr/lib/extlinux/chain.c32 "${_EXTLINUX_DIRECTORY}"
316 # Create os-prober.cfg
317 _CONFIG="\
318 ## ${_EXTLINUX_DIRECTORY}/os-prober.cfg
320 ## IMPORTANT WARNING
322 ## The configuration of this file is generated automatically.
323 ## Do not edit this file manually, use: extlinux-update
328 for _OS in $(os-prober | tr ' ' '^' | paste -s -d ' ')
330 _DEVICE="$(echo ${_OS} | cut -d ':' -f 1)"
331 _LONGNAME="$(echo ${_OS} | cut -d ':' -f 2 | tr '^' ' ')"
332 _LABEL="$(echo ${_OS} | cut -d ':' -f 3 | tr '^' ' ')"
333 _BOOT="$(echo ${_OS} | cut -d ':' -f 4)"
335 if [ "${_BOOT}" != "chain" ]
336 then
337 continue
340 if [ -z "${_LONGNAME}" ]
341 then
342 _LONGNAME="${_LABEL}"
345 _NUMBER="${_NUMBER:-0}"
347 echo "P: Writing config for ${_LONGNAME} on ${_DEVICE}..."
349 _DEVICENAME="$(echo ${_DEVICE} | sed -e 's/^\/dev\/[sh]d//' -e 'y/abcdefghij/0123456789/' -e 's/./& /')"
351 # Writing other os entry
352 _CONFIG="${_CONFIG}
354 label o${_NUMBER}
355 menu label Other OS, ${_LONGNAME} (on ${_DEVICE})
356 kernel chain.c32
357 append hd${_DEVICENAME}"
359 _NUMBER="$((${_NUMBER} + 1))"
360 done
362 _NUMBER=""
364 Update "${_EXTLINUX_DIRECTORY}/os-prober.cfg" "${_CONFIG}"
368 # Create the main extlinux.conf file
369 _CONFIG="\
370 ## ${_EXTLINUX_DIRECTORY}/extlinux.conf
372 ## IMPORTANT WARNING
374 ## The configuration of this file is generated automatically.
375 ## Do not edit this file manually, use: extlinux-update
378 default ${EXTLINUX_DEFAULT}
379 prompt 1
380 timeout ${EXTLINUX_TIMEOUT}
383 if [ -n "${EXTLINUX_THEME}" ] && [ "${EXTLINUX_THEME}" != "none" ]
384 then
385 if [ ! -e "/usr/share/syslinux/themes/${EXTLINUX_THEME}/extlinux" ]
386 then
387 echo "E: /usr/share/syslinux/themes/${EXTLINUX_THEME}/extlinux: No such file or directory"
388 exit 1
389 else
390 echo -n "P: Installing ${EXTLINUX_THEME} theme..."
391 rm -rf "${_EXTLINUX_DIRECTORY}/themes/${EXTLINUX_THEME}"
393 mkdir -p "${_EXTLINUX_DIRECTORY}/themes"
395 EXTLINUX_THEME_ORIG="$(readlink /usr/share/syslinux/themes/${EXTLINUX_THEME})" || true
397 if [ -n "${EXTLINUX_THEME_ORIG}" ]
398 then
399 cp -aL "/usr/share/syslinux/themes/${EXTLINUX_THEME_ORIG}/extlinux" "${_EXTLINUX_DIRECTORY}/themes/${EXTLINUX_THEME_ORIG}"
400 ln -sf "${EXTLINUX_THEME_ORIG}" "${_EXTLINUX_DIRECTORY}/themes/${EXTLINUX_THEME}"
401 else
402 cp -aL "/usr/share/syslinux/themes/${EXTLINUX_THEME}/extlinux" "${_EXTLINUX_DIRECTORY}/themes/${EXTLINUX_THEME}"
405 echo " done."
408 _CONFIG="${_CONFIG}
409 include themes/${EXTLINUX_THEME}/theme.cfg"
411 else
413 _CONFIG="${_CONFIG}
414 display boot.txt
415 include linux.cfg"
417 if [ "${EXTLINUX_MEMDISK}" = "true" ] && [ -e "${_EXTLINUX_DIRECTORY}/memdisk.cfg" ]
418 then
420 _CONFIG="${_CONFIG}
421 include memdisk.cfg"
425 if [ "${EXTLINUX_OS_PROBER}" = "true" ] && [ -e "${_EXTLINUX_DIRECTORY}/os-prober.cfg" ]
426 then
428 _CONFIG="${_CONFIG}
429 include os-prober.cfg"
433 if [ ! -e "${_EXTLINUX_DIRECTORY}/boot.txt" ]
434 then
435 echo "Wait 5 seconds or press ENTER to " > "${_EXTLINUX_DIRECTORY}/boot.txt"
439 Update "${_EXTLINUX_DIRECTORY}/extlinux.conf" "${_CONFIG}"