install.sh 1.8 KB

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