#!/bin/bash
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/portage/bin/dosbin,v 1.8 2003/04/09 14:36:59 carpaski Exp $

if [ ${#} -lt 1 ] ; then
	echo "${0}: at least one argument needed"
	exit 1
fi
if [ ! -d "${D}${DESTTREE}/sbin" ] ; then
	install -d "${D}${DESTTREE}/sbin"
fi

if [ ! -z "${CBUILD}" ] && [ "${CBUILD}" != "${CHOST}" ]; then
	STRIP=${CHOST}-strip
else
	STRIP=strip
fi

for x in "$@" ; do
	if [ -x "${x}" ] ; then
		if [ "${FEATURES//*nostrip*/true}" != "true" ] && [ "${RESTRICT//*nostrip*/true}" != "true" ] ; then
			MYVAL=`file "${x}" | grep "ELF"`
			if [ "$MYVAL" ] ; then
				${STRIP} "${x}"
			fi
		fi
		#if executable, use existing perms
		install -m0755 "${x}" "${D}${DESTTREE}/sbin"
	else
		#otherwise, use reasonable defaults
		echo ">>> dosbin: making ${x} executable..."
		install -m0755 --owner=root --group=root "${x}" "${D}${DESTTREE}/sbin"
	fi
done
