install 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/bash
  2. #=================================================
  3. # Exit on command errors and treat unset variables as an error
  4. #=================================================
  5. set -eu
  6. #=================================================
  7. # GENERIC STARTING
  8. #=================================================
  9. # IMPORT GENERIC HELPERS
  10. #=================================================
  11. source .fonctions
  12. source /usr/share/yunohost/helpers
  13. #=================================================
  14. # MANAGE FAILURE OF THE SCRIPT
  15. #=================================================
  16. ynh_check_error # Active trap pour arrêter le script si une erreur est détectée.
  17. #=================================================
  18. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  19. #=================================================
  20. domain=$YNH_APP_ARG_DOMAIN
  21. path=$YNH_APP_ARG_PATH
  22. admin_prestashop=$YNH_APP_ARG_ADMIN
  23. language=$YNH_APP_ARG_LANGUAGE
  24. is_public=$YNH_APP_ARG_IS_PUBLIC
  25. db_pwd=$YNH_APP_ARG_PASSWD
  26. email=$YNH_APP_ARG_EMAIL
  27. app=$YNH_APP_INSTANCE_NAME
  28. #=================================================
  29. # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
  30. #=================================================
  31. CHECK_VAR "$app" "app name not set"
  32. CHECK_USER "$admin_prestashop"
  33. CHECK_PATH
  34. CHECK_DOMAINPATH
  35. CHECK_FINALPATH
  36. #=================================================
  37. # STORE SETTINGS FROM MANIFEST
  38. #=================================================
  39. ynh_app_setting_set $app domain $domain
  40. ynh_app_setting_set $app path $path
  41. ynh_app_setting_set $app admin $admin_prestashop
  42. ynh_app_setting_set $app is_public $is_public
  43. ynh_app_setting_set $app language $language
  44. ynh_app_setting_set $app db_pwd $db_pwd
  45. ynh_app_setting_set $app email $email
  46. #=================================================
  47. # Check password strength
  48. #=================================================
  49. [[ ${#db_pwd} -gt 5 ]] || ynh_die \
  50. "The password is too weak, it must be longer than 5 characters"
  51. #=================================================
  52. # CREATE A SQL BDD
  53. #=================================================
  54. db_name=$app
  55. db_user=$app
  56. db_pwd=$(ynh_string_random)
  57. ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
  58. ynh_app_setting_set "$app" db_name "$db_name"
  59. ynh_app_setting_set "$app" db_pwd "$db_pwd"
  60. ynh_app_setting_set "$app" db_user "$db_user"
  61. #=================================================
  62. # Crée le repertoire de destination et check les permissions
  63. #=================================================
  64. sudo mkdir "$final_path"
  65. sudo chown -R www-data: $final_path
  66. #=================================================
  67. # Download, check and unpack source
  68. #=================================================
  69. ynh_app_setting_set $app final_path $final_path
  70. SETUP_SOURCE "prestashop_1.7.0.5.zip" # Télécharge la source, décompresse et copie dans $final_path
  71. #=================================================
  72. # Installation de Prestashop
  73. #=================================================
  74. pushd $final_path/install/
  75. sudo php index_cli.php install \
  76. --db_server=localhost \
  77. --db_user=$db_user \
  78. --db_password=$db_pass \
  79. --db_name=$db_name \
  80. --db_driver=amysqli \
  81. --db_port=3306 \
  82. --lastname=$db_user \
  83. --password=$db_pwd \
  84. --email=$email \
  85. --domain=$domain \
  86. --prefix=_ps_
  87. popd
  88. #=================================================
  89. # Set /etc/hosts
  90. #=================================================
  91. echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
  92. #=================================================
  93. # NGINX CONFIGURATION
  94. #=================================================
  95. sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
  96. sudo sed -i "s@__PATHTOCHANGE__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
  97. sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf
  98. sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf
  99. #=================================================
  100. # SETUP SSOWAT
  101. #=================================================
  102. ynh_app_setting_set "$app" is_public "$is_public"
  103. if [ "$is_public" = "Yes" ];
  104. then
  105. ynh_app_setting_set "$app" unprotected_uris "/"
  106. fi
  107. #=================================================
  108. # PHP-FPM CONFIGURATION
  109. #=================================================
  110. POOL_FPM
  111. #=================================================
  112. # Régénère la configuration de SSOwat
  113. #=================================================
  114. sudo yunohost app ssowatconf
  115. #=================================================
  116. # Reload Nginx and regenerate SSOwat conf
  117. #=================================================
  118. sudo service php5-fpm restart
  119. sudo service nginx reload
  120. #=================================================
  121. # Nettoyer hosts
  122. #=================================================
  123. sudo sed -i '/#PRESTASHOP/d' /etc/hosts