File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22Description =SCW set hostname from metadata on first boot
33Requires =network-online.target
44After =network.target network-online.target
5- ConditionFileNotEmpty =!/etc/hostname
65
76[Service]
87Type =oneshot
Original file line number Diff line number Diff line change 11#! /bin/bash
22
33old_hostname=$( hostnamectl status | grep ' hostname' | cut -d " :" -f2 | tr -d " " )
4- new_hostname=$( scw-metadata --cached HOSTNAME)
4+ new_hostname=$( scw-metadata HOSTNAME)
5+
6+ if ! [ -s /etc/hosts ]; then
7+ cp /etc/hosts.default /etc/hosts
8+ sed -i " s/\bserver\b/$new_hostname /g" /etc/hosts
9+ fi
10+
511hostnamectl set-hostname $new_hostname
612if grep -q " $old_hostname " /etc/hosts; then
7- sed -i " /$old_hostname /s/.*/127.0.0.1\t $ new_hostname /" /etc/hosts
13+ sed -i " /$old_hostname /s/\b $old_hostname \b/ $ new_hostname /g " /etc/hosts
814else
915 echo -e " 127.0.0.1\t$new_hostname " >> /etc/hosts
1016fi
You can’t perform that action at this time.
0 commit comments