78 lines
2.5 KiB
Bash
Executable File
78 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
set -eE
|
|
|
|
function clean() {
|
|
echo "==== CLEAN ERR ===="
|
|
sudo umount "$WORKDIR/squashfs" || :
|
|
sudo umount /tmp/livecd || :
|
|
}
|
|
|
|
trap clean ERR
|
|
|
|
SPATH=$(cd $(dirname $0) && pwd)
|
|
if [ -z $1 ]; then
|
|
echo "Usage: prepare.sh <iso_path>"
|
|
exit 1
|
|
fi
|
|
full_iso=$1
|
|
iso_wo_ext=${full_iso##*/}
|
|
iso_wo_ext=${iso_wo_ext%.iso}
|
|
|
|
WORKDIR="$SPATH/$iso_wo_ext"
|
|
|
|
echo "==== Prepare CD ===="
|
|
mkdir /tmp/livecd || :
|
|
sudo mount -o loop "$1" /tmp/livecd
|
|
|
|
mkdir -p "$WORKDIR"
|
|
rsync --exclude=/casper/filesystem.squashfs -a /tmp/livecd/ "$WORKDIR/cd"
|
|
mkdir "$WORKDIR/squashfs" "$WORKDIR/custom"
|
|
sudo modprobe squashfs
|
|
sudo mount -t squashfs -o loop /tmp/livecd/casper/filesystem.squashfs "$WORKDIR/squashfs/"
|
|
|
|
echo "==== Copy squashfs contents to $WORKDIR/custom ===="
|
|
sudo cp -a "$WORKDIR"/squashfs/* "$WORKDIR/custom"
|
|
|
|
# network access
|
|
sudo cp /etc/resolv.conf /etc/hosts "$WORKDIR/custom/etc/"
|
|
|
|
# mount proc, sys, opens a shell (for changes), and clean everything after
|
|
echo "==== CHROOT ===="
|
|
cat "$SPATH/tasks.sh" | sudo chroot "$WORKDIR/custom" /bin/bash
|
|
|
|
echo "==== Mod ISOLINUX (BIOS) AND GRUB (EFI) ===="
|
|
# isolinux
|
|
chmod -R +w "$WORKDIR/cd/isolinux"
|
|
cp isolinux/* "$WORKDIR/cd/isolinux/"
|
|
# grub
|
|
chmod -R +w "$WORKDIR/cd/boot/grub"
|
|
cp grub/* "$WORKDIR/cd/boot/grub/"
|
|
|
|
# setup iso
|
|
echo "==== Setup ISO ===="
|
|
chmod +w "$WORKDIR/cd/casper/filesystem.manifest"
|
|
sudo chroot "$WORKDIR/custom" dpkg-query -W --showformat='${Package} ${Version}\n' > "$WORKDIR/cd/casper/filesystem.manifest"
|
|
sudo cp "$WORKDIR/cd/casper/filesystem.manifest" "$WORKDIR/cd/casper/filesystem.manifest-desktop"
|
|
sudo mksquashfs "$WORKDIR/custom" "$WORKDIR/cd/casper/filesystem.squashfs"
|
|
sudo rm "$WORKDIR/cd/MD5SUMS"
|
|
sudo chmod +w "$WORKDIR/cd"
|
|
sudo bash -c 'cd '"$WORKDIR"'/cd && find . -type f -exec md5sum {} +' > "$WORKDIR"/cd/MD5SUMS
|
|
|
|
# create iso
|
|
echo "==== Create ISO ===="
|
|
cd "$WORKDIR/cd"
|
|
# create a DVD-burnable ISO with BIOS (isolinux) and EFI (grub) support
|
|
sudo mkisofs -U -A "$iso_wo_ext-LIS67" -V "$iso_wo_ext-LIS67" -volset "$iso_wo_ext-LIS67" -J -joliet-long -r -v -T -o "$WORKDIR/$iso_wo_ext-lis67.iso" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot .
|
|
|
|
# convert iso to a bootable USB drive iso
|
|
sudo isohybrid --uefi "$WORKDIR/$iso_wo_ext-lis67.iso"
|
|
|
|
# umount & clean
|
|
echo "==== Clean ===="
|
|
sudo umount "$WORKDIR/squashfs"
|
|
sudo umount /tmp/livecd
|
|
sudo chown -R $USER: "$WORKDIR"
|
|
|
|
echo "Final ISO: $WORKDIR/$iso_wo_ext-lis67.iso"
|
|
echo "Done"
|