I'm trying to create a bash script that will either prompt for input during init or launch itself in a gnome terminal before a user is asked to log in.
The purpose of this script is to run as root, request a hostname from the user and write this to /etc/sysconfig/network before disabling itself and rebooting the system
The issue I'm trying to address is conflicting hostnames when deploying vmware templates.
Here's what I've done so far, as an init script it just runs past and fails, even with -i after /bin/bash and X-Interactive =true. As an interactive script when logged in it works fine. I'm happy to just launch it as a once off terminal over GDM if someone can suggest a way to do that.
I'm not set on doing it this way, if anyone can suggest an alternative that would be great too.
#!/bin/bash
### BEGIN INIT INFO
# Provides: sethostname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set hostname on first boot then disable this service
# Description: takes hostname as input and writes /etc/sysconfig/network
# X-Interactive: true
### END INIT INFO
case "$1" in
start)
domain=mydomain.com
read -p "Please enter hostname for the system (Only hostname,do not enter .mydomain.com) " HOSTNAME
while [ -z "${HOSTNAME}" ]; do
read -p "Hostname cannot be empty. Please enter hostname " HOSTNAME
done
echo -e "HOSTNAME=${HOSTNAME}\nNETWORKING=yes\nNISDOMAIN=$ {domain}\nNTPSERVERARGS=iburst" > /etc/sysconfig/network
chkconfig sethostname off
reboot
exit 0
;;
stop)
exit 0
;;
restart | reload | force-reload | status | condrestart | try-restart)
exit 0
;;
usage)
exit 0
;;
asec