install 6.2 KB

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