Kickstart - how to exit if an OS already exists
I have what is surely a remedial question for anyone with more Linux experience. I need to check if an operating system is already installed in my kickstart script, and if so, prompt the user if they would like to continue (basically reinstall) or to exit.
What is the most efficient way to do this?
I was thinking of doing something like the following:
%pre
#!/bin/sh
if [ -f some_file ]; then
read -p "An OS already exists, do you want to re-install?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
fi
I'm not sure what file would be best to use in place of "some_file" in my example, or if this is even a good way to go about it.
Note that the reason I need to do this is because this Linux installation is part of a much larger automated installation so a user is not there to manually check if the OS exists already.
Solution 1:
Where would the / filesystem reside, if an operating system were installed? Would it be in the same place on all the nodes you intend to install?
You could test for the presence of a partition:
[ -b /dev/sdXY ] && { do something ; }
Or a logical volume:
[ -b /dev/mapper/vg00/lvXYZ ] && { do something ; }
You could attempt to mount it, and test for the presence of a certain file:
mkdir /tmp/mt
if mount /dev/sdXY /tmp/mt && [ -f /tmp/mt/filename ]; then
do something
fi