install 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. source /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. ### MySQL (can be removed if not used) ###
  38. # If your app use a MySQL database you can use these lines to bootstrap
  39. # a database, an associated user and save the password in app settings.
  40. #
  41. # # Generate MySQL password and create database
  42. # dbuser=$app
  43. # dbname=$app
  44. # dbpass=$(ynh_string_random 12)
  45. # ynh_app_setting_set "$app" mysqlpwd "$dbpass"
  46. # ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
  47. #
  48. # # Load initial SQL into the new database
  49. # ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \
  50. # < "../sources/sql/mysql.init.sql"
  51. ### MySQL end ###
  52. # Modify Nginx configuration file and copy it to Nginx conf directory
  53. nginx_conf=../conf/nginx.conf
  54. sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
  55. sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf
  56. # If a dedicated php-fpm process is used:
  57. # Don't forget to modify ../conf/nginx.conf accordingly or your app will not work!
  58. # sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf
  59. sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
  60. ### PHP (can be removed if not used) ###
  61. # If a dedicated php-fpm process is used:
  62. # Don't forget to modify ../conf/php-fpm.conf accordingly or your app will not work!
  63. #
  64. # # Modify PHP-FPM pool configuration and copy it to the pool directory
  65. # sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
  66. # sed -i "s@YNH_WWW_ALIAS@$src_path/@g" ../conf/php-fpm.conf
  67. # finalphpconf=/etc/php5/fpm/pool.d/$app.conf
  68. # sudo cp ../conf/php-fpm.conf $finalphpconf
  69. # sudo chown root: $finalphpconf
  70. # sudo chmod 644 $finalphpconf
  71. # sudo service php5-fpm reload
  72. ### PHP end ###
  73. # If app is public, add url to SSOWat conf as skipped_uris
  74. if [[ $is_public -eq 1 ]]; then
  75. # unprotected_uris allows SSO credentials to be passed anyway.
  76. ynh_app_setting_set "$app" unprotected_uris "/"
  77. fi
  78. # Reload services
  79. sudo service nginx reload