2017-04-01 18:16:18 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source .fonctions
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2017-04-01 18:16:18 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path=$(ynh_app_setting_get $app path)
|
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
2017-04-03 19:21:30 +02:00
|
|
|
port=$(ynh_app_setting_get $app port)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
secret=$(ynh_app_setting_get $app secret)
|
2017-04-01 18:16:18 +02:00
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# 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 [ "${#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
|
|
|
|
|
|
|
|
CHECK_PATH # Checks and corrects the syntax of the path.
|
2017-04-01 18:16:18 +02:00
|
|
|
|
|
|
|
# Get source
|
|
|
|
SETUP_SOURCE
|
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Et copie le fichier de config nginx
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2017-04-01 18:16:18 +02:00
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2017-04-03 19:21:30 +02:00
|
|
|
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
|
|
|
|
|
2017-04-01 18:16:18 +02:00
|
|
|
|
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
then
|
|
|
|
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
fi
|
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2017-04-07 19:55:15 +02:00
|
|
|
# SETUP LUFI
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
## Copie et configuration du fichier de conf.
|
2017-04-07 19:55:15 +02:00
|
|
|
CHECK_MD5_CONFIG "lufi.conf" "$final_path/lufi.conf" # Créé un backup du fichier de config si il a été modifié.
|
|
|
|
sudo cp ../conf/lufi.conf.template "$final_path/lufi.conf"
|
|
|
|
sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/lufi.conf"
|
2017-04-19 03:03:36 +02:00
|
|
|
sudo sed -i "s@__PATH__@$path@g" "$final_path/lufi.conf"
|
2017-04-07 19:55:15 +02:00
|
|
|
sudo sed -i "s@__PORT__@$port@g" "$final_path/lufi.conf"
|
2017-04-03 19:21:30 +02:00
|
|
|
sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lufi.conf"
|
2017-04-07 19:52:20 +02:00
|
|
|
STORE_MD5_CONFIG "lufi.conf" "$final_path/lufi.conf" # Réenregistre la somme de contrôle du fichier de config
|
2017-04-03 19:21:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Mise en place du script systemd
|
|
|
|
sudo systemctl stop $app
|
2017-04-07 19:52:20 +02:00
|
|
|
sudo cp ../conf/lufi.service /etc/systemd/system/$app.service
|
2017-04-03 19:21:30 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP CRON
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-07 19:52:20 +02:00
|
|
|
sudo cp ../conf/cron_lufi /etc/cron.d/$app
|
2017-04-03 19:21:30 +02:00
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/cron.d/$app
|
|
|
|
|
|
|
|
#=================================================
|
2017-04-07 19:55:15 +02:00
|
|
|
# UPDATE LUFI WITH CARTON
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
pushd $final_path # cd avec une stack pour revenir en arrière
|
2017-04-19 03:03:36 +02:00
|
|
|
echo yes | sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
|
2017-04-03 19:21:30 +02:00
|
|
|
popd # Revient au dossier courant avant pushd
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SECURING FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-19 14:52:02 +02:00
|
|
|
sudo chown -R www-data: $final_path
|
2017-04-03 19:21:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-04-07 19:55:15 +02:00
|
|
|
# RESTART LUFI
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-04-19 14:52:02 +02:00
|
|
|
sudo systemctl restart lufi.service
|
2017-04-03 19:21:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
|
|
if [ $is_public -eq 0 ]
|
|
|
|
then
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2017-04-01 18:16:18 +02:00
|
|
|
fi
|
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
2017-04-01 18:16:18 +02:00
|
|
|
sudo systemctl reload nginx
|
2017-04-03 19:21:30 +02:00
|
|
|
sudo yunohost app ssowatconf
|