install 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. final_path=/var/www/$app
  32. sudo mkdir -p $final_path
  33. sudo cp -a ../sources/. $final_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:root $final_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. sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
  52. sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
  53. # If a dedicated php-fpm process is used:
  54. # Don't forget to modify ../conf/nginx.conf accordingly or your app will not work!
  55. #
  56. # sudo sed -i "s@YNH_WWW_APP@$app@g" ../conf/nginx.conf
  57. sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
  58. # If a dedicated php-fpm process is used:
  59. # Don't forget to modify ../conf/php-fpm.conf accordingly or your app will not work!
  60. #
  61. # # Modify PHP-FPM pool configuration and copy it to the pool directory
  62. # sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
  63. # sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/php-fpm.conf
  64. # finalphpconf=/etc/php5/fpm/pool.d/$app.conf
  65. # sudo cp ../conf/php-fpm.conf $finalphpconf
  66. # sudo chown root: $finalphpconf
  67. # sudo chmod 644 $finalphpconf
  68. # If app is public, add url to SSOWat conf as skipped_uris
  69. if [[ $is_public -eq 1 ]];
  70. then
  71. # unprotected_uris allows SSO credentials to be passed anyway.
  72. ynh_app_setting_set "$app" unprotected_uris "/"
  73. fi
  74. # If a dedicated php-fpm process is used:
  75. #
  76. # sudo service php5-fpm reload
  77. # Restart services
  78. sudo service nginx reload