Sha256: 1aa1698c437e855dff5fd1e231c15f88310c80e902bac6462b5a13db99ac63a8

Contents?: true

Size: 689 Bytes

Versions: 3

Compression:

Stored size: 689 Bytes

Contents

hostname="$1"

if [ "$(hostname)" != "${hostname}" ]; then
  echo "$hostname" > /etc/hostname
  hostname --file /etc/hostname
fi

fqdn=$(hostname --fqdn || true)
if [ "$fqdn" != "$hostname" ]; then
  # if hostname is bar.example.com, we also want `bar` to be in /etc/hosts
  short_hostname=$(echo "$hostname" | cut -d . -f 1)
  if [ "$short_hostname" != "$hostname" ] && ! grep -q "\s${short_hostname}" /etc/hosts; then
    hostname="$hostname $short_hostname"
  fi
  printf "127.0.1.1\t%s\n" "$hostname" >> /etc/hosts
fi

# Stop cloud-init from resetting the hostname
if [ -f /etc/cloud/cloud.cfg ]; then
  sed -i -e '/^\s*-\s*\(set_hostname\|update_hostname\)/d' /etc/cloud/cloud.cfg
fi

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chake-0.92 lib/chake/bootstrap/00_set_hostname.sh
chake-0.91 lib/chake/bootstrap/00_set_hostname.sh
chake-0.90.3 lib/chake/bootstrap/00_set_hostname.sh