install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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_USER "$admin_prestashop" # Vérifie la validité de l'user admin
  32. path=$(ynh_normalize_url_path $path) # Vérifie et corrige la syntaxe du path.
  33. CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
  34. CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
  35. #=================================================
  36. # STORE SETTINGS FROM MANIFEST
  37. #=================================================
  38. ynh_app_setting_set $app domain $domain
  39. ynh_app_setting_set $app path $path
  40. ynh_app_setting_set $app admin $admin_prestashop
  41. ynh_app_setting_set $app is_public $is_public
  42. ynh_app_setting_set $app language $language
  43. ynh_app_setting_set $app pass $pass
  44. ynh_app_setting_set $app email $email
  45. #=================================================
  46. # Check password strength
  47. #=================================================
  48. [[ ${#pass} -gt 5 ]] || ynh_die \
  49. "The password is too weak, it must be longer than 5 characters"
  50. #=================================================
  51. # CREATE A SQL BDD
  52. #=================================================
  53. GENERATE_DB $app # Create a database and a dedicated user in the app name
  54. #=================================================
  55. # NGINX CONFIGURATION
  56. #=================================================
  57. final_path=/var/www/$app
  58. sudo sed -i "s@__PATHTOCHANGE__@$path@g" ../conf/nginx.conf
  59. sudo sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf
  60. sudo sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/nginx.conf
  61. sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
  62. #=================================================
  63. # PHP-FPM CONFIGURATION
  64. #=================================================
  65. POOL_FPM
  66. #=================================================
  67. # Crée le repertoire de destination
  68. #=================================================
  69. sudo mkdir "$final_path"
  70. #=================================================
  71. # DOWNLOAD, CHECK AND UNPACK SOURCE
  72. #=================================================
  73. final_path=/var/www/$app
  74. ynh_app_setting_set $app final_path $final_path
  75. SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
  76. #=================================================
  77. # Installation de Prestashop
  78. #=================================================
  79. pushd $final_path/install/
  80. sudo php index_cli.php \
  81. --db_server=localhost \
  82. --db_user=$db_user \
  83. --db_password=$db_pwd \
  84. --db_name=$db_name \
  85. --db_driver=amysqli \
  86. --db_port=3306 \
  87. --language=${language:0:2} \
  88. --lastname=$admin_prestashop \
  89. --password=$pass \
  90. --email=$email \
  91. --domain=$domain \
  92. --base_uri=$path \
  93. --prefix=_ps_
  94. popd
  95. sudo rm -fr $final_path/install
  96. #=================================================
  97. # check les permissions
  98. #=================================================
  99. sudo chown -R www-data: $final_path
  100. #=================================================
  101. # Set /etc/hosts
  102. #=================================================
  103. echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
  104. #=================================================
  105. # SETUP SSOWAT
  106. #=================================================
  107. ynh_app_setting_set "$app" is_public "$is_public"
  108. if [ "$is_public" = "Yes" ];
  109. then
  110. ynh_app_setting_set "$app" unprotected_uris "/"
  111. fi
  112. #=================================================
  113. # Régénère la configuration de SSOwat
  114. #=================================================
  115. sudo yunohost app ssowatconf
  116. #=================================================
  117. # Reload Nginx and regenerate SSOwat conf
  118. #=================================================
  119. sudo service php5-fpm restart
  120. sudo service nginx reload
  121. #=================================================
  122. # Nettoyer hosts
  123. #=================================================
  124. sudo sed -i '/#PRESTASHOP/d' /etc/hosts