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

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-30 22:52:55 +02:00 committed by Alexandre Aubin
parent 46d40f422e
commit febf5a2059
10 changed files with 168 additions and 250 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
*.swp
*~
Notes
*.sw[op]
.DS_Store

View file

@ -8,8 +8,8 @@ User=__APP__
Group=__APP__
WorkingDirectory=__INSTALL_DIR__/
Environment=ETHERPAD_PRODUCTION=true
Environment="__YNH_NODE_LOAD_PATH__"
ExecStart=__YNH_NODE__ __INSTALL_DIR__/src/node/server.js
Environment="PATH=__PATH_WITH_NODEJS__"
ExecStart=__NODEJS_DIR__/node __INSTALL_DIR__/src/node/server.js
StandardOutput=append:/var/log/__APP__/etherpad.log
StandardError=inherit
Restart=always

View file

@ -17,7 +17,8 @@ admindoc = "http://etherpad.org/doc/v1.9.0"
code = "https://github.com/ether/etherpad-lite"
[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = ["arm64", "amd64"]
multi_instance = true
ldap = false

View file

@ -1,7 +1,7 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
# NodeJS version
@ -24,17 +24,9 @@ ep_spellcheck_version=0.0.43
ep_subscript_and_superscript_version=0.2.47
ep_font_size_version=0.4.44
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
ynh_maintenance_mode_ON () {
mkdir -p /var/www/html/
# Create an html to serve as maintenance notice
echo "<!DOCTYPE html>
<html>
@ -94,7 +86,3 @@ ynh_maintenance_mode_OFF () {
systemctl reload nginx
}
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,38 +1,29 @@
#!/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"
#=================================================
# BACKUP FAIL2BAN CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
ynh_backup "/etc/fail2ban/jail.d/$app.conf"
ynh_backup "/etc/fail2ban/filter.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
@ -40,23 +31,23 @@ ynh_backup --src_path="/etc/fail2ban/filter.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 MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_print_info "Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
ynh_mysql_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,12 +1,6 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
if ynh_in_ci_tests; then
sleep 60
fi
@ -19,24 +13,20 @@ source /usr/share/yunohost/helpers
ynh_maintenance_mode_ON
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=3
ynh_script_progression "Updating NGINX web server configuration..."
ynh_change_url_nginx_config
ynh_config_change_url_nginx
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=10
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
ynh_systemctl --service=$app --action=restart --wait_until="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
#=================================================
# DEACTIVE MAINTENANCE MODE
@ -48,4 +38,4 @@ ynh_maintenance_mode_OFF
# 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,6 +1,6 @@
#!/bin/bash
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
if ynh_in_ci_tests; then
sleep 10
fi
@ -8,65 +8,21 @@ source _common.sh
source /usr/share/yunohost/helpers
# Save the passord (not saved automatically by the core)
ynh_app_setting_set --app=$app --key=password --value="$password"
ynh_app_setting_set --key=password --value="$password"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing nodejs..." --weight=50
ynh_script_progression "Installing nodejs..."
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
ynh_nodejs_install
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Initializing MySQL database..." --weight=1
ynh_script_progression "Initializing MySQL database..."
echo "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=4
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
# Create log directory
mkdir -p /var/log/$app
touch /var/log/$app/etherpad.log
chown $app -R /var/log/$app
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Configure etherpad..."
abiword_path="null"
soffice_path="null"
if [[ "$export" == "abiword" ]]
then
abiword_path="\"$(which abiword)\""
echo "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | ynh_mysql_db_shell abiword_path="\"$(which abiword)\""
elif [[ "$export" == "libreoffice" ]]
then
soffice_path="\"$(which soffice)\""
@ -81,56 +37,56 @@ fi
# Calculate and store the config file checksum into the app settings
ynh_add_config --template="settings.json" --destination="$install_dir/settings.json"
ynh_add_config --template="credentials.json" --destination="$install_dir/credentials.json"
ynh_config_add --template="settings.json" --destination="$install_dir/settings.json"
ynh_config_add --template="credentials.json" --destination="$install_dir/credentials.json"
chmod 600 "$install_dir/settings.json"
chown $app:$app "$install_dir/settings.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 600 "$install_dir/settings.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/settings.json"
chmod 600 "$install_dir/credentials.json"
chown $app:$app "$install_dir/credentials.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 600 "$install_dir/credentials.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/credentials.json"
#=================================================
# INSTALL ETHERPAD'S PLUGINS
#=================================================
ynh_script_progression --message="Installing Etherpad plugins..." --weight=90
ynh_script_progression "Installing Etherpad plugins..."
pushd "$install_dir"
# Add Left/Center/Right/Justify to lines of text in a pad
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_align@${ep_align_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_align@${ep_align_version}
# Framapad - Adds author names to span titles
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_author_hover@${ep_author_hover_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_author_hover@${ep_author_hover_version}
# Framapad - Adds comments on sidebar and link it to the text.
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_comments_page@${ep_comments_page_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_comments_page@${ep_comments_page_version}
# Framapad - Displays paragraphs, sentences, words and characters counts.
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_countable@${ep_countable_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_countable@${ep_countable_version}
# Framapad - Delete pads which were never edited
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_delete_empty_pads@${ep_delete_empty_pads_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_delete_empty_pads@${ep_delete_empty_pads_version}
# Framapad - Apply colors to fonts
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_font_color@${ep_font_color_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_font_color@${ep_font_color_version}
# Framapad - Adds heading support to Etherpad Lite.
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_headings2@${ep_headings2_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_headings2@${ep_headings2_version}
# Framapad - Edit and Export as Markdown in Etherpad
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_markdown@${ep_markdown_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_markdown@${ep_markdown_version}
if [ $mypads -eq 1 ]; then
# Framapad - Groups and private pads for Etherpad
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_mypads@${mypads_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_mypads@${mypads_version}
fi
# Framapad - Add support to do 'Spell checking'
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_spellcheck@${ep_spellcheck_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_spellcheck@${ep_spellcheck_version}
# Framapad - Add support for Subscript and Superscript
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_subscript_and_superscript@${ep_subscript_and_superscript_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_subscript_and_superscript@${ep_subscript_and_superscript_version}
# Framapad - User Pad Contents font size can be set in settings, this does not effect other peoples views
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_font_size@${ep_font_size_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_font_size@${ep_font_size_version}
popd
#=================================================
# INSTALL ETHERPAD
#=================================================
ynh_script_progression --message="Installing Etherpad..." --weight=90
ynh_script_progression "Installing Etherpad..."
pushd $install_dir
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH ETHERPAD_PRODUCTION=true src/bin/installDeps.sh
ynh_hide_warnings ynh_exec_as_app node_load_PATH ETHERPAD_PRODUCTION=true src/bin/installDeps.sh
popd
#=================================================
@ -139,14 +95,14 @@ popd
if [ $mypads -eq 1 ]
then
ynh_script_progression --message="Tweaking mypad configuration..." --weight=1
ynh_script_progression "Tweaking mypad configuration..."
# Add a link to Etherpad to allow anonymous pads creation from MyPads.
ynh_replace_string --match_string="^ *\"DESCRIPTION\": .*</ul>" --replace_string="&<a href=../>Pads anonymes</a>" --target_file=$install_dir/node_modules/ep_mypads/static/l10n/fr.json
ynh_replace_string --match_string="^ *\"DESCRIPTION\": .*</ul>" --replace_string="&<a href=../>Anonymous pads</a>" --target_file=$install_dir/node_modules/ep_mypads/static/l10n/en.json
ynh_replace --match="^ *\"DESCRIPTION\": .*</ul>" --replace="&<a href=../>Pads anonymes</a>" --file=$install_dir/node_modules/ep_mypads/static/l10n/fr.json
ynh_replace --match="^ *\"DESCRIPTION\": .*</ul>" --replace="&<a href=../>Anonymous pads</a>" --file=$install_dir/node_modules/ep_mypads/static/l10n/en.json
# And a link to etherpad admin from Mypads.
ynh_replace_string --match_string="^ *\"FOOTER\": .*2.0" --replace_string="& | <a href='../admin'>Etherpad admin</a>" --target_file=$install_dir/node_modules/ep_mypads/static/l10n/en.json
ynh_replace_string --match_string="^ *\"FOOTER\": .*2.0" --replace_string="& | <a href='../admin'>Etherpad admin</a>" --target_file=$install_dir/node_modules/ep_mypads/static/l10n/fr.json
ynh_replace --match="^ *\"FOOTER\": .*2.0" --replace="& | <a href='../admin'>Etherpad admin</a>" --file=$install_dir/node_modules/ep_mypads/static/l10n/en.json
ynh_replace --match="^ *\"FOOTER\": .*2.0" --replace="& | <a href='../admin'>Etherpad admin</a>" --file=$install_dir/node_modules/ep_mypads/static/l10n/fr.json
# Find the /div just after the field to open a pad in order to add a link to MyPads plugin.
sed -i '157i<center><br><font size="4"><a href="./mypads/" style="text-decoration: none; color: #555">MyPads</a></font></center>' $install_dir/src/templates/index.html
@ -155,44 +111,44 @@ fi
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring systemd service..." --weight=4
ynh_script_progression "Configuring systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd
# Intgrate in YunoHost
yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/etherpad.log"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --specific_user=$app/$app
ynh_config_add_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting systemd service..." --weight=20
ynh_script_progression "Starting systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
ynh_systemctl --service=$app --action=restart --wait_until="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
if [ $mypads -eq 1 ]
then
ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="../conf/lang_mypads.sql"
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/lang_mypads.sql"
ynh_replace --match="__LANGUAGE__" --replace="$language" --file="../conf/lang_mypads.sql"
ynh_mysql_db_shell < "../conf/lang_mypads.sql"
# Wait for etherpad to be fully started
ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
ynh_systemctl --action=restart --wait_until="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
fi
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --weight=13
ynh_script_progression "Configuring Fail2Ban..."
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex="<HOST> .* .POST /mypads/api/auth/login HTTP/1.1. 400" --max_retry=5
ynh_config_add_fail2ban --logpath="/var/log/nginx/$domain-access.log" --failregex="<HOST> .* .POST /mypads/api/auth/login HTTP/1.1. 400"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -1,47 +1,42 @@
#!/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 integration..." --weight=2
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
ynh_remove_nodejs
ynh_nodejs_remove
# Remove the dedicated Fail2Ban config
ynh_remove_fail2ban_config
ynh_config_remove_fail2ban
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
#REMOVEME? (Apps should not remove their log dir during remove ... this should only happen if --purge is used, and be handled by the core...) ynh_safe_rm "/var/log/$app"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -7,67 +7,62 @@ source /usr/share/yunohost/helpers
# RESTORE THE APP MAIN DIR
#=================================================
#
ynh_script_progression --message="Restoring the app main directory..." --weight=5
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:$app "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 600 "$install_dir/settings.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/settings.json"
chmod 600 "$install_dir/settings.json"
chown $app:$app "$install_dir/settings.json"
chmod 600 "$install_dir/credentials.json"
chown $app:$app "$install_dir/credentials.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 600 "$install_dir/credentials.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/credentials.json"
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..."
ynh_script_progression "Restoring system configurations related to $app..."
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
ynh_nodejs_install
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
mkdir -p /var/log/$app
touch /var/log/$app/etherpad.log
chown $app -R /var/log/$app
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app -R /var/log/$app
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
ynh_restore "/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore "/etc/logrotate.d/$app"
yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/etherpad.log"
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
ynh_restore "/etc/fail2ban/jail.d/$app.conf"
ynh_restore "/etc/fail2ban/filter.d/$app.conf"
ynh_systemctl --action=restart --service=fail2ban
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=5
ynh_script_progression "Restoring the MySQL database..."
echo "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
echo "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | ynh_mysql_db_shell < ./db.sql
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..."
ynh_script_progression "Reloading NGINX web server and $app's service..."
ynh_systemd_action --service_name=$app --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
ynh_systemctl --service=$app --action=restart --wait_until="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
ynh_systemd_action --action=reload --service_name=nginx
ynh_systemctl --action=reload --service=nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -3,112 +3,110 @@
source _common.sh
source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activating maintenance mode..." --weight=2
ynh_script_progression "Activating maintenance mode..."
# Wait for etherpad to be fully started # (... but why ???)
ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
ynh_systemctl --action=restart --wait_until="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=3
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
ynh_systemctl --service=$app --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
ynh_script_progression "Ensuring downward compatibility..."
if [ -z "${language:-}" ]; then
# If upgrading from a version which doesn't support translations, set language to English by default
language=en
ynh_app_setting_set --app=$app --key=language --value=$language
ynh_app_setting_set --key=language --value=$language
fi
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=export --value=none
if [ -z "${export:-}" ]; then
export=none
ynh_app_setting_set --app=$app --key=export --value=$export
ynh_app_setting_set --key=export --value=$export
fi
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=mypads --value=1
if [ -z "${mypads:-}" ]; then
mypads=1
ynh_app_setting_set --app=$app --key=mypads --value=$mypads
ynh_app_setting_set --key=mypads --value=$mypads
fi
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=useldap --value=0
if [ -z "${useldap:-}" ]; then
useldap=0
ynh_app_setting_set --app=$app --key=useldap --value=$useldap
ynh_app_setting_set --key=useldap --value=$useldap
fi
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=path --value="/"
if [ -z "${path:-}" ]; then
path="/"
ynh_app_setting_set --app=$app --key=path --value=$path
ynh_app_setting_set --key=path --value=$path
fi
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=password --value=$(ynh_string_random --length=32)
if [ -z "${password:-}" ]; then
password=$(ynh_string_random --length=32)
ynh_app_setting_set --app=$app --key=password --value="$password"
ynh_app_setting_set --key=password --value="$password"
fi
# Support full Unicode in MySQL databases
ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \
ynh_mysql_db_shell \
<<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed
if ynh_app_upstream_version_changed
then
ynh_script_progression --message="Upgrading source files..." --weight=4
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="settings.json credentials.json"
fi
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_script_progression "Upgrading dependencies..."
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
ynh_nodejs_install
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
ynh_script_progression "Upgrading NGINX web server configuration..."
ynh_add_nginx_config
ynh_config_add_nginx
#=================================================
# SPECIFIC UPGRADE
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
ynh_script_progression "Configuring log rotation..."
# Create log directory
chown $app -R /var/log/$app
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app -R /var/log/$app
#=================================================
# CONFIGURE ETHERPAD
#=================================================
ynh_script_progression --message="Configure etherpad..."
ynh_script_progression "Configure etherpad..."
abiword_path="null"
soffice_path="null"
@ -130,76 +128,78 @@ fi
# Calculate and store the config file checksum into the app settings
ynh_add_config --template="settings.json" --destination="$install_dir/settings.json"
ynh_add_config --template="credentials.json" --destination="$install_dir/credentials.json"
ynh_config_add --template="settings.json" --destination="$install_dir/settings.json"
ynh_config_add --template="credentials.json" --destination="$install_dir/credentials.json"
chmod 600 "$install_dir/settings.json"
chown $app:$app "$install_dir/settings.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 600 "$install_dir/settings.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/settings.json"
chmod 600 "$install_dir/credentials.json"
chown $app:$app "$install_dir/credentials.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 600 "$install_dir/credentials.json"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/credentials.json"
#=================================================
# INSTALL ETHERPAD'S PLUGINS
#=================================================
# If upgrading from an old version and table of content is there, remove it
if ynh_compare_current_package_version --comparison lt --version 1.9.1~ynh3
if ynh_app_upgrading_from_version_before 1.9.1~ynh3
then
pushd "$install_dir"
if ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm ls 2>/dev/null | grep -q ep_table_of_contents
if ynh_exec_as_app node_load_PATH npm ls 2>/dev/null | grep -q ep_table_of_contents
then
ynh_script_progression --message="Uninstalling ep_table_of_contents..." --weight=2
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm uninstall ep_table_of_contents
ynh_script_progression "Uninstalling ep_table_of_contents..."
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm uninstall ep_table_of_contents
fi
popd
fi
ynh_script_progression --message="Installing Etherpad plugins..." --weight=10
ynh_script_progression "Installing Etherpad plugins..."
pushd "$install_dir"
# Add Left/Center/Right/Justify to lines of text in a pad
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_align@${ep_align_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_align@${ep_align_version}
# Framapad - Adds author names to span titles
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_author_hover@${ep_author_hover_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_author_hover@${ep_author_hover_version}
# Framapad - Adds comments on sidebar and link it to the text.
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_comments_page@${ep_comments_page_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_comments_page@${ep_comments_page_version}
# Framapad - Displays paragraphs, sentences, words and characters counts.
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_countable@${ep_countable_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_countable@${ep_countable_version}
# Framapad - Delete pads which were never edited
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_delete_empty_pads@${ep_delete_empty_pads_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_delete_empty_pads@${ep_delete_empty_pads_version}
# Framapad - Apply colors to fonts
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_font_color@${ep_font_color_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_font_color@${ep_font_color_version}
# Framapad - Adds heading support to Etherpad Lite.
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_headings2@${ep_headings2_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_headings2@${ep_headings2_version}
# Framapad - Edit and Export as Markdown in Etherpad
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_markdown@${ep_markdown_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_markdown@${ep_markdown_version}
if [ $mypads -eq 1 ]; then
# Framapad - Groups and private pads for Etherpad
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_mypads@${mypads_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_mypads@${mypads_version}
fi
# Framapad - Add support to do 'Spell checking'
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_spellcheck@${ep_spellcheck_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_spellcheck@${ep_spellcheck_version}
# Framapad - Add support for Subscript and Superscript
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_subscript_and_superscript@${ep_subscript_and_superscript_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_subscript_and_superscript@${ep_subscript_and_superscript_version}
# Framapad - User Pad Contents font size can be set in settings, this does not effect other peoples views
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_font_size@${ep_font_size_version}
ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install --no-save ep_font_size@${ep_font_size_version}
popd
#=================================================
# UPGRADE NPM MODULES
#=================================================
ynh_script_progression --message="Upgrading Etherpad..." --weight=10
ynh_script_progression "Upgrading Etherpad..."
pushd $install_dir
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH ETHERPAD_PRODUCTION=true src/bin/installDeps.sh
ynh_hide_warnings ynh_exec_as_app node_load_PATH ETHERPAD_PRODUCTION=true src/bin/installDeps.sh
popd
#=================================================
# ADD MYPADS LINK
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] && [ $mypads -eq 1 ]
# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed
if ynh_app_upstream_version_changed && [ $mypads -eq 1 ]
then
# Find the /div just after the field to open a pad in order to add a link to MyPads plugin.
sed -i '157i<center><br><font size="4"><a href="./mypads/" style="text-decoration: none; color: #555">MyPads</a></font></center>' $install_dir/src/templates/index.html
@ -208,35 +208,35 @@ fi
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring systemd service..." --weight=2
ynh_script_progression "Configuring systemd service..."
ynh_add_systemd_config
ynh_config_add_systemd
# Integrate in YunoHost
yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/etherpad.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append --specific_user=$app/$app
ynh_config_add_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting systemd service..." --weight=9
ynh_script_progression "Starting systemd service..."
ynh_systemd_action --service_name=$app --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
ynh_systemctl --service=$app --action=restart --wait_until="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=8
ynh_script_progression "Reconfiguring Fail2Ban..."
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex="<HOST> .* .POST /mypads/api/auth/login HTTP/1.1. 400" --max_retry=5
ynh_config_add_fail2ban --logpath="/var/log/nginx/$domain-access.log" --failregex="<HOST> .* .POST /mypads/api/auth/login HTTP/1.1. 400"
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Disabling maintenance mode..." --weight=5
ynh_script_progression "Disabling maintenance mode..."
ynh_maintenance_mode_OFF
@ -244,4 +244,4 @@ ynh_maintenance_mode_OFF
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"