install 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. if [ "$path_url" != "/" ]
  85. then
  86. ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
  87. fi
  88. ynh_add_nginx_config
  89. #=================================================
  90. # CREATE DEDICATED USER
  91. #=================================================
  92. # Create a system user
  93. ynh_system_user_create $app
  94. #=================================================
  95. # PHP-FPM CONFIGURATION
  96. #=================================================
  97. # Create a dedicated php-fpm config
  98. ynh_add_fpm_config
  99. #=================================================
  100. # SPECIFIC SETUP
  101. #=================================================
  102. # ...
  103. #=================================================
  104. #=================================================
  105. # SETUP SYSTEMD
  106. #=================================================
  107. # Create a dedicated systemd config
  108. ynh_systemd_config
  109. #=================================================
  110. # SETUP APPLICATION WITH CURL
  111. #=================================================
  112. # Set right permissions for curl install
  113. chown -R $app: $final_path
  114. # Set the app as temporarily public for curl call
  115. ynh_app_setting_set $app skipped_uris "/"
  116. # Reload SSOwat config
  117. yunohost app ssowatconf
  118. # Reload Nginx
  119. systemctl reload nginx
  120. # Installation with curl
  121. ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
  122. #=================================================
  123. # MODIFY A CONFIG FILE
  124. #=================================================
  125. ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE"
  126. #=================================================
  127. # STORE THE CHECKSUM OF THE CONFIG FILE
  128. #=================================================
  129. # Calculate and store the config file checksum into the app settings
  130. ynh_store_file_checksum "$final_path/CONFIG_FILE"
  131. #=================================================
  132. # GENERIC FINALIZATION
  133. #=================================================
  134. # SECURE FILES AND DIRECTORIES
  135. #=================================================
  136. # Set permissions to app files
  137. chown -R root: $final_path
  138. #=================================================
  139. # SETUP LOGROTATE
  140. #=================================================
  141. # Use logrotate to manage application logfile(s)
  142. ynh_use_logrotate
  143. #=================================================
  144. # ADVERTISE SERVICE IN ADMIN PANEL
  145. #=================================================
  146. yunohost service add NAME_INIT.D --log "/var/log/FILE.log"
  147. #=================================================
  148. # SETUP SSOWAT
  149. #=================================================
  150. if [ $is_public -eq 0 ]
  151. then # Remove the public access
  152. ynh_app_setting_delete $app skipped_uris
  153. fi
  154. # Make app public if necessary
  155. if [ $is_public -eq 1 ]
  156. then
  157. # unprotected_uris allows SSO credentials to be passed anyway.
  158. ynh_app_setting_set $app unprotected_uris "/"
  159. fi
  160. #=================================================
  161. # RELOAD NGINX
  162. #=================================================
  163. systemctl reload nginx