install 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. ynh_clean_setup () {
  13. ### Remove this function if there's nothing to clean before calling the remove script.
  14. true
  15. }
  16. # Exit if an error occurs during the execution of the script
  17. ynh_abort_if_errors
  18. #=================================================
  19. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  20. #=================================================
  21. domain=$YNH_APP_ARG_DOMAIN
  22. path_url="/"
  23. is_public=$YNH_APP_ARG_IS_PUBLIC
  24. app=$YNH_APP_INSTANCE_NAME
  25. #=================================================
  26. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  27. #=================================================
  28. ynh_script_progression --message="Validating installation parameters..." --weight=1
  29. final_path=/var/www/$app
  30. test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
  31. # Register (book) web path
  32. ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
  33. #=================================================
  34. # STORE SETTINGS FROM MANIFEST
  35. #=================================================
  36. ynh_script_progression --message="Storing installation settings..." --weight=1
  37. ynh_app_setting_set --app=$app --key=domain --value=$domain
  38. ynh_app_setting_set --app=$app --key=path --value=$path_url
  39. #=================================================
  40. # STANDARD MODIFICATIONS
  41. #=================================================
  42. # FIND AND OPEN A PORT
  43. #=================================================
  44. ynh_script_progression --message="Finding an available port..." --weight=1
  45. # Find an available port
  46. port=$(ynh_find_port --port=8095)
  47. ynh_app_setting_set --app=$app --key=port --value=$port
  48. #=================================================
  49. # INSTALL DEPENDENCIES
  50. #=================================================
  51. ynh_script_progression --message="Installing dependencies..." --weight=1
  52. # Install Nodejs
  53. ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
  54. # Install Yarn
  55. ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
  56. #=================================================
  57. # CREATE DEDICATED USER
  58. #=================================================
  59. ynh_script_progression --message="Configuring system user..." --weight=1
  60. # Create a system user
  61. ynh_system_user_create --username=$app --home_dir="$final_path"
  62. #=================================================
  63. # DOWNLOAD, CHECK AND UNPACK SOURCE
  64. #=================================================
  65. ynh_script_progression --message="Setting up source files..." --weight=1
  66. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  67. # Download, check integrity, uncompress and patch the source from app.src
  68. ynh_setup_source --dest_dir="$final_path"
  69. chmod 750 "$final_path"
  70. chmod -R o-rwx "$final_path"
  71. chown -R $app:www-data "$final_path"
  72. #=================================================
  73. # NGINX CONFIGURATION
  74. #=================================================
  75. ynh_script_progression --message="Configuring NGINX web server..." --weight=1
  76. # Create a dedicated NGINX config
  77. ynh_add_nginx_config
  78. #=================================================
  79. # INSTALL HOMARR
  80. #=================================================
  81. ynh_script_progression --message="Installing The app..." --weight=10
  82. pushd $final_path
  83. ynh_use_nodejs
  84. ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install
  85. ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_ENV=production yarn build
  86. popd
  87. #=================================================
  88. # SETUP SYSTEMD
  89. #=================================================
  90. ynh_script_progression --message="Configuring a systemd service..." --weight=1
  91. env_path="$PATH"
  92. # Create a dedicated systemd config
  93. ynh_add_systemd_config
  94. #=================================================
  95. # INTEGRATE SERVICE IN YUNOHOST
  96. #=================================================
  97. ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  98. yunohost service add $app --description="Customizable browser's home page" --log="/var/log/$app/$app.log"
  99. #=================================================
  100. # START SYSTEMD SERVICE
  101. #=================================================
  102. ynh_script_progression --message="Starting a systemd service..." --weight=1
  103. # Start a systemd service
  104. ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
  105. #=================================================
  106. # SETUP SSOWAT
  107. #=================================================
  108. ynh_script_progression --message="Configuring permissions..." --weight=1
  109. # Make app public if necessary
  110. if [ $is_public -eq 1 ]
  111. then
  112. # Everyone can access the app.
  113. # The "main" permission is automatically created before the install script.
  114. ynh_permission_update --permission="main" --add="visitors"
  115. fi
  116. #=================================================
  117. # RELOAD NGINX
  118. #=================================================
  119. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  120. ynh_systemd_action --service_name=nginx --action=reload
  121. #=================================================
  122. # END OF SCRIPT
  123. #=================================================
  124. ynh_script_progression --message="Installation of $app completed" --last