install 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. password=$YNH_APP_ARG_PASSWORD
  22. email=$(ynh_user_get_info --username=$admin --key=mail)
  23. app=$YNH_APP_INSTANCE_NAME
  24. #=================================================
  25. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  26. #=================================================
  27. ynh_script_progression --message="Validating installation parameters..." --weight=1
  28. final_path=/var/www/$app
  29. test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
  30. # Register (book) web path
  31. ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
  32. #=================================================
  33. # STORE SETTINGS FROM MANIFEST
  34. #=================================================
  35. ynh_script_progression --message="Storing installation settings..." --weight=1
  36. ynh_app_setting_set --app=$app --key=domain --value=$domain
  37. ynh_app_setting_set --app=$app --key=path --value=$path_url
  38. ynh_app_setting_set --app=$app --key=admin --value=$admin
  39. ynh_app_setting_set --app=$app --key=password --value=$password
  40. ynh_app_setting_set --app=$app --key=email --value=$email
  41. #=================================================
  42. # CREATE DEDICATED USER
  43. #=================================================
  44. ynh_script_progression --message="Configuring system user..." --weight=1
  45. # Create a system user
  46. ynh_system_user_create --username=$app --home_dir="$final_path"
  47. #=================================================
  48. # CREATE A MYSQL DATABASE
  49. #=================================================
  50. ynh_script_progression --message="Creating a MySQL database..." --weight=1
  51. db_name=$(ynh_sanitize_dbid --db_name=$app)
  52. db_user=$db_name
  53. ynh_app_setting_set --app=$app --key=db_name --value=$db_name
  54. ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
  55. #=================================================
  56. # DOWNLOAD, CHECK AND UNPACK SOURCE
  57. #=================================================
  58. ynh_script_progression --message="Setting up source files..." --weight=3
  59. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  60. # Download, check integrity, uncompress and patch the source from app.src
  61. ynh_setup_source --dest_dir="$final_path"
  62. chmod 750 "$final_path"
  63. chmod -R o-rwx "$final_path"
  64. chown -R $app:www-data "$final_path"
  65. #=================================================
  66. # NGINX CONFIGURATION
  67. #=================================================
  68. ynh_script_progression --message="Configuring NGINX web server..." --weight=1
  69. # Create a dedicated NGINX config
  70. ynh_add_nginx_config
  71. #=================================================
  72. # PHP-FPM CONFIGURATION
  73. #=================================================
  74. ynh_script_progression --message="Configuring PHP-FPM..." --weight=3
  75. # Create a dedicated PHP-FPM config
  76. ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies"
  77. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  78. #=================================================
  79. # SETUP SSOWAT
  80. #=================================================
  81. ynh_script_progression --message="Configuring permissions..." --weight=1
  82. # Make app public if necessary
  83. if [ $is_public -eq 1 ]
  84. then
  85. ynh_permission_update --permission="main" --add="visitors"
  86. fi
  87. #=================================================
  88. # RELOAD NGINX
  89. #=================================================
  90. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  91. ynh_systemd_action --service_name=nginx --action=reload
  92. #=================================================
  93. # END OF SCRIPT
  94. #=================================================
  95. ynh_script_progression --message="Installation of $app completed" --last