mirror of
https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git
synced 2024-09-03 18:36:09 +02:00
176 lines
6.7 KiB
Bash
176 lines
6.7 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
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
|
|
#=================================================
|
|
|
|
ynh_setup_source # Télécharge la source, décompresse et copie dans $final_path
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# CONFIGURE ETHERPAD
|
|
#=================================================
|
|
|
|
# Copie ou modification d'un fichier de config
|
|
ynh_compare_checksum_config "$final_path/settings.json" # Créé un backup du fichier de config si il a été modifié.
|
|
ynh_compare_checksum_config "$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"
|
|
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)
|
|
password=$(ynh_app_setting_get $app password)
|
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json"
|
|
ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json"
|
|
ynh_replace_string "__PASSWD__" "$password" "$final_path/credentials.json"
|
|
if [ "$abiword" -eq 1 ]
|
|
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
|
|
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"
|
|
ynh_store_checksum_config "$final_path/settings.json" # Réenregistre la somme de contrôle du fichier de config
|
|
ynh_store_checksum_config "$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
|
|
#=================================================
|
|
|
|
ynh_systemd_config
|
|
|
|
#=================================================
|
|
# SOME HACKS
|
|
#=================================================
|
|
|
|
mod_line=$(grep -nA5 "index.createOpenPad" $final_path/src/templates/index.html | grep "</div>" | cut -d '-' -f 1) # Recherche le /div situé sous le champs d'ouverture de pad.
|
|
sudo sed -i "$mod_line s@div>@&\n\t<center><br><font size="5"><a href="./mypads">Mypads</a></font></center>@" $final_path/src/templates/index.html # Pour ajouter un lien vers le plugin mypads depuis la page d'Etherpad.
|
|
|
|
#=================================================
|
|
# START ETHERPAD IN BACKGROUND
|
|
#=================================================
|
|
|
|
# Démarre etherpad
|
|
WARNING echo "Démarrage d'etherpad"
|
|
tempfile="$(mktemp)"
|
|
tail -f -n1 /var/log/$app/etherpad.log > "$tempfile" & # Suit le démarrage dans le log
|
|
PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan.
|
|
sudo systemctl start $app # Démarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long...
|
|
|
|
#=================================================
|
|
# 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
|
|
#=================================================
|
|
|
|
sudo systemctl reload nginx
|
|
|
|
#=================================================
|
|
# CHECK ETHERPAD STARTING
|
|
#=================================================
|
|
|
|
for i in `seq 1 60`
|
|
do # La boucle attend le démarrage d'etherpad. Ou 1 minute. Cette boucle évite simplement un 502 au début, car le démarrage est long...
|
|
if grep -q "You can access your Etherpad instance at" "$tempfile"; then
|
|
WARNING echo "Le service $app a démarré correctement."
|
|
break # Si le log annonce le démarrage d'etherpad, sort de la boucle.
|
|
fi
|
|
WARNING echo -n "."
|
|
sleep 1
|
|
done
|
|
echo ""
|
|
QUIET kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
|
|
ynh_secure_remove "$tempfile"
|