|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +################################################################################ |
| 4 | +# Name : make_iso.sh # |
| 5 | +# Author : Ibrahim Musayev # |
| 6 | +# Purpose : creates a new ISO image named CentOS-7-x86_64.iso and includes # |
| 7 | +# latest version of kickstart script. # |
| 8 | +# History : 15.05.23 Ibrahim Musayev, creation # |
| 9 | +################################################################################ |
| 10 | + |
| 11 | +iso_file="CentOS-7-x86_64-Everything-2009.iso" |
| 12 | +new_iso_name="CentOS-7-x86_64.iso" |
| 13 | +downloads_dir="$HOME/Downloads" |
| 14 | +new_iso_dir=$downloads_dir/iso |
| 15 | +mnt_iso_dir="/mnt/iso" |
| 16 | +tmp_workdir="/tmp/workdir" |
| 17 | +tmp_workdir_iso="$tmp_workdir/iso" |
| 18 | +kickstart_dir="$tmp_workdir_iso/kickstart" |
| 19 | +ks_cfg=$1 |
| 20 | + |
| 21 | +# Check if the kickstart script name is provided |
| 22 | +if [ -z "$1" ]; then |
| 23 | + read -p "Please provide the name of the kickstart script: " ks_cfg |
| 24 | +else |
| 25 | + ks_cfg=$1 |
| 26 | +fi |
| 27 | + |
| 28 | +# Check if the ISO file exists in the Downloads folder and proceed further |
| 29 | +if [ -f "$downloads_dir/$iso_file" ]; then |
| 30 | + echo "ISO file found in Downloads folder..." |
| 31 | + # Check if the /mnt/iso directory exists |
| 32 | + if [ ! -d "$mnt_iso_dir" ]; then |
| 33 | + echo "Creating $mnt_iso_dir directory..." |
| 34 | + sudo mkdir -p "$mnt_iso_dir" |
| 35 | + else |
| 36 | + echo "Unmount $mnt_iso_dir directory before starting..." |
| 37 | + sudo umount $mnt_iso_dir |
| 38 | + fi |
| 39 | + |
| 40 | + # Check if the /tmp/workdir directory exists |
| 41 | + if [ ! -d "$tmp_workdir" ]; then |
| 42 | + echo "Creating $tmp_workdir directory..." |
| 43 | + sudo mkdir -p "$tmp_workdir" |
| 44 | + else |
| 45 | + echo "Cleaning $tmp_workdir directory..." |
| 46 | + sudo rm -rf $tmp_workdir/* |
| 47 | + fi |
| 48 | + |
| 49 | + # Check if the $HOME/Downloads/iso directory exists |
| 50 | + if [ ! -d "$new_iso_dir" ]; then |
| 51 | + echo "Creating $new_iso_dir directory..." |
| 52 | + sudo mkdir -p "$new_iso_dir" |
| 53 | + else |
| 54 | + echo "Cleaning $new_iso_dir directory..." |
| 55 | + sudo rm -rf $new_iso_dir/* |
| 56 | + fi |
| 57 | + |
| 58 | + # Mount the ISO file to /mnt/iso directory |
| 59 | + sudo mount "$downloads_dir/$iso_file" "$mnt_iso_dir" |
| 60 | + sleep 3 |
| 61 | + echo "ISO file mounted to $mnt_iso_dir and copying contents to $tmp_workdir" |
| 62 | + sudo cp -Rpf $mnt_iso_dir $tmp_workdir |
| 63 | + sleep 2 |
| 64 | + if [ $? -eq 0 ]; then |
| 65 | + echo "Directory copied successfully." |
| 66 | + echo "The $kickstart_dir directory doesn't exist. Creating it..." |
| 67 | + sudo mkdir -p "$kickstart_dir" |
| 68 | + sudo cp -p "$ks_cfg" "$kickstart_dir/ks.cfg" |
| 69 | + sudo cp -p "isolinux.cfg" "$tmp_workdir_iso/isolinux/isolinux.cfg" |
| 70 | + # Check if the copy operation was successful |
| 71 | + if [ $? -eq 0 ]; then |
| 72 | + echo "Kickstart script copied successfully." |
| 73 | + echo "Creating a $new_iso_name File" && cd $tmp_workdir_iso |
| 74 | + sudo genisoimage -o $new_iso_name -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -V "CentOS 7 x86_64" -R -J -v -T . |
| 75 | + if [ $? -eq 0 ]; then |
| 76 | + echo "$new_iso_name File successfully created..." |
| 77 | + sudo mv $new_iso_name $new_iso_dir |
| 78 | + echo "The new file is moved to the $new_iso_dir directory..." |
| 79 | + sudo umount "$mnt_iso_dir" |
| 80 | + else |
| 81 | + echo "$new_iso_name File creation failed. Exiting..." |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + else |
| 85 | + echo "Failed to copy the kickstart script. Exiting..." |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | + else |
| 89 | + echo "Failed to copy the directory." |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | +else |
| 93 | + echo "Please download the ISO file: $iso_file" |
| 94 | + echo "First you need a CentOS-7 ISO --> https://www.centos.org/download/" |
| 95 | + exit 1 |
| 96 | +fi |
0 commit comments