install.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/sh
  2. # Install script for burncd.
  3. # Copyright 2017-2018 orbea
  4. # All rights reserved.
  5. #
  6. # Redistribution and use of this script, with or without modification, is
  7. # permitted provided that the following conditions are met:
  8. #
  9. # 1. Redistributions of this script must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  13. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  15. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  18. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  19. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  20. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  21. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. IFS='
  23. '
  24. \unset -f command printf unalias : 2>/dev/null
  25. \unalias -a 2>/dev/null
  26. PATH="$(command -p getconf PATH):$PATH"
  27. LC_ALL=C; export LC_ALL
  28. set -euf
  29. cmd () {
  30. command=; print=
  31. while [ $# -gt 1 ]; do
  32. var="$1"; shift
  33. command="${command} $var"
  34. case "$var" in
  35. -- ) continue ;;
  36. * ) print="${print} $var" ;;
  37. esac
  38. done
  39. dir="$1"
  40. printf %s\\n " $print '$dir'"
  41. eval "set -- $command"
  42. command -p "$@" "$dir"
  43. }
  44. die () {
  45. ret="$1"; shift
  46. case "$ret" in
  47. : ) printf %s\\n "$@" >&2; return 0 ;;
  48. 0 ) printf %s\\n "$@" ;;
  49. * ) printf %s\\n "$@" >&2 ;;
  50. esac
  51. exit "$ret"
  52. }
  53. case "${1:-}" in
  54. install ) INSTALL=1 ;;
  55. uninstall ) INSTALL=0 ;;
  56. '' ) die 1 'No install target.' ;;
  57. * ) die 1 "No rule to install target '$1'." ;;
  58. esac
  59. PREFIX=; BINDIR=; DOCDIR=; MANDIR=; DESTDIR=
  60. PRGNAM=burncd
  61. VERSION=0.0
  62. shift
  63. while [ $# -gt 0 ]; do
  64. arg="$1"; shift
  65. case "${arg%%=*}" in
  66. PREFIX|BINDIR|DOCDIR|MANDIR|DESTDIR ) eval "${arg%%=*}=\"\${arg#*=}\"" ;;
  67. * ) die : "WARNING: Variable '${arg%%=*}' was not used by $PRGNAM." ;;
  68. esac
  69. done
  70. PREFIX="${PREFIX:-/usr/local}"
  71. BINDIR="${BINDIR:-${PREFIX}/bin}"
  72. DOCDIR="${DOCDIR:-${PREFIX}/share/doc}/$PRGNAM-$VERSION"
  73. MANDIR="${MANDIR:-${PREFIX}/share/man}/man1"
  74. DESTDIR="${DESTDIR:-}"
  75. for i in \$BINDIR \$DOCDIR \$MANDIR; do
  76. eval "dest=\"$i\""
  77. case "${dest:?}" in
  78. /*|${PREFIX}* ) : ;;
  79. * ) eval "${i#*$}=\"\${PREFIX}/$i\"" ;;
  80. esac
  81. done
  82. case $INSTALL in
  83. 1 )
  84. printf %s\\n 'Installing...'
  85. cmd mkdir -p -- "${DESTDIR}${BINDIR}"
  86. cmd mkdir -p -- "${DESTDIR}${DOCDIR}"
  87. cmd mkdir -p -- "${DESTDIR}${MANDIR}"
  88. cmd rm -f -- "${DESTDIR}${BINDIR}/$PRGNAM"
  89. cmd cp -- $PRGNAM "${DESTDIR}${BINDIR}"
  90. cmd rm -f -- "${DESTDIR}${MANDIR}/$PRGNAM.1"
  91. cmd cp -- $PRGNAM.1 "${DESTDIR}${MANDIR}"
  92. cmd rm -f -- "${DESTDIR}${DOCDIR}/LICENSE"
  93. cmd cp -- LICENSE "${DESTDIR}${DOCDIR}"
  94. cmd rm -f -- "${DESTDIR}${DOCDIR}/README"
  95. cmd cp -- README "${DESTDIR}${DOCDIR}"
  96. cmd chmod 0755 -- "${DESTDIR}${BINDIR}/$PRGNAM"
  97. ;;
  98. 0 )
  99. printf %s\\n 'Uninstalling...'
  100. cmd rm -rf -- "${DESTDIR}${DOCDIR}"
  101. cmd rm -f -- "${DESTDIR}${BINDIR}/$PRGNAM"
  102. cmd rm -f -- "${DESTDIR}${MANDIR}/$PRGNAM.1"
  103. ;;
  104. esac
  105. exit 0