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..402ecb5 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,55 +1,36 @@ #!/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 +# SYSTEM 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 -#================================================= -# BACKUP LOGROTATE -#================================================= +ynh_backup "/etc/logrotate.d/$app" -ynh_backup --src_path="/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..416fe86 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,10 @@ 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 --preserve-env=PATH install lodash --save + ynh_exec_as_app --preserve-env=PATH $install_dir/nodebb setup "${setup}" 2>/dev/null + popd chmod 400 "$install_dir/config.json" @@ -79,26 +73,24 @@ 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..93c838d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,41 +1,30 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - 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_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..957616d 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,38 +7,35 @@ 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" -#================================================= -# SPECIFIC RESTORATION #================================================= # 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 +43,13 @@ 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_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=$app --action="start" --log_path="systemd" +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..defa2f6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -2,39 +2,30 @@ #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 --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 $ynh_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" @@ -43,28 +34,25 @@ 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"