install 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. # Exit if an error occurs during the execution of the script
  13. ynh_abort_if_errors
  14. #=================================================
  15. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  16. #=================================================
  17. domain=$YNH_APP_ARG_DOMAIN
  18. path_url=$YNH_APP_ARG_PATH
  19. admin=$YNH_APP_ARG_ADMIN
  20. is_public=$YNH_APP_ARG_IS_PUBLIC
  21. language=$YNH_APP_ARG_LANGUAGE
  22. # This is a multi-instance app, meaning it can be installed several times independently
  23. # The id of the app as stated in the manifest is available as $YNH_APP_ID
  24. # The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
  25. # The app instance name is available as $YNH_APP_INSTANCE_NAME
  26. # - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
  27. # - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
  28. # - ynhexample__{N} for the subsequent installations, with N=3,4, ...
  29. # The app instance name is probably what you are interested the most, since this is
  30. # guaranteed to be unique. This is a good unique identifier to define installation path,
  31. # db names, ...
  32. app=$YNH_APP_INSTANCE_NAME
  33. #=================================================
  34. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  35. #=================================================
  36. final_path=/var/www/$app
  37. test ! -e "$final_path" || ynh_die "This path already contains a folder"
  38. # Normalize the url path syntax
  39. path_url=$(ynh_normalize_url_path $path_url)
  40. # Check web path availability
  41. ynh_webpath_available $domain $path_url
  42. # Register (book) web path
  43. ynh_webpath_register $app $domain $path_url
  44. #=================================================
  45. # STORE SETTINGS FROM MANIFEST
  46. #=================================================
  47. ynh_app_setting_set $app domain $domain
  48. ynh_app_setting_set $app path $path_url
  49. ynh_app_setting_set $app admin $admin
  50. ynh_app_setting_set $app is_public $is_public
  51. ynh_app_setting_set $app language $language
  52. #=================================================
  53. # STANDARD MODIFICATIONS
  54. #=================================================
  55. # FIND AND OPEN A PORT
  56. #=================================================
  57. # Find a free port
  58. port=$(ynh_find_port 8095)
  59. # Open this port
  60. yunohost firewall allow --no-upnp TCP $port 2>&1
  61. ynh_app_setting_set $app port $port
  62. #=================================================
  63. # INSTALL DEPENDENCIES
  64. #=================================================
  65. ynh_install_app_dependencies deb1 deb2
  66. #=================================================
  67. # CREATE A MYSQL DATABASE
  68. #=================================================
  69. # If your app uses a MySQL database, you can use these lines to bootstrap
  70. # a database, an associated user and save the password in app settings
  71. db_name=$(ynh_sanitize_dbid $app)
  72. ynh_app_setting_set $app db_name $db_name
  73. ynh_mysql_setup_db $db_name $db_name
  74. #=================================================
  75. # DOWNLOAD, CHECK AND UNPACK SOURCE
  76. #=================================================
  77. ynh_app_setting_set $app final_path $final_path
  78. # Download, check integrity, uncompress and patch the source from app.src
  79. ynh_setup_source "$final_path"
  80. #=================================================
  81. # NGINX CONFIGURATION
  82. #=================================================
  83. # Create a dedicated nginx config
  84. ynh_add_nginx_config
  85. if [ "$path_url" != "/" ]
  86. then
  87. ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
  88. fi
  89. ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
  90. #=================================================
  91. # CREATE DEDICATED USER
  92. #=================================================
  93. # Create a system user
  94. ynh_system_user_create $app
  95. #=================================================
  96. # PHP-FPM CONFIGURATION
  97. #=================================================
  98. # Create a dedicated php-fpm config
  99. ynh_add_fpm_config
  100. #=================================================
  101. # SPECIFIC SETUP
  102. #=================================================
  103. # ...
  104. #=================================================
  105. #=================================================
  106. # SETUP SYSTEMD
  107. #=================================================
  108. # Create a dedicated systemd config
  109. ynh_add_systemd_config
  110. #=================================================
  111. # SETUP APPLICATION WITH CURL
  112. #=================================================
  113. # Set right permissions for curl install
  114. chown -R $app: $final_path
  115. # Set the app as temporarily public for curl call
  116. ynh_app_setting_set $app skipped_uris "/"
  117. # Reload SSOwat config
  118. yunohost app ssowatconf
  119. # Reload Nginx
  120. systemctl reload nginx
  121. # Installation with curl
  122. ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
  123. #=================================================
  124. # MODIFY A CONFIG FILE
  125. #=================================================
  126. ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE"
  127. #=================================================
  128. # STORE THE CHECKSUM OF THE CONFIG FILE
  129. #=================================================
  130. # Calculate and store the config file checksum into the app settings
  131. ynh_store_file_checksum "$final_path/CONFIG_FILE"
  132. #=================================================
  133. # GENERIC FINALIZATION
  134. #=================================================
  135. # SECURE FILES AND DIRECTORIES
  136. #=================================================
  137. # Set permissions to app files
  138. chown -R root: $final_path
  139. #=================================================
  140. # SETUP LOGROTATE
  141. #=================================================
  142. # Use logrotate to manage application logfile(s)
  143. ynh_use_logrotate
  144. #=================================================
  145. # ADVERTISE SERVICE IN ADMIN PANEL
  146. #=================================================
  147. yunohost service add NAME_INIT.D --log "/var/log/FILE.log"
  148. #=================================================
  149. # SETUP SSOWAT
  150. #=================================================
  151. if [ $is_public -eq 0 ]
  152. then # Remove the public access
  153. ynh_app_setting_delete $app skipped_uris
  154. fi
  155. # Make app public if necessary
  156. if [ $is_public -eq 1 ]
  157. then
  158. # unprotected_uris allows SSO credentials to be passed anyway.
  159. ynh_app_setting_set $app unprotected_uris "/"
  160. fi
  161. #=================================================
  162. # RELOAD NGINX
  163. #=================================================
  164. systemctl reload nginx