install-sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. mkdirprog="${MKDIRPROG-mkdir -p}"
  23. instcmd="$mvprog"
  24. chmodcmd=""
  25. chowncmd=""
  26. chgrpcmd=""
  27. stripcmd=""
  28. rmcmd="$rmprog -f"
  29. mvcmd="$mvprog"
  30. src=""
  31. dst=""
  32. mkdir=n
  33. while [ x"$1" != x ]; do
  34. case $1 in
  35. -c) instcmd="$cpprog"
  36. shift
  37. continue;;
  38. -d) instcmd="$mkdirprog"
  39. mkdir=y
  40. src="/dev/null"
  41. shift
  42. continue;;
  43. -m) chmodcmd="$chmodprog $2"
  44. shift
  45. shift
  46. continue;;
  47. -o) chowncmd="$chownprog $2"
  48. shift
  49. shift
  50. continue;;
  51. -g) chgrpcmd="$chgrpprog $2"
  52. shift
  53. shift
  54. continue;;
  55. -s) stripcmd="$stripprog"
  56. shift
  57. continue;;
  58. *) if [ x"$src" = x ]
  59. then
  60. src=$1
  61. else
  62. dst=$1
  63. fi
  64. shift
  65. continue;;
  66. esac
  67. done
  68. if [ x"$src" = x ]
  69. then
  70. echo "install: no input file specified"
  71. exit 1
  72. fi
  73. if [ x"$dst" = x ]
  74. then
  75. echo "install: no destination specified"
  76. exit 1
  77. fi
  78. if [ $mkdir = y ]; then
  79. $doit $instcmd $dst
  80. dsttmp=$dst
  81. else
  82. # If destination is a directory, append the input filename; if your
  83. # system does not like double slashes in filenames, you may need to
  84. # add some logic
  85. if [ $mkdir = n -a -d $dst ]
  86. then
  87. dst="$dst"/`basename $src`
  88. fi
  89. # Make a temp file name in the proper directory.
  90. dstdir=`dirname $dst`
  91. dsttmp=$dstdir/#inst.$$#
  92. # Move or copy the file name to the temp name
  93. $doit $instcmd $src $dsttmp
  94. fi
  95. # and set any options; do chmod last to preserve setuid bits
  96. if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
  97. if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
  98. if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
  99. if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
  100. if [ $mkdir = n ]; then
  101. # Now rename the file to the real destination.
  102. $doit $rmcmd $dst
  103. $doit $mvcmd $dsttmp $dst
  104. fi
  105. exit 0