#!/bin/sh

copy="mv" ;
progs=
destdir=
strip=
next=
owner=
mode=
group=
add_prog=

for arg do
	case ${next} in
		-m)
			mode=${arg}
			next=
			;;
		-o)
			owner=${arg}
			next=
			;;
		-g)
			group=${arg}
			next=
			;;
		*)
			case ${arg} in
				-c)
					copy="cp -p"
					;;
				-s)
					strip="strip"
					;;
				-[mog])
					next=${arg}
					;;
				-*)
					echo "$0: unknown option: ${arg}"
					exit 1
					;;
				*)
					if [ -z "${progs}" ]; then
						progs="${destdir}"
					else 
						progs="${progs} ${destdir}"
					fi
					destdir=${arg}
					;;
			esac
			;;
	esac
done

if [ -z "${progs}" ]; then
	echo "$0: no programs specified"
	exit 1
fi
if [ -z "${destdir}" ]; then
	echo "$0: destination directory not specified"
	exit 1
fi
if [ -d ${destdir} ]; then
	add_prog=yes
fi
for prog in ${progs}; do
	if [ ! -f ${prog} ]; then
		echo "$0: '${prog}' does not exist"
		exit 1
	fi
done

for prog in ${progs}; do
	${copy} ${prog} ${destdir}
	if [ ! -z "${add_prog}" ]; then
		prog=${destdir}/${prog} ;
	fi
	if [ ! -z "${strip}" ]; then
		strip ${prog} ;
	fi
	if [ ! -z "${owner}" ]; then
		chown ${owner} ${prog} ;
	fi
	if [ ! -z "${group}" ]; then
		chgrp ${owner} ${prog} ;
	fi
	if [ ! -z "${mode}" ]; then
		chmod ${mode} ${prog} ;
	fi
done