-
Notifications
You must be signed in to change notification settings - Fork 3
/
RH8.test.sh
executable file
·141 lines (113 loc) · 4.3 KB
/
RH8.test.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
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
clear
# Notes: https://access.redhat.com/solutions/60959
set -e
set -u
ISO='/home/dan/tmp/ISOs/rhel-8.0-x86_64-dvd.iso'
NEWISO='/var/tmp/rhel8new.iso'
TS="$(date)"
# Get the LABEL variable
export $(blkid -o export "${ISO}")
function finish {
# Cleanup before exit
sudo umount ${TMPMOUNT}
#rm -rf ${BUILDDIR} ${TMPMOUNT}
}
trap finish EXIT
#BUILDDIR="$(mktemp -d /var/tmp/temp_expand.XXX)"
#TMPMOUNT="$(mktemp -d /var/tmp/temp_mount.XXX)"
BUILDDIR="/var/tmp/temp_expand"
TMPMOUNT="/var/tmp/temp_mount"
mkdir -p ${BUILDDIR}
mkdir -p ${TMPMOUNT}
echo "Mounting ISO onto ${TMPMOUNT}"
echo "Expanding ISO into ${BUILDDIR}"
MYKS="./ksfiles/RHEL8.ks"
UEFI_MENUFILE="isolinux/isolinux.cfg"
UEFI_START="^label\ linux"
UEFI_END="label linux"
UEFI_MENU="label kickstart
menu label ^Dans ${TS} Custom UEFI RHEL8.0
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=${LABEL} inst.ks=cdrom:/ks.cfg
label linux"
GRUB_MENUFILE="EFI/BOOT/grub.cfg"
GRUB_START="### BEGIN .etc.grub.d.10_linux ###"
GRUB_END="menuentry 'Install Red Hat Enterprise Linux 8.0.0' --class fedora --class gnu-linux --class gnu --class os {"
GRUB_CFG="### BEGIN /etc/grub.d/10_linux ###
menuentry 'Dans ${TS} Custom MBR RHEL 8.0' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=${LABEL} inst.ks=cdrom:/ks.cfg
initrdefi /images/pxeboot/initrd.img
}
${GRUB_END}"
sudo mount -o loop,ro ${ISO} ${TMPMOUNT}
mkdir -p "${BUILDDIR}"
shopt -s dotglob
rsync -a --progress --delete ${TMPMOUNT}/* ${BUILDDIR}
cp ${MYKS} ${BUILDDIR}/ks.cfg
echo "################################################"
echo "# Fix up the isolinux.cfg"
echo "#"
# Save initial isolinux/ directory permissions
INIT_PERM_D=$(stat -c%a $(dirname ${BUILDDIR}))
INIT_PERM_F=$(stat -c%a ${BUILDDIR})
chmod u+w "${BUILDDIR}/$(dirname ${UEFI_MENUFILE})"
chmod u+w "${BUILDDIR}/${UEFI_MENUFILE}"
cp -p "${BUILDDIR}/${UEFI_MENUFILE}" "${BUILDDIR}/${UEFI_MENUFILE}.orig"
awk -v sb="${UEFI_MENU}" "/${UEFI_START}/,/${UEFI_END}/ { if ( \$0 ~ /${UEFI_START}/) print sb; next } 1" "${BUILDDIR}/${UEFI_MENUFILE}" > "${BUILDDIR}/${UEFI_MENUFILE}.new"
echo "Added these lines to the ${BUILDDIR}/${UEFI_MENUFILE} file:"
/usr/bin/diff -C8 "${BUILDDIR}/${UEFI_MENUFILE}.orig" "${BUILDDIR}/${UEFI_MENUFILE}.new" | cat -n
echo "Diff done"
cat "${BUILDDIR}/${UEFI_MENUFILE}.new" > "${BUILDDIR}/${UEFI_MENUFILE}"
# Restore permissions
chmod ${INIT_PERM_F} "${BUILDDIR}/${UEFI_MENUFILE}"
chmod ${INIT_PERM_D} "${BUILDDIR}/$(dirname ${UEFI_MENUFILE})"
echo "################################################"
echo "# Fix up the grub.cfg"
echo "#"
# Save initial isolinux/ directory permissions
INIT_PERM_D=$(stat -c%a ${BUILDDIR}/$(dirname ${GRUB_MENUFILE}))
INIT_PERM_F=$(stat -c%a ${BUILDDIR}/${GRUB_MENUFILE})
chmod u+w "${BUILDDIR}/$(dirname ${GRUB_MENUFILE})"
chmod u+w "${BUILDDIR}/${GRUB_MENUFILE}"
cp -p "${BUILDDIR}/${GRUB_MENUFILE}" "${BUILDDIR}/${GRUB_MENUFILE}.orig"
awk -v sb="${GRUB_CFG}" "/${GRUB_START}/,/${GRUB_END}/ { if ( \$0 ~ /${GRUB_START}/) print sb; next } 1" "${BUILDDIR}/${GRUB_MENUFILE}" > "${BUILDDIR}/${GRUB_MENUFILE}.new"
echo "Added these lines to the ${BUILDDIR}/${GRUB_MENUFILE} file:"
/usr/bin/diff -C8 "${BUILDDIR}/${GRUB_MENUFILE}.orig" "${BUILDDIR}/${GRUB_MENUFILE}.new" | cat -n
echo "Diff done"
cp "${BUILDDIR}/${GRUB_MENUFILE}.new" "${BUILDDIR}/${GRUB_MENUFILE}"
# Restore permissions
chmod ${INIT_PERM_F} "${BUILDDIR}/${GRUB_MENUFILE}"
chmod ${INIT_PERM_D} "${BUILDDIR}/$(dirname ${GRUB_MENUFILE})"
pushd ${BUILDDIR}/
echo "################################################"
echo "# Building ${NEWISO}"
echo "#"
sudo rm -f ${NEWISO}
sudo mkisofs -o ${NEWISO} \
-b isolinux/isolinux.bin \
-J \
-R \
-l \
-c isolinux/boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e images/efiboot.img \
-no-emul-boot \
-graft-points \
-V "${LABEL}" . \
2>&1 | egrep -v 'estimate finish|^Using\ .*for\ |^Done with:|^Writing:|^Scanning |^Excluded: ..*TRANS.TBL$'
sudo chown ${USER}:$(id -gn) ${NEWISO}
echo "################################################"
echo "# Running isohybrid on ISO"
echo "#"
isohybrid --uefi ${NEWISO}
echo "################################################"
echo "# Running implantisomd5 on ISO"
echo "#"
implantisomd5 ${NEWISO}
popd
echo "Done at $(date):"
ls -altrh ${NEWISO}