#!/bin/sh
#
# Create /etc/sysctl.conf and support
#

# Only run once
[ -n "${POST_UPGRADE_CACHE}" ] && touch "${POST_UPGRADE_CACHE}/`basename $0`"

cd /etc

# First the config file itself, try not to overwrite any existing config
if [ -e sysctl.conf ]
then
	if [ ! -e sysctl.conf.local ]
	then
		if [ ! -L sysctl.conf ]
		then
			mv sysctl.conf sysctl.conf.local
			ln -s sysctl.conf.local sysctl.conf
		else
			touch sysctl.conf.local
		fi
	fi
else
	[ -e sysctl.conf.local ] || touch sysctl.conf.local
	[ -L sysctl.conf ] || ln -s sysctl.conf.local sysctl.conf
fi

# Now the rc.local to run sysctl at startup
SCDIR=rc.local.d.local
SCTGT=${SCDIR}/1000-run-sysctl.sh
if [ ! -e $SCTGT ]
then
	mkdir -p $SCDIR
	cat << 'EOF' >> $SCTGT
#!/bin/sh
#
# Run the sysctl command if we have a configuration file
#
CFGFILE=/etc/sysctl.conf

[ -s $CFGFILE ] && sysctl -q -p $CFGFILE
EOF
	chmod +x $SCTGT
fi

cd /
