install 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. # Exit on command errors and treat unset variables as an error
  3. set -eu
  4. # This is a multi-instance app, meaning it can be installed several times independently
  5. # The id of the app as stated in the manifest is available as $YNH_APP_ID
  6. # The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
  7. # The app instance name is available as $YNH_APP_INSTANCE_NAME
  8. # - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
  9. # - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
  10. # - ynhexample__{N} for the subsequent installations, with N=3,4, ...
  11. # The app instance name is probably what you are interested the most, since this is
  12. # guaranteed to be unique. This is a good unique identifier to define installation path,
  13. # db names, ...
  14. app=$YNH_APP_INSTANCE_NAME
  15. # Retrieve arguments
  16. domain=$YNH_APP_ARG_DOMAIN
  17. path=$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. # Source YunoHost helpers
  22. . /usr/share/yunohost/helpers
  23. # Save app settings
  24. ynh_app_setting_set "$app" admin "$admin"
  25. ynh_app_setting_set "$app" is_public "$is_public"
  26. ynh_app_setting_set "$app" language "$language"
  27. # Check domain/path availability
  28. sudo yunohost app checkurl "${domain}${path}" -a "$app" \
  29. || ynh_die "Path not available: ${domain}${path}"
  30. # Copy source files
  31. src_path=/var/www/$app
  32. sudo mkdir -p $src_path
  33. sudo cp -a ../sources/. $src_path
  34. # Set permissions to app files
  35. # you may need to make some file and/or directory writeable by www-data (nginx user)
  36. sudo chown -R root: $src_path
  37. # If your app use a MySQL database you can use these lines to bootstrap
  38. # a database, an associated user and save the password in app settings.
  39. #
  40. # # Generate MySQL password and create database
  41. # dbuser=$app
  42. # dbname=$app
  43. # dbpass=$(ynh_string_random 12)
  44. # ynh_app_setting_set "$app" mysqlpwd "$dbpass"
  45. # ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
  46. #
  47. # # Load initial SQL into the new database
  48. # ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \
  49. # < "../sources/sql/mysql.init.sql"
  50. # Modify Nginx configuration file and copy it to Nginx conf directory
  51. nginx_conf=../conf/nginx.conf
  52. sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
  53. sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf
  54. # If a dedicated php-fpm process is used:
  55. # Don't forget to modify ../conf/nginx.conf accordingly or your app will not work!
  56. #
  57. # sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf
  58. sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
  59. # If a dedicated php-fpm process is used:
  60. # Don't forget to modify ../conf/php-fpm.conf accordingly or your app will not work!
  61. #
  62. # # Modify PHP-FPM pool configuration and copy it to the pool directory
  63. # sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
  64. # sed -i "s@YNH_WWW_ALIAS@$src_path/@g" ../conf/php-fpm.conf
  65. # finalphpconf=/etc/php5/fpm/pool.d/$app.conf
  66. # sudo cp ../conf/php-fpm.conf $finalphpconf
  67. # sudo chown root: $finalphpconf
  68. # sudo chmod 644 $finalphpconf
  69. # If app is public, add url to SSOWat conf as skipped_uris
  70. if [[ $is_public -eq 1 ]]; then
  71. # unprotected_uris allows SSO credentials to be passed anyway.
  72. ynh_app_setting_set "$app" unprotected_uris "/"
  73. fi
  74. # Reload services
  75. sudo service nginx reload
  76. # If a dedicated php-fpm process is used:
  77. # sudo service php5-fpm reload