"By using a script
1) How can I set this value in /etc/sysconfig/network "HOSTNAME=..."
2) How can I add this hostname in /etc/hosts
"127.0.0.1 localhost.localdomain localhost ...""
The heart of your script will be two sed commands. One sed command will be used to change /etc/hosts and the other sed command will be used to change /etc/sysconfig/network.
Here is an explanation of how to use sed:
Be prepared. Create a LifeBoat CD.