Annotation of /trunk/mlivecdbuild/mlivecdbuild2.sh
Parent Directory | Revision Log
Revision 978 -
(hide annotations)
(download)
(as text)
Thu Apr 29 20:37:04 2010 UTC (14 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 8959 byte(s)
Thu Apr 29 20:37:04 2010 UTC (14 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 8959 byte(s)
-hwdetect rc script not needed anymore
1 | niro | 346 | #!/bin/bash |
2 | |||
3 | # some default settings - gets overidden with the profile config | ||
4 | niro | 360 | CDPROFILE="$2" |
5 | niro | 346 | [[ -z ${CDPROFILE} ]] && CDPROFILE="default" |
6 | LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}" | ||
7 | CDCHROOTDIR="${LIVECDROOT}/chroot" | ||
8 | CDISONAME="livecd-${CDPROFILE}.iso" | ||
9 | CDISOROOT="${LIVECDROOT}/isoroot" | ||
10 | CDKERNELNAME="magelive" | ||
11 | CDHOSTNAME="livecd-${CDPROFILE}" | ||
12 | MAGERC="/etc/mage.rc" | ||
13 | MAGE_PROFILE="$(basename $(readlink /etc/mage-profile))" | ||
14 | #TOOLCHAIN=toolchain | ||
15 | BASESYSTEM=livecdsystem26 | ||
16 | CDID="mlcd-$(date +%F-%k%M)" | ||
17 | |||
18 | # global profile pathes | ||
19 | PROFILES_DIR="/usr/lib/mlivecdbuild/profiles" | ||
20 | GLOBAL_PROFILE="${PROFILES_DIR}/global" | ||
21 | |||
22 | die() { echo "ERROR: $@"; exit 1; } | ||
23 | |||
24 | # get_profile $filename | ||
25 | get_profile() | ||
26 | { | ||
27 | local file="$1" | ||
28 | |||
29 | if [[ -z ${file} ]] || [[ ! -e ${PROFILES_DIR}/${CDPROFILE}/${file} ]] | ||
30 | then | ||
31 | echo "${GLOBAL_PROFILE}/${file}" | ||
32 | return 0 | ||
33 | fi | ||
34 | |||
35 | echo "${PROFILES_DIR}/${CDPROFILE}/${file}" | ||
36 | } | ||
37 | |||
38 | bootstrap_system() | ||
39 | { | ||
40 | mage-bootstrap \ | ||
41 | --root "${CDCHROOTDIR}" \ | ||
42 | --magerc "${MAGERC}" \ | ||
43 | --profile "${MAGE_PROFILE}" \ | ||
44 | --toolchain "${TOOLCHAIN}" \ | ||
45 | --basesystem "${BASESYSTEM}" \ | ||
46 | || die "bootstrapping toolchain" | ||
47 | } | ||
48 | |||
49 | niro | 360 | custom_services() |
50 | { | ||
51 | local cmd="$1" | ||
52 | local services="$2" | ||
53 | |||
54 | case ${cmd} in | ||
55 | niro | 471 | add|del|default) |
56 | # add given services from profile | ||
57 | if [[ -n ${services} ]] | ||
58 | then | ||
59 | local i | ||
60 | for i in ${services} | ||
61 | do | ||
62 | MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}" | ||
63 | done | ||
64 | fi | ||
65 | ;; | ||
66 | niro | 360 | *) die "custom_services: unkown command ${cmd}";; |
67 | esac | ||
68 | } | ||
69 | |||
70 | add_initrc() | ||
71 | { | ||
72 | local var="$1" | ||
73 | |||
74 | # sanity checks | ||
75 | niro | 473 | [[ -z ${CDCHROOTDIR} ]] && die "\$CDCHROOTDIR not given." |
76 | niro | 360 | echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var" |
77 | } | ||
78 | |||
79 | custom_packages() | ||
80 | { | ||
81 | local cmd="$1" | ||
82 | local packages="$2" | ||
83 | |||
84 | case ${cmd} in | ||
85 | niro | 471 | install|uninstall) |
86 | if [[ -n ${packages} ]] | ||
87 | then | ||
88 | :> ${CDCHROOTDIR}/.installrc | ||
89 | niro | 472 | |
90 | # respect proxies | ||
91 | [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}" | ||
92 | [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}" | ||
93 | [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}" | ||
94 | |||
95 | niro | 580 | # do not auto-start any services! |
96 | add_initrc "export MAGE_BOOTSTRAP=true" | ||
97 | niro | 863 | add_initrc 'die() { if [ $? -eq 1 ]; then echo "ERROR: $@"; exit 1; fi; }' |
98 | niro | 580 | |
99 | niro | 471 | local i |
100 | for i in ${packages} | ||
101 | do | ||
102 | niro | 863 | add_initrc "mage ${cmd} ${i} || die ${i}" |
103 | niro | 471 | done |
104 | add_initrc "mage clean" | ||
105 | |||
106 | # now run the .installrc script | ||
107 | mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc" | ||
108 | mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys" | ||
109 | mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev" | ||
110 | chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting" | ||
111 | umount ${CDCHROOTDIR}/dev || die "umount dev" | ||
112 | umount ${CDCHROOTDIR}/proc || die "umount proc" | ||
113 | umount ${CDCHROOTDIR}/sys || die "umount sys" | ||
114 | [ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc | ||
115 | fi | ||
116 | ;; | ||
117 | niro | 360 | *) die "custom_packages: unkown command ${cmd}";; |
118 | esac | ||
119 | } | ||
120 | |||
121 | read_config() | ||
122 | { | ||
123 | local file="$1" | ||
124 | local pkg | ||
125 | |||
126 | ( cat ${file}; echo ) | while read pkg | ||
127 | do | ||
128 | case "${pkg}" in | ||
129 | \#*|"") continue ;; | ||
130 | esac | ||
131 | echo "${pkg}" | ||
132 | done | ||
133 | } | ||
134 | |||
135 | niro | 346 | prepare_iso() |
136 | { | ||
137 | echo Preparing LiveCD ISO Image ... | ||
138 | |||
139 | # fixes some issues with xfree/xorg xkb | ||
140 | niro | 473 | if [[ -L ${CDCHROOTDIR}/etc/X11/xkb ]] && [[ -d /usr/X11R6/lib/X11/xkb ]] |
141 | niro | 346 | then |
142 | rm ${CDCHROOTDIR}/etc/X11/xkb || die | ||
143 | mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die | ||
144 | ln -s ../../../../etc/X11/xkb ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb || die | ||
145 | fi | ||
146 | |||
147 | install -m 0644 $(get_profile inittab) ${CDCHROOTDIR}/etc/inittab || die | ||
148 | install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die | ||
149 | install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die | ||
150 | install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die | ||
151 | niro | 712 | install -m 0644 $(get_profile net.eth0) ${CDCHROOTDIR}/etc/conf.d/net.eth0 || die |
152 | niro | 346 | echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die |
153 | |||
154 | echo Setting up services ... | ||
155 | |||
156 | niro | 978 | # # add hardware detection |
157 | # MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect" | ||
158 | niro | 346 | |
159 | # del checkfs | ||
160 | MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs" | ||
161 | |||
162 | niro | 360 | # add custom packages |
163 | [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}" | ||
164 | [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))" | ||
165 | |||
166 | # del custom packages | ||
167 | [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}" | ||
168 | [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))" | ||
169 | |||
170 | # add given services from profile | ||
171 | [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}" | ||
172 | [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))" | ||
173 | |||
174 | # del given services from profile | ||
175 | [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}" | ||
176 | [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))" | ||
177 | |||
178 | # setup default runlevel | ||
179 | [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}" | ||
180 | |||
181 | if [ -f $(get_profile prepare_custom) ] | ||
182 | then | ||
183 | echo Running custom user script ... | ||
184 | source $(get_profile prepare_custom) || die "running custom user script" | ||
185 | fi | ||
186 | |||
187 | niro | 346 | echo Cleaning unwanted files ... |
188 | :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab" | ||
189 | niro | 360 | [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history |
190 | niro | 346 | } |
191 | |||
192 | generate_rootfs() | ||
193 | { | ||
194 | echo Generating squashfs compressed rootfs loopfile ... | ||
195 | mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh #>/dev/null 2>&1 | ||
196 | |||
197 | echo Moving rootfs loopfile to isoroot ... | ||
198 | install -d ${CDISOROOT} | ||
199 | mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT} | ||
200 | } | ||
201 | |||
202 | install_bootloader() | ||
203 | { | ||
204 | echo Installing Bootloader ... | ||
205 | |||
206 | # iso linux binary | ||
207 | install -d ${CDISOROOT}/isolinux | ||
208 | niro | 348 | install /usr/lib/mkinitrd/isolinux.bin ${CDISOROOT}/isolinux || die |
209 | niro | 346 | |
210 | # kernel | ||
211 | local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))" | ||
212 | install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/isolinux/${CDKERNELNAME} || die | ||
213 | |||
214 | install -m 0644 $(get_profile isolinux.cfg) ${CDISOROOT}/isolinux || die | ||
215 | install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die | ||
216 | install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die | ||
217 | install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die | ||
218 | |||
219 | return 0 | ||
220 | } | ||
221 | |||
222 | generate_initrd() | ||
223 | { | ||
224 | local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})" | ||
225 | |||
226 | echo Generating initrd image ... | ||
227 | echo '#!/bin/bash' > ${CHROOTSH} || die | ||
228 | echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die | ||
229 | echo 'kv="${kv/kernel-}/"' >> ${CHROOTSH} || die | ||
230 | echo 'mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die | ||
231 | chmod +x ${CHROOTSH} || die | ||
232 | chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die | ||
233 | [[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die | ||
234 | |||
235 | # move initrd to isoroot | ||
236 | install -d ${CDISOROOT}/isolinux || die | ||
237 | mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die | ||
238 | } | ||
239 | |||
240 | generate_iso() | ||
241 | { | ||
242 | echo Generating ISO Image ... | ||
243 | install -d ${CDISOROOT} | ||
244 | pushd ${CDISOROOT} && | ||
245 | mkisofs -rock \ | ||
246 | -full-iso9660-filenames \ | ||
247 | -allow-leading-dots \ | ||
248 | -disable-deep-relocation \ | ||
249 | -output ${LIVECDROOT}/${CDISONAME} \ | ||
250 | -eltorito-boot isolinux/isolinux.bin \ | ||
251 | -eltorito-catalog isolinux/boot.cat \ | ||
252 | -no-emul-boot \ | ||
253 | -boot-load-size 4 \ | ||
254 | -boot-info-table \ | ||
255 | -volid "${CDID}" \ | ||
256 | ${CDISOROOT} #&> /dev/null | ||
257 | popd | ||
258 | } | ||
259 | |||
260 | enter_livecd() | ||
261 | { | ||
262 | niro | 609 | mount -t sysfs sysfs ${CDCHROOTDIR}/sys |
263 | niro | 346 | mount -t proc proc ${CDCHROOTDIR}/proc |
264 | mount -o bind /dev ${CDCHROOTDIR}/dev | ||
265 | |||
266 | chroot ${CDCHROOTDIR} \ | ||
267 | /usr/bin/env -i \ | ||
268 | HOME=/root \ | ||
269 | TERM=$TERM PS1='\u:\w\$ ' \ | ||
270 | PATH=/bin:/usr/bin:/sbin:/usr/sbin \ | ||
271 | niro | 472 | http_proxy=${http_proxy} \ |
272 | ftp_proxy=${ftp_proxy} \ | ||
273 | no_proxy=${no_proxy} \ | ||
274 | niro | 346 | /bin/bash -i |
275 | niro | 609 | |
276 | umount ${CDCHROOTDIR}/dev | ||
277 | umount ${CDCHROOTDIR}/proc | ||
278 | umount ${CDCHROOTDIR}/sys | ||
279 | niro | 346 | } |
280 | |||
281 | niro | 360 | usage() |
282 | { | ||
283 | echo "Usage: $(basename $0) [command] [profile] ..." | ||
284 | echo | ||
285 | echo "Commands:" | ||
286 | echo " bootstrap - bootstraps the rootfs for the livecd" | ||
287 | echo " prepare - prepare the rootfs to run from a livecd" | ||
288 | echo " rootfs - generates the squashfs rootfs image" | ||
289 | echo " initrd - generates a livecd suitable initrd" | ||
290 | echo " bootloader - installs the bootloader" | ||
291 | echo " isogen - generate the final livecd iso image" | ||
292 | echo " all - runs all tasks to get a livecd from zero" | ||
293 | niro | 472 | echo " enter - enters the rootfs of a livecd" |
294 | niro | 360 | echo |
295 | echo " for example '$(basename $0) all default'" | ||
296 | echo " creates a livecd using the default profile." | ||
297 | echo | ||
298 | } | ||
299 | |||
300 | niro | 346 | # source profile config - overrides all other vars |
301 | [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config | ||
302 | |||
303 | niro | 360 | case $1 in |
304 | bootstrap) bootstrap_system;; | ||
305 | prepare) prepare_iso;; | ||
306 | rootfs) generate_rootfs;; | ||
307 | initrd) generate_initrd;; | ||
308 | bootloader) install_bootloader;; | ||
309 | isogen) generate_iso;; | ||
310 | all) | ||
311 | bootstrap_system | ||
312 | prepare_iso | ||
313 | generate_rootfs | ||
314 | generate_initrd | ||
315 | install_bootloader | ||
316 | niro | 713 | generate_iso |
317 | niro | 360 | ;; |
318 | niro | 472 | enter) enter_livecd ;; |
319 | niro | 360 | *|'') usage;; |
320 | esac |