install.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  2. ##
  3. ## install.sh -- install a program, script or datafile
  4. ##
  5. ## Based on `install-sh' from the X Consortium's X11R5 distribution
  6. ## as of 89/12/18 which is freely available.
  7. ## Cleaned up for Apache's Autoconf-style Interface (APACI)
  8. ## by Ralf S. Engelschall <rse@apache.org>
  9. ##
  10. #
  11. # This script falls under the Apache License.
  12. # See http://www.apache.org/docs/LICENSE
  13. #
  14. # put in absolute paths if you don't have them in your path;
  15. # or use env. vars.
  16. #
  17. mvprog="${MVPROG-mv}"
  18. cpprog="${CPPROG-cp}"
  19. chmodprog="${CHMODPROG-chmod}"
  20. chownprog="${CHOWNPROG-chown}"
  21. chgrpprog="${CHGRPPROG-chgrp}"
  22. stripprog="${STRIPPROG-strip}"
  23. rmprog="${RMPROG-rm}"
  24. #
  25. # parse argument line
  26. #
  27. instcmd="$mvprog"
  28. chmodcmd=""
  29. chowncmd=""
  30. chgrpcmd=""
  31. stripcmd=""
  32. rmcmd="$rmprog -f"
  33. mvcmd="$mvprog"
  34. ext=""
  35. src=""
  36. dst=""
  37. while [ "x$1" != "x" ]; do
  38. case $1 in
  39. -c) instcmd="$cpprog"
  40. shift; continue
  41. ;;
  42. -m) chmodcmd="$chmodprog $2"
  43. shift; shift; continue
  44. ;;
  45. -o) chowncmd="$chownprog $2"
  46. shift; shift; continue
  47. ;;
  48. -g) chgrpcmd="$chgrpprog $2"
  49. shift; shift; continue
  50. ;;
  51. -s) stripcmd="$stripprog"
  52. shift; continue
  53. ;;
  54. -S) stripcmd="$stripprog $2"
  55. shift; shift; continue
  56. ;;
  57. -e) ext="$2"
  58. shift; shift; continue
  59. ;;
  60. *) if [ "x$src" = "x" ]; then
  61. src=$1
  62. else
  63. dst=$1
  64. fi
  65. shift; continue
  66. ;;
  67. esac
  68. done
  69. if [ "x$src" = "x" ]; then
  70. echo "install.sh: no input file specified"
  71. exit 1
  72. fi
  73. if [ "x$dst" = "x" ]; then
  74. echo "install.sh: no destination specified"
  75. exit 1
  76. fi
  77. #
  78. # If destination is a directory, append the input filename; if
  79. # your system does not like double slashes in filenames, you may
  80. # need to add some logic
  81. #
  82. if [ -d $dst ]; then
  83. dst="$dst/`basename $src`"
  84. fi
  85. # Add a possible extension (such as ".exe") to src and dst
  86. src="$src$ext"
  87. dst="$dst$ext"
  88. # Make a temp file name in the proper directory.
  89. dstdir=`dirname $dst`
  90. dsttmp=$dstdir/#inst.$$#
  91. # Move or copy the file name to the temp name
  92. $instcmd $src $dsttmp
  93. # And set any options; do chmod last to preserve setuid bits
  94. if [ "x$chowncmd" != "x" ]; then $chowncmd $dsttmp; fi
  95. if [ "x$chgrpcmd" != "x" ]; then $chgrpcmd $dsttmp; fi
  96. if [ "x$stripcmd" != "x" ]; then $stripcmd $dsttmp; fi
  97. if [ "x$chmodcmd" != "x" ]; then $chmodcmd $dsttmp; fi
  98. # Now rename the file to the real destination.
  99. $rmcmd $dst
  100. $mvcmd $dsttmp $dst
  101. exit 0