3 # Purpose: build process script for generating a (grml based) Linux Live-ISO
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2 or any later version.
7 # Latest change: Thu Oct 04 22:16:28 CEST 2007 [mika]
8 ################################################################################
10 # read configuration files, set some misc variables {{{
18 # we need root permissions for the build-process:
19 if [ "$(id -u 2>/dev/null)" != 0 ] ; then
20 echo "Error: please run this script with uid 0 (root)." >&2
24 if [ -r /var/run/fai/FAI_INSTALLATION_IN_PROGRESS ] ; then
25 echo "/usr/sbin/fai already running or was aborted before."&>2
26 echo "You may remove /var/run/fai/FAI_INSTALLATION_IN_PROGRESS and try again.">&2
30 # make sure they are not set by default
34 if [ -r /etc/grml/lsb-functions ] ; then
35 . /etc/grml/lsb-functions
37 einfo() { echo " [*] $*" ;}
38 eerror() { echo " [!] $*">&2 ;}
39 ewarn() { echo " [x] $*" ;}
43 # source main configuration file:
44 LIVE_CONF=/etc/grml/grml-live.conf
52 [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_TARGET}/${MIRROR_DIRECTORY}"
53 [ -n "$1" ] && EXIT="$1" || EXIT="1"
54 [ -n "$2" ] && eerror "$2">&2
60 # check for important variables {{{
61 [ -n "$GRML_FAI_CONFIG" ] || GRML_FAI_CONFIG=/etc/grml/fai
62 [ -n "$HOSTNAME" ] || HOSTNAME=grml
63 [ -n "$USERNAME" ] || USERNAME=grml
64 [ -n "$CLASSES" ] || CLASSES="GRML,I386"
65 [ -n "$BOOT_METHOD" ] || BOOT_METHOD='isolinux'
66 [ -n "$TARGET" ] || bailout 1 "${PN}: \$TARGET not specified. Please adjust $LIVE_CONF. Exiting."
68 [ -n "$VERSION" ] || VERSION="0.0.1"
69 [ -n "$RELEASENAME" ] || RELEASENAME="grml-live rocks"
70 [ -n "$GRML_NAME" ] || GRML_NAME='grml'
72 [ -n "$LOGDIR" ] || LOGDIR="/var/log/fai/dirinstall/$HOSTNAME"
73 [ -d "$LOGDIR" ] || mkdir -p $LOGDIR
74 LOGFILE="$LOGDIR/grml-live.log"
77 # some important functions {{{
80 # usage: log "string to log"
81 log() { echo "$*" >> $LOGFILE ; }
83 # cut string at character number int = $1
84 # usage: cut_string 5 "1234567890" will output "12345"
86 [ -n "$2" ] || return 1
87 echo "$2" | head -c "$1"; echo -ne "\n"
90 # prepend int = $1 spaces before string = $2
91 # usage: extend_string_begin 5 "123" will output " 123"
92 extend_string_begin() {
93 [ -n "$2" ] || return 1
94 local COUNT="$(echo $2 | wc -c)"
95 local FILL="$(expr $COUNT - $1)"
96 while [ "$FILL" -gt 1 ] ; do
98 local FILL=$(expr $FILL - 1)
100 while [ "$FILL" -lt 1 ] ; do
102 local FILL=$(expr $FILL + 1)
104 echo "$2" | head -c "$1"; echo -ne "\n"
107 # append int = $1 spaces to string = $2
108 # usage: extend_string_begin 5 "123" will output "123 "
109 extend_string_end() {
110 [ -n "$2" ] || return 1
111 echo -n "$2" | head -c "$1"
112 local COUNT="$(echo $2 | wc -c)"
113 local FILL="$(expr $COUNT - $1)"
114 while [ "$FILL" -gt 1 ] ; do
116 local FILL=$(expr $FILL - 1)
118 while [ "$FILL" -lt 1 ] ; do
120 local FILL=$(expr $FILL + 1)
126 # usage information {{{
130 $PN - build process script for generating a (grml based) Linux Live-ISO
132 Usage: $PN [-c <classe[s]>] [-g <grml_name>] [-i <iso_name> ] \\
133 [-r <release_name>] [-s <suite>] [-t <target_directory>] \\
134 [-v <version_number>] [-FVh]
139 $PN -c GRMLBASE,GRML_X,I386 -t /grml/
140 $PN -c GRMLBASE,I386 -t /dev/shm/grml
141 $PN -c GRMLBASE,GRML_SMALL,I386 -g grml-small -v 1.0
142 $PN -c GRMLBASE,I386 -i grml_0.0-1.iso
143 $PN -c GRMLBASE,I386 -s sid -V
145 More details: man grml-live
146 /usr/share/doc/grml-live/grml-live.html
148 Please send your bug reports, feedback,.. to the grml-team.
149 http://grml.org/bugs/
154 # command line parsing {{{
156 while getopts "c:g:i:r:s:t:v:FhV" opt; do
158 c) CLASSES="$OPTARG" ;;
159 g) GRML_NAME="$OPTARG" ;;
160 i) ISO_NAME="$OPTARG" ;;
161 r) RELEASENAME="$OPTARG" ;;
162 s) SUITE="$OPTARG" ;;
164 CHROOT_TARGET="$TARGET/grml_chroot"
165 BUILD_TARGET="$TARGET/grml_cd"
166 ISO_TARGET="$TARGET/grml_isos"
168 v) VERSION="$OPTARG" ;;
170 h) usage ; bailout 0 ;;
172 ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;;
175 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
179 # some misc checks before executing FAI {{{
180 [ -n "$CLASSES" ] || bailout 1 "Error: \$CLASSES unset, please set it in $LIVE_CONF or
181 specify it on the command line using the -c|--classes option."
182 [ -n "$TARGET" ] || bailout 1 "Error: \$TARGET unset, please set it in $LIVE_CONF or
183 specify it on the command line using the -t|--target option."
186 # ask user whether the setup is ok {{{
187 if [ -z "$FORCE" ] ; then
189 echo "${PN}: check your configuration (or use -F to force execution without prompting):"
191 echo " FAI classes: $CLASSES"
192 echo " main directory: $TARGET"
193 [ -n "$CHROOT_TARGET" ] && echo " chroot target: $CHROOT_TARGET"
194 [ -n "$BUILD_TARGET" ] && echo " build target: $BUILD_TARGET"
195 [ -n "$ISO_TARGET" ] && echo " ISO target: $ISO_TARGET"
196 [ -n "$GRML_NAME" ] && echo " grml name: $GRML_NAME"
197 [ -n "$RELEASENAME" ] && echo " release name: $RELEASENAME"
198 [ -n "$VERSION" ] && echo " grml version: $VERSION"
199 [ -n "$SUITE" ] && echo " Debian suite: $SUITE"
200 [ -n "$BOOT_METHOD" ] && echo " Boot method: $BOOT_METHOD"
201 [ -n "$FAI_ARGS" ] && echo " additional arguments for FAI: $FAI_ARGS"
202 [ -n "$VERBOSE" ] && echo " Using VERBOSE mode."
204 echo -n "Is this ok for you? [y/N] "
206 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
207 bailout 1 "Exiting as requested."
211 start_seconds=$(cut -d . -f 1 /proc/uptime)
212 log "------------------------------------------------------------------------------"
213 log "Starting grml-live run [$(date)]"
217 # on-the-fly configuration {{{
218 if [ -n "$MIRROR_DIRECTORY" ] ; then
219 if ! [ -d "$MIRROR_DIRECTORY/debian" ] ; then
220 log "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting. [$(date)]"
221 eerror "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting."
224 echo "$MIRROR_SOURCES" > /etc/grml/fai/apt/sources.list
225 if [ -n "$GRML_LIVE_SOURCES" ] ; then
226 echo "$GRML_LIVE_SOURCES" >> /etc/grml/fai/apt/sources.list
228 elif [ -n "$GRML_LIVE_SOURCES" ] ; then
229 echo "$GRML_LIVE_SOURCES" > /etc/grml/fai/apt/sources.list
232 if [ -n "$FAI_DEBOOTSTRAP" ] ; then
233 sed -i "s#^FAI_DEBOOTSTRAP=.*#FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"#" /etc/grml/fai/make-fai-nfsroot.conf
236 # does this suck? YES!
237 if [ -n "$SUITE" ] ; then
238 sed -i "s/SUITE=.*/SUITE=\"$SUITE\"/" $LIVE_CONF
240 DIST="\|\ etch\ \|\ stable\ \|\ lenny\ \|\ testing\ \|\ sid\ \|\ unstable\ "
241 sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" $LIVE_CONF
242 sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" /etc/grml/fai/apt/sources.list
244 DIST='\"etch\|=\"stable=\"lenny=\"testing=\"sid=\"unstable'
245 sed -i "s#FAI_DEBOOTSTRAP=$DIST#FAI_DEBOOTSTRAP=\"$SUITE#" $LIVE_CONF
246 sed -i "s#FAI_DEBOOTSTRAP=$DIST#FAI_DEBOOTSTRAP=\"$SUITE#" /etc/grml/fai/make-fai-nfsroot.conf
250 # CHROOT_TARGET - execute FAI {{{
251 [ -n "$CHROOT_TARGET" ] || CHROOT_TARGET="$TARGET/grml_chroot"
253 if [ -d "$CHROOT_TARGET/bin" ] ; then
254 log "$CHROOT_TARGET exists already, skipping stage 'fai dirinstall'"
255 ewarn "$CHROOT_TARGET exists already, skipping stage 'fai dirinstall'" ; eend 0
257 mkdir -p "$CHROOT_TARGET" || bailout 5 "Problem with creating $CHROOT_TARGET for FAI"
258 if [ -n "${MIRROR_DIRECTORY}" ] ; then
259 mkdir -p "${CHROOT_TARGET}/${MIRROR_DIRECTORY}"
260 mount --bind "${MIRROR_DIRECTORY}" "${CHROOT_TARGET}/${MIRROR_DIRECTORY}"
262 fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" -u "$HOSTNAME" dirinstall "$CHROOT_TARGET" $FAI_ARGS | tee -a $LOGFILE
263 umount $CHROOT_TARGET/proc 2>/dev/null || /bin/true
264 umount $CHROOT_TARGET/sys 2>/dev/null || /bin/true
265 [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_TARGET}/${MIRROR_DIRECTORY}"
267 # notice: 'fai dirinstall' does not seem to exit appropriate, so:
269 if [ -r "/var/log/fai/dirinstall/$HOSTNAME/software.log" ] ; then
270 grep 'dpkg: error processing' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=1
273 if [ -r "/var/log/fai/dirinstall/$HOSTNAME/shell.log" ] ; then
274 grep 'FAILED with exit code' /var/log/fai/dirinstall/$HOSTNAME/shell.log >> $LOGFILE && ERROR=2
277 if [ -n "$ERROR" ] ; then
278 log "There was an error during execution of stage 'fai dirinstall' [$(date)]"
279 eerror "There was an error during execution of stage 'fai dirinstall'"
280 echo " Check out /var/log/fai/dirinstall/$HOSTNAME/ for details. [exit ${ERROR}]"
283 log "Finished execution of stage 'fai dirinstall' [$(date)]"
284 einfo "Finished execution of stage 'fai dirinstall'"
289 # BUILD_TARGET - execute arch specific stuff and squashfs {{{
290 [ -n "$BUILD_TARGET" ] || BUILD_TARGET="$TARGET/grml_cd"
291 mkdir -p "$BUILD_TARGET" || bailout 6 "Problem with creating $BUILD_TARGET for stage ARCH"
293 [ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)"
296 if [ "$ARCH" = i386 ] || [ "$ARCH" = amd64 ] ; then
297 if [ -d "$BUILD_TARGET"/boot ] ; then
298 log "$BUILD_TARGET/boot exists already, skipping stage 'boot'"
299 ewarn "$BUILD_TARGET/boot exists already, skipping stage 'boot'" ; eend 0
302 mkdir -p "$BUILD_TARGET"/boot/isolinux
303 cp /boot/memtest86+.bin "$BUILD_TARGET"/boot/isolinux/memtest
304 cp "$CHROOT_TARGET"/boot/initrd* "$BUILD_TARGET"/boot/isolinux/initrd.gz
305 cp "$CHROOT_TARGET"/boot/vmlinuz* "$BUILD_TARGET"/boot/isolinux/linux26
306 cp /usr/lib/syslinux/chain.c32 "$BUILD_TARGET"/boot/isolinux/
307 cp /usr/lib/syslinux/isolinux.bin "$BUILD_TARGET"/boot/isolinux/
308 cp /usr/lib/syslinux/memdisk "$BUILD_TARGET"/boot/isolinux/
309 cp /usr/lib/syslinux/menu.c32 "$BUILD_TARGET"/boot/isolinux/
310 cp /usr/share/grml-live/templates/boot/isolinux/* "$BUILD_TARGET"/boot/isolinux/
311 cp /usr/share/grml-live/templates/boot/isolinux/* "$BUILD_TARGET"/boot/isolinux/
312 cp -a /usr/share/grml-live/templates/boot/grub "$BUILD_TARGET"/boot/
314 [ -d "$BUILD_TARGET"/GRML ] || mkdir "$BUILD_TARGET"/GRML
315 cp -a /usr/share/grml-live/templates/GRML/* "$BUILD_TARGET"/GRML/
317 # adjust boot splash information:
318 ISO_DATE="$(date +%Y-%m-%d)"
319 RELEASE_INFO="$GRML_NAME $VERSION - Release Codename $RELEASENAME"
320 RELEASE_INFO="$(cut_string 68 "$RELEASE_INFO")"
321 RELEASE_INFO="$(extend_string_end 68 "$RELEASE_INFO")"
323 sed -i "s/%RELEASE_INFO%/$GRML_NAME $VERSION - $RELEASENAME/" "$BUILD_TARGET"/GRML/grml-version
324 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_TARGET"/GRML/grml-version
326 sed -i "s/%RELEASE_INFO%/$RELEASE_INFO/" "$BUILD_TARGET"/boot/isolinux/boot.msg
327 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_TARGET"/boot/isolinux/boot.msg
329 sed -i "s/%RELEASE_INFO%/$RELEASE_INFO/" "$BUILD_TARGET"/boot/isolinux/boot-beep.msg
330 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_TARGET"/boot/isolinux/boot-beep.msg
332 sed -i "s/%VERSION%/$VERSION/" "$BUILD_TARGET"/boot/grub/menu.lst
333 sed -i "s/%GRML_NAME%/$GRML_NAME/" "$BUILD_TARGET"/boot/grub/menu.lst
335 # autostart for Windows:
336 cp /usr/share/grml-live/templates/windows/autostart/* "$BUILD_TARGET"/
338 if [ -n "$WINDOWS_BINARIES" ] ; then
339 if [ -f "$BUILD_TARGET"/windows/putty.exe ] ; then
340 log "$BUILD_TARGET/windows exists already, skipping stage 'WINDOWS_BINARIES'"
341 ewarn "$BUILD_TARGET/windows exists already, skipping stage 'WINDOWS_BINARIES'" ; eend 0
343 mkdir "$BUILD_TARGET"/windows
344 ( cd "$BUILD_TARGET"/windows
345 for file in pageant plink pscp psftp putty puttygen ; do
346 wget -O ${file}.exe ${WINDOWS_BINARIES}/${file}.exe
349 log "Finished execution of stage 'WINDOWS_BINARIES' [$(date)]"
350 einfo "Finished execution of stage 'WINDOWS_BINARIES'" ; eend 0
352 einfo "Finished execution of stage 'boot'" ; eend 0
355 elif [ "$ARCH" = powerpc ] ; then
356 ewarn 'Warning: formorer, it is your turn. :)'>&2
359 eerror 'Error: Unsupported ARCH, sorry. Want to support it? Contribute!' ; eend 1
362 if [ -f "$BUILD_TARGET"/live/grml.squashfs ] ; then
363 log "$BUILD_TARGET/live exists already, skipping stage 'squashfs'"
364 ewarn "$BUILD_TARGET/live exists already, skipping stage 'squashfs'" ; eend 0
366 mkdir "$BUILD_TARGET"/live
367 mksquashfs $CHROOT_TARGET/* $BUILD_TARGET/live/grml.squashfs -noappend
368 log "Finished execution of stage 'squashfs' [$(date)]"
369 einfo "Finished execution of stage 'squashfs'" ; eend 0
372 # create md5sum file:
373 ( cd $BUILD_TARGET/GRML &&
374 find .. -type f -not -name md5sums -not -name isolinux.bin -exec md5sum {} \; > md5sums )
377 # ISO_TARGET - mkisofs {{{
378 [ -n "$ISO_TARGET" ] || ISO_TARGET="$TARGET/grml_isos"
379 [ -n "$ISO_NAME" ] || ISO_NAME="${GRML_NAME}_${VERSION}.iso"
381 if [ "$BOOT_METHOD" = "isolinux" ] ; then
382 BOOT_FILE="boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat"
383 elif [ "$BOOT_METHOD" = "grub" ] ; then
384 BOOT_FILE="boot/grub/stage2_eltorito"
387 if [ -f "${ISO_TARGET}/${ISO_NAME}" ] ; then
388 log "$ISO_TARGET exists already, skipping stage 'iso build'"
389 ewarn "$ISO_TARGET exists already, skipping stage 'iso build'" ; eend 0
391 mkdir -p "$ISO_TARGET" || bailout 6 "Problem with creating $ISO_TARGET for stage 'iso build'"
393 cd "$BUILD_TARGET" &&
394 mkisofs -V "grml $VERSION" -publisher 'grml-live | grml.org' \
395 -l -r -J -no-emul-boot -boot-load-size 4 -boot-info-table \
397 -o "${ISO_TARGET}/${ISO_NAME}" . ; RC=$?
399 if [ "$RC" = 0 ] ; then
400 log "Finished execution of stage 'iso build' [$(date)]"
401 einfo "Finished execution of stage 'iso build'" ; eend 0
403 log "There was an error ($RC) executing stage 'iso build' [$(date)]"
404 eerror "There was an error executing stage 'iso build'" ; eend 1
411 [ -n "$start_seconds" ] && SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]"
412 einfo "Sucessfully finished execution of $PN [running ${SECONDS} seconds]" ; eend 0
413 log "Sucessfully finished execution of $PN [running ${SECONDS} seconds]"
414 log "------------------------------------------------------------------------------"
418 ## END OF FILE #################################################################
419 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3