install 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. final_path=/var/www/$app
  70. ynh_app_setting_set $app final_path $final_path
  71. SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
  72. #=================================================
  73. # Installation de Prestashop
  74. #=================================================
  75. pushd $final_path/install/
  76. sudo php index_cli.php install \
  77. --db_server=localhost \
  78. --db_user=$db_user \
  79. --db_password=$db_pass \
  80. --db_name=$db_name \
  81. --db_driver=amysqli \
  82. --db_port=3306 \
  83. --lastname=$db_user \
  84. --password=$db_pwd \
  85. --email=$email \
  86. --domain=$domain \
  87. --prefix=_ps_
  88. popd
  89. #=================================================
  90. # Set /etc/hosts
  91. #=================================================
  92. echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
  93. #=================================================
  94. # NGINX CONFIGURATION
  95. #=================================================
  96. sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
  97. sudo sed -i "s@__PATHTOCHANGE__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
  98. sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf
  99. sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf
  100. #=================================================
  101. # SETUP SSOWAT
  102. #=================================================
  103. ynh_app_setting_set "$app" is_public "$is_public"
  104. if [ "$is_public" = "Yes" ];
  105. then
  106. ynh_app_setting_set "$app" unprotected_uris "/"
  107. fi
  108. #=================================================
  109. # PHP-FPM CONFIGURATION
  110. #=================================================
  111. POOL_FPM
  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