#!/bin/bash -e

# debirf module: network
# setup default network interface configuration
#
# The debirf scripts were written by
# Jameson Rollins <jrollins@fifthhorseman.net>
# and
# Daniel Kahn Gillmor <dkg@fifthhorseman.net>.
#
# They are Copyright 2007-2011, and are all released under the GPL,
# version 3 or later.
#
# Copyright (C) 2018-2020 Gunter Miegel coinboot.io

# Cosmic is missing the 'ifupdown' out of the box
# which leads to a unconfigured NIC in early userspace.
debirf_exec apt update
debirf_exec apt install --yes ifupdown

# reset default udev persistent-net rule
rm -f "${DEBIRF_ROOT}"/etc/udev/rules.d/*_persistent-net.rules

mkdir -p "${DEBIRF_ROOT}/etc/network"

# write /etc/network/interfaces
cat <<EOF > "${DEBIRF_ROOT}/etc/network/interfaces"
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.

auto lo
iface lo inet loopback

# A default dynamic ethernet address.

allow-hotplug eth0
iface eth0 inet dhcp
EOF
