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: Wed Sep 19 23:59:48 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 # make sure they are not set by default
28 if [ -r /etc/grml/lsb-functions ] ; then
29 . /etc/grml/lsb-functions
31 einfo() { echo " [*] $*" ;}
32 eerror() { echo " [!] $*">&2 ;}
33 ewarn() { echo " [x] $*" ;}
37 # source main configuration file:
38 LIVE_CONF=/etc/grml/grml-live.conf
46 [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_TARGET}/${MIRROR_DIRECTORY}"
47 [ -n "$1" ] && EXIT="$1" || EXIT="1"
48 [ -n "$2" ] && eerror "$2">&2
54 # check for important variables {{{
55 [ -n "$GRML_FAI_CONFIG" ] || GRML_FAI_CONFIG=/etc/grml/fai
56 [ -n "$HOSTNAME" ] || HOSTNAME=grml
57 [ -n "$USERNAME" ] || USERNAME=grml
58 [ -n "$CLASSES" ] || CLASSES="GRML,I386"
59 [ -n "$TARGET" ] || bailout 1 "${PN}: \$TARGET not specified. Please adjust $LIVE_CONF. Exiting."
61 [ -n "$VERSION" ] || VERSION="0.0.1"
62 [ -n "$RELEASENAME" ] || RELEASENAME="grml-live rocks"
64 [ -n "$LOGDIR" ] || LOGDIR="/var/log/fai/dirinstall/$HOSTNAME"
65 [ -d "$LOGDIR" ] || mkdir $LOGDIR
66 LOGFILE="$LOGDIR/grml-live.conf"
69 # some important functions {{{
72 # usage: log "string to log"
73 log() { echo "$*" >> $LOGFILE ; }
75 # cut string at character number int = $1
76 # usage: cut_string 5 "1234567890" will output "12345"
78 [ -n "$2" ] || return 1
79 echo "$2" | head -c "$1"; echo -ne "\n"
82 # prepend int = $1 spaces before string = $2
83 # usage: extend_string_begin 5 "123" will output " 123"
84 extend_string_begin() {
85 [ -n "$2" ] || return 1
86 local COUNT="$(echo $2 | wc -c)"
87 local FILL="$(expr $COUNT - $1)"
88 while [ "$FILL" -gt 1 ] ; do
90 local FILL=$(expr $FILL - 1)
92 while [ "$FILL" -lt 1 ] ; do
94 local FILL=$(expr $FILL + 1)
96 echo "$2" | head -c "$1"; echo -ne "\n"
99 # append int = $1 spaces to string = $2
100 # usage: extend_string_begin 5 "123" will output "123 "
101 extend_string_end() {
102 [ -n "$2" ] || return 1
103 echo -n "$2" | head -c "$1"
104 local COUNT="$(echo $2 | wc -c)"
105 local FILL="$(expr $COUNT - $1)"
106 while [ "$FILL" -gt 1 ] ; do
108 local FILL=$(expr $FILL - 1)
110 while [ "$FILL" -lt 1 ] ; do
112 local FILL=$(expr $FILL + 1)
118 # usage information {{{
122 $PN - build process script for generating a (grml based) Linux Live-ISO
124 Usage: $PN [-c <classe[s]>] [-i <iso_name> ] [-r <release_name>] \\
125 [-s <suite>] [-t <target_directory>] [-v <version_number>] [-Fvh]
130 $PN -c GRMLBASE,GRML_X,I386 -t /grml/
131 $PN -c GRMLBASE,I386 -t /dev/shm/grml
132 $PN -c GRMLBASE,GRML_SMALL,I386
133 $PN -c GRMLBASE,I386 -v -i grml_0.0-1.iso
134 $PN -c GRMLBASE,I386 -s sid
136 More details: man grml-live
137 /usr/share/doc/grml-live/grml-live.html
139 Please send your bug reports, feedback,.. to the grml-team.
140 http://grml.org/bugs/
145 # command line parsing {{{
147 while getopts "c:i:r:s:t:v:FhV" opt; do
149 c) CLASSES="$OPTARG" ;;
150 i) ISO_NAME="$OPTARG" ;;
151 r) RELEASENAME="$OPTARG" ;;
152 s) SUITE="$OPTARG" ;;
154 CHROOT_TARGET="$TARGET/grml_chroot"
155 BUILD_TARGET="$TARGET/grml_cd"
156 ISO_TARGET="$TARGET/grml_isos"
158 v) VERSION="$OPTARG" ;;
160 h) usage ; bailout 0 ;;
162 ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;;
165 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
169 # some misc checks before executing FAI {{{
170 [ -n "$CLASSES" ] || bailout 1 "Error: \$CLASSES unset, please set it in $LIVE_CONF or
171 specify it on the command line using the -c|--classes option."
172 [ -n "$TARGET" ] || bailout 1 "Error: \$TARGET unset, please set it in $LIVE_CONF or
173 specify it on the command line using the -t|--target option."
176 # ask user whether the setup is ok {{{
177 if [ -z "$FORCE" ] ; then
179 echo "${PN}: check your configuration (or use -F to force execution without prompting):"
181 echo " FAI classes: $CLASSES"
182 echo " main directory: $TARGET"
183 [ -n "$CHROOT_TARGET" ] && echo " chroot target: $CHROOT_TARGET"
184 [ -n "$BUILD_TARGET" ] && echo " build target: $BUILD_TARGET"
185 [ -n "$ISO_TARGET" ] && echo " ISO target: $ISO_TARGET"
186 [ -n "$SUITE" ] && echo " Debian suite: $SUITE"
187 [ -n "$FAI_ARGS" ] && echo " additional arguments for FAI: $FAI_ARGS"
188 [ -n "$VERBOSE" ] && echo " Using VERBOSE mode."
190 echo -n "Is this ok for you? [y/N] "
192 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
193 bailout 1 "Exiting as requested."
197 start_seconds=$(cut -d . -f 1 /proc/uptime)
198 log "------------------------------------------------------------------------------"
199 log "Starting grml-live run [$(date)]"
203 # on-the-fly configuration {{{
204 if [ -n "$MIRROR_DIRECTORY" ] ; then
205 if ! [ -d "$MIRROR_DIRECTORY/debian" ] ; then
206 eerror "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting."
207 log "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting. [$(date)]"
210 echo "$MIRROR_SOURCES" > /etc/grml/fai/apt/sources.list
211 if [ -n "$GRML_LIVE_SOURCES" ] ; then
212 echo "$GRML_LIVE_SOURCES" >> /etc/grml/fai/apt/sources.list
214 elif [ -n "$GRML_LIVE_SOURCES" ] ; then
215 echo "$GRML_LIVE_SOURCES" > /etc/grml/fai/apt/sources.list
218 if [ -n "$FAI_DEBOOTSTRAP" ] ; then
219 sed -i "s#^FAI_DEBOOTSTRAP=.*#FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"#" /etc/grml/fai/make-fai-nfsroot.conf
222 # does this suck? YES!
223 if [ -n "$SUITE" ] ; then
224 sed -i "s/SUITE=.*/SUITE=\"$SUITE\"/" $LIVE_CONF
226 DIST="\|\ etch\ \|\ stable\ \|\ lenny\ \|\ testing\ \|\ sid\ \|\ unstable\ "
227 sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" $LIVE_CONF
228 sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" /etc/grml/fai/apt/sources.list
230 DIST='\"etch\|=\"stable=\"lenny=\"testing=\"sid=\"unstable'
231 sed -i "s#FAI_DEBOOTSTRAP=$DIST#FAI_DEBOOTSTRAP=\"$SUITE#" $LIVE_CONF
232 sed -i "s#FAI_DEBOOTSTRAP=$DIST#FAI_DEBOOTSTRAP=\"$SUITE#" /etc/grml/fai/make-fai-nfsroot.conf
236 # CHROOT_TARGET - execute FAI {{{
237 [ -n "$CHROOT_TARGET" ] || CHROOT_TARGET="$TARGET/grml_chroot"
239 if [ -d "$CHROOT_TARGET/bin" ] ; then
240 ewarn "$CHROOT_TARGET exists already, skipping stage 'fai dirinstall'" ; eend 0
241 log "$CHROOT_TARGET exists already, skipping stage 'fai dirinstall'"
243 mkdir -p "$CHROOT_TARGET" || bailout 5 "Problem with creating $CHROOT_TARGET for FAI"
244 if [ -n "${MIRROR_DIRECTORY}" ] ; then
245 mkdir -p "${CHROOT_TARGET}/${MIRROR_DIRECTORY}"
246 mount --bind "${MIRROR_DIRECTORY}" "${CHROOT_TARGET}/${MIRROR_DIRECTORY}"
248 fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" dirinstall "$CHROOT_TARGET" $FAI_ARGS | tee -a $LOGFILE
249 umount $CHROOT_TARGET/proc 2>/dev/null || /bin/true
250 umount $CHROOT_TARGET/sys 2>/dev/null || /bin/true
251 [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_TARGET}/${MIRROR_DIRECTORY}"
253 # notice: 'fai dirinstall' does not seem to exit appropriate, so:
255 if [ -r "/var/log/fai/dirinstall/$HOSTNAME/software.log" ] ; then
256 grep 'dpkg: error processing' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=1
259 if [ -r "/var/log/fai/dirinstall/$HOSTNAME/shell.log" ] ; then
260 grep 'FAILED with exit code' /var/log/fai/dirinstall/$HOSTNAME/shell.log >> $LOGFILE && ERROR=2
263 if [ -n "$ERROR" ] ; then
264 eerror "There was an error during execution of stage 'fai dirinstall'"
265 echo " Check out /var/log/fai/dirinstall/$HOSTNAME/... for details. [exit ${ERROR}]"
266 log "There was an error during execution of stage 'fai dirinstall' [$(date)]"
269 einfo "Finished execution of stage 'fai dirinstall'"
270 log "Finished execution of stage 'fai dirinstall' [$(date)]"
275 # BUILD_TARGET - execute arch specific stuff and squashfs {{{
276 [ -n "$BUILD_TARGET" ] || BUILD_TARGET="$TARGET/grml_cd"
277 mkdir -p "$BUILD_TARGET" || bailout 6 "Problem with creating $BUILD_TARGET for stage ARCH"
280 [ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)"
281 if [ "$ARCH" = i386 ] ; then
282 if [ -d "$BUILD_TARGET"/boot/isolinux ] ; then
283 ewarn "$BUILD_TARGET/boot exists already, skipping stage 'boot/isolinux'" ; eend 0
284 log "$BUILD_TARGET/boot exists already, skipping stage 'boot/isolinux'"
287 mkdir -p "$BUILD_TARGET"/boot/isolinux
288 [ -d "$BUILD_TARGET"/GRML ] || mkdir "$BUILD_TARGET"/GRML
289 cp /boot/memtest86+.bin "$BUILD_TARGET"/boot/isolinux/memtest
290 cp "$CHROOT_TARGET"/boot/initrd* "$BUILD_TARGET"/boot/isolinux/initrd.gz
291 cp "$CHROOT_TARGET"/boot/vmlinuz* "$BUILD_TARGET"/boot/isolinux/linux26
292 cp /usr/lib/syslinux/chain.c32 "$BUILD_TARGET"/boot/isolinux/
293 cp /usr/lib/syslinux/isolinux.bin "$BUILD_TARGET"/boot/isolinux/
294 cp /usr/lib/syslinux/memdisk "$BUILD_TARGET"/boot/isolinux/
295 cp /usr/lib/syslinux/menu.c32 "$BUILD_TARGET"/boot/isolinux/
296 cp /usr/share/grml-live/i386_files/boot/isolinux/allinone.img "$BUILD_TARGET"/boot/isolinux/
297 cp /usr/share/grml-live/i386_files/boot/isolinux/balder10.imz "$BUILD_TARGET"/boot/isolinux/
298 cp /usr/share/grml-live/i386_files/boot/isolinux/boot-beep.msg "$BUILD_TARGET"/boot/isolinux/
299 cp /usr/share/grml-live/i386_files/boot/isolinux/boot.msg "$BUILD_TARGET"/boot/isolinux/
300 cp /usr/share/grml-live/i386_files/boot/isolinux/f* "$BUILD_TARGET"/boot/isolinux/
301 cp /usr/share/grml-live/i386_files/boot/isolinux/isolinux.cfg "$BUILD_TARGET"/boot/isolinux/
302 cp /usr/share/grml-live/i386_files/boot/isolinux/logo.16 "$BUILD_TARGET"/boot/isolinux/
303 cp /usr/share/grml-live/i386_files/boot/isolinux/syslinux.cfg "$BUILD_TARGET"/boot/isolinux/
305 # adjust boot splash information:
306 ISO_DATE="$(date +%Y-%m-%d)"
307 VERSION="$(cut_string 5 "$VERSION")" ; VERSION="$(extend_string_end 5 "$VERSION")"
308 RELEASENAME="$(cut_string 30 "$RELEASENAME")" ; RELEASENAME="$(extend_string_end 30 "$RELEASENAME")"
310 sed -i "s/%VERSION%/$VERSION/" "$BUILD_TARGET"/boot/isolinux/boot.msg
311 sed -i "s/%RELEASENAME%/$RELEASENAME/" "$BUILD_TARGET"/boot/isolinux/boot.msg
312 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_TARGET"/boot/isolinux/boot.msg
314 sed -i "s/%VERSION%/$VERSION/" "$BUILD_TARGET"/boot/isolinux/boot-beep.msg
315 sed -i "s/%RELEASENAME%/$RELEASENAME/" "$BUILD_TARGET"/boot/isolinux/boot-beep.msg
316 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_TARGET"/boot/isolinux/boot-beep.msg
318 # autostart for Windows:
319 cp /usr/share/grml-live/windows/autostart/autorun.bat "$BUILD_TARGET"/
320 cp /usr/share/grml-live/windows/autostart/autorun.inf "$BUILD_TARGET"/
321 cp /usr/share/grml-live/windows/autostart/autorun.pif "$BUILD_TARGET"/
322 cp /usr/share/grml-live/windows/autostart/cdrom.ico "$BUILD_TARGET"/
324 if [ -n "$WINDOWS_BINARIES" ] ; then
325 if [ -f "$BUILD_TARGET"/windows/putty.exe ] ; then
326 ewarn "$BUILD_TARGET/windows exists already, skipping stage 'WINDOWS_BINARIES'" ; eend 0
327 log "$BUILD_TARGET/windows exists already, skipping stage 'WINDOWS_BINARIES'"
329 mkdir "$BUILD_TARGET"/windows
330 ( cd "$BUILD_TARGET"/windows
331 for file in pageant plink pscp psftp putty puttygen ; do
332 wget -O ${file}.exe ${WINDOWS_BINARIES}/${file}.exe
335 einfo "Finished execution of stage 'WINDOWS_BINARIES'" ; eend 0
336 log "Finished execution of stage 'WINDOWS_BINARIES' [$(date)]"
338 einfo "Finished execution of stage 'boot/isolinux'" ; eend 0
341 elif [ "$ARCH" = amd64 ] ; then
342 ewarn 'Warning: gebi, it is your turn. :)'>&2
344 elif [ "$ARCH" = powerpc ] ; then
345 ewarn 'Warning: formorer, it is your turn. :)'>&2
348 eerror 'Error: Unsupported ARCH, sorry. Want to support it? Contribute!' ; eend 1
351 if [ -f "$BUILD_TARGET"/live/grml.squashfs ] ; then
352 ewarn "$BUILD_TARGET/live exists already, skipping stage 'squashfs'" ; eend 0
353 log "$BUILD_TARGET/live exists already, skipping stage 'squashfs'"
355 mkdir "$BUILD_TARGET"/live
356 mksquashfs $CHROOT_TARGET/* $BUILD_TARGET/live/grml.squashfs -noappend
357 einfo "Finished execution of stage 'squashfs'" ; eend 0
358 log "Finished execution of stage 'squashfs' [$(date)]"
362 # ISO_TARGET - mkisofs {{{
363 [ -n "$ISO_TARGET" ] || ISO_TARGET="$TARGET/grml_isos"
364 [ -n "$ISO_NAME" ] || ISO_NAME="grml_${VERSION}.iso"
366 if [ -f "${ISO_TARGET}/${ISO_NAME}" ] ; then
367 ewarn "$ISO_TARGET exists already, skipping stage 'iso build'" ; eend 0
368 log "$ISO_TARGET exists already, skipping stage 'iso build'"
370 mkdir -p "$ISO_TARGET" || bailout 6 "Problem with creating $ISO_TARGET for stage 'iso build'"
371 ( cd "$BUILD_TARGET" &&
372 mkisofs -V "grml $VERSION" -publisher 'grml-live | grml.org' \
373 -l -r -J -no-emul-boot -boot-load-size 4 -boot-info-table \
374 -c boot/isolinux/boot.cat -b boot/isolinux/isolinux.bin \
375 -o "${ISO_TARGET}/${ISO_NAME}" .
377 einfo "Finished execution of stage 'iso build'" ; eend 0
378 log "Finished execution of stage 'iso build' [$(date)]"
383 SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]"
384 einfo "Sucessfully finished execution of $PN [running ${SECONDS} seconds]" ; eend 0
385 log "Sucessfully finished execution of $PN [running ${SECONDS} seconds]"
386 log "------------------------------------------------------------------------------"
390 ## END OF FILE #################################################################
391 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3