1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git synced 2024-09-03 18:36:09 +02:00
etherpad_mypads_ynh/scripts/upgrade
2016-12-22 11:05:11 +01:00

117 lines
5.4 KiB
Bash

#!/bin/bash
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
# Source app helpers
source /usr/share/yunohost/helpers
# Récupère les infos de l'application.
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path=$(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)
abiword=$(ynh_app_setting_get $app abiword)
SETUP_SOURCE "1.6.0.tar.gz" # Télécharge la source, décompresse et copie dans $final_path
# Et 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
# 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)
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
# Configure les droits d'accès au fichiers
# Les fichiers appartiennent à etherpad
sudo chown -R $app: $final_path
sudo chmod 600 "$final_path/credentials.json" # Restreint l'accès à credentials.json
# Configuration de logrotate
sed -i "s@__APP__@$app@g" ../conf/logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/$app
# Mise en place du script systemd
sudo service $app stop
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.service
# Ajoute un lien vers etherpad pour créer des pads anonymes depuis Mypads.
# sudo sed -i "s@^ *\"DESCRIPTION\": .*</ul>@&<a href=../>Pads anonymes</a>@g" $final_path/node_modules/ep_mypads/static/l10n/fr.json
# sudo sed -i "s@^ *\"DESCRIPTION\": .*</ul>@&<a href=../>Anonymous pads</a>@g" $final_path/node_modules/ep_mypads/static/l10n/en.json
# Et un lien vers l'admin etherpad depuis Mypads.
# sudo sed -i "s@^ *\"FOOTER\": .*2.0@& | <a href='../admin'>Etherpad admin</a>@g" $final_path/node_modules/ep_mypads/static/l10n/en.json $final_path/node_modules/ep_mypads/static/l10n/fr.json
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.
# sudo mkdir -p /home/.etherpad
# sudo chown $app: -R /home/.etherpad
# sudo usermod -d /home/.etherpad $app
# Démarre etherpad
echo "Démarrage d'etherpad" >&2
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 service $app start # Démarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long...
# Make app public if necessary
if [ "$is_public" = "Yes" ]; 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
# Recharge la configuration Nginx
sudo service nginx reload
# Régénère la configuration de SSOwat
sudo yunohost app ssowatconf
# Surveille le démarrage du service.
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
echo "Le service $app a démarré correctement." >&2
break # Si le log annonce le démarrage d'etherpad, sort de la boucle.
fi
echo -n "." >&2
sleep 1
done
echo ""
kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail.
sudo rm "$tempfile"