#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers # Load common variables for all scripts. source _variables #================================================= # LOAD SETTINGS #================================================= app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) admin=$(ynh_app_setting_get $app admin) language=$(ynh_app_setting_get $app language) is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) port=$(ynh_app_setting_get $app port) export=$(ynh_app_setting_get $app export) db_name=$(ynh_app_setting_get $app db_name) mypads=$(ynh_app_setting_get $app mypads) useldap=$(ynh_app_setting_get $app useldap) #================================================= # CHECK VERSION #================================================= # Wait for etherpad to be fully started ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" ynh_abort_if_up_to_date #================================================= # FIX OLD THINGS #================================================= if [ "$is_public" = "Yes" ]; then ynh_app_setting_set $app is_public 1 # Convert is_public to boolean is_public=1 elif [ "$is_public" = "No" ]; then ynh_app_setting_set $app is_public 0 is_public=0 fi if [ -z $db_name ]; then # If db_name setting doesn't exist db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name fi if [ -z $abiword ]; then # If abiword setting doesn't exist abiword=0 ynh_app_setting_set $app abiword $abiword fi if [ -n $abiword ]; then # If abiword setting exists if [ $abiword -eq 1 ]; then export=abiword fi ynh_app_setting_set $app export $export ynh_app_setting_delete $app abiword fi if [ -z $export ]; then # If export setting doesn't exist export=none ynh_app_setting_set $app export $export fi if [ -z $mypads ]; then # If mypads setting doesn't exist mypads=1 ynh_app_setting_set $app mypads $mypads fi if [ -z $useldap ]; then # If useldap setting doesn't exist useldap=0 ynh_app_setting_set $app useldap $useldap fi if [ -z $path_url ]; then # If path_url setting doesn't exist path_url="/" ynh_app_setting_set $app path $path_url fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { # Cleanup installatioNettoyage des résidus d'installation non pris en charge par le script remove. 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 #================================================= # STOP ETHERPAD #================================================= systemctl stop $app #================================================= # STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_setup_source "$final_path" # Download, check integrity and uncompress the source from app.src #================================================= # NGINX CONFIGURATION #================================================= if [ "$path_url" != "/" ] then ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" fi ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf" ynh_add_nginx_config #================================================= # UPGRADE NODEJS #================================================= # Remove the old nvm helper. if [ -d /opt/nvm ] then ynh_secure_remove "/opt/nvm" sed --in-place "/NVM_DIR/d" /root/.bashrc fi ynh_install_nodejs $nodejs_version #================================================= # UPGRADE NPM MODULES #================================================= # Update the main modules of etherpad (cd "$final_path/src" npm cache clean ynh_exec_warn_less npm update) # Then update the additionnal modules while read node_module do echo "Update $node_module" (cd "$final_path/node_modules/$node_module" npm cache clean ynh_exec_warn_less npm update) done <<< "$(ls -1 "$final_path/node_modules")" #================================================= # SPECIFIC UPGRADE #================================================= # CONFIGURE ETHERPAD #================================================= ynh_backup_if_checksum_is_different "$final_path/settings.json" # Verify the checksum and backup the file if it's different ynh_backup_if_checksum_is_different "$final_path/credentials.json" # Verify the checksum and backup the file if it's different cp ../conf/settings.json "$final_path/settings.json" cp ../conf/credentials.json "$final_path/credentials.json" ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" ynh_replace_string "__DB_USER__" "$app" "$final_path/credentials.json" db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" ynh_print_OFF; ynh_replace_special_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON if [ "$export" = "abiword" ] then abiword_path=`which abiword` # Get abiword binary path ynh_replace_string "\"abiword\" : null" "\"abiword\" : \"$abiword_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad elif [ "$export" = "libreoffice" ] then soffice_path=`which soffice` # Get soffice binary path ynh_replace_string "\"soffice\" : null" "\"soffice\" : \"$soffice_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad fi if test -z $language; then language=en # If upgrading from a version which doesn't support translations, set language to English by default ynh_app_setting_set $app language $language fi ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" # Use ldap for mypads if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] then ynh_replace_string "//noldap" "" "$final_path/settings.json" fi ynh_store_file_checksum "$final_path/settings.json" # Recalculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/credentials.json" # Recalculate and store the config file checksum into the app settings #================================================= # CREATE DEDICATED USER #================================================= ynh_system_user_create $app $final_path # Create the dedicated user, if it doesn't exist #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Set files ownership to etherpad chown -R $app: $final_path chmod 600 "$final_path/credentials.json" # Restrict access to credentials.json chown $app -R /var/log/$app/etherpad.log #================================================= # UPGRADE FAIL2BAN #================================================= ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" " .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" 5 #================================================= # SETUP LOGROTATE #================================================= ynh_use_logrotate --non-append #================================================= # SETUP SYSTEMD #================================================= ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" ynh_add_systemd_config #================================================= # SOME HACKS #================================================= if [ $mypads -eq 1 ] then mod_line=$(grep -nA5 "index.createOpenPad" $final_path/src/templates/index.html | grep "" | cut -d '-' -f 1) # Recherche le /div situé sous le champs d'ouverture de pad. sed -i "$mod_line s@div>@&\n\t

Mypads
@" $final_path/src/templates/index.html # Pour ajouter un lien vers le plugin mypads depuis la page d'Etherpad. fi #================================================= # SETUP SSOWAT #================================================= # Make app public if necessary if [ $is_public -eq 1 ]; then ynh_app_setting_set $app skipped_uris "/" else ynh_app_setting_set $app skipped_uris "/admin" # etherpad admin page doesn't support SSO... fi #================================================= # RELOAD NGINX #================================================= systemctl reload nginx #================================================= # CHECK ETHERPAD STARTING #================================================= # Wait for etherpad to be fully started ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120"