#!/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 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 # Fixe is_public en booléen 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 # Si db_name n'est pas renseigné dans app setting db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name fi if [ -z $abiword ]; then # Si abiword n'est pas renseigné dans app setting abiword=0 ynh_app_setting_set $app abiword $abiword fi if [ -n $abiword ]; then # Si abiword est renseigné dans app setting 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 # Si export n'est pas renseigné dans app setting export=none ynh_app_setting_set $app export $export fi if [ -z $mypads ]; then # Si mypads n'est pas renseigné dans app setting mypads=1 ynh_app_setting_set $app mypads $mypads fi if [ -z $useldap ]; then # If useldap doesn't exist yet in settings.yml useldap=0 ynh_app_setting_set $app useldap $useldap fi if [ -z $path_url ]; then # Si path_url n'est pas renseigné dans app setting 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 () { # Nettoyage 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" # Télécharge la source, décompresse et copie dans $final_path #================================================= # 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 #================================================= npm cache clean npm update #================================================= # SPECIFIC UPGRADE #================================================= # CONFIGURE ETHERPAD #================================================= # Copie ou modification d'un fichier de config ynh_backup_if_checksum_is_different "$final_path/settings.json" # Créé un backup du fichier de config si il a été modifié. ynh_backup_if_checksum_is_different "$final_path/credentials.json" # Créé un backup du fichier de config si il a été modifié. 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` # Récupère l'emplacement de l'exécutable de abiword 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` # Récupère l'emplacement de l'exécutable de abiword 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 # En cas d'upgrade d'une version ne gérant pas la langue, la langue est anglais par défaut 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" # Réenregistre la somme de contrôle du fichier de config ynh_store_file_checksum "$final_path/credentials.json" # Réenregistre la somme de contrôle du fichier de config #================================================= # CREATE DEDICATED USER #================================================= ynh_system_user_create $app $final_path # Create the dedicated user, if not exist #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Les fichiers appartiennent à etherpad chown -R $app: $final_path chmod 600 "$final_path/credentials.json" # Restreint l'accès à 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" # La page d'admin etherpad ne supporte pas le sso... fi #================================================= # RELOAD NGINX #================================================= systemctl reload nginx #================================================= # CHECK ETHERPAD STARTING #================================================= # Wait for etherpad fully started ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120"