summaryrefslogtreecommitdiffstats
path: root/bootcd/build.sh
blob: 153ecf08b5151512c9852e04179d6db5dbb447d8 (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
#!/bin/bash

#inst.stage2 in isolinux.cfg needs to match the label of ISO, to get lable use 'file <name.iso>' or 'isoinfo -d -i <name.iso>'
#Lantronix Spider does not provide CDROM labels (we can add inst.stage2=cdrom, but this may break booting on multicd systems)
centos74_label="CentOS 7 x86_64"
centos75_label="CentOS 7 x86_64"
fedora28_label="Fedora-S-dvd-x86_64-28"

die() { echo "$*" 1>&2 ; exit 1; }
usage() {  echo "Usage: $0 <distrib> [--cdrom]"; }

[ $# -gt 0 ] || { usage; exit 1; }

distrib=$(echo $1 | grep -oP '[\w\d_\-]+')
label_arg=$(echo ${distrib}_label)
label_std=${!label_arg}

[ -d $distrib ] || die "$distrib is not found"
[ -n "$label_std" ] || die "Label for $distrib is not configured"

shift

ver=1
rhver=$(echo $distrib | grep -oP '\d+')
dname=$(echo $distrib | grep -oP '[^\d]+')


extra=""
isoname="$distrib-ands$(if [ $ver -gt 1 ]; then echo $ver ; fi)"

while [ $# -gt 0 ]; do
  case "$1" in
    --cdrom) 
	media=$(if [[ "$2" =~ ^[[:alnum:]] ]]; then echo $2; else echo "cdrom"; fi)
	extra="$extra inst.stage2=$media"
	isoname="$isoname-$media"
	echo $media
	shift $(if [[ "$2" =~ ^[[:alnum:]] ]]; then echo 2; else echo 1; fi)
	;;
    h | *) usage; exit 0 ;;
  esac
done


isolinux="isolinux-${distrib}.cfg"
[ -f $isolinux ] || isolinux="isolinux-${dname}.cfg"
[ -f $isolinux ] || die "Configuration $isolinux is not found"

echo "Building ${isoname}.iso with extra parameters \"$extra\" and the label \"$label_std\""
echo "Using configuration: $isolinux"

#Generating config
chmod +w $distrib/isolinux
chmod +w $distrib/isolinux/isolinux.cfg
sed -e "s/@EXTRA@/$extra/g" $isolinux > $distrib/isolinux/isolinux.cfg || die "Can't overwrite the configuration"

#Creating output folder
mkdir -p iso

#Building ISO
( 
    cd $distrib || die "Can't chdir"
    chmod 664 isolinux/isolinux.bin

    rm -f iso/${isoname}.iso

#    On Forums Disc1 label is recommended, but it is not recognized (at least by Fedora)
#    mkisofs -o ../iso/${isoname}.iso -A "$label_std" -V "$label_std Disc 1" -volset "$label_std" \

    mkisofs -o ../iso/${isoname}.iso -A "$label_std" -V "$label_std" -volset "$label_std" \
	-U -J -joliet-long -r -v -T \
	-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
	-eltorito-alt-boot -e images/efiboot.img -no-emul-boot \
	.
)

#Installing
scp iso/${isoname}.iso root@192.168.26.134:/virtual/images/