-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-iso.sh
executable file
·132 lines (118 loc) · 3.41 KB
/
build-iso.sh
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
#!/bin/bash
#
# Info: Build RHV-H ISO after modifications are made
# Author: Jason Woods <[email protected]>
# Created: 2018-12-14
# This script has no warranty implied or otherwise.
#
# 2019-02-11 jwoods added function update_efiboot and call to it
# 2019-02-12 jwoods added function update_from_mods if ISO_MODDIR exists
# 2019-02-14 jwoods changed variables to start with ISO_
# 2019-02-14 jwoods added code to read $0.rc file, remove .sh in .rc file name
# where to find/put stuff
ISO_BASEDIR="/u/RHV-H_custom"
ISO_BUILDDIR="BUILD"
ISO_IN="${ISO_BASEDIR}/RHVH-4.2-20190117.0-RHVH-x86_64-dvd1.iso"
ISO_OUT="RHVH-4.2-custom.x86_64.iso"
ISO_MNTDIR="${ISO_BASEDIR}/temp-mnt"
ISO_MODDIR="${ISO_BASEDIR}/modifications"
# these can be left auto-configured, or changed as desired
ISO_OUTDIR="${ISO_BASEDIR}/${ISO_BUILDDIR}"
ISO_OUTPUT="${ISO_BASEDIR}/${ISO_OUT}"
# string to use when outputing a note
ISO_NOTE="#-# "
# if exists and is readable, source .rc file for variables
ISO_RCFILE="$(echo "$0" | sed 's/\.sh$//;').rc"
# name of this program
ISO_PROGNAME="$(basename "${0}")"
case "$(echo "${1}" | sed 's/^-*//;')" in
prep|PREP|p|P)
# default to prep ISO build files
ISO_MODE="PREP"
;;
build|BUILD|b|B|*)
# default to build ISO
ISO_MODE="BUILD"
;;
esac
function iso_name () {
# this needs work
grep "LABEL=" BUILD/isolinux/isolinux.cfg | head -n1 | \
sed 's/:/#/;' | \
cut -f2 -d# | \
cut -f1 -d' ' | \
sed 's/LABEL=//;s/\\x20/ /;'
}
function update_from_mods () {
echo "${ISO_NOTE}Updating ISO files from '${ISO_MODDIR}'..."
pushd "${ISO_MODDIR}" >/dev/null || {
echo " ERROR: unable to change to '${ISO_MODDIR}'"
return
}
find . -type f -exec cp -v "{}" "${ISO_OUTDIR}/{}" \;
popd >/dev/null
}
function update_efiboot () {
echo "${ISO_NOTE}Updating EFIBOOT image ..."
[ ! -d "${ISO_MNTDIR}" ] && mkdir "${ISO_MNTDIR}"
mount "${ISO_OUTDIR}/images/efiboot.img" "${ISO_MNTDIR}" && {
cp "${ISO_OUTDIR}/EFI/BOOT/grub.cfg" "${ISO_MNTDIR}/EFI/BOOT/grub.cfg"
} || {
echo " ERROR: unable to mount efiboot.img"
}
sleep 1
umount "${ISO_MNTDIR}" && echo " SUCCESS"
}
function iso_build () {
# build ISO from files
ISO_NAME="$(iso_name)"
cd "${ISO_BASEDIR}"
# update ISO files from modifications directory files
update_from_mods
# update efiboot image, redirect any errors to stdout
update_efiboot
echo "${ISO_NOTE}Generating ISO image ..."
genisoimage \
-follow-links \
-o "${ISO_OUTPUT}" -joliet-long -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 -R -J -v -T \
-input-charset utf-8 \
-V "${ISO_NAME}" -A "${ISO_NAME}" \
"${ISO_OUTDIR}"
if [ $? = 0 ] ; then
echo "${ISO_NOTE}Making ISO UEFI bootable ..."
isohybrid -uefi "${ISO_OUTPUT}"
echo " EXIT: $?"
echo "${ISO_NOTE}Adding MD5 to ISO ..."
implantisomd5 "${ISO_OUTPUT}"
echo " EXIT: $?"
else
echo
echo " ERROR: failed to build ISO."
echo
fi
}
function iso_prep () {
# prep files for building ISO
# TMPTMP
echo "PREPPING!"
}
function main () {
# report if using a .rc file
if [ -r "${ISO_RCFILE}" ] ; then
echo "${ISO_NOTE}Used ISO_RCFILE='${ISO_RCFILE}'"
source "${ISO_RCFILE}"
fi
# run according to BUILD or PREP mode
case "${ISO_MODE}" in
PREP)
iso_prep
;;
BUILD|*)
iso_build
;;
esac
}
main 2>&1 | tee build.out