install 6.2 KB

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