#!/bin/sh
# check for /usr/local/bin, create if necessary
if [ ! -d /usr/local/bin ]; then
	mkdir -p /usr/local/bin
fi

# make backups of /etc/profile and /etc/csh.login
if [ -f /etc/profile ]; then
	if [ ! -f /etc/profile_old ]; then
		cp /etc/profile /etc/profile_old
	fi
fi
if [ -f /etc/csh.login ]; then
	if [ ! -f /etc/csh.login_old ]; then
		cp /etc/csh.login /etc/csh.login_old
	fi
fi

# check for /usr/local/bin in /etc/profile, create if necessary
if [ `grep PATH /etc/profile | grep -c "/usr/local/bin" /etc/profile` -eq 0 ]; then
	cp /etc/profile /etc/profile_orig
	sed 's/PATH="/PATH="\/usr\/local\/bin:/g' /etc/profile_orig > /etc/profile
fi

# check for /usr/local/bin in /etc/csh.login, create if necessary
if [ `grep PATH /etc/csh.login | grep -c "/usr/local/bin" /etc/csh.login` -eq 0 ]; then
	cp /etc/csh.login /etc/csh.login_orig
	sed 's/PATH\ "/PATH\ "\/usr\/local\/bin:/g' /etc/csh.login_orig > /etc/csh.login
fi

# rename rsync at /usr/local/bin if necessary
if [ -f /usr/local/bin/rsync ]; then
	if [ ! -f /usr/local/bin/rsync_orig ]; then
		cp /usr/local/bin/rsync /usr/local/bin/rsync_orig
	fi
fi
