install 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. db_name=$app
  54. db_user=$app
  55. db_pwd=$(ynh_string_random)
  56. ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
  57. ynh_app_setting_set "$app" db_name "$db_name"
  58. ynh_app_setting_set "$app" db_pwd "$db_pwd"
  59. ynh_app_setting_set "$app" db_user "$db_user"
  60. #=================================================
  61. # NGINX CONFIGURATION
  62. #=================================================
  63. final_path=/var/www/$app
  64. sudo sed -i "s@__PATHTOCHANGE__@$path@g" ../conf/nginx.conf
  65. sudo sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf
  66. sudo sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/nginx.conf
  67. sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
  68. #=================================================
  69. # PHP-FPM CONFIGURATION
  70. #=================================================
  71. POOL_FPM
  72. #=================================================
  73. # Crée le repertoire de destination
  74. #=================================================
  75. sudo mkdir "$final_path"
  76. #=================================================
  77. # DOWNLOAD, CHECK AND UNPACK SOURCE
  78. #=================================================
  79. final_path=/var/www/$app
  80. ynh_app_setting_set $app final_path $final_path
  81. SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
  82. #=================================================
  83. # Installation de Prestashop
  84. #=================================================
  85. pushd $final_path/install/
  86. sudo php index_cli.php \
  87. --db_server=localhost \
  88. --db_user=$db_user \
  89. --db_password=$db_pwd \
  90. --db_name=$db_name \
  91. --db_driver=amysqli \
  92. --db_port=3306 \
  93. --language=${language:0:2} \
  94. --lastname=$admin_prestashop \
  95. --password=$pass \
  96. --email=$email \
  97. --domain=$domain \
  98. --base_uri=$path \
  99. --prefix=_ps_
  100. popd
  101. sudo rm -fr $final_path/install
  102. #=================================================
  103. # check les permissions
  104. #=================================================
  105. sudo chown -R www-data: $final_path
  106. #=================================================
  107. # Set /etc/hosts
  108. #=================================================
  109. echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
  110. #=================================================
  111. # SETUP SSOWAT
  112. #=================================================
  113. ynh_app_setting_set "$app" is_public "$is_public"
  114. if [ "$is_public" = "Yes" ];
  115. then
  116. ynh_app_setting_set "$app" unprotected_uris "/"
  117. fi
  118. #=================================================
  119. # Régénère la configuration de SSOwat
  120. #=================================================
  121. sudo yunohost app ssowatconf
  122. #=================================================
  123. # Reload Nginx and regenerate SSOwat conf
  124. #=================================================
  125. sudo service php5-fpm restart
  126. sudo service nginx reload
  127. #=================================================
  128. # Nettoyer hosts
  129. #=================================================
  130. sudo sed -i '/#PRESTASHOP/d' /etc/hosts