Adding debian version 3.86+dfsg-5.
[syslinux-debian/hramrach.git] / debian / local / update-extlinux
blob82523fcf52bfeca45008bd334fcbc48aae230651
1 #!/bin/sh
3 set -e
5 DEVICE="${1}"
7 # User is unprivileged
8 if [ "$(id -u)" -ne 0 ]
9 then
10 echo "E: need root privileges"
11 exit 1
14 # Searching extlinux directory
15 echo -n "P: Searching for EXTLINUX directory..."
17 for LOCATION in /boot/extlinux /boot/boot/exlinux /extlinux
19 if [ -e "${LOCATION}" ]
20 then
21 DIRECTORY="${LOCATION}"
23 echo " found: ${DIRECTORY}"
24 break
26 done
28 if [ -z "${DIRECTORY}" ]
29 then
30 echo " not found."
32 echo "E: To create a template run 'mkdir /boot/extlinux' first."
33 echo "E: To install extlinux, do it manually or try the 'extlinux-install' command."
34 echo "E: Warning, extlinux-install is used to change your MBR."
36 exit 1
39 if [ ! -e /etc/default/extlinux ]
40 then
41 EXTLINUX_UPDATE="true"
42 EXTLINUX_ALTERNATIVES="default recovery"
43 EXTLINUX_DEFAULT="0"
45 if [ -x "$(which lsb_release 2>/dev/null)" ]
46 then
47 EXTLINUX_MENU_LABEL="$(lsb_release -i -s) GNU/Linux, kernel"
48 else
49 EXTLINUX_MENU_LABEL="Debian GNU/Linux, kernel"
52 EXTLINUX_PARAMETERS="ro quiet"
54 # Find root partition
55 while read LINE
58 read fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno << EOF
59 ${LINE}
60 EOF
62 if [ "${fs_spec}" != "#" ] && [ "${fs_file}" = "/" ]
63 then
64 EXTLINUX_ROOT="root=${fs_spec}"
65 break
67 done < /etc/fstab
69 if [ -e /usr/share/syslinux/themes/debian/extlinux ]
70 then
71 EXTLINUX_THEME=debian
72 else
73 EXTLINUX_THEME=
76 EXTLINUX_TIMEOUT="50"
78 cat > "/etc/default/extlinux" << EOF
79 ## /etc/default/extlinux
81 EXTLINUX_UPDATE="${EXTLINUX_UPDATE}"
83 EXTLINUX_ALTERNATIVES="${EXTLINUX_ALTERNATIVES}"
84 EXTLINUX_DEFAULT="${EXTLINUX_DEFAULT}"
85 EXTLINUX_MENU_LABEL="${EXTLINUX_MENU_LABEL}"
86 EXTLINUX_PARAMETERS="${EXTLINUX_PARAMETERS}"
87 EXTLINUX_ROOT="${EXTLINUX_ROOT}"
88 EXTLINUX_THEME="${EXTLINUX_THEME}"
89 EXTLINUX_TIMEOUT="${EXTLINUX_TIMEOUT}"
90 EOF
92 else
93 . /etc/default/extlinux
96 if [ "${EXTLINUX_UPDATE}" != "true" ]
97 then
98 echo "P: extlinux-update is disabled in /etc/default/extlinux."
100 exit 0
103 # Create linux.cfg
104 cat > "${DIRECTORY}/linux.cfg" << EOF
105 ## ${DIRECTORY}/linux.cfg
107 ## IMPORTANT WARNING
109 ## The configuration of this file is generated automatically.
110 ## Do not edit this file manually, use: update-extlinux
114 # Find linux versions
115 VERSIONS="$(cd /boot && ls vmlinuz-* | sed -e 's|vmlinuz-||g' | sort -r)"
117 if [ "$(stat --printf %d /)" = "$(stat --printf %d /boot)" ]
118 then
119 # / and /boot are on the same filesystem
120 BOOT="/boot"
121 else
122 # / and /boot are not on the same filesystem
123 BOOT=""
126 for VERSION in ${VERSIONS}
128 echo "P: Writing config for /boot/vmlinuz-${VERSION}..."
130 NUMBER="${NUMBER:-0}"
132 if [ -e /boot/initrd.img-${VERSION} ]
133 then
134 INITRD="initrd=${BOOT}/initrd.img-${VERSION}"
135 else
136 INITRD=""
139 if echo ${EXTLINUX_ALTERNATIVES} | grep -q default
140 then
142 # Writing default entry
143 cat >> "${DIRECTORY}/linux.cfg" << EOF
145 label ${NUMBER}
146 menu label ${EXTLINUX_MENU_LABEL} ${VERSION}
147 menu default
148 kernel ${BOOT}/vmlinuz-${VERSION}
149 append ${INITRD} ${EXTLINUX_ROOT} ${EXTLINUX_PARAMETERS}
154 if echo ${EXTLINUX_ALTERNATIVES} | grep -q live
155 then
157 # Writing live entry
158 cat >> "${DIRECTORY}/linux.cfg" << EOF
160 label ${NUMBER}l
161 menu label ${EXTLINUX_MENU_LABEL} ${VERSION} (live mode)
162 menu default
163 kernel ${BOOT}/vmlinuz-${VERSION}
164 append ${INITRD} ${EXTLINUX_ROOT} ${EXTLINUX_PARAMETERS} boot=live plainroot
165 text help
166 This option boots the system into live mode (non-persistent)
167 endtext
172 if echo ${EXTLINUX_ALTERNATIVES} | grep -q recovery
173 then
175 # Writing recovery entry
176 cat >> "${DIRECTORY}/linux.cfg" << EOF
178 label ${NUMBER}r
179 menu label ${EXTLINUX_MENU_LABEL} ${VERSION} (recovery mode)
180 menu default
181 kernel ${BOOT}/vmlinuz-${VERSION}
182 append ${INITRD} ${EXTLINUX_ROOT} ${EXTLINUX_PARAMETERS} single
183 text help
184 This option boots the system into recovery mode (single-user)
185 endtext
190 NUMBER="$((${NUMBER} + 1))"
191 done
193 cat > "${DIRECTORY}/extlinux.conf" << EOF
194 ## ${DIRECTORY}/extlinux.conf
196 ## IMPORTANT WARNING
198 ## The configuration of this file is generated automatically.
199 ## Do not edit this file manually, use: update-extlinux
202 default ${EXTLINUX_DEFAULT}
203 prompt 1
204 timeout ${EXTLINUX_TIMEOUT}
207 if [ -n "${EXTLINUX_THEME}" ]
208 then
209 if [ ! -e "/usr/share/syslinux/themes/${EXTLINUX_THEME}/extlinux" ]
210 then
211 echo "E: /usr/share/syslinux/${EXTLINUX_THEME}/extlinux: No such file or directory"
212 exit 1
213 else
214 echo -n "P: Installing ${EXTLINUX_THEME} theme..."
215 rm -rf "${DIRECTORY}/themes/${EXTLINUX_THEME}"
217 mkdir -p "${DIRECTORY}/themes"
218 cp -aL "/usr/share/syslinux/themes/${EXTLINUX_THEME}/extlinux" "${DIRECTORY}/themes/${EXTLINUX_THEME}"
219 echo " done."
222 cat >> "${DIRECTORY}/extlinux.conf" << EOF
224 include themes/${EXTLINUX_THEME}/theme.cfg
227 else
229 cat >> "${DIRECTORY}/extlinux.conf" << EOF
231 display boot.txt
232 include linux.cfg
235 if [ ! -e "${DIRECTORY}/boot.txt" ]
236 then
237 echo "Wait 5 seconds or press ENTER to " > "${DIRECTORY}/boot.txt"