File: extlinux-update

package info (click to toggle)
syslinux 2%3A4.02%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 23,804 kB
  • ctags: 71,027
  • sloc: ansic: 270,621; pascal: 9,631; asm: 9,089; perl: 3,492; makefile: 1,588; sh: 511; python: 266; xml: 39
file content (264 lines) | stat: -rw-r--r-- 5,733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/sh

set -e

_DEVICE="${1}"
_DIRECTORY="/boot/extlinux"

# User is unprivileged
if [ "$(id -u)" -ne 0 ]
then
	echo "E: need root privileges"
	exit 1
fi

# Redirect stdout to stderr due Debconf usage
exec 1>&2

# Checking extlinux directory
echo -n "P: Checking for EXTLINUX directory..."

# Creating extlinux directory
if [ ! -e "${_DIRECTORY}" ]
then
	echo " not found."

	echo -n "P: Creating EXTLINUX directory..."
	mkdir -p "${_DIRECTORY}"
	echo " done: ${_DIRECTORY}"
else
	echo " found."
fi

# Reading old default file
if [ -e /etc/default/extlinux ]
then
	. /etc/default/extlinux
fi

# Setting defaults
EXTLINUX_UPDATE="${EXTLINUX_UPDATE:-true}"
EXTLINUX_ALTERNATIVES="${EXTLINUX_ALTERNATIVES:-default recovery}"
EXTLINUX_DEFAULT="${EXTLINUX_DEFAULT:-0}"
EXTLINUX_ENTRIES="${EXTLINUX_ENTRIES:-all}"

if [ -z "${EXTLINUX_MENU_LABEL}" ]
then
	if [ -x "$(which lsb_release 2>/dev/null)" ]
	then
		EXTLINUX_MENU_LABEL="$(lsb_release -i -s) GNU/Linux, kernel"
	else
		EXTLINUX_MENU_LABEL="Debian GNU/Linux, kernel"
	fi
fi

EXTLINUX_PARAMETERS="${EXTLINUX_PARAMETERS:-ro quiet}"

if [ -z "${EXTLINUX_ROOT}" ]
then
	# Find root partition
	while read _LINE
	do

read _FS_SPEC _FS_FILE _FS_VFSTYPE _FS_MNTOPS _FS_FREQ _FS_PASSNO << EOF
${_LINE}
EOF

		if [ "${_FS_SPEC}" != "#" ] && [ "${_FS_FILE}" = "/" ]
		then
			EXTLINUX_ROOT="root=${_FS_SPEC}"
			break
		fi
	done < /etc/fstab
fi

if [ -z "${EXTLINUX_THEME}" ]
then
	# Using default menu if available
	if [ -e /usr/share/syslinux/themes/debian/extlinux ]
	then
		EXTLINUX_THEME="debian"
	else
		EXTLINUX_THEME="none"
	fi
fi

EXTLINUX_TIMEOUT="${EXTLINUX_TIMEOUT:-50}"

# Writing new default file
cat > "/etc/default/extlinux" << EOF
## /etc/default/extlinux - configuration file for extlinux-update(8)

EXTLINUX_UPDATE="${EXTLINUX_UPDATE}"

EXTLINUX_ALTERNATIVES="${EXTLINUX_ALTERNATIVES}"
EXTLINUX_DEFAULT="${EXTLINUX_DEFAULT}"
EXTLINUX_ENTRIES="${EXTLINUX_ENTRIES}"
EXTLINUX_MENU_LABEL="${EXTLINUX_MENU_LABEL}"
EXTLINUX_PARAMETERS="${EXTLINUX_PARAMETERS}"
EXTLINUX_ROOT="${EXTLINUX_ROOT}"
EXTLINUX_THEME="${EXTLINUX_THEME}"
EXTLINUX_TIMEOUT="${EXTLINUX_TIMEOUT}"
EOF

if [ "${EXTLINUX_UPDATE}" != "true" ]
then
	echo "P: extlinux-update is disabled in /etc/default/extlinux."

	exit 0
fi

# Create linux.cfg
cat > "${_DIRECTORY}/linux.cfg" << EOF
## ${_DIRECTORY}/linux.cfg
##
## IMPORTANT WARNING
##
## The configuration of this file is generated automatically.
## Do not edit this file manually, use: extlinux-update


default 0

EOF

# Find linux versions
_VERSIONS="$(cd /boot && ls vmlinuz-* | sed -e 's|vmlinuz-||g' | sort -r)"

if [ "$(stat --printf %d /)" = "$(stat --printf %d /boot)" ]
then
	# / and /boot are on the same filesystem
	_BOOT="/boot"
