summaryrefslogtreecommitdiff
path: root/scripts/build/lb_binary_syslinux
blob: 391c860262ec83eb1a5e5775473f32df5ff68925 (plain)
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
#!/bin/sh

## live-build(7) - System Build Scripts
## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
##
## live-build comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


set -e

# Including common functions
. "${LB_BASE:-/usr/share/live/build}"/scripts/build.sh

# Setting static variables
DESCRIPTION="$(Echo 'installs syslinux into binary')"
HELP=""
USAGE="${PROGRAM} [--force]"

Arguments "${@}"

# Reading configuration files
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
Set_defaults

if [ "${LB_BOOTLOADER}" != "syslinux" ]
then
	exit 0
fi

Echo_message "Begin installing syslinux..."

# Requiring stage file
Require_stagefile .stage/config .stage/bootstrap

# Checking stage file
Check_stagefile .stage/binary_syslinux

# Checking lock file
Check_lockfile .lock

# Creating lock file
Create_lockfile .lock

# Check architecture
Check_architectures amd64 i386
Check_crossarchitectures

# Assembling image specifics
case "${LB_BINARY_IMAGES}" in
	iso*)
		_BOOTLOADER="isolinux"
		_TARGET="binary/isolinux"
		;;

	net*)
		_BOOTLOADER="pxelinux"
		_TARGET="tftpboot"
		;;

	hdd*|*)
		_BOOTLOADER="syslinux"
		_TARGET="binary/syslinux"
		;;
esac

# Checking depends
case "${LB_BUILD_WITH_CHROOT}" in
	true)
		Check_package chroot/usr/bin/syslinux syslinux
		Check_package chroot/usr/lib/syslinux syslinux-common

		if [ "${LB_SYSLINUX_THEME}" != "live-build" ]
		then
			Check_package chroot/usr/share/syslinux/themes/${LB_SYSLINUX_THEME} syslinux-themes-${LB_SYSLINUX_THEME}

			case "${LB_MODE}" in
				ubuntu)
					Check_package chroot/usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz gfxboot-theme-ubuntu
					;;
			esac
		fi
		;;

	false)
		if [ ! -e /usr/bin/syslinux ]
		then
			# syslinux
			Echo_error "/usr/bin/syslinux - no such file."
			exit 1
		fi

		if [ ! -e /usr/lib/syslinux ]
		then
			# syslinux-common
			Echo_error "/usr/lib/syslinux - no such directory"
			exit 1
		fi

		if [ "${LB_SYSLINUX_THEME}" != "live-build" ]
		then
			if [ ! -e /usr/share/syslinux/themes/${LB_SYSLINUX_THEME} ]
			then
				# syslinux-theme
				Echo_error "/usr/share/syslinux/themes/${LB_SYSLINUX_THEME} - no such directory."
				exit 1
			fi
		fi
		;;
esac

# Restoring cache
Restore_cache cache/packages_binary

# Installing depends
Install_package

# FIXME: cleanup, unify, and extend themes for ${_BOOTLOADER}-live and ${_BOOTLOADER}-installer
if [ "${LB_SYSLINUX_THEME}" = "live-build" ]
then
	if [ -e "config/bootloaders/${_BOOTLOADER}" ]
	then
		# Internal local copy
		_SOURCE="config/bootloaders/${_BOOTLOADER}"
	else
		# Internal system copy
		_SOURCE="${LB_BASE:-/usr/share/live/build}/bootloaders/${_BOOTLOADER}"
	fi
else
	# External copy from chroot or system
	_SOURCE="/usr/share/syslinux/themes/${LB_SYSLINUX_THEME}/${_BOOTLOADER}-live"
fi

# Copying files
mkdir -p $(dirname ${_TARGET})

case "${LB_BUILD_WITH_CHROOT}" in
	true)
		# Copy in two steps since the theme can have absolute symlinks and would therefore not be dereferenced correctly
		if [ "${LB_SYSLINUX_THEME}" = "live-build" ]
		then
			cp -a ${_SOURCE} chroot/root
			Chroot chroot cp -aL /root/$(basename ${_SOURCE}) /root/$(basename ${_SOURCE}).tmp
			rm -rf chroot/$(basename ${_SOURCE})
		else
			Chroot chroot cp -aL ${_SOURCE} /root/$(basename ${_SOURCE}).tmp
		fi

		case "${LB_MODE}" in
			ubuntu)
				Chroot chroot "tar xfz /usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz -C /root/tmp"
				;;
		esac

		mv chroot/root/$(basename ${_SOURCE}).tmp ${_TARGET}
		;;

	false)
		cp -aL ${_SOURCE}/* ${_TARGET}

		case "${LB_MODE}" in
			ubuntu)
				tar xfz /usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz -C ${_TARGET}
				;;
		esac
		;;
esac

# Configuring files
if [ -e "${_TARGET}/live.cfg.in" ]
then
	# This is all rather suboptimal.. needs prettifying at some point
	_FLAVOURS="$(echo ${LB_LINUX_FLAVOURS} | wc -w)"

	case "${_FLAVOURS}" in
		1)
			mv binary/live/vmlinuz-* binary/live/vmlinuz
			mv binary/live/initrd.img-* binary/live/initrd.img

			sed -e "s|@FLAVOUR@|${LB_LINUX_FLAVOUR}|g" \
			    -e "s|@KERNEL@|/live/vmlinuz|g" \
			    -e "s|@INITRD@|/live/initrd.img|g" \
			    -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
			"${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"

			rm -f "${_TARGET}/live.cfg.in"
			;;

		*)
			_NUMBER="0"

			for _FLAVOUR in ${LB_LINUX_FLAVOURS}
			do
				_NUMBER="$((${_NUMBER} + 1))"

				mv binary/live/vmlinuz-*-${_FLAVOUR} binary/live/vmlinuz${_NUMBER}
				mv binary/live/initrd.img-*-${_FLAVOUR} binary/live/initrd${_NUMBER}.img

				sed -e "s|@FLAVOUR@|${_FLAVOUR}|g" \
				    -e "s|@KERNEL@|/live/vmlinuz${_NUMBER}|g" \
				    -e "s|@INITRD@|/live/initrd${_NUMBER}.img|g" \
				    -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
				"${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
			done

			rm -f "${_TARGET}/live.cfg.in"
			;;
	esac
elif [ -e "${_TARGET}/live.cfg" ]
then
	sed -i -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
	${_TARGET}/live.cfg
fi

if [ -e ${_TARGET}/install.cfg ]
then
	sed -i -e "s|@LB_BOOTAPPEND_INSTALL@|${LB_BOOTAPPEND_INSTALL}|g" \
	${_TARGET}/install.cfg
fi

case "${LB_BUILD_WITH_CHROOT}" in
	true)
		# Saving cache
		Save_cache cache/packages_binary

		# Removing depends
		Remove_package
		;;
esac

# Creating stage file
Create_stagefile .stage/binary_syslinux