install-sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #!/bin/sh
  2. #############################################################################
  3. #
  4. # MODULE: GRASS Compilation
  5. # AUTHOR(S): Original author MIT (X11R5)
  6. # PURPOSE: This file is required by configure to create the config.cache
  7. # file.
  8. # COPYRIGHT: Please see below for details.
  9. #
  10. #############################################################################
  11. #
  12. # install - install a program, script, or datafile
  13. # This comes from X11R5 (mit/util/scripts/install.sh).
  14. #
  15. # Copyright 1991 by the Massachusetts Institute of Technology
  16. #
  17. # Permission to use, copy, modify, distribute, and sell this software and its
  18. # documentation for any purpose is hereby granted without fee, provided that
  19. # the above copyright notice appear in all copies and that both that
  20. # copyright notice and this permission notice appear in supporting
  21. # documentation, and that the name of M.I.T. not be used in advertising or
  22. # publicity pertaining to distribution of the software without specific,
  23. # written prior permission. M.I.T. makes no representations about the
  24. # suitability of this software for any purpose. It is provided "as is"
  25. # without express or implied warranty.
  26. #
  27. # Calling this script install-sh is preferred over install.sh, to prevent
  28. # `make' implicit rules from creating a file called install from it
  29. # when there is no Makefile.
  30. #
  31. # This script is compatible with the BSD install script, but was written
  32. # from scratch. It can only install one file at a time, a restriction
  33. # shared with many OS's install programs.
  34. #
  35. #############################################################################
  36. # set DOITPROG to echo to test this script
  37. # Don't use :- since 4.3BSD and earlier shells don't like it.
  38. doit="${DOITPROG-}"
  39. # put in absolute paths if you don't have them in your path; or use env. vars.
  40. mvprog="${MVPROG-mv}"
  41. cpprog="${CPPROG-cp}"
  42. chmodprog="${CHMODPROG-chmod}"
  43. chownprog="${CHOWNPROG-chown}"
  44. chgrpprog="${CHGRPPROG-chgrp}"
  45. stripprog="${STRIPPROG-strip}"
  46. rmprog="${RMPROG-rm}"
  47. mkdirprog="${MKDIRPROG-mkdir}"
  48. transformbasename=""
  49. transform_arg=""
  50. instcmd="$mvprog"
  51. chmodcmd="$chmodprog 0755"
  52. chowncmd=""
  53. chgrpcmd=""
  54. stripcmd=""
  55. rmcmd="$rmprog -f"
  56. mvcmd="$mvprog"
  57. src=""
  58. dst=""
  59. dir_arg=""
  60. while [ x"$1" != x ]; do
  61. case $1 in
  62. -c) instcmd="$cpprog"
  63. shift
  64. continue;;
  65. -d) dir_arg=true
  66. shift
  67. continue;;
  68. -m) chmodcmd="$chmodprog $2"
  69. shift
  70. shift
  71. continue;;
  72. -o) chowncmd="$chownprog $2"
  73. shift
  74. shift
  75. continue;;
  76. -g) chgrpcmd="$chgrpprog $2"
  77. shift
  78. shift
  79. continue;;
  80. -s) stripcmd="$stripprog"
  81. shift
  82. continue;;
  83. -t=*) transformarg=`echo "$1" | sed 's/-t=//'`
  84. shift
  85. continue;;
  86. -b=*) transformbasename=`echo "$1" | sed 's/-b=//'`
  87. shift
  88. continue;;
  89. *) if [ x"$src" = x ]
  90. then
  91. src="$1"
  92. else
  93. # this colon is to work around a 386BSD /bin/sh bug
  94. :
  95. dst="$1"
  96. fi
  97. shift
  98. continue;;
  99. esac
  100. done
  101. if [ x"$src" = x ]
  102. then
  103. echo "install: no input file specified"
  104. exit 1
  105. else
  106. true
  107. fi
  108. if [ x"$dir_arg" != x ]; then
  109. dst="$src"
  110. src=""
  111. if [ -d "$dst" ]; then
  112. instcmd=:
  113. else
  114. instcmd=mkdir
  115. fi
  116. else
  117. # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
  118. # might cause directories to be created, which would be especially bad
  119. # if $src (and thus $dsttmp) contains '*'.
  120. if [ -f "$src" -o -d "$src" ]
  121. then
  122. true
  123. else
  124. echo "install: $src does not exist"
  125. exit 1
  126. fi
  127. if [ x"$dst" = x ]
  128. then
  129. echo "install: no destination specified"
  130. exit 1
  131. else
  132. true
  133. fi
  134. # If destination is a directory, append the input filename; if your system
  135. # does not like double slashes in filenames, you may need to add some logic
  136. if [ -d "$dst" ]
  137. then
  138. dst="$dst"/`basename $src`
  139. else
  140. true
  141. fi
  142. fi
  143. ## this sed command emulates the dirname command
  144. dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
  145. # Make sure that the destination directory exists.
  146. # this part is taken from Noah Friedman's mkinstalldirs script
  147. # Skip lots of stat calls in the usual case.
  148. if [ ! -d "$dstdir" ]; then
  149. defaultIFS='
  150. '
  151. IFS="${IFS-${defaultIFS}}"
  152. oIFS="${IFS}"
  153. # Some sh's can't handle IFS=/ for some reason.
  154. IFS='%'
  155. set - `echo "${dstdir}" | sed -e 's@/@%@g' -e 's@^%@/@'`
  156. IFS="${oIFS}"
  157. pathcomp=''
  158. while [ $# -ne 0 ] ; do
  159. pathcomp="${pathcomp}${1}"
  160. shift
  161. if [ ! -d "${pathcomp}" ] ;
  162. then
  163. $mkdirprog "${pathcomp}"
  164. else
  165. true
  166. fi
  167. pathcomp="${pathcomp}/"
  168. done
  169. fi
  170. if [ x"$dir_arg" != x ]
  171. then
  172. "$doit" "$instcmd" "$dst" &&
  173. if [ x"$chowncmd" != x ]; then "$doit" "$chowncmd" "$dst"; else true ; fi &&
  174. if [ x"$chgrpcmd" != x ]; then "$doit" "$chgrpcmd" "$dst"; else true ; fi &&
  175. if [ x"$stripcmd" != x ]; then "$doit" "$stripcmd" "$dst"; else true ; fi &&
  176. if [ x"$chmodcmd" != x ]; then "$doit" "$chmodcmd" "$dst"; else true ; fi
  177. else
  178. # If we're going to rename the final executable, determine the name now.
  179. if [ x"$transformarg" = x ]
  180. then
  181. dstfile=`basename "$dst"`
  182. else
  183. dstfile=`basename "$dst" "$transformbasename" |
  184. sed "$transformarg"`"$transformbasename"
  185. fi
  186. # don't allow the sed command to completely eliminate the filename
  187. if [ x"$dstfile" = x ]
  188. then
  189. dstfile=`basename "$dst"`
  190. else
  191. true
  192. fi
  193. # Make a temp file name in the proper directory.
  194. dsttmp="$dstdir"/#inst.$$#
  195. # Move or copy the file name to the temp name
  196. "$doit" "$instcmd" "$src" "$dsttmp" &&
  197. trap 'rm -f "${dsttmp}"' 0 &&
  198. # and set any options; do chmod last to preserve setuid bits
  199. # If any of these fail, we abort the whole thing. If we want to
  200. # ignore errors from any of these, just make sure not to ignore
  201. # errors from the above "$doit $instcmd $src $dsttmp" command.
  202. if [ x"$chowncmd" != x ]; then "$doit" "$chowncmd" "$dsttmp"; else true;fi &&
  203. if [ x"$chgrpcmd" != x ]; then "$doit" "$chgrpcmd" "$dsttmp"; else true;fi &&
  204. if [ x"$stripcmd" != x ]; then "$doit" "$stripcmd" "$dsttmp"; else true;fi &&
  205. if [ x"$chmodcmd" != x ]; then "$doit" "$chmodcmd" "$dsttmp"; else true;fi &&
  206. # Now rename the file to the real destination.
  207. "$doit" "$rmcmd" -f "$dstdir/$dstfile" &&
  208. "$doit" "$mvcmd" "$dsttmp" "$dstdir/$dstfile"
  209. fi &&
  210. exit 0