else
	# / and /boot are not on the same filesystem
	_BOOT=""
fi


for _VERSION in ${_VERSIONS}
do
	echo "P: Writing config for /boot/vmlinuz-${_VERSION}..."

	_NUMBER="${_NUMBER:-0}"
	_ENTRY="${_ENTRY:-1}"

	if [ -e /boot/initrd.img-${_VERSION} ]
	then
		_INITRD="initrd=${_BOOT}/initrd.img-${_VERSION}"
	else
		_INITRD=""
	fi

	if echo ${EXTLINUX_ALTERNATIVES} | grep -q default
	then

# Writing default entry
cat >> "${_DIRECTORY}/linux.cfg" << EOF

label ${_NUMBER}
	menu label ${EXTLINUX_MENU_LABEL} ${_VERSION}
	kernel ${_BOOT}/vmlinuz-${_VERSION}
	append ${_INITRD} ${EXTLINUX_ROOT} ${EXTLINUX_PARAMETERS}
EOF

	fi

	if echo ${EXTLINUX_ALTERNATIVES} | grep -q live
	then

# Writing live entry
cat >> "${_DIRECTORY}/linux.cfg" << EOF

label ${_NUMBER}l
	menu label ${EXTLINUX_MENU_LABEL} ${_VERSION} (live mode)
	kernel ${_BOOT}/vmlinuz-${_VERSION}
	append ${_INITRD} ${EXTLINUX_ROOT} ${EXTLINUX_PARAMETERS} boot=live plainroot
	text help
   This option boots the system into live mode (non-persistent)
	endtext
EOF

	fi

	if echo ${EXTLINUX_ALTERNATIVES} | grep -q recovery
	then

# Writing recovery entry
cat >> "${_DIRECTORY}/linux.cfg" << EOF

label ${_NUMBER}r
	menu label ${EXTLINUX_MENU_LABEL} ${_VERSION} (recovery mode)
	kernel ${_BOOT}/vmlinuz-${_VERSION}
	append ${_INITRD} ${EXTLINUX_ROOT} $(echo ${EXTLINUX_PARAMETERS} | sed -e 's| quiet||') single
	text help
   This option boots the system into recovery mode (single-user)
	endtext
EOF

	fi

	_NUMBER="$((${_NUMBER} + 1))"

	if [ "${EXTLINUX_ENTRIES}" = "${_ENTRY}" ]
	then
		break
	fi
done

cat > "${_DIRECTORY}/extlinux.conf" << EOF
## ${_DIRECTORY}/extlinux.conf
##
## IMPORTANT WARNING
##
## The configuration of this file is generated automatically.
## Do not edit this file manually, use: extlinux-update


default ${EXTLINUX_DEFAULT}
prompt 1
timeout ${EXTLINUX_TIMEOUT}
EOF

if [ -n "${EXTLINUX_THEME}" ] && [ "${EXTLINUX_THEME}" != "none" ]
then
	if [ ! -e "/usr/share/syslinux/themes/${EXTLINUX_THEME}/extlinux" ]
	then
		echo "E: /usr/share/syslinux/${EXTLINUX_THEME}/extlinux: No such file or directory"
		exit 1
	else
		echo -n "P: Installing ${EXTLINUX_THEME} theme..."
		rm -rf "${_DIRECTORY}/themes/${EXTLINUX_THEME}"

		mkdir -p "${_DIRECTORY}/themes"

		EXTLINUX_THEME_ORIG="$(readlink /usr/share/syslinux/themes/${EXTLINUX_THEME})" || true

		if [ -n "${EXTLINUX_THEME_ORIG}" ]
		then
			cp -aL "/usr/share/syslinux/themes/${EXTLINUX_THEME_ORIG}/extlinux" "${_DIRECTORY}/themes/${EXTLINUX_THEME_ORIG}"
			ln -sf "${EXTLINUX_THEME_ORIG}" "${_DIRECTORY}/themes/${EXTLINUX_THEME}"
		else
			cp -aL "/usr/share/syslinux/themes/${EXTLINUX_THEME}/extlinux" "${_DIRECTORY}/themes/${EXTLINUX_THEME}"
		fi

		echo " done."
	fi

cat >> "${_DIRECTORY}/extlinux.conf" << EOF

include themes/${EXTLINUX_THEME}/theme.cfg
EOF

else

cat >> "${_DIRECTORY}/extlinux.conf" << EOF

display boot.txt
include linux.cfg
EOF

	if [ ! -e "${_DIRECTORY}/boot.txt" ]
	then
		echo "Wait 5 seconds or press ENTER to " > "${_DIRECTORY}/boot.txt"
	fi
fi