1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/abantecart_ynh.git synced 2024-09-03 18:06:16 +02:00

Big refactoring

This commit is contained in:
frju365 2018-02-11 19:15:16 +01:00 committed by GitHub
parent de39ac7e88
commit e6712e7226
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,20 +1,20 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# GENERIC STARTING # GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source .fonctions source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
set -eu
#================================================= #=================================================
# MANAGE FAILURE OF THE SCRIPT # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_check_error # Active trap pour arrêter le script si une erreur est détectée. # Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#================================================= #=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST # RETRIEVE ARGUMENTS FROM THE MANIFEST
@ -30,19 +30,25 @@ admin_pass=$YNH_APP_ARG_ADMIN_PASS
admin_email=$YNH_APP_ARG_ADMIN_EMAIL admin_email=$YNH_APP_ARG_ADMIN_EMAIL
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
CHECK_USER "$admin_name" # Vérifie la validité de l'user admin final_path=/var/www/$app
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path. test ! -e "$final_path" || ynh_die "This path already contains a folder"
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é. # Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#================================================= #=================================================
# Install dependencies using Helpers # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_package_install_from_equivs ../conf/abantecart-deps.control \
|| ynh_die "Unable to install dependencies" ynh_install_app_dependencies php5-mysql
#================================================= #=================================================
# Check password strength # Check password strength
@ -65,21 +71,19 @@ ynh_app_setting_set "$app" admin_email "$admin_email"
# Initialize database as needed # Initialize database as needed
#================================================= #=================================================
db_name=$app db_name=$(ynh_sanitize_dbid $app)
db_user=$app ynh_app_setting_set $app db_name $db_name
db_pass=$(ynh_string_random) ynh_mysql_setup_db $db_name $db_name $db_pass
ynh_mysql_create_db "$db_name" "$db_user" "$db_pass" ynh_app_setting_set $app db_pass $db_pass
ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set $app" db_user $db_user
ynh_app_setting_set "$app" db_pass "$db_pass"
ynh_app_setting_set "$app" db_user "$db_user"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set $app final_path $final_path
SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#================================================= #=================================================
@ -88,17 +92,17 @@ SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
# Cleaning # Cleaning
#================================================= #=================================================
sudo rm -rf $final_path/tests ynh_secure_remove $final_path/tests
sudo rm -rf $final_path/install.txt ynh_secure_remove $final_path/install.txt
sudo mv $final_path/public_html/* $final_path/ mv $final_path/public_html/* $final_path/
sudo rm -rf $final_path/public_html ynh_secure_remove $final_path/public_html
#================================================= #=================================================
# CLI installation # CLI installation
#================================================= #=================================================
pushd $final_path/install/ pushd $final_path/install/
sudo php cli_install.php install \ php cli_install.php install \
--db_host=localhost \ --db_host=localhost \
--db_user=$db_user \ --db_user=$db_user \
--db_password=$db_pass \ --db_password=$db_pass \
@ -117,53 +121,60 @@ popd
# Cleaning # Cleaning
#================================================= #=================================================
sudo rm -rf /var/www/$app/install/ ynh_secure_remove /var/www/$app/install/
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
#================================================= #=================================================
# Set permissions # Set permissions
#================================================= #=================================================
# file owned by www-data before checking permissions # file owned by www-data before checking permissions
sudo chown www-data:www-data $final_path -R chown $app:$app $final_path -R
#================================================= #=================================================
# NGINX CONFIGURATION # SETUP LOGROTATE
#================================================= #=================================================
sed -i "s@YNH_WWW_PATH@$path_url@g" ../conf/nginx.conf # Use logrotate to manage application logfile(s)
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf ynh_use_logrotate
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 # SETUP SSOWAT
#================================================= #=================================================
# Make app private if necessary if [ $is_public -eq 0 ]
ynh_app_setting_set "$app" is_public "$is_public" then # Remove the public access
if [ "$is_public" = "Yes" ]; ynh_app_setting_delete $app skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
then then
ynh_app_setting_set "$app" unprotected_uris "/" # unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
sudo service php5-fpm reload systemctl reload nginx
sudo service nginx reload
sudo yunohost app ssowatconf