This file is indexed.

/usr/sbin/fai-cd is in fai-server 4.3.1+deb8u1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/bin/bash

#*********************************************************************
#
# fai-cd -- make a fai CD, a bootable CD that performs the FAI
#
# This script is part of FAI (Fully Automatic Installation)
# (c) 2004-2014 by Thomas Lange, lange@informatik.uni-koeln.de
# Universitaet zu Koeln
# Support for grub2 added by Sebastian Hetze, s.hetze@linux-ag.de
# with major support from Michael Prokop, prokop@grml-solutions.com
#
# based on a script called make-fai-bootcd by Niall Young <niall@holbytla.org>
#
#*********************************************************************
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# A copy of the GNU General Public License is available as
# `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html.  You
# can also obtain it by writing to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#*********************************************************************

set -e

# last die exit code 22

boot_image="boot/grub/eltorito.img"
config_space=""
configset=0
forceremoval=0
burn=0
bootonly=0
keep=0
makeiso=1
nomirror=0
hidedirs="/usr/share/locale /usr/share/doc /var/lib/apt /var/cache/apt /usr/share/man /var/lib/dpkg/info /media/mirror/aptcache "

# we need FAI_CONFIGDIR, NFSROOT

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
usage() {

    cat <<-EOF
	fai-cd Copyright (C) 2004-2014 Thomas Lange

	Usage: fai-cd [OPTIONS] -m MIRRORDIR ISONAME
	Usage: fai-cd [OPTIONS] -B ISONAME
	Usage: fai-cd [OPTIONS] -d CONFIG_SRC
	Create a FAI CD, a bootable CD that performs the FAI.
	Read the man pages pages fai-cd(8).
EOF
exit 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
die() {

    local e=$1   # first parameter is the exit code
    shift

    echo "ERROR: $@" >&2   # print error message
    exit $e
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
create_grub2_image() {

    mkdir -p $tmp/boot/grub $NFSROOT/boot/grub
    if [ -f $NFSROOT/boot/grub/core.img ]; then
        cp $NFSROOT/boot/grub/core.img $tmp/boot/grub
        MODULEBASE=$NFSROOT/usr/lib/grub/
    elif [ -f $NFSROOT/usr/lib/grub/i386-pc/cdboot.img ]; then
        chroot $NFSROOT /usr/bin/grub-mkimage -d /usr/lib/grub/i386-pc -o /boot/grub/core.img biosdisk iso9660 --format=i386-pc
        cp $NFSROOT/boot/grub/core.img $tmp/boot/grub
        MODULEBASE=$NFSROOT/usr/lib/grub/
    else
        echo "no grub2 installation found in NFSROOT, using downloaded $grubPackage"
        apt-get -y -d install --reinstall grub-pc >/dev/null
        grubPackage=`ls -rt /var/cache/apt/archives/grub-pc*|tail -1`
        if [ -z "$grubPackage" ]; then
            die 22 "Downloading grub2 failed."
        fi
        GRUBDIR=$tmp/grubPackage
        mkdir -p $GRUBDIR
        dpkg -x $grubPackage $GRUBDIR
        cd $GRUBDIR
        ./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o $tmp/boot/grub/core.img biosdisk iso9660 --format=i386-pc
        MODULEBASE=$GRUBDIR/usr/lib/grub/
    fi

    # check for jessie path
    if strings /usr/lib/grub/i386-pc/kernel.img | grep -q i386-pc/%s.mod; then
	grubtarget=$tmp/boot/grub/i386-pc
    else
	# wheezy
	grubtarget=$tmp/boot/grub
    fi

    mkdir -p $grubtarget
    for a in $MODULEBASE/*-pc/{*.mod,efiemu??.o,cdboot.img,boot.img,command.lst,moddep.lst,fs.lst,handler.lst,parttool.lst}; do
        [[ -e $a ]] && cp $a $grubtarget
    done
    rm -rf $GRUBDIR
    cp $grub_config $tmp/boot/grub/grub.cfg
    # insert date into grub menu
    perl -pi -e "s/_VERSIONSTRING_/   $isoversion     /" $tmp/boot/grub/grub.cfg
    if [ -n "$config_space" ] || [ $configset -eq 1 ]; then
	perl -pi -e "s|FAI_CONFIG_SRC=(.*?)\S+|FAI_CONFIG_SRC=$config_space|" $tmp/boot/grub/grub.cfg
    fi
    cp -p $NFSROOT/boot/vmlinuz-$kernelversion $tmp/boot/vmlinuz
    cp -p $NFSROOT/boot/initrd.img-$kernelversion $tmp/boot/initrd.img
    cp -p $NFSROOT/boot/config-$kernelversion $tmp/boot/
    cat $grubtarget/cdboot.img $tmp/boot/grub/core.img > $tmp/boot/grub/eltorito.img
    boot_image="boot/grub/eltorito.img"

    cat $grubtarget/boot.img $tmp/boot/grub/core.img > $tmp/boot/grub/embed.img
    embed_image="$tmp/boot/grub/embed.img"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
provide_memtest_boot_option() {

    if [ -f $NFSROOT/boot/memtest86+.bin ]; then
        cp $NFSROOT/boot/memtest86+.bin $tmp/boot
    elif [ -f /boot/memtest86+.bin ]; then
        cp /boot/memtest86+.bin $tmp/boot
    else
        echo "no memtest86+.bin found, omit memtest boot option"
        return
    fi

        cat >> $tmp/boot/grub/grub.cfg <<EOF

menuentry "Memory test (memtest86+)" {
    linux16 /boot/memtest86+.bin
}
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
customize_nfsroot() {

    # hide some dirs to save space and make the CD image smaller
    local d

    mkdir -p $tmp/empty
    for d in $hidedirs; do
        if [ -d $nfsrootdir/$d ]; then
            [ "$debug" ] && echo "hiding $d"
            mount --bind $tmp/empty $nfsrootdir/$d
        fi
    done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
unhide_dirs() {

    set +e
    for d in $hidedirs; do
        if [ -d $nfsrootdir/$d ]; then
            [ "$debug" ] && echo "disclosing $d"
            umount $nfsrootdir/$d 2>/dev/null
        fi
    done
    set -e
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
umount_dirs() {

    set +e
    local d
    local dirs="boot $FAI media/mirror"
    for d in $dirs; do
        umount $nfsrootdir/$d 2>/dev/null
    done
    mountpoint -q $nfsrootdir && umount $nfsrootdir
    mountpoint -q $cow && umount $cow
    set -e
    rm -rf $tmp $cow
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
sleep_now() {

        sleep 6666 || true
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
mkiso() {

    [ $makeiso -eq 0 ] && return

    echo "Writing FAI CD-ROM image to $isoname. This may need some time."
    xorriso -report_about HINT -as mkisofs -graft-points -b $boot_image \
        -V "$vname" -A "$aname" \
        -no-emul-boot -boot-info-table --embedded-boot ${embed_image} --protective-msdos-label -o $isoname \
        -R $tmp --sort-weight 0 / --sort-weight 1 /boot || die 12 "xorriso failed."
    echo -n "ISO image size and filename: "; du -h $isoname
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
create_iso() {

    # Create the El Torito bootable iso9660 cdrom image

    mkdir -p $nfsrootdir/media/mirror || true

    if [ -z "$config_space" ] && [ $configset -eq 0 ]; then
	mount --bind $FAI_CONFIGDIR $nfsrootdir/$FAI && echo "Config space $FAI_CONFIGDIR mounted"
	mount -o remount,ro,bind $nfsrootdir/$FAI
    fi

    addmirror

    customize_nfsroot

    if [ $keep -eq 1 ]; then
        echo "fai-cd script stopped for 6666 seconds. The filesystem is now available in $tmp."
        echo "To continue the script and call the cleanup call: pkill -f 'sleep 6666'"
        sleep_now 2>/dev/null || true
        echo "Continue cleanup."
    fi

    mkiso
    unhide_dirs
    umount_dirs
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
addmirror() {

    [ $nomirror -eq 1 ] && return
    
    mount --bind $mirrordir $nfsrootdir/media/mirror && echo "Mirror $mirrordir mounted"
    mount -o remount,ro,bind $nfsrootdir/media/mirror
# TODO: customize /etc/apt, copy apt preferences etc.

    # create the sources.list for the CD
    cat > $nfsrootdir/etc/apt/sources.list <<EOF
# mirror location for fai CD, file generated by fai-cd
EOF

    dists=$(find $mirrordir -name "Packages*" | grep binary | sed 's/binary-.*//' | \
         sed "s#$mirrordir/*dists/##" | xargs -r -n 1 dirname | sort | uniq )
    [ -z "$dists" ] && die 19 "No suitable Packages file found in mirror."

    for i in $dists ; do
        comp=$(find $mirrordir/dists/$i -maxdepth 2 -type d -name "binary-*" | \
        sed -e "s#$mirrordir/*dists/$i/##" -e 's#/binary-.*##' | uniq | tr '\n' " ")
        echo "deb file:/media/mirror $i $comp" >> $nfsrootdir/etc/apt/sources.list
    done

}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
burniso() {

    wodim -v -eject $isoname
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
# main program

rsync=0
if [ -x "$(which rsync)" ] ; then rsync=1 ; fi

# Parse commandline options
while getopts "nkfhHg:bBMm:C:d:" opt ; do
    case "$opt" in
        C)  cdir="$OPTARG" ;;
        f)  forceremoval=1 ;;
        h)  usage ;;
        H)  hidedirs="" ;;
        g)  grub_config="$OPTARG" ;;
        k)  keep=1 ;;
        M)  nomirror=1 ;;
        m)  mirrordir="$OPTARG" ;;
        n)  makeiso=0 ;;
        b)  burn=1 ;;
        B)  bootonly=1 ;;
	d)  config_space="$OPTARG"; configset=1 ;;
        ?)  usage ;;
    esac
