install-client.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/sh
  2. # -*- coding: utf-8 -*-
  3. basedir="$(realpath "$0" | xargs dirname)"
  4. info()
  5. {
  6. echo "--- $*"
  7. }
  8. error()
  9. {
  10. echo "=== ERROR: $*" >&2
  11. }
  12. warning()
  13. {
  14. echo "=== WARNING: $*" >&2
  15. }
  16. die()
  17. {
  18. error "$*"
  19. exit 1
  20. }
  21. do_install()
  22. {
  23. info "install $*"
  24. install "$@" || die "Failed install $*"
  25. }
  26. do_chown()
  27. {
  28. info "chown $*"
  29. chown "$@" || die "Failed to chown $*"
  30. }
  31. do_chmod()
  32. {
  33. info "chmod $*"
  34. chmod "$@" || die "Failed to chmod $*"
  35. }
  36. entry_checks()
  37. {
  38. [ -d "$target" ] || die "letmein is not built! Run ./build.sh"
  39. [ "$(id -u)" = "0" ] || die "Must be root to install letmein."
  40. }
  41. install_dirs()
  42. {
  43. do_install \
  44. -o root -g root -m 0755 \
  45. -d /opt/letmein/bin
  46. do_install \
  47. -o root -g root -m 0755 \
  48. -d /opt/letmein/etc
  49. }
  50. install_conf()
  51. {
  52. if [ -e /opt/letmein/etc/letmein.conf ]; then
  53. do_chown root:root /opt/letmein/etc/letmein.conf
  54. do_chmod 0644 /opt/letmein/etc/letmein.conf
  55. else
  56. do_install \
  57. -o root -g root -m 0644 \
  58. "$basedir/letmein/letmein.conf" \
  59. /opt/letmein/etc/letmein.conf
  60. fi
  61. }
  62. install_letmein()
  63. {
  64. do_install \
  65. -o root -g root -m 0755 \
  66. "$target/letmein" \
  67. /opt/letmein/bin/
  68. }
  69. release="release"
  70. while [ $# -ge 1 ]; do
  71. case "$1" in
  72. --debug|-d)
  73. release="debug"
  74. ;;
  75. --release|-r)
  76. release="release"
  77. ;;
  78. *)
  79. die "Invalid option: $1"
  80. ;;
  81. esac
  82. shift
  83. done
  84. target="$basedir/target/$release"
  85. entry_checks
  86. install_dirs
  87. install_conf
  88. install_letmein
  89. # vim: ts=4 sw=4 expandtab