install 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. # 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. --lastname=$admin_prestashop \
  94. --password=$pass \
  95. --email=$email \
  96. --domain=$domain \
  97. --base_uri=$path \
  98. --prefix=_ps_
  99. popd
  100. sudo rm -fr $final_path/install
  101. #=================================================
  102. # Insert de l'utilisateur dans la base
  103. #=================================================
  104. if [ "$language"=="fr_FR" ]
  105. then
  106. id_lang=2
  107. elif [ "$language"=="en_EN" ]; then
  108. id_lang=1
  109. fi
  110. mysql -e "INSERT INTO _ps_employee (id_employee, id_profile, id_lang, lastname, firstname, email, passwd, last_passwd_gen, stats_date_from, stats_date_to, stats_compare_from, stats_compare_to, stats_compare_option, preselect_date_range, bo_color, bo_theme, bo_css, default_tab, bo_width, bo_menu, active, optin, id_last_order, id_last_customer_message, id_last_customer, last_connection_date, reset_password_token, reset_password_validity) VALUES (NULL, '1', '$id_lang', '', '', '$admin_prestashop@$domain', MD5('$pass'), CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL, '1', NULL, NULL, NULL, NULL, '0', '0', '1', '1', '1', '0', '0', '0', NULL, NULL, NULL);" -u $db_user -p$db_pwd $db_name
  111. #=================================================
  112. # check les permissions
  113. #=================================================
  114. sudo chown -R www-data: $final_path
  115. #=================================================
  116. # Set /etc/hosts
  117. #=================================================
  118. echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
  119. #=================================================
  120. # SETUP SSOWAT
  121. #=================================================
  122. ynh_app_setting_set "$app" is_public "$is_public"
  123. if [ "$is_public" = "Yes" ];
  124. then
  125. ynh_app_setting_set "$app" unprotected_uris "/"
  126. fi
  127. #=================================================
  128. # Régénère la configuration de SSOwat
  129. #=================================================
  130. sudo yunohost app ssowatconf
  131. #=================================================
  132. # Reload Nginx and regenerate SSOwat conf
  133. #=================================================
  134. sudo service php5-fpm restart
  135. sudo service nginx reload
  136. #=================================================
  137. # Nettoyer hosts
  138. #=================================================
  139. sudo sed -i '/#PRESTASHOP/d' /etc/hosts