1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-30 22:50:10 +03:00

Merge remote-tracking branch 'origin/feature-2453'

This commit is contained in:
Ruben S. Montero 2014-03-13 18:14:53 +01:00
commit 387100cb72
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#!/bin/bash
CONFIG_FILE="/etc/hostname"
function set_hostname() {
NAME=$1
[ -n "$NAME" ] || exit 0
echo $NAME > $CONFIG_FILE
hostname $NAME
}
function get_dns_name() {
first_ip=$(hostname -I | cut -d' ' -f1)
text=$(host $first_ip)
[ $? = 0 ] || exit 0
[[ $text == *"has no PTR record" ]] && exit 0
name=$(echo "$text" | awk '{print $(NF)}' | sed 's/\.$//')
echo $name
}
if [ -n "$SET_HOSTNAME" ]; then
set_hostname $SET_HOSTNAME
elif [ -n "$DNS_HOSTNAME" ]; then
set_hostname $(get_dns_name)
fi

View File

@ -0,0 +1,29 @@
#!/bin/bash
CONFIG_FILE="/etc/sysconfig/network"
function set_hostname() {
NAME=$1
[ -n "$NAME" ] || exit 0
sed -i '/^HOSTNAME=.*$/d' $CONFIG_FILE
echo "HOSTNAME=$NAME" >> $CONFIG_FILE
hostname $NAME
}
function get_dns_name() {
first_ip=$(hostname -I | cut -d' ' -f1)
text=$(host $first_ip)
[ $? = 0 ] || exit 0
[[ $text == *"has no PTR record" ]] && exit 0
name=$(echo "$text" | awk '{print $(NF)}' | sed 's/\.$//')
echo $name
}
if [ -n "$SET_HOSTNAME" ]; then
set_hostname $SET_HOSTNAME
elif [ -n "$DNS_HOSTNAME" ]; then
set_hostname $(get_dns_name)
fi