mirror of
https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git
synced 2024-09-03 18:36:09 +02:00
463 lines
18 KiB
Bash
463 lines
18 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..." --weight=20
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
language=$(ynh_app_setting_get --app=$app --key=language)
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
export=$(ynh_app_setting_get --app=$app --key=export)
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
db_user=$db_name
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
password=$(ynh_app_setting_get --app=$app --key=password)
|
|
mypads=$(ynh_app_setting_get --app=$app --key=mypads)
|
|
useldap=$(ynh_app_setting_get --app=$app --key=useldap)
|
|
overwrite_settings=$(ynh_app_setting_get --app=$app --key=overwrite_settings)
|
|
overwrite_credentials=$(ynh_app_setting_get --app=$app --key=overwrite_credentials)
|
|
overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx)
|
|
overwrite_systemd=$(ynh_app_setting_get --app=$app --key=overwrite_systemd)
|
|
|
|
# Optional parameters from config-panel feature
|
|
pad_config_nocolors=$(ynh_app_setting_get --app=$app --key=pad_config_nocolors)
|
|
pad_config_showlinenumbers=$(ynh_app_setting_get --app=$app --key=pad_config_showlinenumbers)
|
|
pad_config_chatandusers=$(ynh_app_setting_get --app=$app --key=pad_config_chatandusers)
|
|
pad_config_alwaysshowchat=$(ynh_app_setting_get --app=$app --key=pad_config_alwaysshowchat)
|
|
pad_config_show_markdown=$(ynh_app_setting_get --app=$app --key=pad_config_show_markdown)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
nh_script_progression --message="Checking version..."
|
|
|
|
# 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"
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=35
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
# Restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# ACTIVATE MAINTENANCE MODE
|
|
#=================================================
|
|
ynh_script_progression --message="Activating maintenance mode..." --weight=2
|
|
|
|
ynh_maintenance_mode_ON
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=3
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop"
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
|
|
|
|
# If db_name doesn't exist, create it
|
|
if [ -z "$db_name" ]; then
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
fi
|
|
|
|
# If abiword setting doesn't exist
|
|
if [ -z "$abiword" ]; then
|
|
abiword=0
|
|
ynh_app_setting_set --app=$app --key=abiword --value=$abiword
|
|
fi
|
|
|
|
# If abiword setting exists
|
|
if [ -n "$abiword" ]; then
|
|
if [ $abiword -eq 1 ]; then
|
|
export=abiword
|
|
fi
|
|
ynh_app_setting_set --app=$app --key=export --value=$export
|
|
ynh_app_setting_delete --app=$app --key=abiword
|
|
fi
|
|
|
|
# If export setting doesn't exist
|
|
if [ -z "$export" ]; then
|
|
export=none
|
|
ynh_app_setting_set --app=$app --key=export --value=$export
|
|
fi
|
|
|
|
# If mypads setting doesn't exist
|
|
if [ -z "$mypads" ]; then
|
|
mypads=1
|
|
ynh_app_setting_set --app=$app --key=mypads --value=$mypads
|
|
fi
|
|
|
|
# If useldap setting doesn't exist
|
|
if [ -z "$useldap" ]; then
|
|
useldap=0
|
|
ynh_app_setting_set --app=$app --key=useldap --value=$useldap
|
|
fi
|
|
|
|
# If path_url setting doesn't exist
|
|
if [ -z "$path_url" ]; then
|
|
path_url="/"
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
fi
|
|
|
|
# If overwrite_settings doesn't exist, create it
|
|
if [ -z "$overwrite_settings" ]; then
|
|
overwrite_settings=1
|
|
ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings
|
|
fi
|
|
|
|
# If overwrite_credentials doesn't exist, create it
|
|
if [ -z "$overwrite_credentials" ]; then
|
|
overwrite_credentials=1
|
|
ynh_app_setting_set --app=$app --key=overwrite_credentials --value=$overwrite_credentials
|
|
fi
|
|
|
|
# If overwrite_nginx doesn't exist, create it
|
|
if [ -z "$overwrite_nginx" ]; then
|
|
overwrite_nginx=1
|
|
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
|
|
fi
|
|
|
|
# If overwrite_systemd doesn't exist, create it
|
|
if [ -z "$overwrite_systemd" ]; then
|
|
overwrite_systemd=1
|
|
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=$overwrite_systemd
|
|
fi
|
|
|
|
# Cleaning legacy permissions
|
|
if ynh_legacy_permissions_exists; then
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
fi
|
|
|
|
if ! ynh_permission_exists --permission="admin"; then
|
|
# Create the required permissions
|
|
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
|
|
else
|
|
# Make sure the admin panel is not exposed to the SSO's authentication headers
|
|
# AFAIK there is no helper to check if that flag is up or not, so let's force it.
|
|
ynh_permission_url --permission="admin" --auth_header=false
|
|
fi
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --weight=4
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$final_path" --keep="settings.json credentials.json"
|
|
fi
|
|
|
|
chmod 750 "$final_path"
|
|
chmod -R o-rwx "$final_path"
|
|
chown -R $app:$app "$final_path"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
|
|
|
|
# Overwrite the NGINX configuration only if it's allowed
|
|
if [ $overwrite_nginx -eq 1 ]
|
|
then
|
|
ynh_add_nginx_config
|
|
fi
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=5
|
|
|
|
if [ "$export" = "abiword" ]; then
|
|
ynh_exec_warn_less ynh_install_app_dependencies $abiword_app_depencencies
|
|
elif [ "$export" = "libreoffice" ]; then
|
|
ynh_exec_warn_less ynh_install_app_dependencies $libreoffice_app_dependencies
|
|
fi
|
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
ynh_use_nodejs
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
|
|
|
# Create log directory
|
|
install_log=/var/log/$app/installation.log
|
|
touch $install_log
|
|
chown $app -R /var/log/$app
|
|
|
|
#=================================================
|
|
# CONFIGURE ETHERPAD
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Reconfiguring Etherpad..." --weight=3
|
|
|
|
# Overwrite the settings config file only if it's allowed
|
|
if [ $overwrite_settings -eq 1 ]
|
|
then
|
|
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
|
|
ynh_backup_if_checksum_is_different --file="$final_path/settings.json"
|
|
cp ../conf/settings.json "$final_path/settings.json"
|
|
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/settings.json"
|
|
|
|
if [ "$export" = "abiword" ]
|
|
then
|
|
# Get abiword binary path
|
|
abiword_path=`which abiword`
|
|
# Set the path of Abiword into Etherpad config
|
|
ynh_replace_string --match_string="\"abiword\" : null" --replace_string="\"abiword\" : \"$abiword_path\"" --target_file="$final_path/settings.json"
|
|
elif [ "$export" = "libreoffice" ]
|
|
then
|
|
# Get soffice binary path
|
|
soffice_path=`which soffice`
|
|
# Set the path of soffice into Etherpad config
|
|
ynh_replace_string --match_string="\"soffice\" : null" --replace_string="\"soffice\" : \"$soffice_path\"" --target_file="$final_path/settings.json"
|
|
fi
|
|
|
|
if test -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
|
|
fi
|
|
ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/settings.json"
|
|
|
|
# Use LDAP for MyPads
|
|
if [ $mypads -eq 1 ] && [ $useldap -eq 1 ]
|
|
then
|
|
ynh_replace_string --match_string="//noldap" --replace_string="" --target_file="$final_path/settings.json"
|
|
fi
|
|
|
|
# Optional parameters from config-panel feature
|
|
if [ -n "$pad_config_nocolors" ]; then
|
|
ynh_replace_string --match_string="\(\"noColors\" *: \).*," --replace_string="\1$pad_config_nocolors," --target_file="$final_path/settings.json"
|
|
fi
|
|
if [ -n "$pad_config_showlinenumbers" ]; then
|
|
ynh_replace_string --match_string="\(\"showLineNumbers\" *: \).*," --replace_string="\1$pad_config_showlinenumbers," --target_file="$final_path/settings.json"
|
|
fi
|
|
if [ -n "$pad_config_chatandusers" ]; then
|
|
ynh_replace_string --match_string="\(\"chatAndUsers\" *: \).*," --replace_string="\1$pad_config_chatandusers," --target_file="$final_path/settings.json"
|
|
fi
|
|
if [ -n "$pad_config_alwaysshowchat" ]; then
|
|
ynh_replace_string --match_string="\(\"alwaysShowChat\" *: \).*," --replace_string="\1$pad_config_alwaysshowchat," --target_file="$final_path/settings.json"
|
|
fi
|
|
if [ -n "$pad_config_show_markdown" ]; then
|
|
ynh_replace_string --match_string="\(\"ep_markdown_default\" *: \).*," --replace_string="\1$pad_config_show_markdown," --target_file="$final_path/settings.json"
|
|
fi
|
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
|
ynh_store_file_checksum --file="$final_path/settings.json"
|
|
fi
|
|
|
|
# Overwrite the credentials config file only if it's allowed
|
|
if [ $overwrite_credentials -eq 1 ]
|
|
then
|
|
ynh_add_config --template="../conf/credentials.json" --destination="$final_path/credentials.json"
|
|
fi
|
|
fi
|
|
|
|
chmod 600 "$final_path/credentials.json"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
|
|
|
|
# Create a dedicated systemd config
|
|
if [ $overwrite_systemd -eq 1 ]
|
|
then
|
|
ynh_add_systemd_config
|
|
fi
|
|
|
|
#=================================================
|
|
# INSTALL ETHERPAD'S PLUGINS
|
|
#=================================================
|
|
ynh_script_progression --message="Installing Etherpad plugins..." --weight=90
|
|
|
|
pushd "$final_path"
|
|
# 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}
|
|
# 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}
|
|
# 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}
|
|
# 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}
|
|
# 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}
|
|
# 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}
|
|
# 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}
|
|
# 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}
|
|
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}
|
|
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}
|
|
# 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}
|
|
# Framapad - View a table of contents for your pad
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --no-save ep_table_of_contents@${ep_table_of_contents_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}
|
|
popd
|
|
|
|
#=================================================
|
|
# UPGRADE NPM MODULES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading Etherpad..." --weight=60
|
|
|
|
pushd $final_path
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH bin/installDeps.sh
|
|
popd
|
|
|
|
#=================================================
|
|
# SOME HACKS
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ] && [ $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>' $final_path/src/templates/index.html
|
|
fi
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=2
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append --specific_user=$app/$app
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/etherpad.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=9
|
|
|
|
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"
|
|
|
|
#=================================================
|
|
# UPGRADE FAIL2BAN
|
|
#=================================================
|
|
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=8
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# DEACTIVE MAINTENANCE MODE
|
|
#=================================================
|
|
ynh_script_progression --message="Disabling maintenance mode..." --weight=5
|
|
|
|
ynh_maintenance_mode_OFF
|
|
|
|
#=================================================
|
|
# SEND A README FOR THE ADMIN
|
|
#=================================================
|
|
|
|
# Get main domain and buid the URL of the admin panel of the app.
|
|
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
|
|
|
|
# Build the changelog
|
|
# Get the value of admin_mail_html
|
|
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
|
|
admin_mail_html="${admin_mail_html:-0}"
|
|
# If a html email is required. Apply html to the changelog.
|
|
if [ "$admin_mail_html" -eq 1 ]; then
|
|
format=html
|
|
else
|
|
format=plain
|
|
fi
|
|
ynh_app_changelog --format=$format
|
|
|
|
if [ $mypads -eq 1 ]
|
|
then
|
|
Informations="You can access 2 different admin panels, for Etherpad by accessing https://$domain${path_url%/}/admin and for MyPads by accessing https://$domain${path_url%/}/mypads/?/admin."
|
|
else
|
|
Informations="You can access the admin panel by accessing https://$domain${path_url%/}/admin."
|
|
fi
|
|
|
|
echo "$Informations
|
|
You can also find a config file for Etherpad at this path /var/www/etherpad_mypads/settings.json.
|
|
|
|
If you are facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/etherpad_mypads_ynh
|
|
|
|
---
|
|
|
|
Changelog since your last upgrade:
|
|
$(cat changelog)" > mail_to_send
|
|
|
|
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type=upgrade
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|