#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source .fonctions source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) 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) abiword=$(ynh_app_setting_get $app abiword) db_name=$(ynh_app_setting_get $app db_name) #================================================= # 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_make_valid_dbid $app) ynh_app_setting_set $app db_name $db_name fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= BACKUP_BEFORE_UPGRADE # Backup the current version of the app ynh_clean_setup () { BACKUP_FAIL_UPGRADE # restore it if the upgrade fails } ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. #================================================= # STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path #================================================= # NGINX CONFIGURATION #================================================= # Copie le fichier de config nginx sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Modifie les variables dans le fichier de configuration nginx sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf #================================================= # SPECIFIC UPGRADE #================================================= # CONFIGURE ETHERPAD #================================================= # Copie ou modification d'un fichier de config CHECK_MD5_CONFIG "settings.json" "$final_path/settings.json" # Créé un backup du fichier de config si il a été modifié. CHECK_MD5_CONFIG "credentials.json" "$final_path/credentials.json" # Créé un backup du fichier de config si il a été modifié. sudo cp ../conf/settings.json "$final_path/settings.json" sudo cp ../conf/credentials.json "$final_path/credentials.json" sudo sed -i "s/__PORT__/$port/g" "$final_path/settings.json" sudo sed -i "s/__DB_USER__/$app/g" "$final_path/credentials.json" db_pwd=$(ynh_app_setting_get $app mysqlpwd) password=$(ynh_app_setting_get $app password) sudo sed -i "s/__DB_PWD__/$db_pwd/g" "$final_path/credentials.json" sudo sed -i "s/__ADMIN__/$admin/g" "$final_path/credentials.json" sudo sed -i "s/__PASSWD__/$password/g" "$final_path/credentials.json" if [ "$abiword" -eq 1 ] then abiword_path=`which abiword` # Récupère l'emplacement de l'exécutable de abiword sudo sed -i "s@\"abiword\" : null@\"abiword\" : \"$abiword_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 sudo sed -i "s/__LANGUAGE__/$language/g" "$final_path/settings.json" STORE_MD5_CONFIG "settings.json" "$final_path/settings.json" # Réenregistre la somme de contrôle du fichier de config STORE_MD5_CONFIG "credentials.json" "$final_path/credentials.json" # Réenregistre la somme de contrôle du fichier de config #================================================= # CREATE DEDICATED USER #================================================= ynh_system_user_create $app # Create the dedicated user, if not exist #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Les fichiers appartiennent à etherpad sudo chown -R $app: $final_path sudo chmod 600 "$final_path/credentials.json" # Restreint l'accès à credentials.json sudo chown $app -R /var/log/$app/etherpad.log #================================================= # SETUP LOGROTATE #================================================= ynh_use_logrotate #================================================= # SETUP SYSTEMD #================================================= # Mise en place du script systemd sudo systemctl stop $app sudo cp ../conf/etherpad.service /etc/systemd/system/$app.service sudo chown root: /etc/systemd/system/$app.service sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/$app.service sudo sed -i "s@__APP__@$app@g" /etc/systemd/system/$app.service ## Démarrage auto du service sudo systemctl enable $app #================================================= # SOME HACKS #================================================= 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. sudo sed -i "$mod_line s@div>@&\n\t