install.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_systemctl()
  27. {
  28. info "systemctl $*"
  29. systemctl "$@" || die "Failed to systemctl $*"
  30. }
  31. do_chown()
  32. {
  33. info "chown $*"
  34. chown "$@" || die "Failed to chown $*"
  35. }
  36. do_chmod()
  37. {
  38. info "chmod $*"
  39. chmod "$@" || die "Failed to chmod $*"
  40. }
  41. try_systemctl()
  42. {
  43. info "systemctl $*"
  44. systemctl "$@" 2>/dev/null
  45. }
  46. do_chown()
  47. {
  48. info "chown $*"
  49. chown "$@" || die "Failed to chown $*"
  50. }
  51. do_chmod()
  52. {
  53. info "chmod $*"
  54. chmod "$@" || die "Failed to chmod $*"
  55. }
  56. entry_checks()
  57. {
  58. [ -d "$target" ] || die "feedreader is not built! Run ./build.sh"
  59. [ "$(id -u)" = "0" ] || die "Must be root to install feedreader."
  60. }
  61. stop_services()
  62. {
  63. try_systemctl stop feedsd.service
  64. try_systemctl disable feedsd.service
  65. }
  66. start_services()
  67. {
  68. do_systemctl start feedsd.service
  69. }
  70. install_dirs()
  71. {
  72. do_install \
  73. -o root -g root -m 0755 \
  74. -d /opt/feedreader/bin
  75. do_install \
  76. -o root -g root -m 0755 \
  77. -d /opt/feedreader/lib/cgi-bin
  78. do_install \
  79. -o root -g root -m 0755 \
  80. -d /opt/feedreader/var/lib
  81. do_install \
  82. -o root -g www-data -m 0775 \
  83. -d /opt/feedreader/var/lib/feedreader
  84. do_install \
  85. -o root -g root -m 0755 \
  86. -d /opt/feedreader/share/feedreader
  87. }
  88. install_feedsd()
  89. {
  90. do_install \
  91. -o root -g root -m 0755 \
  92. "$target/feedsd" \
  93. /opt/feedreader/bin/
  94. do_install \
  95. -o root -g root -m 0644 \
  96. "$basedir/feedsd/feedsd.service" \
  97. /etc/systemd/system/
  98. do_systemctl enable feedsd.service
  99. }
  100. install_feeds()
  101. {
  102. do_install \
  103. -o root -g root -m 0755 \
  104. "$target/feeds" \
  105. /opt/feedreader/lib/cgi-bin/
  106. do_install \
  107. -o root -g root -m 0644 \
  108. "$basedir/resources/icon.png" \
  109. /opt/feedreader/share/feedreader/
  110. do_install \
  111. -o root -g root -m 0644 \
  112. "$basedir/resources/style.css" \
  113. /opt/feedreader/share/feedreader/
  114. }
  115. install_feedscli()
  116. {
  117. do_install \
  118. -o root -g root -m 0755 \
  119. "$target/feedscli" \
  120. /opt/feedreader/bin/
  121. }
  122. release="release"
  123. while [ $# -ge 1 ]; do
  124. case "$1" in
  125. --debug|-d)
  126. release="debug"
  127. ;;
  128. --release|-r)
  129. release="release"
  130. ;;
  131. *)
  132. die "Invalid option: $1"
  133. ;;
  134. esac
  135. shift
  136. done
  137. target="$basedir/target/$release"
  138. entry_checks
  139. stop_services
  140. install_dirs
  141. install_feedsd
  142. install_feeds
  143. install_feedscli
  144. start_services
  145. # vim: ts=4 sw=4 expandtab