summaryrefslogtreecommitdiff
path: root/assets/network/cloudstack-guest-setup
blob: 3583afea4650b517ea0615a0262079daaae9fe86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
#
# From https://github.com/shankerbalan/cloudstack-scripts
# Stripped out the non-Debian and Plesk stuff, the cron
# randomisation and the 127.0.1.1 removal in /etc/hosts.
#
# TODO: Rewrite in CHICKEN?
#
# /etc/dhcp/dhclient-exit-hooks.d/cloudstack-guest-setup (debian/ubuntu)
# runs on firstboot after acquiring DHCP lease

if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]; then
    return
fi

# set hostname
logger -t "cloudstack" "Setting hostname to \"${new_host_name}\""
hostname "$new_host_name" > /dev/null 2>&1
echo "$new_host_name" > /etc/hostname

# add hostname to /etc/hosts and remove previous localhost-style
sed -i "/127.0.0.1/a $new_ip_address $new_host_name.$new_domain_name $new_host_name" /etc/hosts > /dev/null 2>&1

# generate ssh host keys
logger -t "cloudstack" "Generating ssh host keys"
ssh-keygen -A && rm /etc/ssh/ssh_host_key /etc/ssh/ssh_host_key.pub
# remove self
rm /etc/dhcp/dhclient-exit-hooks.d/cloudstack-guest-setup > /dev/null 2>&1

exit 0