1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hedgedoc_ynh.git synced 2024-09-03 19:25:52 +02:00
This commit is contained in:
Éric Gaspar 2024-06-24 18:56:23 +02:00
parent e5fec91d12
commit 1ae20c286a
10 changed files with 94 additions and 141 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*~
*.sw[op]
.DS_Store

View file

@ -8,9 +8,9 @@ Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__INSTALL_DIR__
Environment="__YNH_NODE_LOAD_PATH__"
Environment="PATH=__PATH_WITH_NODEJS__"
Environment="NODE_ENV=production"
ExecStart=__YNH_NPM__ start --production
ExecStart=__NODEJS_DIR__/npm start --production
Restart=always
# Sandboxing options to harden security

View file

@ -17,7 +17,8 @@ admindoc = "https://docs.hedgedoc.org/"
code = "https://github.com/hedgedoc/hedgedoc"
[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.16"
helpers_version = "2.1"
architectures = "all"
multi_instance = true

View file

@ -1,19 +1,7 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
nodejs_version=20
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,42 +1,33 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
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"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
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)."

View file

@ -1,29 +1,21 @@
#!/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=systemd
ynh_systemctl --service=$app --action=stop --log_path=systemd
#=================================================
# 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
#=================================================
# SPECIFIC MODIFICATIONS
@ -31,28 +23,26 @@ ynh_change_url_nginx_config
# CONFIGURE HEDGEDOC
#=================================================
ynh_backup_if_checksum_is_different --file="$install_dir/config.json"
ynh_backup_if_checksum_is_different "$install_dir/config.json"
domain=$new_domain
url_path=${new_path#/}
ynh_add_config --template="../conf/config.json.example" --destination="$install_dir/config.json"
ynh_config_add --template="config.json.example" --destination="$install_dir/config.json"
chmod 400 "$install_dir/config.json"
chown $app:$app "$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..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="HTTP Server listening"
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="HTTP Server listening"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -23,24 +17,24 @@ require_free_url_authentication=false
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set --app=$app --key=allow_anonymous --value=$allow_anonymous
ynh_app_setting_set --app=$app --key=allow_email_registration --value=$allow_email_registration
ynh_app_setting_set --app=$app --key=allow_free_url --value=$allow_free_url
ynh_app_setting_set --app=$app --key=require_free_url_authentication --value=$require_free_url_authentication
ynh_app_setting_set --app=$app --key=allow_anonymous_edits --value=$allow_anonymous_edits
ynh_app_setting_set --key=allow_anonymous --value=$allow_anonymous
ynh_app_setting_set --key=allow_email_registration --value=$allow_email_registration
ynh_app_setting_set --key=allow_free_url --value=$allow_free_url
ynh_app_setting_set --key=require_free_url_authentication --value=$require_free_url_authentication
ynh_app_setting_set --key=allow_anonymous_edits --value=$allow_anonymous_edits
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=20
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
ynh_setup_source --dest_dir=$install_dir
@ -51,11 +45,11 @@ chown -R $app:www-data "$install_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
ynh_script_progression "Adding system configurations related to $app..."
ynh_add_nginx_config
ynh_config_add_nginx
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add $app --description="Collaborative Markdown editor" --log="/var/log/$app/$app.log"
@ -64,21 +58,21 @@ yunohost service add $app --description="Collaborative Markdown editor" --log="/
#==============================================
# INSTALL HEDGEDOC
#==============================================
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=10
ynh_script_progression "Building $app... (this will take some time and resources!)"
pushd "$install_dir"
ynh_use_nodejs
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn workspaces focus --production
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn cache clean
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn workspaces focus --production
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn cache clean
popd
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..." --weight=1
ynh_script_progression "Updating configuration..."
url_path=${path#/}
ynh_add_config --template="config.json.example" --destination="$install_dir/config.json"
ynh_config_add --template="config.json.example" --destination="$install_dir/config.json"
chmod 600 "$install_dir/config.json"
chown $app:$app "$install_dir/config.json"
@ -86,13 +80,13 @@ chown $app:$app "$install_dir/config.json"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="HTTP Server listening"
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="HTTP Server listening"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -1,36 +1,31 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
# REMOVE SYSTEMD SERVICE
# REMOVE SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
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..." --weight=1
ynh_script_progression "Removing $app service..."
yunohost service remove $app
fi
ynh_remove_systemd_config
ynh_config_remove_systemd
ynh_remove_nodejs
ynh_nodejs_remove
ynh_remove_nginx_config
ynh_config_remove_nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -1,20 +1,14 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring HedgeDoc main directory..." --weight=10
ynh_script_progression "Restoring HedgeDoc 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"
@ -24,26 +18,26 @@ chown -R $app:www-data "$install_dir"
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=6
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 system configurations related to $app..." --weight=1
ynh_script_progression "Restoring system configurations related to $app..."
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="Collaborative Markdown editor" --log="/var/log/$app/$app.log"
@ -51,14 +45,14 @@ yunohost service add $app --description="Collaborative Markdown editor" --log="/
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_script_progression "Reloading NGINX web server and $app's service..."
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="HTTP Server listening"
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="HTTP Server listening"
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"

View file

@ -1,57 +1,54 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
ynh_script_progression "Ensuring downward compatibility..."
# FIXME: maybe replace with: ynh_app_setting_set_default --key=allow_anonymous --value="false"
if [ -z "${allow_anonymous:-}" ]; then
allow_anonymous="false"
ynh_app_setting_set --app=$app --key=allow_anonymous --value=$allow_anonymous
ynh_app_setting_set --key=allow_anonymous --value=$allow_anonymous
fi
# FIXME: maybe replace with: ynh_app_setting_set_default --key=allow_anonymous_edits --value="false"
if [ -z "${allow_anonymous_edits:-}" ]; then
allow_anonymous_edits="false"
ynh_app_setting_set --app=$app --key=allow_anonymous_edits --value=$allow_anonymous_edits
ynh_app_setting_set --key=allow_anonymous_edits --value=$allow_anonymous_edits
fi
# FIXME: maybe replace with: ynh_app_setting_set_default --key=allow_email_registration --value="false"
if [ -z "${allow_email_registration:-}" ]; then
allow_email_registration="false"
ynh_app_setting_set --app=$app --key=allow_email_registration --value=$allow_email_registration
ynh_app_setting_set --key=allow_email_registration --value=$allow_email_registration
fi
# FIXME: maybe replace with: ynh_app_setting_set_default --key=allow_free_url --value="false"
if [ -z "${allow_free_url:-}" ]; then
allow_free_url="false"
ynh_app_setting_set --app=$app --key=allow_free_url --value=$allow_free_url
ynh_app_setting_set --key=allow_free_url --value=$allow_free_url
fi
# FIXME: maybe replace with: ynh_app_setting_set_default --key=require_free_url_authentication --value="false"
if [ -z "${require_free_url_authentication:-}" ]; then
require_free_url_authentication="false"
ynh_app_setting_set --app=$app --key=require_free_url_authentication --value=$require_free_url_authentication
ynh_app_setting_set --key=require_free_url_authentication --value=$require_free_url_authentication
fi
#=================================================
# 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=10
ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir=$install_dir --keep="config.json"
@ -62,35 +59,35 @@ chown -R $app:www-data "$install_dir"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_script_progression "Upgrading system configurations related to $app..."
ynh_add_nginx_config
ynh_config_add_nginx
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_nodejs_install
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add $app --description="Collaborative Markdown editor" --log="/var/log/$app/$app.log"
#==============================================
# INSTALL HEDGEDOC
#==============================================
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=10
ynh_script_progression "Building $app... (this will take some time and resources!)"
pushd "$install_dir"
ynh_secure_remove /usr/local/share/.cache/yarn
ynh_use_nodejs
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn workspaces focus --production
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn cache clean
ynh_safe_rm /usr/local/share/.cache/yarn
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn workspaces focus --production
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn cache clean
popd
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..." --weight=1
ynh_script_progression "Updating configuration..."
url_path=${path#/}
ynh_add_config --template="config.json.example" --destination="$install_dir/config.json"
ynh_config_add --template="config.json.example" --destination="$install_dir/config.json"
chmod 600 "$install_dir/config.json"
chown $app:$app "$install_dir/config.json"
@ -98,12 +95,12 @@ chown $app:$app "$install_dir/config.json"
#=================================================
# 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 --line_match="HTTP Server listening"
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="HTTP Server listening"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"