#!/bin/sh
# this forces fakeroot to have an independent, empty network namespace

if [ "$(uname -s)" = "Linux" ]
then
	apt-get install -y net-tools util-linux
	mv /usr/bin/fakeroot /usr/bin/fakeroot.original
	cat > /usr/bin/fakeroot <<- EOF
		#!/usr/bin/perl

		system("unshare", "-n", "/usr/bin/fakeroot.wrapper", @ARGV);
		EOF
	cat > /usr/bin/fakeroot.wrapper <<- EOF
		#!/usr/bin/perl

		system("/sbin/ifconfig", "lo", "up");
		system("/usr/bin/fakeroot.original", @ARGV);
		EOF
	chmod +x /usr/bin/fakeroot
	chmod +x /usr/bin/fakeroot.wrapper
fi
