#!/bin/bash
# virtme-udhcpc-script: A trivial udhcpc script
# Copyright © 2014 Andy Lutomirski
# Licensed under the GPLv2, which is available in the virtme distribution
# as a file called LICENSE with SHA-256 hash:
# 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643

if [[ "$1" == "deconfig" ]]; then
    ip link set dev "$interface" up
    ip addr flush dev "$interface"
elif [[ "$1" == "bound" ]]; then
    ip addr add "$ip/$mask" dev "$interface"
    ip route add default via "$router" dev "$interface"
    if [[ -n "$dns" ]]; then
	# A lot of systems will have /etc/resolv.conf symlinked to
	# /run/NetworkManager/something_or_other. Debian symlinks to /run/resolvconf.
	# Create both directories.
	install -d /run/NetworkManager
	install -d /run/resolvconf

	echo -e "# Generated by virtme-udhcpc-script\n\nnameserver $dns" \
	    >/etc/resolv.conf
    fi
fi
