install 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. TRAP_ON # Active trap to stop the script if an error is detected.
  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. pass=$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" # Vérifie la validité de l'user admin
  33. path=$(ynh_normalize_url_path $path) # Vérifie et corrige la syntaxe du path.
  34. CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
  35. CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
  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 pass $pass
  45. ynh_app_setting_set $app email $email
  46. #=================================================
  47. # Check password strength
  48. #=================================================
  49. [[ ${#pass} -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. GENERATE_DB $app # Create a database and a dedicated user in the app name
  55. #=================================================
  56. # NGINX CONFIGURATION
  57. #=================================================
  58. final_path=/var/www/$app
  59. sudo sed -i "s@__PATHTOCHANGE__@$path@g" ../conf/nginx.conf
  60. sudo sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf
  61. sudo sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/nginx.conf
  62. sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
  63. #=================================================
  64. # PHP-FPM CONFIGURATION
  65. #=================================================
  66. POOL_FPM
  67. #=================================================
  68. # Crée le repertoire de destination
  69. #=================================================
  70. sudo mkdir "$final_path"
  71. #=================================================
  72. # DOWNLOAD, CHECK AND UNPACK SOURCE
  73. #=================================================
  74. final_path=/var/www/$app
  75. ynh_app_setting_set $app final_path $final_path
  76. SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
  77. #=================================================
  78. # Installation de Prestashop
  79. #=================================================
  80. pushd $final_path/install/
  81. sudo php index_cli.php \
  82. --db_server=localhost \
  83. --db_user=$db_user \
  84. --db_password=$db_pwd \
  85. --db_name=$app \
  86. --db_driver=amysqli \
  87. --db_port=3306 \
  88. --language=${language:0:2} \
  89. --lastname=$admin_prestashop \
  90. --firstname=$admin_prestashop \
  91. --password=$pass \
  92. --email=$email \
  93. --domain=$domain \
  94. --base_uri=$path \
  95. --prefix=_ps_
  96. popd
  97. sudo rm -fr $final_path/install
  98. #=================================================
  99. # check les permissions
  100. #=================================================
  101. sudo chown -R www-data: $final_path
  102. #=================================================
  103. # active ssl
  104. #=================================================
  105. mysql -u $db_user -p$db_pwd $db_user -e "UPDATE _ps_configuration SET value=1 WHERE name='PS_SSL_ENABLED';"
  106. mysql -u $db_user -p$db_pwd $db_user -e "INSERT INTO _ps_configuration (id_configuration, id_shop_group, id_shop, name, value, date_add, date_upd) VALUES (NULL, NULL, NULL, 'PS_SSL_ENABLED_EVERYWHERE', '1', NOW(), NOW());"
  107. #=================================================
  108. # Set /etc/hosts
  109. #=================================================
  110. echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
  111. #=================================================
  112. # SETUP SSOWAT
  113. #=================================================
  114. ynh_app_setting_set "$app" is_public "$is_public"
  115. if [ "$is_public" = "Yes" ];
  116. then
  117. ynh_app_setting_set "$app" unprotected_uris "/"
  118. fi
  119. #=================================================
  120. # Régénère la configuration de SSOwat
  121. #=================================================
  122. sudo yunohost app ssowatconf
  123. #=================================================
  124. # Reload Nginx and regenerate SSOwat conf
  125. #=================================================
  126. sudo systemctl reload php5-fpm
  127. sudo systemctl reload nginx
  128. #=================================================
  129. # Nettoyer hosts
  130. #=================================================
  131. sudo sed -i '/#PRESTASHOP/d' /etc/hosts