install.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. usage() {
  3. [[ "$@" != "" ]] && printf "%s\n" "$@"
  4. cat <<EOF
  5. Usage: $0 [-p path] [uninstall]
  6. Installs the opennic-resolve* files to their locations.
  7. A prefix is used for the binary, configuration and service files
  8. are installed under /etc.
  9. If the first non-option argument is "uninstall", those files are removed again.
  10. -p str Choose a different prefix. Default: $prefix
  11. -h This text
  12. EOF
  13. exit 1
  14. }
  15. basename=opennic-resolve
  16. prefix="/usr"
  17. while getopts p:h opt; do
  18. case $opt in
  19. p)
  20. [ -d "$OPTARG" ] && [ -w "$OPTARG" ] || usage "the directory $OPTARG is not writeable or not a directory"
  21. prefix="$OPTARG"
  22. ;;
  23. h|*) usage
  24. ;;
  25. esac
  26. done
  27. shift $((OPTIND-1))
  28. files=(
  29. "$prefix/bin/$basename"
  30. "/etc/systemd/system/$basename.service"
  31. "/etc/systemd/system/$basename.timer"
  32. "/etc/$basename/$basename.conf"
  33. )
  34. if [[ "${1,,}" == uninstall ]]; then
  35. echo "Uninstalling..."
  36. for f in "${files[@]}"; do
  37. rm -v "$f"
  38. done
  39. exit
  40. fi
  41. echo "Installing..."
  42. for f in "${files[@]}"; do
  43. [[ "${f%/*}" == */?(s)bin ]] && perms=755 || perms=644
  44. echo install -Dm$perms -t "${f%/*}" "${f##*/}"
  45. install -Dm$perms -t "${f%/*}" "${f##*/}"
  46. done