2015-03-16 21:10:39 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-06-15 23:56:45 +02:00
|
|
|
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
|
|
|
|
|
2015-11-18 00:28:42 +01:00
|
|
|
# Récupère les infos de l'application.
|
2016-11-08 13:33:28 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2015-03-26 13:07:01 +01:00
|
|
|
domain=$(sudo yunohost app setting $app domain)
|
|
|
|
path=$(sudo yunohost app setting $app path)
|
|
|
|
is_public=$(sudo yunohost app setting $app is_public)
|
|
|
|
port=$(sudo yunohost app setting $app port)
|
|
|
|
always_encrypt=$(sudo yunohost app setting $app always_encrypt)
|
2015-11-18 00:28:42 +01:00
|
|
|
final_path=$(sudo yunohost app setting $app final_path)
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2016-03-31 23:26:35 +02:00
|
|
|
if [ "${#final_path}" -eq 0 ]
|
|
|
|
then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien script, code final_path en dur
|
|
|
|
final_path=/var/www/$app
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-06-15 23:56:45 +02:00
|
|
|
CHECK_PATH # Vérifie et corrige la syntaxe du path.
|
2015-03-27 23:26:10 +01:00
|
|
|
# Modifie le domaine pour qu'il passe dans une regex
|
|
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
|
|
|
|
2016-06-15 23:56:45 +02:00
|
|
|
SETUP_SOURCE "lutim.tar.gz" # Télécharge la source, décompresse et copie dans $final_path
|
|
|
|
|
2015-11-18 00:28:42 +01:00
|
|
|
# Et copie le fichier de config nginx
|
2015-03-26 13:07:01 +01:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2015-03-26 13:07:01 +01:00
|
|
|
# Change variables in nginx configuration
|
|
|
|
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
## Copie et configuration du fichier de conf.
|
2016-06-15 23:56:45 +02:00
|
|
|
CHECK_MD5_CONFIG "lutim.conf" "$final_path/lutim.conf" # Créé un backup du fichier de config si il a été modifié.
|
2015-03-26 13:07:01 +01:00
|
|
|
sudo cp ../conf/lutim.conf.template "$final_path/lutim.conf"
|
|
|
|
sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/lutim.conf"
|
|
|
|
sudo sed -i "s@__PATH__@$path@g" "$final_path/lutim.conf"
|
|
|
|
sudo sed -i "s@__PORT__@$port@g" "$final_path/lutim.conf"
|
|
|
|
if [ "always_encrypt" = "No" ]; then
|
|
|
|
always_encrypt=0
|
|
|
|
else
|
|
|
|
always_encrypt=1
|
|
|
|
fi
|
|
|
|
sudo sed -i "s@__ENCRYPT__@$always_encrypt@g" "$final_path/lutim.conf"
|
2016-06-15 23:56:45 +02:00
|
|
|
STORE_MD5_CONFIG "lutim.conf" "$final_path/lutim.conf" # Réenregistre la somme de contrôle du fichier de config
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2016-03-31 22:41:54 +02:00
|
|
|
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
|
|
|
|
sudo yunohost app setting $app codename -v $codename
|
|
|
|
if [ "$codename" = "wheezy" ]
|
|
|
|
then # On utilise le script init pour wheezy.
|
|
|
|
# Mise en place du script init
|
|
|
|
sudo cp ../conf/lutim.init /etc/init.d/lutim
|
|
|
|
sudo cp ../conf/lutim.default /etc/default/lutim
|
|
|
|
sudo chmod +x /etc/init.d/lutim
|
|
|
|
sudo chown root: /etc/init.d/lutim /etc/default/lutim
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/default/lutim
|
|
|
|
## Démarrage auto du service
|
|
|
|
sudo update-rc.d lutim defaults
|
|
|
|
else # Et le script systemd à partir de jessie
|
|
|
|
if [ -e /etc/init.d/lutim ]
|
|
|
|
then # Supprime le script init.d si il existe.
|
|
|
|
sudo rm -f /etc/default/lutim
|
|
|
|
sudo rm -f /etc/init.d/lutim
|
|
|
|
sudo update-rc.d -f lutim remove
|
|
|
|
fi
|
2016-03-31 23:26:35 +02:00
|
|
|
# Mise en place du script systemd
|
|
|
|
sudo cp ../conf/lutim.service /etc/systemd/system/lutim.service
|
|
|
|
sudo chown root:root /etc/systemd/system/lutim.service
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/lutim.service
|
|
|
|
## Démarrage auto du service
|
|
|
|
sudo systemctl enable lutim.service
|
|
|
|
|
2016-03-31 22:41:54 +02:00
|
|
|
fi
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2015-03-26 13:07:01 +01:00
|
|
|
## Mise en place des crons
|
|
|
|
sudo cp ../conf/cron_lutim /etc/cron.d/$app
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/cron.d/$app
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2016-05-15 12:15:08 +02:00
|
|
|
# Configuration de logrotate
|
|
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/logrotate
|
|
|
|
sudo cp ../conf/logrotate /etc/logrotate.d/$app
|
|
|
|
|
2015-08-19 21:33:40 +02:00
|
|
|
# Mise à jour de lutim via carton
|
|
|
|
cd $final_path
|
|
|
|
sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
|
|
|
|
|
2015-03-26 13:07:01 +01:00
|
|
|
# Make app public or private
|
|
|
|
sudo yunohost app setting $app skipped_uris -v "/"
|
2015-03-16 21:10:39 +01:00
|
|
|
if [ "$is_public" = "No" ];
|
2015-03-26 13:07:01 +01:00
|
|
|
then # Si l'app est privée, seul le visionnage des images reste public
|
2016-06-15 23:56:45 +02:00
|
|
|
sudo yunohost app setting $app protected_regex -v "$domain_regex$path/stats$","$domain_regex$path/manifest.webapp$","$domain_regex$path/$","$domain_regex$path/d/.*$","$domain_regex$path/m/.*$"
|
2015-03-16 21:10:39 +01:00
|
|
|
fi
|
|
|
|
|
2015-11-18 00:28:42 +01:00
|
|
|
# Configure les droits d'accès au fichiers
|
2015-03-26 13:07:01 +01:00
|
|
|
sudo chown -R www-data: $final_path
|
|
|
|
# Restart lutim
|
2016-03-31 22:41:54 +02:00
|
|
|
sudo service lutim restart
|
2015-03-26 13:07:01 +01:00
|
|
|
|
|
|
|
|
2015-11-18 00:28:42 +01:00
|
|
|
# Recharge la configuration Nginx
|
2015-03-16 21:10:39 +01:00
|
|
|
sudo service nginx reload
|
2015-11-18 00:28:42 +01:00
|
|
|
# Régénère la configuration de SSOwat
|
2015-03-16 21:10:39 +01:00
|
|
|
sudo yunohost app ssowatconf
|