install.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/bin/sh
  2. # Install script for burncd.
  3. # Copyright 2017-2020 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. die () {
  30. ret="$1"; shift
  31. case "$ret" in
  32. : ) printf %s\\n "$@" >&2; return 0 ;;
  33. 0 ) printf %s\\n "$@" ;;
  34. * ) printf %s\\n "$@" >&2 ;;
  35. esac
  36. exit "$ret"
  37. }
  38. case "${1:-}" in
  39. install ) INSTALL=1 ;;
  40. uninstall ) INSTALL=0 ;;
  41. '' ) die 1 'No install target.' ;;
  42. * ) die 1 "No rule to install target '$1'." ;;
  43. esac
  44. cmd () {
  45. print=
  46. for command do
  47. case "$command" in
  48. -- ) : ;;
  49. */* ) print="${print} '$command'" ;;
  50. * ) print="${print} $command" ;;
  51. esac
  52. done
  53. printf " %s\\n" "$print"
  54. command -p "$@"
  55. }
  56. is_absolute () { case "$1" in /*) return 0 ;; *) return 1 ;; esac; }
  57. PREFIX=; BINDIR=; DATADIR=; DATAROOTDIR=; DOCDIR=; MANDIR=; SYSCONFDIR=
  58. DESTDIR=
  59. CWD="$(pwd)"
  60. if [ "$0" != "${0%/*}" ]; then
  61. SOURCE_DIR="$(cd -- "${0%/*}/" && pwd -P)"
  62. else
  63. SOURCE_DIR="$(pwd -P)"
  64. fi
  65. PRGNAM=burncd
  66. VERSION=0.0
  67. shift
  68. install_args=
  69. while [ $# -gt 0 ]; do
  70. arg="$1"; shift
  71. case "${arg%%=*}" in
  72. DESTDIR|PREFIX )
  73. eval "${arg%%=*}=\"\${arg#*=}\""
  74. ;;
  75. BINDIR|DATADIR|DATAROOTDIR|DOCDIR|MANDIR|SYSCONFDIR )
  76. install_args=1
  77. eval "${arg%%=*}=\"\${arg#*=}\""
  78. ;;
  79. * )
  80. die : "WARNING: Variable '${arg%%=*}' was not used by $PRGNAM."
  81. ;;
  82. esac
  83. done
  84. PREFIX="${PREFIX:-/usr/local}"
  85. BINDIR="${BINDIR:-${PREFIX}/bin}"
  86. DOCDIR="${DOCDIR:-${PREFIX}/share/doc}/$PRGNAM-$VERSION"
  87. MANDIR="${MANDIR:-${PREFIX}/share/man}"
  88. DATAROOTDIR="${DATAROOTDIR:-${PREFIX}/share}"
  89. DATADIR="${DATADIR:-${DATAROOTDIR}}/$PRGNAM"
  90. SYSCONFDIR="${SYSCONFDIR:-${PREFIX}/etc}"
  91. DESTDIR="${DESTDIR:-}"
  92. is_absolute "$PREFIX" || PREFIX="$CWD/$PREFIX"
  93. if [ -n "$install_args" ]; then
  94. for i in \$BINDIR \$DATADIR \$DATAROOTDIR \$DOCDIR \$MANDIR \$SYSCONFDIR; do
  95. eval "dest=\"$i\""
  96. is_absolute "${dest:?}" || eval "${i#*$}=\"\${PREFIX}/$i\""
  97. done
  98. fi
  99. case $INSTALL in
  100. 1 )
  101. printf %s\\n 'Installing...'
  102. cmd mkdir -p -- "${DESTDIR}${BINDIR}"
  103. cmd mkdir -p -- "${DESTDIR}${DOCDIR}"
  104. cmd mkdir -p -- "${DESTDIR}${MANDIR}/man1"
  105. cmd mkdir -p -- "${DESTDIR}${SYSCONFDIR}"
  106. cmd rm -f -- "${DESTDIR}${BINDIR}/$PRGNAM"
  107. cmd cp -- "${SOURCE_DIR}/$PRGNAM" "${DESTDIR}${BINDIR}"
  108. cmd rm -f -- "${DESTDIR}${MANDIR}/man1/$PRGNAM.1"
  109. cmd cp -- "${SOURCE_DIR}/$PRGNAM.1" "${DESTDIR}${MANDIR}/man1"
  110. cmd rm -f -- "${DESTDIR}${DOCDIR}/LICENSE"
  111. cmd rm -f -- "${DESTDIR}${SYSCONFDIR}/$PRGNAM.conf"
  112. cmd cp -- "${SOURCE_DIR}/$PRGNAM.conf" "${DESTDIR}${SYSCONFDIR}"
  113. cmd cp -- "${SOURCE_DIR}"/LICENSE "${DESTDIR}${DOCDIR}"
  114. cmd rm -f -- "${DESTDIR}${DOCDIR}/README"
  115. cmd cp -- "${SOURCE_DIR}"/README "${DESTDIR}${DOCDIR}"
  116. cmd chmod 0755 -- "${DESTDIR}${BINDIR}/$PRGNAM"
  117. ;;
  118. 0 )
  119. printf %s\\n 'Uninstalling...'
  120. cmd rm -rf -- "${DESTDIR}${DOCDIR}"
  121. cmd rm -f -- "${DESTDIR}${BINDIR}/$PRGNAM"
  122. cmd rm -f -- "${DESTDIR}${MANDIR}/man1/$PRGNAM.1"
  123. cmd rm -f -- "${DESTDIR}${SYSCONFDIR}/$PRGNAM.conf"
  124. ;;
  125. esac
  126. exit 0