mirror of
https://github.com/YunoHost-Apps/abantecart_ynh.git
synced 2024-09-03 18:06:16 +02:00
172 lines
5.5 KiB
Bash
172 lines
5.5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source .fonctions
|
|
source /usr/share/yunohost/helpers
|
|
set -eu
|
|
|
|
#=================================================
|
|
# 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
|
|
#=================================================
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path_url=$YNH_APP_ARG_PATH
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
admin_name=$YNH_APP_ARG_ADMIN_NAME
|
|
admin_pass=$YNH_APP_ARG_ADMIN_PASS
|
|
admin_email=$YNH_APP_ARG_ADMIN_EMAIL
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
#=================================================
|
|
|
|
CHECK_USER "$admin_name" # Vérifie la validité de l'user admin
|
|
path_url=$(ynh_normalize_url_path $path_url) # 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é.
|
|
|
|
#=================================================
|
|
# Install dependencies using Helpers
|
|
#=================================================
|
|
ynh_package_install_from_equivs ../conf/abantecart-deps.control \
|
|
|| ynh_die "Unable to install dependencies"
|
|
|
|
#=================================================
|
|
# Check password strength
|
|
#=================================================
|
|
|
|
[[ ${#admin_pass} -gt 5 ]] || ynh_die \
|
|
"The password is too weak, it must be longer than 5 characters"
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
|
|
user="$app"
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
|
ynh_app_setting_set "$app" admin_pass "$admin_pass"
|
|
ynh_app_setting_set "$app" admin_name "$admin_name"
|
|
ynh_app_setting_set "$app" admin_email "$admin_email"
|
|
|
|
#=================================================
|
|
# Initialize database as needed
|
|
#=================================================
|
|
|
|
db_name=$app
|
|
db_user=$app
|
|
db_pass=$(ynh_string_random)
|
|
ynh_mysql_create_db "$db_name" "$db_user" "$db_pass"
|
|
ynh_app_setting_set "$app" db_name "$db_name"
|
|
ynh_app_setting_set "$app" db_pass "$db_pass"
|
|
ynh_app_setting_set "$app" db_user "$db_user"
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# Cleaning
|
|
#=================================================
|
|
|
|
sudo rm -rf $final_path/tests
|
|
sudo rm -rf $final_path/install.txt
|
|
sudo mv $final_path/public_html/* $final_path/
|
|
sudo rm -rf $final_path/public_html
|
|
|
|
#=================================================
|
|
# CLI installation
|
|
#=================================================
|
|
|
|
pushd $final_path/install/
|
|
sudo php cli_install.php install \
|
|
--db_host=localhost \
|
|
--db_user=$db_user \
|
|
--db_password=$db_pass \
|
|
--db_name=$db_name \
|
|
--db_driver=amysqli \
|
|
--db_port=3306 \
|
|
--username=$admin_name \
|
|
--password=$admin_pass \
|
|
--email=$admin_email \
|
|
--http_server=$domain$path_url \
|
|
--db_prefix=_ac_ \
|
|
--admin_path=admin
|
|
popd
|
|
|
|
#=================================================
|
|
# Cleaning
|
|
#=================================================
|
|
|
|
sudo rm -rf /var/www/$app/install/
|
|
|
|
#=================================================
|
|
# Set permissions
|
|
#=================================================
|
|
|
|
# file owned by www-data before checking permissions
|
|
sudo chown www-data:www-data $final_path -R
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
sed -i "s@YNH_WWW_PATH@$path_url@g" ../conf/nginx.conf
|
|
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
|
|
sudo sed -i "s@NAMETOCHANGE@$app@g" ../conf/nginx.conf
|
|
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
|
|
sudo cp ../conf/nginx.conf $nginxconf
|
|
sudo chown root: $nginxconf
|
|
sudo chmod 644 $nginxconf
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
|
|
sudo sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
|
|
sudo sed -i "s@FOLDERTOCHANGE@$final_path@g" ../conf/php-fpm.conf
|
|
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
|
sudo cp ../conf/php-fpm.conf $finalphpconf
|
|
sudo chown root:root $finalphpconf
|
|
sudo chmod 644 $finalphpconf
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
|
|
# Make app private if necessary
|
|
ynh_app_setting_set $app is_public "$is_public"
|
|
if [ $is_public -eq 0 ];
|
|
then
|
|
# Retire l'autorisation d'accès de la page d'install.
|
|
ynh_app_setting_delete $app unprotected_uris
|
|
# Rend la page d'actualisation accessible pour le script cron.
|
|
ynh_app_setting_get $app skipped_uris "/action.php"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
sudo service php5-fpm reload
|
|
sudo service nginx reload
|
|
sudo yunohost app ssowatconf
|