From f3dfd81099a7628082b2ae9e50af2c0640fcafcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:16:00 +0200 Subject: [PATCH 1/3] cleaning --- .gitignore | 3 +++ conf/systemd.service | 4 ++-- manifest.toml | 3 ++- scripts/_common.sh | 14 +------------- scripts/backup | 25 ++++++++----------------- scripts/change_url | 26 ++++++++------------------ scripts/install | 41 ++++++++++++++++++----------------------- scripts/remove | 20 +++++++------------- scripts/restore | 32 +++++++++++++------------------- scripts/upgrade | 35 ++++++++++++++--------------------- 10 files changed, 76 insertions(+), 127 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f144f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.sw[op] +.DS_Store diff --git a/conf/systemd.service b/conf/systemd.service index 1f81799..3d0f6d7 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -10,8 +10,8 @@ Group=__APP__ Environment=NODE_ENV=production WorkingDirectory=__INSTALL_DIR__/ #PIDFile=__INSTALL_DIR__/pidfile -Environment="__YNH_NODE_LOAD_PATH__" -ExecStart=__YNH_NODE__ __INSTALL_DIR__/nodebb start +Environment="PATH=__PATH_WITH_NODEJS__" +ExecStart=__NODEJS_DIR__/node __INSTALL_DIR__/nodebb start #loader.js Restart=always diff --git a/manifest.toml b/manifest.toml index e9d23f3..6537871 100644 --- a/manifest.toml +++ b/manifest.toml @@ -17,7 +17,8 @@ admindoc = "https://docs.nodebb.org" code = "https://github.com/NodeBB/NodeBB" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.16" +helpers_version = "2.1" architectures = "all" multi_instance = true diff --git a/scripts/_common.sh b/scripts/_common.sh index 307dff1..53f3661 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,20 +1,8 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= nodejs_version=20 nodebb_version=v3.x - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 0f520f0..421c331 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,31 +1,22 @@ #!/bin/bash -#================================================= -# 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 -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP @@ -33,23 +24,23 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP LOGROTATE #================================================= -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the PostgreSQL database..." +ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 933e103..756529a 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,47 +1,37 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action="stop" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # CONFIGURE CONFIG.JSON FILE #================================================= -ynh_replace_string --match_string="\"url\": \".*\"" --replace_string="\"url\": \"https://${new_domain}${new_path}\"" --target_file="$install_dir/config.json" +ynh_replace --match="\"url\": \".*\"" --replace="\"url\": \"https://${new_domain}${new_path}\"" --file="$install_dir/config.json" -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" +ynh_systemctl --service=$app --action="start" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 4f1e217..43140ef 100644 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -20,20 +14,20 @@ email=$(ynh_user_get_info --username=$admin --key=mail) # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set --app=$app --key=$secret --value="$secret" +ynh_app_setting_set --key=$secret --value="$secret" #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=1 +ynh_script_progression "Installing dependencies..." # Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=2 +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src git config --system --add safe.directory $install_dir @@ -45,19 +39,19 @@ chown -R $app:www-data "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=3 +ynh_script_progression "Configuring NGINX web server..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx #================================================= # SPECIFIC SETUP #================================================= # CONFIGURE NODEBB #================================================= -ynh_script_progression --message="Configuring the app..." --weight=2 +ynh_script_progression "Configuring the app..." -ynh_add_config --template="config.json" --destination="$install_dir/config.json" +ynh_config_add --template="config.json" --destination="$install_dir/config.json" setup="{ \"admin:username\": \"$admin\", @@ -67,10 +61,11 @@ setup="{ }" pushd $install_dir - ynh_use_nodejs + npm install npm@latest --location=global - ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install lodash --save - ynh_exec_as $app env $ynh_node_load_PATH $install_dir/nodebb setup "${setup}" 2>/dev/null + ynh_exec_as_app node_load_PATH npm install lodash --save + ynh_exec_as_app node_load_PATH $install_dir/nodebb setup "${setup}" 2>/dev/null + popd chmod 400 "$install_dir/config.json" @@ -79,26 +74,26 @@ chown $app:$app "$install_dir/config.json" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 +ynh_script_progression "Configuring $app's systemd service..." # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd # Use logrotate to manage application logfile(s) -ynh_use_logrotate +ynh_config_add_logrotate yunohost service add $app --description="Forum software" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action=restart --log_path="systemd" +ynh_systemctl --service=$app --action=restart --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index fccea68..488456a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -16,26 +10,26 @@ source /usr/share/yunohost/helpers #================================================= # 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 +if ynh_hide_warnings yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service integration..." --weight=1 + ynh_script_progression "Removing $app service integration..." yunohost service remove $app fi # Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_config_remove_systemd # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx # Remove metapackage and its dependencies -ynh_remove_nodejs +ynh_nodejs_remove #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 5cfcd88..37acc76 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# 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 @@ -13,9 +7,9 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" +ynh_restore "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" @@ -25,26 +19,26 @@ chown -R $app:www-data "$install_dir" #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." +ynh_script_progression "Reinstalling dependencies..." # Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +ynh_psql_db_shell < "./db.sql"" #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +ynh_script_progression "Restoring $app's systemd service..." -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet yunohost service add $app --description="Forum software" --log="/var/log/$app/$app.log" @@ -52,14 +46,14 @@ yunohost service add $app --description="Forum software" --log="/var/log/$app/$a #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" +ynh_systemctl --service=$app --action="start" --log_path="systemd" -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 9b94475..df5ebd6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -2,39 +2,32 @@ #https://docs.nodebb.org/configuring/upgrade/ -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --log_path="systemd" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." --weight=1 +ynh_script_progression "Upgrading source files..." pushd $install_dir - ynh_use_nodejs + # Shut down your forum git config --system --add safe.directory $install_dir - ynh_exec_as $app env "$ynh_node_load_PATH" $install_dir/nodebb stop + ynh_exec_as_app node_load_PATH" $install_dir/nodebb stop # Grab the latest and greatest code git fetch # Grab the latest code from the NodeBB Repository git reset --hard origin/$nodebb_version # Replace v1.12.x with the branch name! # Run the NodeBB upgrade script - ynh_exec_as $app $ynh_node_load_PATH $install_dir/nodebb upgrade 2>/dev/null + ynh_exec_as_app node_load_PATH $install_dir/nodebb upgrade 2>/dev/null + popd chmod -R o-rwx "$install_dir" @@ -43,28 +36,28 @@ chown -R $app:www-data "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 +ynh_script_progression "Upgrading NGINX web server configuration..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add $app --description="Forum software" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" +ynh_systemctl --service=$app --action="start" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed" From 336a571c65962b666346f071507ccfcc6d93a539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:19:30 +0200 Subject: [PATCH 2/3] cleaning --- scripts/backup | 12 +----------- scripts/install | 3 --- scripts/remove | 9 ++------- scripts/restore | 6 +----- scripts/upgrade | 7 +------ 5 files changed, 5 insertions(+), 32 deletions(-) diff --git a/scripts/backup b/scripts/backup index 421c331..402ecb5 100644 --- a/scripts/backup +++ b/scripts/backup @@ -13,23 +13,13 @@ ynh_print_info "Declaring files to be backed up..." ynh_backup "$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - ynh_backup "/etc/logrotate.d/$app" -#================================================= -# BACKUP SYSTEMD -#================================================= - ynh_backup "/etc/systemd/system/$app.service" #================================================= diff --git a/scripts/install b/scripts/install index 43140ef..7ae0c0d 100644 --- a/scripts/install +++ b/scripts/install @@ -61,7 +61,6 @@ setup="{ }" pushd $install_dir - npm install npm@latest --location=global ynh_exec_as_app node_load_PATH npm install lodash --save ynh_exec_as_app node_load_PATH $install_dir/nodebb setup "${setup}" 2>/dev/null @@ -76,10 +75,8 @@ chown $app:$app "$install_dir/config.json" #================================================= ynh_script_progression "Configuring $app's systemd service..." -# Create a dedicated systemd config ynh_config_add_systemd -# Use logrotate to manage application logfile(s) ynh_config_add_logrotate yunohost service add $app --description="Forum software" --log="/var/log/$app/$app.log" diff --git a/scripts/remove b/scripts/remove index 488456a..93c838d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -4,10 +4,9 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression "Removing system configurations related to $app..." # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_hide_warnings yunohost service status $app >/dev/null @@ -16,16 +15,12 @@ then yunohost service remove $app fi -# Remove the dedicated systemd config ynh_config_remove_systemd -# Remove the app-specific logrotate config ynh_config_remove_logrotate -# Remove the dedicated NGINX config ynh_config_remove_nginx -# Remove metapackage and its dependencies ynh_nodejs_remove #================================================= diff --git a/scripts/restore b/scripts/restore index 37acc76..957616d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,14 +14,11 @@ ynh_restore "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" -#================================================= -# SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= ynh_script_progression "Reinstalling dependencies..." -# Install Nodejs ynh_nodejs_install #================================================= @@ -29,7 +26,7 @@ ynh_nodejs_install #================================================= ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_db_shell < "./db.sql"" +ynh_psql_db_shell < "./db.sql" #================================================= # RESTORE SYSTEMD @@ -49,7 +46,6 @@ yunohost service add $app --description="Forum software" --log="/var/log/$app/$a ynh_script_progression "Starting $app's systemd service..." ynh_systemctl --service=$app --action="start" --log_path="systemd" - ynh_systemctl --service=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index df5ebd6..bd0e935 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,16 +18,14 @@ ynh_systemctl --service=$app --action="stop" --log_path="systemd" ynh_script_progression "Upgrading source files..." pushd $install_dir - # Shut down your forum git config --system --add safe.directory $install_dir - ynh_exec_as_app node_load_PATH" $install_dir/nodebb stop + ynh_exec_as_app node_load_PATH $install_dir/nodebb stop # Grab the latest and greatest code git fetch # Grab the latest code from the NodeBB Repository git reset --hard origin/$nodebb_version # Replace v1.12.x with the branch name! # Run the NodeBB upgrade script ynh_exec_as_app node_load_PATH $install_dir/nodebb upgrade 2>/dev/null - popd chmod -R o-rwx "$install_dir" @@ -38,13 +36,10 @@ chown -R $app:www-data "$install_dir" #================================================= ynh_script_progression "Upgrading NGINX web server configuration..." -# Create a dedicated NGINX config ynh_config_add_nginx -# Install Nodejs ynh_nodejs_install -# Create a dedicated systemd config ynh_config_add_systemd yunohost service add $app --description="Forum software" --log="/var/log/$app/$app.log" From 5fb66f86cc76351ccfe4ace86a6db3df94db309b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:21:15 +0200 Subject: [PATCH 3/3] fix --- scripts/install | 4 ++-- scripts/upgrade | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index 7ae0c0d..416fe86 100644 --- a/scripts/install +++ b/scripts/install @@ -62,8 +62,8 @@ setup="{ pushd $install_dir npm install npm@latest --location=global - ynh_exec_as_app node_load_PATH npm install lodash --save - ynh_exec_as_app node_load_PATH $install_dir/nodebb setup "${setup}" 2>/dev/null + ynh_exec_as_app --preserve-env=PATH install lodash --save + ynh_exec_as_app --preserve-env=PATH $install_dir/nodebb setup "${setup}" 2>/dev/null popd diff --git a/scripts/upgrade b/scripts/upgrade index bd0e935..defa2f6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,12 +20,12 @@ ynh_script_progression "Upgrading source files..." pushd $install_dir # Shut down your forum git config --system --add safe.directory $install_dir - ynh_exec_as_app node_load_PATH $install_dir/nodebb stop + ynh_exec_as_app --preserve-env=PATH $install_dir/nodebb stop # Grab the latest and greatest code git fetch # Grab the latest code from the NodeBB Repository git reset --hard origin/$nodebb_version # Replace v1.12.x with the branch name! # Run the NodeBB upgrade script - ynh_exec_as_app node_load_PATH $install_dir/nodebb upgrade 2>/dev/null + ynh_exec_as_app --preserve-env=PATH $install_dir/nodebb upgrade 2>/dev/null popd chmod -R o-rwx "$install_dir"