install-sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. #
  3. # install - install a program, script, or datafile
  4. # This comes from X11R5; it is not part of GNU.
  5. #
  6. # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
  7. #
  8. # This script is compatible with the BSD install script, but was written
  9. # from scratch.
  10. #
  11. # set DOITPROG to echo to test this script
  12. # Don't use :- since 4.3BSD and earlier shells don't like it.
  13. doit="${DOITPROG-}"
  14. # put in absolute paths if you don't have them in your path; or use env. vars.
  15. mvprog="${MVPROG-mv}"
  16. cpprog="${CPPROG-cp}"
  17. chmodprog="${CHMODPROG-chmod}"
  18. chownprog="${CHOWNPROG-chown}"
  19. chgrpprog="${CHGRPPROG-chgrp}"
  20. stripprog="${STRIPPROG-strip}"
  21. rmprog="${RMPROG-rm}"
  22. instcmd="$mvprog"
  23. chmodcmd=""
  24. chowncmd=""
  25. chgrpcmd=""
  26. stripcmd=""
  27. rmcmd="$rmprog -f"
  28. mvcmd="$mvprog"
  29. src=""
  30. dst=""
  31. while [ x"$1" != x ]; do
  32. case $1 in
  33. -c) instcmd="$cpprog"
  34. shift
  35. continue;;
  36. -m) chmodcmd="$chmodprog $2"
  37. shift
  38. shift
  39. continue;;
  40. -o) chowncmd="$chownprog $2"
  41. shift
  42. shift
  43. continue;;
  44. -g) chgrpcmd="$chgrpprog $2"
  45. shift
  46. shift
  47. continue;;
  48. -s) stripcmd="$stripprog"
  49. shift
  50. continue;;
  51. *) if [ x"$src" = x ]
  52. then
  53. src=$1
  54. else
  55. dst=$1
  56. fi
  57. shift
  58. continue;;
  59. esac
  60. done
  61. if [ x"$src" = x ]
  62. then
  63. echo "install: no input file specified"
  64. exit 1
  65. fi
  66. if [ x"$dst" = x ]
  67. then
  68. echo "install: no destination specified"
  69. exit 1
  70. fi
  71. # If destination is a directory, append the input filename; if your system
  72. # does not like double slashes in filenames, you may need to add some logic
  73. if [ -d $dst ]
  74. then
  75. dst="$dst"/`basename $src`
  76. fi
  77. # Make a temp file name in the proper directory.
  78. dstdir=`dirname $dst`
  79. dsttmp=$dstdir/#inst.$$#
  80. # Move or copy the file name to the temp name
  81. $doit $instcmd $src $dsttmp
  82. # and set any options; do chmod last to preserve setuid bits
  83. if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
  84. if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
  85. if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
  86. if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
  87. # Now rename the file to the real destination.
  88. $doit $rmcmd $dst
  89. $doit $mvcmd $dsttmp $dst
  90. exit 0