Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

VM: Force hostname to <iphex>.hostingstack.net

  • Loading branch information...
commit cc1949c2a3798d805a5be9c5e2c05038d44213c8 1 parent 16daa99
@zeha zeha authored
Showing with 52 additions and 7 deletions.
  1. +48 −0 util/build/hshostname
  2. +4 −7 util/build/post-scripts/10-install-stuff
View
48 util/build/hshostname
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+### BEGIN INIT INFO
+# Provides: hshostname
+# Required-Start: mountkernfs $local_fs networking
+# Required-Stop: $local_fs
+# Default-Start: S
+# Default-Stop: 0 6
+# Short-Description: Setup HostingStack hostname
+### END INIT INFO
+
+
+domain = "hostingstack.net"
+hostsfile = '/etc/hosts'
+hostnamefile = '/etc/hostname'
+
+hostname_old = File.read('/etc/hostname').strip
+ip = %x{ip route get 4.4.4.4 | awk '/src/{print $7}'}
+
+if ip.nil? or ip.empty? then
+ print "hshostname: no IP bound, not setting hostname..."
+ exit 1
+end
+
+hostname_new = ip.strip.split('.').map{|l| "%02x" % l }.join
+if hostname_old != hostname_new then
+ puts "Setting FQDN to #{hostname_new}.#{domain} ..."
+ data = File.read(hostsfile).split("\n").map {|l| l.match(/^127.0.0.1/) ? l = "127.0.0.1 #{hostname_new}.#{domain} #{hostname_new} localhost" : l }.join("\n")
+ File.open(hostsfile, "w") do |f|
+ f.write data + "\n"
+ end
+ File.open(hostnamefile, "w") do |f|
+ f.write hostname_new + "\n"
+ end
+ %x{/etc/init.d/hostname.sh start}
+
+ issue = <<EOF
+
+ HostingStack PaaS on \\n -- Terminal \\l
+
+ Management: http://#{hostname_new}.#{domain}:9100/
+ UCP: http://#{hostname_new}.#{domain}:9000/
+EOF
+ File.open("/etc/issue", "w") do |f|
+ f.write issue + "\n"
+ end
+
+end
+
View
11 util/build/post-scripts/10-install-stuff
@@ -70,20 +70,17 @@ if [ -f /var/hspostinst ]; then
/var/hspostinst 2>&1 | tee -a /var/log/hspostinst.log
fi
-HOST_IP=\$(ip route get 4.4.4.4 | awk '/src/{print \$7}')
-cat <<EOI > /etc/issue
-HostingStack Platform on \n -- Terminal \l
-Management: http://\$HOST_IP:9100/
-UCP: http://\$HOST_IP:9000/
-EOI
-
exit 0
EOF
echo "${PACKAGES}" > "$MNTPOINT"/root/packages/list
+
cp "$HS_BASEPATH"/util/build/hspostinst "$MNTPOINT"/var/hspostinst
chmod a+x "$MNTPOINT"/var/hspostinst
+cp "$HS_BASEPATH"/util/build/hshostname "$MNTPOINT"/etc/init.d
+chroot "$MNTPOINT" insserv hshostname
+
echo "The new VM has these SSH Keys:"
for key in "$MNTPOINT"/etc/ssh/ssh_host_*_key.pub ; do
chroot "$MNTPOINT" ssh-keygen -l -f ${key##$MNTPOINT}
Please sign in to comment.
Something went wrong with that request. Please try again.