install 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. source _common.sh
  6. source /usr/share/yunohost/helpers
  7. ### Install parameters are automatically saved as settings
  8. ###
  9. ### Settings are automatically loaded as bash variables
  10. ### in every app script context, therefore typically these will exist:
  11. ### - $domain
  12. ### - $path
  13. ### - $language
  14. ### ... etc
  15. ###
  16. ### Resources defined in the manifest are provisioned prior to this script
  17. ### and corresponding settings are also available, such as:
  18. ### - $install_dir
  19. ### - $port
  20. ### - $db_name
  21. ### ...
  22. ###
  23. ### $app is the app id (i.e. 'example' for first install,
  24. ### or 'example__2', '__3'... for multi-instance installs)
  25. #=================================================
  26. # INITIALIZE AND STORE SETTINGS
  27. #=================================================
  28. # If you need to, you can define custom settings
  29. # (or remove this section entirely if not relevant for you)
  30. foo="bar"
  31. ynh_app_setting_set --key=foo --value=$foo
  32. ynh_app_setting_set --key=php_upload_max_filesize --value=50M
  33. ynh_app_setting_set --key=php_post_max_size --value=50M
  34. #=================================================
  35. # DOWNLOAD, CHECK AND UNPACK SOURCE
  36. #=================================================
  37. ynh_script_progression "Setting up source files..."
  38. ### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
  39. ### downloaded from an upstream source, like a git repository.
  40. ### `ynh_setup_source` use the file manifest.toml
  41. # Download, check integrity, uncompress and patch the source from manifest.toml
  42. ynh_setup_source --dest_dir="$install_dir"
  43. ### $install_dir will automatically be initialized with some decent
  44. ### permission by default... however, you may need to recursively reapply
  45. ### ownership to all files such as after the ynh_setup_source step
  46. chown -R "$app:www-data" "$install_dir"
  47. #=================================================
  48. # APP INITIAL CONFIGURATION
  49. #=================================================
  50. ynh_script_progression "Adding $app's configuration files..."
  51. ### You can add specific configuration files.
  52. ###
  53. ### Typically, put your template conf file in ../conf/your_config_file
  54. ### The template may contain strings such as __FOO__ or __FOO_BAR__,
  55. ### which will automatically be replaced by the values of $foo and $foo_bar
  56. ###
  57. ### ynh_config_add will also keep track of the config file's checksum,
  58. ### which later during upgrade may allow to automatically backup the config file
  59. ### if it's found that the file was manually modified
  60. ###
  61. ### Check the documentation of `ynh_config_add` for more info.
  62. ynh_config_add --template="some_config_file" --destination="$install_dir/some_config_file"
  63. # FIXME: this should be handled by the core in the future
  64. ### You may need to use chmod 600 instead of 400,
  65. ### for example if the app is expected to be able to modify its own config
  66. chmod 400 "$install_dir/some_config_file"
  67. chown "$app:$app" "$install_dir/some_config_file"
  68. ### For more complex cases where you want to replace stuff using regexes,
  69. ### you shoud rely on ynh_replace (which is basically a wrapper for sed)
  70. ### When doing so, you also need to manually call ynh_store_file_checksum
  71. ###
  72. ### ynh_replace --match="match_string" --replace="replace_string" --file="$install_dir/some_config_file"
  73. ### ynh_store_file_checksum "$install_dir/some_config_file"
  74. #=================================================
  75. # SYSTEM CONFIGURATION
  76. #=================================================
  77. ynh_script_progression "Adding system configurations related to $app..."
  78. ### `ynh_config_add_phpfpm` is used to set up a PHP config.
  79. ### You can remove it if your app doesn't use PHP.
  80. ### `ynh_config_add_phpfpm` will use the files conf/extra_php-fpm.conf
  81. ### If you're not using these lines:
  82. ### - You can remove these files in conf/.
  83. ### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script
  84. ### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script
  85. ### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script
  86. ### with the reload at the end of the script.
  87. ### - And the section "PHP-FPM CONFIGURATION" in the upgrade script
  88. # Create a PHP-FPM config (with conf/extra_php-fpm.conf being appended to it)
  89. ynh_config_add_phpfpm
  90. # Create a dedicated NGINX config using the conf/nginx.conf template
  91. ynh_config_add_nginx
  92. ### `ynh_config_add_systemd` is used to configure a systemd script for an app.
  93. ### It can be used for apps that use sysvinit (with adaptation) or systemd.
  94. ### Have a look at the app to be sure this app needs a systemd script.
  95. ### `ynh_config_add_systemd` will use the file conf/systemd.service
  96. ### If you're not using these lines:
  97. ### - You can remove those files in conf/.
  98. ### - Remove the section "BACKUP SYSTEMD" in the backup script
  99. ### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script
  100. ### - As well as the section "RESTORE SYSTEMD" in the restore script
  101. ### - And the section "SETUP SYSTEMD" in the upgrade script
  102. # Create a dedicated systemd config
  103. ynh_config_add_systemd
  104. ### `yunohost service add` integrates a service in YunoHost. It then gets
  105. ### displayed in the admin interface and through the others `yunohost service` commands.
  106. ### (N.B.: this line only makes sense if the app adds a service to the system!)
  107. ### If you're not using these lines:
  108. ### - You can remove these files in conf/.
  109. ### - Remove the section "REMOVE SERVICE INTEGRATION IN YUNOHOST" in the remove script
  110. ### - As well as the section "INTEGRATE SERVICE IN YUNOHOST" in the restore script
  111. ### - And the section "INTEGRATE SERVICE IN YUNOHOST" in the upgrade script
  112. ### Additional options starting with 3.8:
  113. ###
  114. ### --needs_exposed_ports "$port" a list of ports that needs to be publicly exposed
  115. ### which will then be checked by YunoHost's diagnosis system
  116. ### (N.B. DO NOT USE THIS if the port is only internal!!!)
  117. ###
  118. ### --test_status "some command" a custom command to check the status of the service
  119. ### (only relevant if 'systemctl status' doesn't do a good job)
  120. ###
  121. ### --test_conf "some command" some command similar to "nginx -t" that validates the conf of the service
  122. ###
  123. ### Re-calling 'yunohost service add' during the upgrade script is the right way
  124. ### to proceed if you later realize that you need to enable some flags that
  125. ### weren't enabled on old installs (be careful it'll override the existing
  126. ### service though so you should re-provide all relevant flags when doing so)
  127. yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log"
  128. ### `ynh_config_add_logrotate` is used to configure a logrotate configuration for the logs of this app.
  129. ### Use this helper only if there is effectively a log file for this app.
  130. ### If you're not using this helper:
  131. ### - Remove the section "BACKUP LOGROTATE" in the backup script
  132. ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
  133. ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
  134. ### - And the section "SETUP LOGROTATE" in the upgrade script
  135. # Use logrotate to manage application logfile(s)
  136. ynh_config_add_logrotate
  137. # Create a dedicated Fail2Ban config
  138. ynh_config_add_fail2ban --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
  139. #=================================================
  140. # SETUP APPLICATION WITH CURL
  141. #=================================================
  142. ### Use these lines only if the app installation needs to be finalized through
  143. ### web forms. We generally don't want to ask the final user,
  144. ### so we're going to use curl to automatically fill the fields and submit the
  145. ### forms.
  146. # Installation with curl
  147. ynh_script_progression "Finalizing installation..."
  148. ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
  149. #=================================================
  150. # START SYSTEMD SERVICE
  151. #=================================================
  152. ynh_script_progression "Starting $app's systemd service..."
  153. ### `ynh_systemctl` is used to start a systemd service for an app.
  154. ### Only needed if you have configure a systemd service
  155. ### If you're not using these lines:
  156. ### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script
  157. ### - As well as the section "START SYSTEMD SERVICE" in the restore script
  158. ### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script
  159. ### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script
  160. # Start a systemd service
  161. ynh_systemctl --service="$app" --action="start"
  162. #=================================================
  163. # END OF SCRIPT
  164. #=================================================
  165. ynh_script_progression "Installation of $app completed"