install 4.9 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. 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. # Crée le repertoire de destination et check les permissions
  70. #=================================================
  71. sudo mkdir "$final_path"
  72. sudo chown -R www-data: $final_path
  73. #=================================================
  74. # DOWNLOAD, CHECK AND UNPACK SOURCE
  75. #=================================================
  76. final_path=/var/www/$app
  77. ynh_app_setting_set $app final_path $final_path
  78. SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
  79. #=================================================
  80. # Installation de Prestashop
  81. #=================================================
  82. pushd $final_path/install/
  83. sudo php index_cli.php install \
  84. --db_server=localhost \
  85. --db_user=$db_user \
  86. --db_password=$db_pwd \
  87. --db_name=$db_name \
  88. --db_driver=amysqli \
  89. --db_port=3306 \
  90. --lastname=$admin_prestashop \
  91. --password=$pass \
  92. --email=$email \
  93. --domain=$domain \
  94. --prefix=_ps_
  95. popd
  96. #=================================================
  97. # Set /etc/hosts
  98. #=================================================
  99. echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
  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