44# Name : make_iso.sh #
55# Author : Ibrahim Musayev #
66# Purpose : creates a new ISO image named CentOS-7-x86_64.iso and includes #
7- # latest version of kickstart script. #
7+ # latest version of kickstart script. Also, The script provides #
8+ # an interactive menu for the user to choose between generating #
9+ # a new kickstart script or proceeding with an existing one. #
810# History : 15.05.23 Ibrahim Musayev, creation #
911# ###############################################################################
1012
@@ -16,14 +18,56 @@ mnt_iso_dir="/mnt/iso"
1618tmp_workdir=" /tmp/workdir"
1719tmp_workdir_iso=" $tmp_workdir /iso"
1820kickstart_dir=" $tmp_workdir_iso /kickstart"
21+ python_replace_parameters=" replace_parameters_in_ks_cfg.py"
1922ks_cfg=$1
2023
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
24+ detect_python_command () {
25+ if command -v python3 & > /dev/null; then
26+ python_command=" python3"
27+ elif command -v python & > /dev/null; then
28+ python_command=" python"
29+ else
30+ echo " Python is not installed."
31+ exit 1
32+ fi
33+ }
34+
35+ # Function to generate new kickstart script
36+ generate_new_kickstart_script () {
37+ echo " Generating new kickstart script..."
38+ $python_command $python_replace_parameters
39+ ks_cfg=generated-ks.cfg
40+ }
41+
42+ # Function to proceed with existing kickstart script
43+ proceed_with_existing_kickstart_script () {
44+ echo " Proceeding with existing kickstart script..."
45+ # Check if the kickstart script name is provided
46+ if [ -z " $1 " ]; then
47+ read -p " Please provide the name of the kickstart script: " ks_cfg
48+ else
49+ ks_cfg=$1
50+ fi
51+ }
52+
53+ detect_python_command
54+
55+ echo " Do you want to generate a new kickstart script with the new network configuration or proceed with an existing one?"
56+ select option in " Generate new kickstart script" " Proceed with existing kickstart script" ; do
57+ case $option in
58+ " Generate new kickstart script" )
59+ generate_new_kickstart_script
60+ break
61+ ;;
62+ " Proceed with existing kickstart script" )
63+ proceed_with_existing_kickstart_script
64+ break
65+ ;;
66+ * )
67+ echo " Invalid option. Please try again."
68+ ;;
69+ esac
70+ done
2771
2872# Check if the ISO file exists in the Downloads folder and proceed further
2973if [ -f " $downloads_dir /$iso_file " ]; then
@@ -34,7 +78,7 @@ if [ -f "$downloads_dir/$iso_file" ]; then
3478 sudo mkdir -p " $mnt_iso_dir "
3579 else
3680 echo " Unmount $mnt_iso_dir directory before starting..."
37- sudo umount $mnt_iso_dir
81+ sudo umount $mnt_iso_dir 2> /dev/null
3882 fi
3983
4084 # Check if the /tmp/workdir directory exists
@@ -76,7 +120,7 @@ if [ -f "$downloads_dir/$iso_file" ]; then
76120 echo " $new_iso_name File successfully created..."
77121 sudo mv $new_iso_name $new_iso_dir
78122 echo " The new file is moved to the $new_iso_dir directory..."
79- sudo umount " $mnt_iso_dir "
123+ sudo umount " $mnt_iso_dir " 2> /dev/null
80124 else
81125 echo " $new_iso_name File creation failed. Exiting..."
82126 exit 1
0 commit comments