done
shift $(($OPTIND - 1))
isoname=$1

[ $nomirror -eq 1 -a -n "$mirrordir" ]  && die 6 "Do not use -M and -m at the same time."
[ $makeiso -eq 1 -a "$#" -eq 0 ]        && die 2 "Please specify the output file for the ISO image."
if [ $bootonly -eq 0 -a $nomirror -eq 0 ]; then
    [ -z "$mirrordir" ]   && die 4 "Please specify the directory of your mirror using -m"
    [ -d "$mirrordir" ]   || die 5 "$mirrordir is not a directory"
    [ -z "$(ls $mirrordir)" ] && die 18 "No mirror found in $mirrordir. Empty directory."
fi
[ -f "$isoname" ]     && [ $forceremoval -eq 1 ] && rm $isoname
[ -f "$isoname" ]     && die 3 "Outputfile $isoname already exists. Please remove it or use -f."

if [ $bootonly -eq 0 ]; then
    [ $(id -u) != "0" ]   && die 9 "Run this program as root."
fi

if [ $makeiso -eq 1 ]; then
    [ -x "$(which xorriso)" ] || die 8 "xorriso not found. Please install package."
fi

[ -x "$(which strings)" ] || die 8 "command strings not found. Please install package binutils."

# use FAI_ETC_DIR from environment variable
if [ -n "$FAI_ETC_DIR" -a -z "$cdir" ]; then
    echo "Using environment variable \$FAI_ETC_DIR."
    cfdir=$FAI_ETC_DIR
