Bryan Kearney
2009-Jan-06 17:16 UTC
[Ovirt-devel] [PATCH node] Add a hostname configurastion tool which can take user input or direct command line input from the kernel line
---
Makefile.am | 1 +
ovirt-node.spec.in | 3 ++
scripts/ovirt-config-hostname | 42 +++++++++++++++++++++++++++++++++++++++++
scripts/ovirt-early | 10 ++++++++-
scripts/ovirt-firstboot | 1 +
5 files changed, 56 insertions(+), 1 deletions(-)
create mode 100755 scripts/ovirt-config-hostname
diff --git a/Makefile.am b/Makefile.am
index 3e891c4..6847234 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -30,6 +30,7 @@ EXTRA_DIST = \
scripts/ovirt \
scripts/ovirt-awake \
scripts/ovirt-config-boot \
+ scripts/ovirt-config-hostname \
scripts/ovirt-config-logging \
scripts/ovirt-config-networking \
scripts/ovirt-config-password \
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index e5031ad..72b35f2 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -132,6 +132,7 @@ cd -
%{__install} -p -m0755 scripts/ovirt-awake %{buildroot}%{_sbindir}
%{__install} -p -m0755 scripts/ovirt-config-boot %{buildroot}%{_sbindir}
+%{__install} -p -m0755 scripts/ovirt-config-hostname %{buildroot}%{_sbindir}
%{__install} -p -m0755 scripts/ovirt-config-logging %{buildroot}%{_sbindir}
%{__install} -p -m0755 scripts/ovirt-config-networking %{buildroot}%{_sbindir}
%{__install} -p -m0755 scripts/ovirt-config-password %{buildroot}%{_sbindir}
@@ -187,6 +188,7 @@ install -p -m 644 images/syslinux-vesa-splash.jpg
%{buildroot}/usr/lib/anaconda-
%{__install} -d -m0755 %{buildroot}%{_sysconfdir}/ovirt-config-setup.d
%{__ln_s} ../..%{_sbindir}/ovirt-config-networking
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Networking Setup"
%{__ln_s} ../..%{_sbindir}/ovirt-config-storage
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Disk Partitioning"
+%{__ln_s} ../..%{_sbindir}/ovirt-config-hostname
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Set Hostname"
%{__ln_s} ../..%{_sbindir}/ovirt-config-logging
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Logging Setup"
%{__ln_s} ../..%{_sbindir}/ovirt-config-password
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Administrator
Password"
%{__ln_s} ../..%{_sbindir}/ovirt-config-boot
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Local install and
reboot"
@@ -251,6 +253,7 @@ fi
%defattr(-,root,root,0755)
%{_sbindir}/ovirt-awake
%{_sbindir}/ovirt-config-boot
+%{_sbindir}/ovirt-config-hostname
%{_sbindir}/ovirt-config-logging
%{_sbindir}/ovirt-config-networking
%{_sbindir}/ovirt-config-password
diff --git a/scripts/ovirt-config-hostname b/scripts/ovirt-config-hostname
new file mode 100755
index 0000000..8ac46d3
--- /dev/null
+++ b/scripts/ovirt-config-hostname
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# Configures the hostname file based on kernel cmdline or user prompt
+# Source functions library
+. /etc/init.d/functions
+. /etc/init.d/ovirt-functions
+
+HOSTNAME_FILE="/etc/hostname"
+
+function set_hostname {
+ echo $1 > $HOSTNAME_FILE
+}
+
+function prompt_user {
+ printf "\n"
+ read -p "What is the hostname for this node? "
+
+ if [ -n "$REPLY" ]; then
+ set_hostname "$REPLY"
+ printf "\nHostname has been set\n"
+ else
+ if [ -e $HOSTNAME_FILE ]; then
+ rm $HOSTNAME_FILE
+ printf "\nRemoved old hostname configuration\n"
+ else
+ printf "\nAborting hostname configuration.\n"
+ fi
+ fi
+}
+
+# AUTO for auto-install
+if [ "$1" = "AUTO" ]; then
+ if [ -n "$OVIRT_HOSTNAME" ]; then
+ set_hostname "$OVIRT_HOSTNAME"
+ else
+ printf "\nHostname not provided. Skipping.\n"
+ fi
+else
+ prompt_user
+fi
+
+exit 0
diff --git a/scripts/ovirt-early b/scripts/ovirt-early
index bf5f3d0..663e82c 100755
--- a/scripts/ovirt-early
+++ b/scripts/ovirt-early
@@ -133,6 +133,7 @@ start() {
# anaconda format: ip=<client-ip> netmask=<netmask>
gateway=<gw-ip>
# ipv6=dhcp|auto
# syslog=server[:port]
+ # hostname=fqdn
# TBD logrotate maxsize
# BOOTIF=link|eth*|<MAC> (appended by pxelinux)
@@ -180,6 +181,10 @@ start() {
gateway ipv6
+ # hostname=fqdn
+ # hostname
+ hostname+
# syslog=server[:port]
# default syslog server
syslog_server@@ -263,6 +268,9 @@ start() {
ipv6=*)
ipv6=${i#ipv6=}
;;
+ hostname=*)
+ hostname=${i#hostname=}
+ ;;
syslog=*)
i=${i#syslog=}
eval $(printf $i|awk -F: '{print "syslog_server="$1;
print "syslog_port="$2;}')
@@ -280,7 +288,7 @@ start() {
ip_gateway=$gateway
fi
# save boot parameters as defaults for ovirt-config-*
- params="bootif init vol_boot_size vol_swap_size vol_root_size
vol_config_size vol_logging_size local_boot standalone ip_address ip_netmask
ip_gateway ipv6 syslog_server syslog_port bootparams"
+ params="bootif init vol_boot_size vol_swap_size vol_root_size
vol_config_size vol_logging_size local_boot standalone ip_address ip_netmask
ip_gateway ipv6 syslog_server syslog_port bootparams hostname"
mount_config
if [ -e $OVIRT_DEFAULTS ]; then
echo "update ovirt defaults"
diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot
index fe7723f..737dc52 100755
--- a/scripts/ovirt-firstboot
+++ b/scripts/ovirt-firstboot
@@ -33,6 +33,7 @@ start ()
ovirt-config-networking AUTO
ovirt-config-storage AUTO
ovirt-config-logging AUTO
+ ovirt-config-hostname AUTO
if [ "$OVIRT_LOCAL_BOOT" = 1 ]; then
ovirt-config-boot $OVIRT_INIT ""
"$OVIRT_BOOTPARAMS" no
disable_firstbot
--
1.6.0.4
Bryan Kearney
2009-Jan-06 19:03 UTC
[Ovirt-devel] [PATCH node] Add a hostname configurastion tool which can take user input or direct command line input from the kernel line
---
Makefile.am | 1 +
ovirt-node.spec.in | 3 ++
scripts/ovirt-config-hostname | 60 +++++++++++++++++++++++++++++++++++++++++
scripts/ovirt-early | 10 ++++++-
scripts/ovirt-firstboot | 1 +
5 files changed, 74 insertions(+), 1 deletions(-)
create mode 100755 scripts/ovirt-config-hostname
diff --git a/Makefile.am b/Makefile.am
index 3e891c4..6847234 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -30,6 +30,7 @@ EXTRA_DIST = \
scripts/ovirt \
scripts/ovirt-awake \
scripts/ovirt-config-boot \
+ scripts/ovirt-config-hostname \
scripts/ovirt-config-logging \
scripts/ovirt-config-networking \
scripts/ovirt-config-password \
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index e5031ad..72b35f2 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -132,6 +132,7 @@ cd -
%{__install} -p -m0755 scripts/ovirt-awake %{buildroot}%{_sbindir}
%{__install} -p -m0755 scripts/ovirt-config-boot %{buildroot}%{_sbindir}
+%{__install} -p -m0755 scripts/ovirt-config-hostname %{buildroot}%{_sbindir}
%{__install} -p -m0755 scripts/ovirt-config-logging %{buildroot}%{_sbindir}
%{__install} -p -m0755 scripts/ovirt-config-networking %{buildroot}%{_sbindir}
%{__install} -p -m0755 scripts/ovirt-config-password %{buildroot}%{_sbindir}
@@ -187,6 +188,7 @@ install -p -m 644 images/syslinux-vesa-splash.jpg
%{buildroot}/usr/lib/anaconda-
%{__install} -d -m0755 %{buildroot}%{_sysconfdir}/ovirt-config-setup.d
%{__ln_s} ../..%{_sbindir}/ovirt-config-networking
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Networking Setup"
%{__ln_s} ../..%{_sbindir}/ovirt-config-storage
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Disk Partitioning"
+%{__ln_s} ../..%{_sbindir}/ovirt-config-hostname
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Set Hostname"
%{__ln_s} ../..%{_sbindir}/ovirt-config-logging
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Logging Setup"
%{__ln_s} ../..%{_sbindir}/ovirt-config-password
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Administrator
Password"
%{__ln_s} ../..%{_sbindir}/ovirt-config-boot
%{buildroot}%{_sysconfdir}/ovirt-config-setup.d/"Local install and
reboot"
@@ -251,6 +253,7 @@ fi
%defattr(-,root,root,0755)
%{_sbindir}/ovirt-awake
%{_sbindir}/ovirt-config-boot
+%{_sbindir}/ovirt-config-hostname
%{_sbindir}/ovirt-config-logging
%{_sbindir}/ovirt-config-networking
%{_sbindir}/ovirt-config-password
diff --git a/scripts/ovirt-config-hostname b/scripts/ovirt-config-hostname
new file mode 100755
index 0000000..179ead9
--- /dev/null
+++ b/scripts/ovirt-config-hostname
@@ -0,0 +1,60 @@
+#!/bin/bash
+#
+# Configures the hostname file based on kernel cmdline or user prompt
+# Source functions library
+. /etc/init.d/functions
+. /etc/init.d/ovirt-functions
+
+HOSTNAME_FILE="/etc/sysconfig/network"
+
+function set_hostname {
+ augtool > /dev/null <<EOF
+ set /files$HOSTNAME_FILE/HOSTNAME "$1"
+ save
+EOF
+}
+
+function remove_hostname {
+ augtool > /dev/null <<EOF
+ rm /files$HOSTNAME_FILE/HOSTNAME
+ save
+EOF
+}
+
+function prompt_user {
+ printf "\n"
+ read -p "What is the hostname for this node? "
+
+ if [ -n "$REPLY" ]; then
+ set_hostname "$REPLY"
+ printf "\nHostname has been set\n"
+ else
+ printf "\n"
+ read -p "Enter (Y|y) to blank out the hostname, or (N|n) to skip.
"
+ case $REPLY in
+ Y|y)
+ remove_hostname
+ printf "\nHostname was removed.\n"
+ return
+ ;;
+ N|n)
+ printf "\nNo changes made.\n"
+ return
+ ;;
+ *) ;;
+ esac
+ fi
+}
+
+# AUTO for auto-install
+if [ "$1" = "AUTO" ]; then
+ if [ -n "$OVIRT_HOSTNAME" ]; then
+ set_hostname "$OVIRT_HOSTNAME"
+ else
+ printf "\nHostname not provided. Skipping.\n"
+ fi
+else
+ prompt_user
+fi
+
+exit 0
diff --git a/scripts/ovirt-early b/scripts/ovirt-early
index bf5f3d0..663e82c 100755
--- a/scripts/ovirt-early
+++ b/scripts/ovirt-early
@@ -133,6 +133,7 @@ start() {
# anaconda format: ip=<client-ip> netmask=<netmask>
gateway=<gw-ip>
# ipv6=dhcp|auto
# syslog=server[:port]
+ # hostname=fqdn
# TBD logrotate maxsize
# BOOTIF=link|eth*|<MAC> (appended by pxelinux)
@@ -180,6 +181,10 @@ start() {
gateway ipv6
+ # hostname=fqdn
+ # hostname
+ hostname+
# syslog=server[:port]
# default syslog server
syslog_server@@ -263,6 +268,9 @@ start() {
ipv6=*)
ipv6=${i#ipv6=}
;;
+ hostname=*)
+ hostname=${i#hostname=}
+ ;;
syslog=*)
i=${i#syslog=}
eval $(printf $i|awk -F: '{print "syslog_server="$1;
print "syslog_port="$2;}')
@@ -280,7 +288,7 @@ start() {
ip_gateway=$gateway
fi
# save boot parameters as defaults for ovirt-config-*
- params="bootif init vol_boot_size vol_swap_size vol_root_size
vol_config_size vol_logging_size local_boot standalone ip_address ip_netmask
ip_gateway ipv6 syslog_server syslog_port bootparams"
+ params="bootif init vol_boot_size vol_swap_size vol_root_size
vol_config_size vol_logging_size local_boot standalone ip_address ip_netmask
ip_gateway ipv6 syslog_server syslog_port bootparams hostname"
mount_config
if [ -e $OVIRT_DEFAULTS ]; then
echo "update ovirt defaults"
diff --git a/scripts/ovirt-firstboot b/scripts/ovirt-firstboot
index fe7723f..737dc52 100755
--- a/scripts/ovirt-firstboot
+++ b/scripts/ovirt-firstboot
@@ -33,6 +33,7 @@ start ()
ovirt-config-networking AUTO
ovirt-config-storage AUTO
ovirt-config-logging AUTO
+ ovirt-config-hostname AUTO
if [ "$OVIRT_LOCAL_BOOT" = 1 ]; then
ovirt-config-boot $OVIRT_INIT ""
"$OVIRT_BOOTPARAMS" no
disable_firstbot
--
1.6.0.4