install.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #! /bin/sh
  2. #
  3. # Copyright (c) 1999 Marcel Moolenaar
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer
  11. # in this position and unchanged.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. # 3. The name of the author may not be used to endorse or promote products
  16. # derived from this software without specific prior written permission
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. #
  29. # $FreeBSD$
  30. # parse install's options and ignore them completely.
  31. dirmode=""
  32. linkmode=""
  33. while [ $# -gt 0 ]; do
  34. case $1 in
  35. -d) dirmode="YES"; shift;;
  36. -[bCcpSsUv]) shift;;
  37. -[BDfghMmNoT]) shift; shift;;
  38. -[BDfghMmNoT]*) shift;;
  39. -l)
  40. shift
  41. case $1 in
  42. *[sm]*) linkmode="symbolic";; # XXX: 'm' should prefer hard
  43. *h*) linkmode="hard";;
  44. *) echo "invalid link mode"; exit 1;;
  45. esac
  46. shift
  47. ;;
  48. *) break;
  49. esac
  50. done
  51. if [ "$#" -eq 0 ]; then
  52. echo "$0: no files/dirs specified" >&2
  53. exit 1
  54. fi
  55. if [ -z "$dirmode" ] && [ "$#" -lt 2 ]; then
  56. echo "$0: no target specified" >&2
  57. exit 1
  58. fi
  59. # the remaining arguments are assumed to be files/dirs only.
  60. if [ -n "${linkmode}" ]; then
  61. if [ "${linkmode}" = "symbolic" ]; then
  62. ln -fsn "$@"
  63. else
  64. ln -f "$@"
  65. fi
  66. elif [ -z "$dirmode" ]; then
  67. exec install -p "$@"
  68. else
  69. exec install -d "$@"
  70. fi