install 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. ynh_clean_setup () {
  13. ### Remove this function if there's nothing to clean before calling the remove script.
  14. true
  15. }
  16. # Exit if an error occurs during the execution of the script
  17. ynh_abort_if_errors
  18. #=================================================
  19. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  20. #=================================================
  21. domain=$YNH_APP_ARG_DOMAIN
  22. path=$YNH_APP_ARG_PATH
  23. admin_prestashop=$YNH_APP_ARG_ADMIN
  24. language=$YNH_APP_ARG_LANGUAGE
  25. is_public=$YNH_APP_ARG_IS_PUBLIC
  26. pass=$YNH_APP_ARG_PASSWD
  27. email=$YNH_APP_ARG_EMAIL
  28. app=$YNH_APP_INSTANCE_NAME
  29. #=================================================
  30. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  31. #=================================================
  32. final_path=/var/www/$app
  33. test ! -e "$final_path" || ynh_die "This path already contains a folder"
  34. # Normalize the url path syntax
  35. path_url=$(ynh_normalize_url_path $path_url)
  36. # Register (book) web path
  37. ynh_webpath_register $app $domain $path_url
  38. [[ ${#pass} -gt 5 ]] || ynh_die \
  39. "The password is too weak, it must be longer than 5 characters"
  40. #=================================================
  41. # STORE SETTINGS FROM MANIFEST
  42. #=================================================
  43. ynh_app_setting_set $app domain $domain
  44. ynh_app_setting_set $app path $path
  45. ynh_app_setting_set $app admin $admin_prestashop
  46. ynh_app_setting_set $app is_public $is_public
  47. ynh_app_setting_set $app language $language
  48. ynh_app_setting_set $app pass $pass
  49. ynh_app_setting_set $app email $email
  50. #=================================================
  51. # Check password strength
  52. #=================================================
  53. [[ ${#pass} -gt 5 ]] || ynh_die \
  54. "The password is too weak, it must be longer than 5 characters"
  55. #=================================================
  56. # CREATE A MYSQL DATABASE
  57. #=================================================
  58. db_name=$(ynh_sanitize_dbid $app)
  59. ynh_app_setting_set $app db_name $db_name
  60. ynh_mysql_setup_db $db_name $db_name
  61. #=================================================
  62. # NGINX CONFIGURATION
  63. #=================================================
  64. # Create a dedicated nginx config
  65. ynh_add_nginx_config
  66. #=================================================
  67. # PHP-FPM CONFIGURATION
  68. #=================================================
  69. POOL_FPM
  70. #=================================================
  71. # DOWNLOAD, CHECK AND UNPACK SOURCE
  72. #=================================================
  73. ynh_app_setting_set $app final_path $final_path
  74. # Download, check integrity, uncompress and patch the source from app.src
  75. ynh_setup_source "$final_path"
  76. #=================================================
  77. # CREATE DEDICATED USER
  78. #=================================================
  79. # Create a system user
  80. ynh_system_user_create $app
  81. #=================================================
  82. # Installation de Prestashop
  83. #=================================================
  84. pushd $final_path/install/
  85. php7.0 index_cli.php \
  86. --db_server=localhost \
  87. --db_user=$db_name \
  88. --db_password=$db_pwd \
  89. --db_name=$app \
  90. --db_driver=amysqli \
  91. --db_port=3306 \
  92. --language=${language:0:2} \
  93. --lastname=$admin_prestashop \
  94. --firstname=$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 $app:$app $final_path
  106. #=================================================
  107. # active ssl
  108. #=================================================
  109. mysql -u $db_user -p$db_pwd $db_name -e "UPDATE _ps_configuration SET value=1 WHERE name='PS_SSL_ENABLED';"
  110. mysql -u $db_user -p$db_pwd $db_name -e "INSERT INTO _ps_configuration (id_configuration, id_shop_group, id_shop, name, value, date_add, date_upd) VALUES (NULL, NULL, NULL, 'PS_SSL_ENABLED_EVERYWHERE', '1', NOW(), NOW());"
  111. #=================================================
  112. # Set /etc/hosts
  113. #=================================================
  114. echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
  115. #=================================================
  116. # SETUP SSOWAT
  117. #=================================================
  118. # Make app public if necessary
  119. if [ $is_public -eq 1 ]
  120. then
  121. # unprotected_uris allows SSO credentials to be passed anyway.
  122. ynh_app_setting_set $app unprotected_uris "/"
  123. fi
  124. #=================================================
  125. # RELOAD NGINX
  126. #=================================================
  127. systemctl reload nginx
  128. #=================================================
  129. # Nettoyer hosts
  130. #=================================================
  131. sudo sed -i '/#PRESTASHOP/d' /etc/hosts