1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dolibarr_ynh.git synced 2024-09-03 18:35:53 +02:00

Cleanup, apply template

This commit is contained in:
Salamandar 2024-03-25 15:21:41 +01:00
parent 684468098f
commit 4025d5f618
6 changed files with 50 additions and 74 deletions

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -22,24 +20,20 @@ ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$install_dir" ynh_backup --src_path="$install_dir"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# SPECIFIC BACKUP # BACKUP VARIOUS FILES
#=================================================
# BACKUP LOGROTATE
#================================================= #=================================================
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/var/log/$app/"
#================================================= #=================================================
# BACKUP THE MYSQL DATABASE # BACKUP THE MYSQL DATABASE

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -9,8 +7,6 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
@ -18,8 +14,6 @@ ynh_script_progression --message="Updating NGINX web server configuration..." --
ynh_change_url_nginx_config ynh_change_url_nginx_config
#=================================================
# SPECIFIC MODIFICATIONS
#================================================= #=================================================
# UPDATE conf file # UPDATE conf file
#================================================= #=================================================

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -22,15 +20,15 @@ fpm_usage="medium"
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." --weight=2 ynh_script_progression --message="Storing installation settings..." --weight=2
ynh_app_setting_set --app=$app --key=member --value=$member ynh_app_setting_set --app="$app" --key="member" --value="$member"
ynh_app_setting_set --app=$app --key=version --value=$(ynh_app_upstream_version "../manifest.json") ynh_app_setting_set --app="$app" --key="version" --value="$(ynh_app_upstream_version)"
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint ynh_app_setting_set --app="$app" --key="fpm_footprint" --value="$fpm_footprint"
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage ynh_app_setting_set --app="$app" --key="fpm_usage" --value="$fpm_usage"
#================================================= #=================================================
# CREATE A MYSQL DATABASE # CREATE A MYSQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=1 ynh_script_progression --message="Configuring $app's MySQL database..." --weight=1
ynh_mysql_execute_as_root --sql="ALTER DATABASE $db_name charset=utf8" ynh_mysql_execute_as_root --sql="ALTER DATABASE $db_name charset=utf8"
@ -56,9 +54,19 @@ ynh_script_progression --message="Download source files..." --weight=10
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PREPARE AND INSTALL APP
#================================================= #=================================================
ynh_script_progression --message="Configuring PHP-FPM" --weight=2 ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="conf.php" --destination="$install_dir/htdocs/conf/conf.php"
chmod 644 "$install_dir/htdocs/conf/conf.php"
chown "$app:$app" "$install_dir/htdocs/conf/conf.php"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated php-fpm config # Create a dedicated php-fpm config
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
@ -66,23 +74,6 @@ ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# PREPARE AND INSTALL APP
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="../conf/conf.php" --destination="$install_dir/htdocs/conf/conf.php"
chmod 644 "$install_dir/htdocs/conf/conf.php"
chown $app:$app "$install_dir/htdocs/conf/conf.php"
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile="$install_dir/documents/dolibarr.log" ynh_use_logrotate --logfile="$install_dir/documents/dolibarr.log"

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -26,20 +24,19 @@ ynh_script_progression --message="Restoring the data directory..." --weight=1
ynh_restore_file --origin_path="$data_dir" --not_mandatory ynh_restore_file --origin_path="$data_dir" --not_mandatory
# (Same as for install dir) chown -R "$app:www-data" "$data_dir"
chown -R $app:www-data "$data_dir"
#================================================= #=================================================
# RESTORE THE MYSQL DATABASE # RESTORE THE MYSQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=27 ynh_script_progression --message="Restoring the MySQL database..." --weight=27
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
#================================================= #=================================================
# RESTORE THE PHP-FPM CONFIGURATION # RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_print_info --message="Reconfiguring PHP-FPM..." ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
# Restore the file first, so it can have a backup if different # Restore the file first, so it can have a backup if different
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
@ -52,14 +49,18 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # RESTORE VARIOUS FILES
#=================================================
ynh_restore_file --origin_path="/var/log/$app/"
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -71,7 +69,7 @@ then
# While the current version is not the last version, do an upgrade # While the current version is not the last version, do an upgrade
while [ "$last_version" != "$current_version" ] while [ "$last_version" != "$current_version" ]
do do
# The major version is the first part of the version number # The major version is the first part of the version number
current_major_version=${current_version%%.*} current_major_version=${current_version%%.*}
@ -80,7 +78,7 @@ then
else else
source upgrade.d/upgrade.$current_major_version.sh source upgrade.d/upgrade.$current_major_version.sh
fi fi
# If the current version has the same major version than the next one, # If the current version has the same major version than the next one,
# then it's the last upgrade to do # then it's the last upgrade to do
# We also cover the case where the last version is the first of the current major version series # We also cover the case where the last version is the first of the current major version series
@ -88,12 +86,12 @@ then
if [[ ("$last_major_version" -eq "$current_major_version") || ( ("$last_major_version" -eq "$((current_major_version+1))") && ("$next_version" == "$last_version") ) ]]; then if [[ ("$last_major_version" -eq "$current_major_version") || ( ("$last_major_version" -eq "$((current_major_version+1))") && ("$next_version" == "$last_version") ) ]]; then
current_major_version=last current_major_version=last
fi fi
# Load the value for this version # Load the value for this version
source upgrade.d/upgrade.$current_major_version.sh source upgrade.d/upgrade.$current_major_version.sh
ynh_print_info --message="Upgrading app from $current_version to $next_version" ynh_print_info --message="Upgrading app from $current_version to $next_version"
# Create an app.src for this version of Dolibarr # Create an app.src for this version of Dolibarr
cat > ../conf/app.src << EOF cat > ../conf/app.src << EOF
SOURCE_URL=https://github.com/Dolibarr/dolibarr/archive/$next_version.tar.gz SOURCE_URL=https://github.com/Dolibarr/dolibarr/archive/$next_version.tar.gz
@ -103,7 +101,7 @@ SOURCE_FORMAT=tar.bz2
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true
EOF EOF
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
@ -115,30 +113,30 @@ EOF
then then
ynh_secure_remove $lock ynh_secure_remove $lock
fi fi
mkdir -p /var/log/$app/ mkdir -p /var/log/$app/
# Upgrade with CURL # Upgrade with CURL
charset=$(mysql -ss -N -e "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = '$db_name'") charset=$(mysql -ss -N -e "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = '$db_name'")
if [ "$charset" != "utf8" ] if [ "$charset" != "utf8" ]
then then
ynh_print_info --message="Changing Database charset to utf8" ynh_print_info --message="Changing Database charset to utf8"
ynh_mysql_execute_as_root --database=$db_name --sql="ALTER DATABASE $db_name charset=utf8" ynh_mysql_execute_as_root --database=$db_name --sql="ALTER DATABASE $db_name charset=utf8"
ynh_local_curl "/install/repair.php" \ ynh_local_curl "/install/repair.php" \
"force_utf8_on_tables=confirmed" > /var/log/$app/repair.html "force_utf8_on_tables=confirmed" > /var/log/$app/repair.html
fi fi
ynh_exec_fully_quiet sleep 5 ynh_exec_fully_quiet sleep 5
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
pushd $install_dir/htdocs/install/ pushd $install_dir/htdocs/install/
if php$phpversion upgrade.php $current_version $next_version > /var/log/$app/upgrade.html; then if php$phpversion upgrade.php $current_version $next_version > /var/log/$app/upgrade.html; then
ynh_print_info --message="Step 1 upgrading ended successfully" ynh_print_info --message="Step 1 upgrading ended successfully"
else else
@ -161,20 +159,20 @@ EOF
ynh_die --message="Step 3 upgrading ended with error" ynh_die --message="Step 3 upgrading ended with error"
fi fi
popd popd
# Get the new current version number # Get the new current version number
current_version=$next_version current_version=$next_version
current_major_version=${current_version%%.*} current_major_version=${current_version%%.*}
done done
if php$phpversion $install_dir/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y; then if php$phpversion $install_dir/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y; then
ynh_print_info --message="LDAP user update ok" ynh_print_info --message="LDAP user update ok"
else else
ynh_print_info --message="LDAP user update ended with error" ynh_print_info --message="LDAP user update ended with error"
fi fi
ynh_app_setting_set --app=$app --key=version --value=$update_version ynh_app_setting_set --app=$app --key=version --value=$update_version
fi fi