#! /bin/sh
#
# Make sure /etc/hostname, /etc/hosts and /target/etc/network/interfaces
# exist before reboot. This is a fallback in case netcfg doesn't do it.

set -e

if [ ! -e /target/etc/hostname ]; then
	echo "localhost" > /target/etc/hostname
fi

if [ ! -e /target/etc/hosts ]; then
	echo "127.0.0.1 localhost" > /target/etc/hosts
fi

if [ ! -e /target/etc/network/interfaces ] && [ -f /target/etc/netplan/*.yaml ]; then
	cat > /target/etc/network/interfaces <<EOF
# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown
EOF

fi
