_common.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. #=================================================
  3. # COMMON VARIABLES
  4. #=================================================
  5. ## new filenames starting 0.00~ynh5
  6. # make a filename/service name from domain/path
  7. if [[ "$path" == /* ]]; then
  8. url_path="${path:1}"
  9. fi
  10. if [[ "__${url_path}__" == '____' ]]; then
  11. flohmarkt_filename="$domain"
  12. else
  13. flohmarkt_filename="$domain-${url_path}"
  14. fi
  15. # this filename is used for logfile name and systemd.service name
  16. # and for symlinking install_dir and data_dir
  17. flohmarkt_filename="${YNH_APP_ID}_${flohmarkt_filename//[^A-Za-z0-9._-]/_}"
  18. # directory flohmarkts software is installed to
  19. # contains ./venv and ./src as sub-directories
  20. flohmarkt_install="$install_dir"
  21. flohmarkt_sym_install="$( dirname $flohmarkt_install )/$flohmarkt_filename"
  22. flohmarkt_venv_dir="${flohmarkt_install}/venv"
  23. flohmarkt_app_dir="${flohmarkt_install}/app"
  24. # directory containing logfiles
  25. flohmarkt_log_dir="/var/log/${YNH_APP_ID}/${flohmarkt_filename}"
  26. # filename for logfiles - ¡ojo! if not ends with .log will be interpreted
  27. # as a directory by ynh_use_logrotate
  28. # https://github.com/YunoHost/issues/issues/2383
  29. flohmarkt_logfile="${flohmarkt_log_dir}/${app}.log"
  30. # flohmarkt data_dir
  31. flohmarkt_data_dir="$data_dir"
  32. flohmarkt_sym_data_dir="$( dirname $flohmarkt_data_dir )/$flohmarkt_filename"
  33. ## old filenames before 0.00~ynh5 - for reference and needed to
  34. # migrate (see below)
  35. flohmarkt_old_install="/opt/flohmarkt"
  36. flohmarkt_old_venv_dir="${flohmarkt_old_install}/venv"
  37. flohmarkt_old_app_dir="${flohmarkt_old_install}/flohmarkt"
  38. flohmarkt_old_log_dir="/var/log/flohmarkt/"
  39. flohmarkt_old_logfile="flohmarkt"
  40. flohmarkt_old_service="flohmarkt"
  41. #=================================================
  42. # PERSONAL HELPERS
  43. #=================================================
  44. # create venv
  45. flohmarkt_ynh_create_venv() {
  46. python3 -m venv --without-pip "$flohmarkt_venv_dir"
  47. }
  48. # install requirements.txt in venv
  49. flohmarkt_ynh_venv_requirements() {
  50. (
  51. set +o nounset
  52. source "$flohmarkt_venv_dir/bin/activate"
  53. set -o nounset
  54. set -x
  55. $flohmarkt_venv_dir/bin/python3 -m ensurepip
  56. $flohmarkt_venv_dir/bin/pip3 install -r "$flohmarkt_app_dir/requirements.txt"
  57. )
  58. }
  59. # move files and directories to their new places
  60. flohmarkt_ynh_upgrade_path_ynh5() {
  61. # flohmarkt and couchdb are already stopped in upgrade script
  62. # move app_dir into new 'app' folder
  63. mv "$flohmarkt_install/flohmarkt" "$flohmarkt_app_dir"
  64. # yunohost seems to move the venv dir automatically, but this
  65. # doesn't work, because the paths inside the venv are not adjusted
  66. # delete the old, not working venv and create a new one:
  67. ynh_secure_remove --file="$flohmarkt_venv_dir"
  68. flohmarkt_ynh_create_venv
  69. flohmarkt_ynh_venv_requirements
  70. # remove old $install_dir
  71. ynh_secure_remove --file="$flohmarkt_old_install"
  72. # move logfile directory
  73. mkdir -p "$flohmarkt_log_dir"
  74. mv ${flohmarkt_old_log_dir}/${flohmarkt_old_logfile}.* "$flohmarkt_log_dir"
  75. # update settings for above
  76. # @@ automatically done? maybe?
  77. # remove systemd.service - will be generated newly by upgrade
  78. # ynh_remove_systemd_config --service="$flohmarkt_old_service"
  79. ynh_systemd_action --action=stop --service_name="$flohmarkt_old_service"
  80. ynh_systemd_action --action=disable --service_name="$flohmarkt_old_service"
  81. ynh_secure_remove --file="/etc/systemd/system/multi-user.target.wants/flohmarkt.service"
  82. ynh_secure_remove --file="/etc/systemd/system/flohmarkt.service"
  83. # funktioniert nicht? issue?
  84. #ynh_systemd_action --action=daemon-reload
  85. # DEBUG + systemctl daemon-reload flohmarkt
  86. # WARNING Too many arguments.
  87. systemctl daemon-reload
  88. # unit flohmarkt is automatically appended and therefor this fails:
  89. #ynh_systemd_action --action=reset-failed
  90. systemctl reset-failed
  91. # create symlinks
  92. ln -s "$flohmarkt_install" "$flohmarkt_sym_install"
  93. ln -s "$flohmarkt_data_dir" "$flohmarkt_sym_data_dir"
  94. }
  95. #=================================================
  96. # EXPERIMENTAL HELPERS
  97. #=================================================
  98. #=================================================
  99. # FUTURE OFFICIAL HELPERS
  100. #=================================================