home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Networking / wu-ftpd-2.4.2b13-MIHS / util / install < prev    next >
Encoding:
Text File  |  1994-04-01  |  3.3 KB  |  223 lines

  1. #!/bin/sh
  2. #    install    -    implementation of BSD install program for SYSV
  3. #
  4. # SYNTAX:
  5. #    install [-cs] [-g group] [-m mode] [-o owner] file1 file2
  6. #    install [-cs] [-g group] [-m mode] [-o owner] file1 ... directory
  7. #    install -d [-g group] [-m mode] [-o owner] directory
  8. #
  9. # RETURN VALUES:
  10. #    0    success
  11. #    1    failure
  12. #>
  13. #
  14. # HISTORY
  15. #    920709    BM    Version 0.1
  16. #    920710    BM    Version 1.0
  17.  
  18. # ----------------------------- INITIALIZATION ------------------------------
  19.  
  20. ME="`basename $0`"
  21.  
  22. # ------------------------------- SUBROUTINES -------------------------------
  23.  
  24. #
  25. # Usage        - print usage message
  26. #
  27. Usage()
  28. {
  29.     echo "Usage: ${ME} [-cs] [-g group] [-m mode] [-o owner] file1 file2"
  30.     echo "       ${ME} [-cs] [-g group] [-m mode] [-o owner] file1 ... directory"
  31.     echo "       ${ME} -d [-g group] [-m mode] [-o owner] directory"
  32.     exit 1
  33. }
  34.  
  35. #
  36. # Warning        - print warning message
  37. #
  38. Warning()
  39. {
  40.     echo "${ME}: $*"
  41. }
  42.  
  43. #
  44. # Die        - print message and exit with failure
  45. #
  46. Die()
  47. {
  48.     echo "${ME}: $*"
  49.     exit 1
  50. }
  51. # ------------------------------- MAIN PROGRAM -----------------------------
  52.  
  53. #
  54. # We always need at least two arguments
  55. #
  56. if [ $# -lt 2 ]
  57. then
  58.     Usage
  59.     exit 1
  60. fi
  61.  
  62. #
  63. # Process command line options
  64. #
  65. for ARG in $*; do
  66.     if [ "${FLAG}" = "on" ]; then
  67.         case ${ARG} in
  68.         -*)
  69.             Die "The -g, -m and -o flags each require an argument following"
  70.             exit 1
  71.             ;;
  72.         *)
  73.             FLAG=off
  74.             continue
  75.             ;;
  76.         esac
  77.     fi
  78.  
  79.     case ${ARG} in
  80.     -cs | -s)
  81.         STRIP=on
  82.         shift
  83.         ;;
  84.     -g)
  85.         GRP=$2
  86.         FLAG=on
  87.         shift 2
  88.         ;;
  89.     -m)
  90.         MODE=$2
  91.         FLAG=on
  92.         shift 2
  93.         ;;
  94.     -o)
  95.         OWNER=$2
  96.         FLAG=on
  97.         shift 2
  98.         ;;
  99.     -d)
  100.         MKDIR=on
  101.         shift
  102.         ;;    
  103.     -c)
  104.         # For backward compatibility only; ignore
  105.         shift
  106.         ;;
  107.     -*)
  108.         Warning "unknown option ${ARG}"
  109.         Usage
  110.         exit 1 
  111.         ;;
  112.     *)
  113.         break
  114.         ;;
  115.     esac
  116. done
  117.  
  118. #
  119. # Find out what the target is
  120. #
  121. FILES=$*
  122. NARGS=$#
  123. set `echo ${FILES}`
  124. i=1
  125. while [ $i -lt ${NARGS} ]; do
  126.     FLS="${FLS} $1"
  127.     shift
  128.     i=`expr $i + 1`
  129. done
  130. TARGET=$1
  131.  
  132. #
  133. # If more than one file specified, target must be a directory
  134. #
  135. set `echo ${FLS}`
  136. if [ $# -gt 1 ]
  137. then
  138.     if [ ! -d ${TARGET} ]
  139.     then
  140.         Usage
  141.     fi
  142. fi
  143.  
  144. #
  145. # If -d flag was present, see if directory exists. If not create it.
  146. # If group and/or mode and/or owner specified, set them for target
  147. #
  148. if [ "${MKDIR}" = "on" ]
  149. then
  150.     if [ ! -d ${TARGET} ]
  151.     then
  152.         mkdir -p ${TARGET}
  153.     fi
  154.  
  155.     if [ "${GRP}" != "" ]
  156.     then
  157.         chgrp ${GRP} ${TARGET}
  158.     fi
  159.  
  160.     if [ "${MODE}" != "" ]
  161.     then
  162.         chmod ${MODE} ${TARGET}
  163.     fi
  164.  
  165.     if [ "${OWNER}" != "" ]
  166.     then
  167.         if [ "`id -un`" != "root" ]
  168.         then
  169.             Warning "-o: must be superuser to change owner"
  170.         else
  171.             chown ${OWNER} ${TARGET}
  172.         fi
  173.     fi
  174. fi
  175.  
  176. #
  177. # Process each file, taking the command line options into account
  178. # If the target is a directory, set modes for file in that directory,
  179. # otherwise set modes for file.
  180. #
  181. for FILE in ${FLS}
  182. do
  183.     if [ "${STRIP}" = "on" ]
  184.     then
  185.         strip ${FILE}
  186.     fi
  187.  
  188.     cp ${FILE} ${TARGET}
  189.  
  190.     if [ "${GRP}" != "" ]
  191.     then
  192.         if [ ! -d ${TARGET} ]
  193.         then
  194.             chgrp ${GRP} ${FILE}
  195.         else
  196.             chgrp ${GRP} ${TARGET}/${FILE}
  197.         fi
  198.     fi
  199.     
  200.     if [ "${MODE}" != "" ]
  201.     then
  202.         if [ ! -d ${TARGET} ]
  203.         then
  204.             chmod ${MODE} ${FILE}
  205.         else
  206.             chmod ${MODE} ${TARGET}/${FILE}
  207.         fi
  208.     fi
  209.  
  210.     if [ "${OWNER}" != "" ]
  211.     then
  212.         if [ "`id -un`" != "root" ]
  213.         then
  214.             Warning "-o: must be superuser to change owner"
  215.         elif [ ! -d ${TARGET} ]
  216.         then
  217.             chown ${OWNER} ${FILE}
  218.         else
  219.             chown ${OWNER} ${TARGET}/${FILE}
  220.         fi
  221.     fi
  222. done
  223.