File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sudo / install-sh
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 10:46:11 2013 UTC (11 years, 5 months ago) by misho
Branches: sudo, MAIN
CVS tags: v1_8_8p0, v1_8_8, v1_8_7p0, v1_8_7, v1_8_5p1, v1_8_3p2, v1_8_10p3_0, v1_8_10p3, HEAD
1.8.7

    1: #! /bin/sh
    2: 
    3: ## (From INN-1.4, written by Rich Salz)
    4: ##  $Revision: 1.1.1.1 $
    5: ##  A script to install files and directories.
    6: 
    7: PROGNAME=`basename $0`
    8: 
    9: ##  Paths to programs.  CHOWN, STRIP and WHOAMI are checked below.
   10: CHOWN=chown
   11: CHGRP=chgrp
   12: CHMOD=chmod
   13: CP=cp
   14: LN=ln
   15: MKDIR=mkdir
   16: MV=mv
   17: RM=rm
   18: STRIP=strip
   19: WHOAMI="echo root"
   20: 
   21: ##  Some systems don't support -x, so we have to use -f.
   22: for d in /sbin /etc /usr/sbin /usr/etc; do
   23:     if [ -f $d/chown ]; then
   24: 	CHOWN=${d}/chown
   25: 	break
   26:     fi
   27: done
   28: 
   29: for d in /usr/bin /bin /usr/ucb /usr/bsd; do
   30:     if [ -f $d/whoami ]; then
   31: 	WHOAMI=${d}/whoami
   32: 	break
   33:     elif [ -f $d/id ]; then
   34: 	WHOAMI=${d}/id | sed -n 's/^[^(]*(\([^)]*\)).*/\1/p'
   35:     fi
   36: done
   37: 
   38: for d in /usr/ccs/bin /usr/bin /bin; do
   39:     if [ -f $d/strip ]; then
   40: 	STRIP=${d}/strip
   41: 	break
   42:     fi
   43: done
   44: 
   45: ##  Defaults.
   46: CHOWNIT=false
   47: CHGROUPIT=false
   48: CHMODIT=false
   49: STRIPIT=false
   50: BACKIT=false
   51: TOUCHIT=true
   52: DIRMODE=false
   53: 
   54: case `${WHOAMI}` in
   55: root)
   56:     ROOT=true
   57:     ;;
   58: *)
   59:     ROOT=false
   60:     ;;
   61: esac
   62: 
   63: ##  Process JCL.
   64: MORETODO=true
   65: while ${MORETODO} ; do
   66:     case X"$1" in
   67:     X-b)
   68: 	BACKIT=true
   69: 	BACKUP="$2"
   70: 	shift
   71: 	;;
   72:     X-b*)
   73: 	BACKIT=true
   74: 	BACKUP="`echo \"$1\" | sed 's/^..//'`"
   75: 	;;
   76:     X-c)
   77: 	# backwards compatibility
   78: 	;;
   79:     X-d)
   80: 	DIRMODE=true
   81: 	;;
   82:     X-g)
   83: 	GROUP="$2"
   84: 	CHGROUPIT=true
   85: 	shift
   86: 	;;
   87:     X-g*)
   88: 	GROUP="`echo \"$1\" | sed 's/^..//'`"
   89: 	CHGROUPIT=true
   90: 	;;
   91:     X-G)
   92: 	GROUP="$2"
   93: 	shift
   94: 	${ROOT} && CHGROUPIT=true
   95: 	;;
   96:     X-G*)
   97: 	if ${ROOT} ; then
   98: 	    GROUP="`echo \"$1\" | sed 's/^..//'`"
   99: 	    CHGROUPIT=true
  100: 	fi
  101: 	;;
  102:     X-m)
  103: 	MODE="$2"
  104: 	CHMODIT=true
  105: 	shift
  106: 	;;
  107:     X-m*)
  108: 	MODE="`echo \"$1\" | sed 's/^..//'`"
  109: 	CHMODIT=true
  110: 	;;
  111:     X-M)
  112: 	MODE="$2"
  113: 	${ROOT} && CHMODIT=true
  114: 	shift
  115: 	;;
  116:     X-M*)
  117: 	MODE="`echo \"$1\" | sed 's/^..//'`"
  118: 	${ROOT} && CHMODIT=true
  119: 	;;
  120:     X-n)
  121: 	TOUCHIT=false
  122: 	;;
  123:     X-o)
  124: 	OWNER="$2"
  125: 	CHOWNIT=true
  126: 	shift
  127: 	;;
  128:     X-o*)
  129: 	OWNER="`echo \"$1\" | sed 's/^..//'`"
  130: 	CHOWNIT=true
  131: 	;;
  132:     X-O)
  133: 	OWNER="$2"
  134: 	shift
  135: 	${ROOT} && CHOWNIT=true
  136: 	;;
  137:     X-O*)
  138: 	if ${ROOT} ; then
  139: 	    OWNER="`echo \"$1\" | sed 's/^..//'`"
  140: 	    CHOWNIT=true
  141: 	fi
  142: 	;;
  143:     X-s)
  144: 	STRIPIT=true
  145: 	;;
  146:     X--)
  147: 	shift
  148: 	MORETODO=false
  149: 	;;
  150:     X-*)
  151: 	echo "${PROGNAME}:  Unknown flag $1" 1>&2
  152: 	exit 1
  153: 	;;
  154:     *)
  155: 	MORETODO=false
  156: 	;;
  157:     esac
  158:     ${MORETODO} && shift
  159: done
  160: 
  161: ##  Making a directory?
  162: if ${DIRMODE} ; then
  163:     while test $# != 0; do
  164: 	DEST="$1"
  165: 	if [ ! -d "${DEST}" ] ; then
  166: 	    ${MKDIR} "${DEST}" || exit 1
  167: 	fi
  168: 	if ${CHOWNIT} ; then
  169: 	    ${CHOWN} "${OWNER}" "${DEST}" || exit 1
  170: 	fi
  171: 	if ${CHGROUPIT} ; then
  172: 	    ${CHGRP} "${GROUP}" "${DEST}" || exit 1
  173: 	fi
  174: 	if ${CHMODIT} ; then
  175: 	    ${CHMOD} "${MODE}"  "${DEST}" || exit 1
  176: 	fi
  177: 	shift;
  178:     done
  179:     exit 0
  180: fi
  181: 
  182: ##  Process arguments.
  183: if [ $# -ne 2 ] ; then
  184:     echo "Usage:  ${PROGNAME} [flags] source destination"
  185:     exit 1
  186: fi
  187: 
  188: ##  Get the destination and a temp file in the destination diretory.
  189: if [ -d "$2" ] ; then
  190:     DEST="$2/`basename $1`"
  191:     TEMP="$2/$$.tmp"
  192: else
  193:     DEST="$2"
  194:     TEMP="`expr "$2" : '\(.*\)/.*'`/$$.tmp"
  195: fi
  196: 
  197: ##  If not given the same name, we must try to copy.
  198: if [ X"$1" != X"$2" ] ; then
  199:     if cmp -s "$1" "${DEST}" ; then
  200: 	##  Files are same; touch or not.
  201: 	${TOUCHIT} && touch "${DEST}"
  202:     else
  203: 	##  If destination exists and we wish to backup, link to backup.
  204: 	if [ -f "${DEST}" ] ; then
  205: 	    if ${BACKIT} ; then
  206: 		${RM} -f "${DEST}${BACKUP}"
  207: 		${LN} "${DEST}" "${DEST}${BACKUP}"
  208: 	    fi
  209: 	fi
  210: 	##  Copy source to the right dir, then move to right spot.
  211: 	##  Done in two parts so we can hope for atomicity.
  212: 	##  We need to rm DEST due to bugs in "mv -f" on some systems.
  213: 	${RM} -f "${TEMP}" || exit 1
  214: 	${CP} "$1" "${TEMP}" || exit 1
  215: 	${RM} -f "${DEST}" || exit 1
  216: 	${MV} -f "${TEMP}" "${DEST}" || exit 1
  217:     fi
  218: fi
  219: 
  220: ##  Strip and set the modes.
  221: if ${STRIPIT} ; then
  222:     ${STRIP} "${DEST}" || exit 1
  223: fi
  224: if ${CHOWNIT} ; then
  225:     ${CHOWN} "${OWNER}" "${DEST}" || exit 1
  226: fi
  227: if ${CHGROUPIT} ; then
  228:     ${CHGRP} "${GROUP}" "${DEST}" || exit 1
  229: fi
  230: if ${CHMODIT} ; then
  231:     ${CHMOD} "${MODE}"  "${DEST}" || exit 1
  232: fi
  233: exit 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>