#!/bin/sh

BOOT_ARGS="$(llxcfg-bootvar boot)"
[ "$BOOT_ARGS" = "casper" ] && exit 0 

PERSISTENT_NET_RULES_ORIG=/etc/udev/rules.d/70-persistent-net.rules
PERSISTENT_NET_RULES_LLIUREX=/var/lib/lliurex/llxcfg-hwsupport/udev/rules.d/70-persistent-net.rules


update_initram() {
	update-initramfs -u -k all 2>/dev/null || true
	cp -f $PERSISTENT_NET_RULES_ORIG $PERSISTENT_NET_RULES_LLIUREX >/dev/null 2>/dev/null || true
}


if [ ! -f $PERSISTENT_NET_RULES_ORIG ]; then
  update-initramfs -u -k all 2>/dev/null || true

elif [ -f $PERSISTENT_NET_RULES_ORIG ]; then 

	if [ -f $PERSISTENT_NET_RULES_LLIUREX ]; then 
		if ! diff -q $PERSISTENT_NET_RULES_ORIG $PERSISTENT_NET_RULES_LLIUREX >/dev/null 2>/dev/null ; then
			update_initram
		fi
	else
		update_initram
	fi

fi