]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Set hostname at kvmx_up
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 10 Mar 2017 18:31:04 +0000 (15:31 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 10 Mar 2017 18:31:04 +0000 (15:31 -0300)
kvmx
provision/desktop-basic
provision/development

diff --git a/kvmx b/kvmx
index 7c60af9249f13b8f4927cd949c3a8330516ebf3e..cb0e0a03e8aff191d373b761ac695e5b6bf0a542 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -123,6 +123,28 @@ function kvmx_up {
   done
   echo " done."
 
+  echo "Setting hostname..."
+  $SSH_COMMAND -o ConnectTimeout=2 -p $SSH $SSH_LOGIN@127.0.0.1 <<EOF
+  ##### BEGIN REMOTE SCRIPT #####
+  OLD_HOST="\$(hostname)"
+
+  # Set hosts entry
+  if ! grep -q "^127.0.0.1 $hostname.$domain $hostname$" /etc/hosts; then
+    echo "127.0.0.1 $hostname.$domain $hostname" | sudo tee -a /etc/hosts > /dev/null
+  fi
+
+  echo "$hostname.$domain" | sudo tee /etc/hostname > /dev/null
+  sudo hostname $hostname.$domain
+
+  # Remove old hostname from hosts file
+  if [ "\$OLD_HOST" != "$hostname.$domain" ]; then
+    if grep -q \$OLD_HOST /etc/hosts; then
+      sudo sed -i -e '|\$OLD_HOST|d' /etc/hosts
+    fi
+  fi
+  ##### END REMOTE SCRIPT #######
+EOF
+
   # Somehow it is starting before DBUS and then crashing, so we try to start again
   echo "Ensure spice-vdagent is running..."
   echo "sudo /usr/sbin/service spice-vdagent start" | kvmx_ssh
index d71138322467a4c2f107930bb51ca33bb018fa75..dd5531f3a133ccad9366c7507603012b8c2cafe6 100755 (executable)
@@ -26,15 +26,6 @@ DOMAIN="$2"
 MIRROR="$3"
 APT_INSTALL="sudo LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y"
 
-# Set hostname
-echo "$HOSTNAME.$DOMAIN" | sudo tee /etc/hostname > /dev/null
-sudo hostname $HOSTNAME.$DOMAIN
-
-# Set hosts entry
-if ! grep -q "^127.0.0.1 $HOSTNAME.$DOMAIN $HOSTNAME$" /etc/hosts; then
-  echo "127.0.0.1 $HOSTNAME.$DOMAIN $HOSTNAME" | sudo tee -a /etc/hosts > /dev/null
-fi
-
 # Configure keyboard
 cat <<-EOF | sudo tee /etc/default/keyboard > /dev/null
 # KEYBOARD CONFIGURATION FILE
index fa7a3231749674fefdc97f26ae8fe68a5c7a0f89..e14d0acb91a288e3624b6cae3bbe0b4056bf7093 100755 (executable)
@@ -26,15 +26,6 @@ DOMAIN="$2"
 MIRROR="$3"
 APT_INSTALL="sudo LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y"
 
-# Set hostname
-echo "$HOSTNAME.$DOMAIN" | sudo tee /etc/hostname > /dev/null
-sudo hostname $HOSTNAME.$DOMAIN
-
-# Set hosts entry
-if ! grep -q "^127.0.0.1 $HOSTNAME.$DOMAIN $HOSTNAME$" /etc/hosts; then
-  echo "127.0.0.1 $HOSTNAME.$DOMAIN $HOSTNAME" | sudo tee -a /etc/hosts > /dev/null
-fi
-
 # Dependencies
 sudo sed -i -e "s|main$|main contrib non-free|g" /etc/apt/sources.list
 sudo apt-get update