| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #!/bin/bash
- #=================================================
- # Exit on command errors and treat unset variables as an error
- #=================================================
- set -eu
- #=================================================
- # GENERIC STARTING
- #=================================================
- # IMPORT GENERIC HELPERS
- #=================================================
- source .fonctions
- source /usr/share/yunohost/helpers
- #=================================================
- # MANAGE FAILURE OF THE SCRIPT
- #=================================================
- TRAP_ON # Active trap to stop the script if an error is detected.
- #=================================================
- # RETRIEVE ARGUMENTS FROM THE MANIFEST
- #=================================================
- domain=$YNH_APP_ARG_DOMAIN
- path=$YNH_APP_ARG_PATH
- admin_prestashop=$YNH_APP_ARG_ADMIN
- language=$YNH_APP_ARG_LANGUAGE
- is_public=$YNH_APP_ARG_IS_PUBLIC
- pass=$YNH_APP_ARG_PASSWD
- email=$YNH_APP_ARG_EMAIL
- app=$YNH_APP_INSTANCE_NAME
- #=================================================
- # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
- #=================================================
- CHECK_VAR "$app" "app name not set"
- CHECK_USER "$admin_prestashop" # Vérifie la validité de l'user admin
- path=$(ynh_normalize_url_path $path) # Vérifie et corrige la syntaxe du path.
- CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
- CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
- #=================================================
- # STORE SETTINGS FROM MANIFEST
- #=================================================
- ynh_app_setting_set $app domain $domain
- ynh_app_setting_set $app path $path
- ynh_app_setting_set $app admin $admin_prestashop
- ynh_app_setting_set $app is_public $is_public
- ynh_app_setting_set $app language $language
- ynh_app_setting_set $app pass $pass
- ynh_app_setting_set $app email $email
- #=================================================
- # Check password strength
- #=================================================
- [[ ${#pass} -gt 5 ]] || ynh_die \
- "The password is too weak, it must be longer than 5 characters"
- #=================================================
- # CREATE A SQL BDD
- #=================================================
- GENERATE_DB $app # Create a database and a dedicated user in the app name
- #=================================================
- # NGINX CONFIGURATION
- #=================================================
- final_path=/var/www/$app
- sudo sed -i "s@__PATHTOCHANGE__@$path@g" ../conf/nginx.conf
- sudo sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf
- sudo sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/nginx.conf
- sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
- #=================================================
- # PHP-FPM CONFIGURATION
- #=================================================
- POOL_FPM
- #=================================================
- # Crée le repertoire de destination
- #=================================================
- sudo mkdir "$final_path"
- #=================================================
- # DOWNLOAD, CHECK AND UNPACK SOURCE
- #=================================================
- final_path=/var/www/$app
- ynh_app_setting_set $app final_path $final_path
- SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
- #=================================================
- # Installation de Prestashop
- #=================================================
- pushd $final_path/install/
- sudo php index_cli.php \
- --db_server=localhost \
- --db_user=$db_user \
- --db_password=$db_pwd \
- --db_name=$app \
- --db_driver=amysqli \
- --db_port=3306 \
- --language=${language:0:2} \
- --lastname=$admin_prestashop \
- --password=$pass \
- --email=$email \
- --domain=$domain \
- --base_uri=$path \
- --prefix=_ps_
- popd
- sudo rm -fr $final_path/install
- #=================================================
- # check les permissions
- #=================================================
- sudo chown -R www-data: $final_path
- #=================================================
- # active ssl
- #=================================================
- mysql -u $db_user -p$db_pwd $db_user -e "UPDATE _ps_configuration SET value=1 WHERE name='PS_SSL_ENABLED';"
- mysql -u $db_user -p$db_pwd $db_user -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());"
- #=================================================
- # Set /etc/hosts
- #=================================================
- echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
- #=================================================
- # SETUP SSOWAT
- #=================================================
- ynh_app_setting_set "$app" is_public "$is_public"
- if [ "$is_public" = "Yes" ];
- then
- ynh_app_setting_set "$app" unprotected_uris "/"
- fi
- #=================================================
- # Régénère la configuration de SSOwat
- #=================================================
- sudo yunohost app ssowatconf
- #=================================================
- # Reload Nginx and regenerate SSOwat conf
- #=================================================
- sudo service php5-fpm restart
- sudo service nginx reload
- #=================================================
- # Nettoyer hosts
- #=================================================
- sudo sed -i '/#PRESTASHOP/d' /etc/hosts
|