From e4dc45864ac51d324dfcb34503203bdbdebb9c5e Mon Sep 17 00:00:00 2001 From: Laurent Gay Date: Tue, 12 Dec 2023 11:38:41 +0100 Subject: [PATCH] correct --- scripts/_common.sh | 28 +++++++++++++++ scripts/backup | 22 +----------- scripts/install | 26 ++------------ scripts/remove | 29 ---------------- scripts/restore | 33 +++++------------- scripts/upgrade | 85 ++++++---------------------------------------- 6 files changed, 51 insertions(+), 172 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index c8eee12..999eae6 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,6 +4,34 @@ # COMMON VARIABLES #================================================= +APPLITYPE="lucterios.standard" +MODULES="lucterios.contacts,lucterios.documents,lucterios.mailing" +DATABASE="postgresql:name=$db_name,user=$db_user,password=$db_pwd,host=localhost" +if [ "$lct_appli" == "asso" ] +then + MODULES="lucterios.contacts,lucterios.documents,lucterios.mailing,diacamma.member,diacamma.event,diacamma.accounting,diacamma.invoice,diacamma.payoff" + APPLITYPE="diacamma.asso" +fi +if [ "$lct_appli" == "syndic" ] +then + MODULES="lucterios.contacts,lucterios.documents,lucterios.mailing,diacamma.condominium,diacamma.accounting,diacamma.payoff" + APPLITYPE="diacamma.syndic" +fi + #================================================= # PERSONAL HELPERS #================================================= + +function refresh_collect() +{ + python3 manage_${app}.py collectstatic --noinput -l + rm -rf ${app}/static/static + rm -rf ${app}/static/plugins + rm -rf ${app}/static/tmp + rm -rf ${app}/static/archives + rm -rf ${app}/static/usr + rm -rf ${app}/static/__pycache__ + rm -rf ${app}/static/settings.py + rm -rf ${app}/static/django_error.log + rm -rf ${app}/static/__init__.py +} diff --git a/scripts/backup b/scripts/backup index ffd5903..8a37ed6 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,16 +1,5 @@ #!/bin/bash -#### App file generated with YoloGen, the YunoHost app generator, version . -# This is the tutorial version of the app. -# It contains extra commands to explain what should be done in case you want to adjust some part of the script. -# Once you are done, you may remove them. -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -19,17 +8,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_print_info --message="Declaring files to be backed up..." -### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs -### to be backuped and not an actual copy of any file. The actual backup that -### creates and fill the archive with the files happens in the core after this -### script is called. Hence ynh_backups calls takes basically 0 seconds to run. - ynh_backup --src_path="$install_dir" -# The --is_big parameters ensure this folder is not included in the backup by default (taking less space), except if BACKUP_CORE_ONLY=0 is passed before the backup command. You might want to document that for your users. - -ynh_backup --src_path="$data_dir" --is_big - ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" @@ -51,4 +31,4 @@ ynh_print_info --message="Backing up the postgresql database..." # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." \ No newline at end of file +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 124e963..e9a598c 100644 --- a/scripts/install +++ b/scripts/install @@ -9,37 +9,15 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Installing app..." --weight=5 pushd $install_dir -APPLITYPE="lucterios.standard" -MODULES="lucterios lucterios-standard lucterios-contacts lucterios-documents" -DATABASE="postgresql:name=$db_name,user=$db_user,password=$db_pwd,host=localhost" -if [ "$lct_appli" == "asso" ] -then - MODULES="lucterios.contacts,lucterios.documents,lucterios.mailing,diacamma.member,diacamma.event,diacamma.accounting,diacamma.invoice,diacamma.payoff" - APPLITYPE="diacamma.asso" -fi -if [ "$lct_appli" == "syndic" ] -then - MODULES="lucterios.contacts,lucterios.documents,lucterios.mailing,diacamma.condominium,diacamma.accounting,diacamma.payoff" - APPLITYPE="diacamma.syndic" -fi python3 -m venv venv . venv/bin/activate pip3 install -U lucterios lucterios-standard lucterios-contacts lucterios-documents pip3 install -U diacamma-asso diacamma-syndic diacamma-financial pip3 install -U gunicorn psycopg2-binary psycopg2 lucterios_admin.py installed -lucterios_admin.py add -n ${app} -p $APPLITYPE -m $MODULES -d $DATABASE -e '{"LANGUAGES":"'${language}'"}' +lucterios_admin.py add -n ${app} -p "${APPLITYPE}" -m "${MODULES}" -d "${DATABASE}" -e '{"LANGUAGES":"'${language}'"}' -python3 manage_${app}.py collectstatic --noinput -l -rm -rf ${app}/static/static -rm -rf ${app}/static/plugins -rm -rf ${app}/static/tmp -rm -rf ${app}/static/archives -rm -rf ${app}/static/usr -rm -rf ${app}/static/__pycache__ -rm -rf ${app}/static/settings.py -rm -rf ${app}/static/django_error.log -rm -rf ${app}/static/__init__.py +refresh_collect popd diff --git a/scripts/remove b/scripts/remove index b443c7a..a8c5926 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,40 +1,13 @@ #!/bin/bash -# This is the tutorial version of the app. -# It contains extra commands to explain what should be done in case you want to adjust some part of the script. -# Once you are done, you may remove them. - -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= source _common.sh source /usr/share/yunohost/helpers -# Settings are automatically loaded as bash variables -# in every app script context, therefore typically these will exist: -# - $domain -# - $path -# - $language -# - $install_dir -# - $port -# ... - -# For remove operations : -# - the core will deprovision every resource defined in the manifest **after** this script is ran -# this includes removing the install directory, and data directory (if --purge was used) - -#================================================= -# REMOVE SYSTEM CONFIGURATIONS #================================================= # REMOVE SYSTEMD SERVICE #================================================= ynh_script_progression --message="Removing system configurations related to $app..." -# This should be a symetric version of what happens in the install script - -# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then ynh_script_progression --message="Removing $app service integration..." @@ -49,8 +22,6 @@ ynh_remove_logrotate ynh_remove_fail2ban_config -# Remove other various files specific to the app... such as : - ynh_secure_remove --file="/var/log/$app" #================================================= diff --git a/scripts/restore b/scripts/restore index 7d6ed18..610f666 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,16 +1,5 @@ #!/bin/bash -# This is the tutorial version of the app. -# It contains extra commands to explain what should be done in case you want to adjust some part of the script. -# Once you are done, you may remove them. - -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -21,21 +10,17 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$install_dir" -# $install_dir will automatically be initialized with some decent -# permission by default ... however, you may need to recursively reapply -# ownership to all files such as after the ynh_setup_source step +pushd $install_dir +. venv/bin/activate +lucterios_admin.py check +lucterios_admin.py update +lucterios_admin.py refreshall -chown -R $app:www-data "$install_dir" +refresh_collect +popd -#================================================= -# RESTORE THE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Restoring the data directory..." --weight=1 - -ynh_restore_file --origin_path="$data_dir" --not_mandatory - -# (Same as for install dir) -chown -R $app:www-data "$data_dir" +chmod 400 "$install_dir/" +chown ${app}:${app} "$install_dir/" #================================================= # RESTORE THE MYSQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index c8b9c87..79dca16 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,38 +1,8 @@ #!/bin/bash -# This is the tutorial version of the app. -# It contains extra commands to explain what should be done in case you want to adjust some part of the script. -# Once you are done, you may remove them. - -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -# Settings are automatically loaded as bash variables -# in every app script context, therefore typically these will exist: -# - $domain -# - $path -# - $language -# - $install_dir -# - $port -# ... - -# In the context of upgrade, -# - resources are automatically provisioned / updated / deleted (depending on existing resources) -# - a safety backup is automatically created by the core and will be restored if the upgrade fails - -### This helper will compare the version of the currently installed app and the version of the upstream package. -### $upgrade_type can have 2 different values -### - UPGRADE_APP if the upstream app version has changed -### - UPGRADE_PACKAGE if only the YunoHost package has changed -### ynh_check_app_version_changed will stop the upgrade if the app is up to date. -### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. - upgrade_type=$(ynh_check_app_version_changed) #================================================= @@ -68,32 +38,27 @@ ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" #================================================= -# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE +# UPDATE DIACAMMA #================================================= +ynh_script_progression --message="Updating Diacamma..." -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." +pushd $install_dir +. venv/bin/activate +lucterios_admin.py check +lucterios_admin.py update +lucterios_admin.py refreshall - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" -fi +refresh_collect +popd -# $install_dir will automatically be initialized with some decent -# permission by default ... however, you may need to recursively reapply -# ownership to all files such as after the ynh_setup_source step - -chown -R $app:www-data "$install_dir" +chmod 400 "$install_dir/" +chown ${app}:${app} "$install_dir/" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Upgrading system configurations related to $app..." -# This should be a literal copypasta of what happened in the install's "System configuration" section - ynh_add_nginx_config ynh_add_systemd_config @@ -105,34 +70,6 @@ ynh_use_logrotate --non-append # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="" -#================================================= -# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Updating a configuration file..." - -### Same as during install -### -### The file will automatically be backed-up if it's found to be manually modified (because -### ynh_add_config keeps track of the file's checksum) - -ynh_add_config --template="" --destination="$install_dir/" - -# FIXME: this should be handled by the core in the future -# You may need to use chmod 600 instead of 400, -# for example if the app is expected to be able to modify its own config - -chmod 400 "$install_dir/some_config_file" -chown $app:$app "$install_dir/some_config_file" - -### For more complex cases where you want to replace stuff using regexes, -### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) -### When doing so, you also need to manually call ynh_store_file_checksum -### -### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" -### ynh_store_file_checksum --file="$install_dir/some_config_file" - #================================================= # START SYSTEMD SERVICE #=================================================