Skip to content

Commit

Permalink
VM: Force hostname to <iphex>.hostingstack.net
Browse files Browse the repository at this point in the history
  • Loading branch information
zeha committed Apr 15, 2012
1 parent 16daa99 commit cc1949c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
48 changes: 48 additions & 0 deletions util/build/hshostname
Original file line number Diff line number Diff line change
@@ -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

11 changes: 4 additions & 7 deletions util/build/post-scripts/10-install-stuff
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit cc1949c

Please sign in to comment.