#!/bin/bash

# Display functions
function check_out
{
	echo "[checkinst] $1"
}
function check_fatal
{
	check_out "FATAL : $1"
}

# Variables
out_target='/usr/local/bin/'
in_source='./'

# Process arguments
while [ $# -gt 0 ]
do
	case $1 in
        '--help' | '-h')
                check_out "usage : $0 [options]"
                check_out 'Used to check if newer scripts are available.'
                check_out '-h | --help : display this help'
                check_out '-o | --out <directory> : current local installed scripts directory'
                check_out '-i | --in <directory> : available newer scripts'
                ;;
        '--out' | '-o')
				out_target=$2
				shift
                check_out "set output directory to $out_target"
                ;;
        '--in' | '-i')
                in_source=$2
                shift
                check_out "set input directory to $in_source"
                ;;
        *)
                check_fatal "unknown argument $1"
                ;;
	esac
	shift
done

# Check installation
check_out "Checking newer scripts from $in_source to $out_target"

for sc in `ls $in_source`
do
	if [ ! -e "$out_target$sc" ]
	then
		check_out "x - not installed : $sc"
	elif [ "$in_source$sc" -nt "$out_target$sc" ]
	then
		check_out "+ - can be updated : $sc"
	fi
done

# End
check_out 'Done.'
exit $?