fi
[ -n "$cdir" ] && cfdir=$cdir
: ${cfdir:=/etc/fai}
cfdir=$(readlink -f $cfdir) # canonicalize path
if [ ! -d "$cfdir" ]; then
    echo "$cfdir is not a directory" >&2
    exit 6
fi
[ "$verbose" ] && echo "Using configuration files from $cfdir"
. $cfdir/fai.conf
. $cfdir/nfsroot.conf
: ${FAI:=/var/lib/fai/config} # default value
ONFSROOT=$NFSROOT # save original nfsroot

if [ -d $NFSROOT/live ]; then
    NFSROOT="$NFSROOT/live/filesystem.dir"
fi

[ -d "$NFSROOT/etc/fai" ] || die 10 "Please create NFSROOT by calling fai-make-nfsroot or fai-setup."

# if -g is a file name, add prefix

if [ -z "$grub_config" ]; then
    grub_config="$cfdir/grub.cfg" # set default if undefined
fi

# if grub_config contains / do not change it, else add prefix $cfdir
echo $grub_config | grep -q '/' || grub_config="$cfdir/$grub_config"
[ -f "$grub_config" ] || die 13 "Grub menu file $grub_config not found."

if [ $bootonly -eq 0 ]; then
    [ -z "$FAI_CONFIGDIR" ]  && die 14 "Variable \$FAI_CONFIG not set."
    [ -d $FAI_CONFIGDIR ] || die 15 "Can't find config space $FAI_CONFIGDIR."
    [ -d $FAI_CONFIGDIR/class ] || die 16 "Config space $FAI_CONFIGDIR seems to be empty."
fi

tmp=$(mktemp -t -d fai-cd.XXXXXX) || exit 13
cow=$(mktemp -t -d cow-XXXXXX)
mount -n -t tmpfs tmpfs $cow


# check if dracut or live-boot is used
if [ -d $ONFSROOT/live ]; then
    hidedirs="$hidedirs /boot"
    if [ $bootonly -ne 1 ]; then
	mkdir -p $tmp/live/filesystem.dir
	nfsrootdir=$tmp/live/filesystem.dir
	mount -t aufs -o noatime,noxino,dirs=$cow=rw:$ONFSROOT/live/filesystem.dir=rr aufs $nfsrootdir && echo "NFSROOT $NFSROOT mounted"
    fi
else
    # things to do for dracut
    nfsrootdir=$tmp
    mount -t aufs -o noatime,noxino,dirs=$cow=rw:$ONFSROOT=rr aufs $nfsrootdir  && echo "NFSROOT $NFSROOT mounted"
    echo "Found dracut inside nfsroot, but booting a FAI CD with dracut inside the nfsrroot does not yet work." >&2
    echo "Recreate your nfsroot with the live-boot package instead of dracut. Use fai-make-nfsoot -l." >&2
    die 20 "Aborting"
fi

kernelversion=$(ls -tr $NFSROOT/boot/vmlinu?-* | tail -1 | sed -e 's#.*/vmlinuz-##')
faiversion=$(dpkg --root=$NFSROOT -l fai-client|awk '/fai-client/ {print $3}')
isoversion="FAI $faiversion -- build $(date '+%c')"
vname="FAI_CD"
aname="Fully Automatic Installation by Thomas Lange, $isoversion"

create_grub2_image

provide_memtest_boot_option

if [ $bootonly -eq 1 ]; then
    mkiso
    mountpoint -q $cow && umount $cow
else
    trap "unhide_dirs;umount_dirs" EXIT ERR
    create_iso
fi

[ "$burn" -eq 1 ] && burniso
exit 0