mirror of
https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git
synced 2024-09-03 18:36:09 +02:00
110 lines
5.2 KiB
Bash
110 lines
5.2 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=$(sudo yunohost app setting $app domain)
|
|
path=$(sudo yunohost app setting $app path)
|
|
admin=$(sudo yunohost app setting $app admin)
|
|
is_public=$(sudo yunohost app setting $app is_public)
|
|
final_path=$(sudo yunohost app setting $app final_path)
|
|
port=$(sudo yunohost app setting $app port)
|
|
abiword=$(sudo yunohost app setting $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=$(sudo yunohost app setting $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
|
|
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 etherpad: $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 etherpad: -R /home/.etherpad
|
|
sudo usermod -d /home/.etherpad etherpad
|
|
|
|
# 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
|
|
sudo yunohost app setting $app skipped_uris -v "/"
|
|
else
|
|
sudo yunohost app setting $app skipped_uris -v "/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 20`
|
|
do # La boucle attend le démarrage d'etherpad. Ou 20 secondes. 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
|
|
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"
|