#!/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 #================================================= ynh_check_error # Active trap pour arrêter le script si une erreur est détectée. #================================================= # 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_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 #================================================= db_name=$app db_user=$app db_pwd=$(ynh_string_random) ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set "$app" db_pwd "$db_pwd" ynh_app_setting_set "$app" db_user "$db_user" #================================================= # 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=$db_name \ --db_driver=amysqli \ --db_port=3306 \ --lastname=$admin_prestashop \ --password=$pass \ --email=$email \ --domain=$domain \ --base_uri=$path \ --prefix=_ps_ popd sudo rm -fr $final_path/install #================================================= # Insert de l'utilisateur dans la base #================================================= if [ "$language"=="fr_FR" ] then id_lang=2 elif [ "$language"=="en_EN" ]; then id_lang=1 fi 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 #================================================= # check les permissions #================================================= sudo chown -R www-data: $final_path #================================================= # 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