#!/bin/sh
set -e

if [ ! -d /etc/network ]; then
  mkdir -p /etc/network
fi

if [ -f /etc/network/interfaces ] && ! grep -q '^[^#]' /etc/network/interfaces
then
  f=/etc/network/interfaces
  if [ `md5sum < $f | cut -f1 -d ' '` = "4ed352919f69a77ad302ad1593204405" ]; then
    if [ `wc -c < /etc/network/interfaces` -eq 2466 ]; then
      echo -n "Removing old dummy /etc/network/interfaces: "
      rm /etc/network/interfaces
      echo "done."
    fi
  fi
fi

# Transition /etc/init.d/networking between netbase and ifupdown
# NOTE: This can be dropped after 14.04 LTS
if [ "$1" = install ] || [ "$1" = upgrade ]; then
	if [ -e "/etc/init.d/networking" ] && [ -L "/etc/init.d/networking" ] \
	   && [ $(readlink -f "/etc/init.d/networking") = /lib/init/upstart-job ] \
	   && [ $(dpkg-query -W -f='${Conffiles}' ifupdown | awk '/\/etc\/init.d\/networking/ { print $2 }') = newconffile ]
	then
		rm -f "/etc/init.d/networking"
	elif [ "$2" = 0.7.5ubuntu4 ] && [ $(md5sum /etc/init.d/networking | cut -f1 -d ' ') = b91fa5f0529020176659b341b7a1a740 ]; then
		sed -i -e'/^CONFIGURE_INTERFACES/i \
# Make sure that it'"'"'s clear to the user that they shouldn'"'"'t use this\
# script under upstart\
if init_is_upstart; then\
	echo "ERROR: Calling a sysvinit script on a system using upstart isn'"'"'t supported. Please use the '"'"'service'"'"' command instead."\
	exit 1\
fi\
' -e'26a\
verbose=""' /etc/init.d/networking
	fi
fi

#DEBHELPER#
