2017-02-07 22:51:47 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
source .fonctions # Loads the generic functions usually used in the script
|
|
|
|
source /usr/share/yunohost/helpers # Source app helpers
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
CLEAN_SETUP () {
|
2017-04-01 16:53:29 +02:00
|
|
|
# Clean installation residues that are not supported by the remove script.
|
|
|
|
# Clean hosts
|
2017-02-07 22:51:47 +01:00
|
|
|
echo ""
|
|
|
|
}
|
2017-04-01 16:53:29 +02:00
|
|
|
TRAP_ON # Active trap to stop the script if an error is detected.
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
script_dir=$PWD
|
|
|
|
|
|
|
|
# Vérifie que les variables ne sont pas vides.
|
|
|
|
CHECK_VAR "$app" "app name not set"
|
|
|
|
CHECK_VAR "$script_dir" "script_dir not set"
|
|
|
|
|
|
|
|
CHECK_USER "$admin" # Vérifie la validité de l'user admin
|
|
|
|
|
|
|
|
CHECK_PATH # Vérifie et corrige la syntaxe du path.
|
|
|
|
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
|
|
|
|
|
|
|
|
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
|
|
|
|
|
|
|
# Modifie le domaine pour qu'il passe dans une regex
|
|
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
|
|
|
CHECK_VAR "$domain_regex" "domain_regex empty"
|
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
FIND_PORT 8080 # Cherche un port libre.
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
# Enregistre les infos dans la config YunoHost
|
|
|
|
ynh_app_setting_set $app admin $admin
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
|
|
|
ynh_app_setting_set $app port $port
|
|
|
|
|
|
|
|
|
|
|
|
# Créer le repertoire de destination et stocke son emplacement.
|
2017-04-01 16:53:29 +02:00
|
|
|
sudo mkdir "${final_path}"
|
2017-02-07 22:51:47 +01:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
# Copie le fichier de config nginx
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
then
|
|
|
|
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
fi
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
# Installation de perlmagick, interface perl pour imagemagick et de carton, gestionnaire de dépendances perl
|
2017-04-01 16:53:29 +02:00
|
|
|
ynh_package_update
|
|
|
|
ynh_package_install carton
|
|
|
|
ynh_package_install perlmagick
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
## Copie et configuration du fichier de conf.
|
2017-04-01 16:53:29 +02:00
|
|
|
sudo cp ../conf/lufi.conf.template "${final_path}/lufi.conf"
|
|
|
|
sudo sed -i "s@__DOMAIN__@$domain@g" "${final_path}/lufi.conf"
|
|
|
|
sudo sed -i "s@__PATH__@$path@g" "${final_path}/lufi.conf"
|
|
|
|
sudo sed -i "s@__PORT__@$port@g" "${final_path}/lufi.conf"
|
2017-02-07 22:51:47 +01:00
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
#sudo sed -i "s@__ENCRYPT__@$always_encrypt@g" "${final_path}/lufi.conf"
|
2017-02-07 22:51:47 +01:00
|
|
|
secret=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
|
|
CHECK_VAR "$secret" "secret empty"
|
2017-04-01 16:53:29 +02:00
|
|
|
sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lufi.conf"
|
|
|
|
STORE_MD5_CONFIG "lufi.conf" "${final_path}/lufi.conf" # Enregistre la somme de contrôle du fichier de config
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
|
|
|
|
CHECK_VAR "$codename" "codename empty"
|
|
|
|
ynh_app_setting_set $app codename $codename
|
|
|
|
if [ "$codename" = "wheezy" ]
|
|
|
|
then # On utilise le script init pour wheezy.
|
|
|
|
# Mise en place du script init
|
|
|
|
sudo cp ../conf/lufi.init /etc/init.d/lufi
|
|
|
|
sudo cp ../conf/lufi.default /etc/default/lufi
|
|
|
|
sudo chmod +x /etc/init.d/lufi
|
|
|
|
sudo chown root: /etc/init.d/lufi /etc/default/lufi
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/default/lufi
|
|
|
|
## Démarrage auto du service
|
|
|
|
sudo update-rc.d lufi defaults
|
|
|
|
else # Et le script systemd à partir de jessie
|
|
|
|
# Mise en place du script systemd
|
|
|
|
sudo cp ../conf/lufi.service /etc/systemd/system/lufi.service
|
|
|
|
sudo chown root: /etc/systemd/system/lufi.service
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/lufi.service
|
|
|
|
## Démarrage auto du service
|
|
|
|
sudo systemctl enable lufi.service
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Mise en place des crons
|
|
|
|
sudo cp ../conf/cron_lufi /etc/cron.d/$app
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/cron.d/$app
|
|
|
|
sudo chmod +x $final_path/script/lufi
|
|
|
|
|
|
|
|
# Configuration de logrotate
|
|
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/logrotate
|
|
|
|
sudo cp ../conf/logrotate /etc/logrotate.d/$app
|
|
|
|
|
|
|
|
# Installation de lufi via carton
|
|
|
|
sudo mkdir -p /var/log/$app/
|
|
|
|
cd $final_path
|
|
|
|
sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
|
2017-04-01 16:53:29 +02:00
|
|
|
# sudo carton exec hypnotoad script/lufi
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
# Configure le path du dossier perl en fonction de l'architecture système
|
|
|
|
arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu)
|
|
|
|
if [ "$?" -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "Impossible de trouver le dossier relatif à l'architecture système." | sudo tee -a "/var/log/$app/setup_carton.log"
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
CHECK_VAR "$arch_dir" "arch_dir empty"
|
|
|
|
sudo sed -i "s@__ARCHDIR__@$arch_dir@g" "$final_path/script/lufi"
|
2017-04-01 16:53:29 +02:00
|
|
|
# TODO: fix a bug service restart
|
|
|
|
# Add contact
|
|
|
|
sudo sed -i "/thumbnail_size => 100,/a contact => 'webmaster@$domain'\," "${final_path}/lib/Lutim.pm"
|
|
|
|
|
2017-02-07 22:51:47 +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
|
|
|
|
|
|
|
|
# Make app public or private
|
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
|
|
if [ "$is_public" = "No" ];
|
|
|
|
then # Si l'app est privée, seul le visionnage des images reste public
|
|
|
|
if [ "$path" == "/" ]; then
|
|
|
|
path="" # Si path correspond à la racine, supprime le / pour éviter une erreur de la regex.
|
|
|
|
fi
|
|
|
|
ynh_app_setting_set $app protected_regex "$domain_regex$path/stats$","$domain_regex$path/manifest.webapp$","$domain_regex$path/$","$domain_regex$path/d/.*$","$domain_regex$path/m/.*$"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Making log symbolic link to /var/log
|
|
|
|
sudo touch /var/log/$app/production.log
|
|
|
|
sudo chown www-data: /var/log/$app/production.log
|
|
|
|
sudo ln -s /var/log/$app/production.log "$final_path/log/production.log"
|
|
|
|
|
|
|
|
# Configure les droits d'accès au fichiers
|
|
|
|
sudo chown -R www-data: $final_path
|
|
|
|
|
|
|
|
# Start lufi
|
2017-04-01 16:53:29 +02:00
|
|
|
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
|
|
|
|
CHECK_VAR "$codename" "codename empty"
|
|
|
|
ynh_app_setting_set $app codename $codename
|
|
|
|
if [ "$codename" = "wheezy" ]
|
|
|
|
then # On utilise le script init pour wheezy.
|
|
|
|
sudo /etc/init.d/lufi start
|
|
|
|
sudo update-rc.d lufi defaults
|
|
|
|
sudo service lufi start
|
|
|
|
else
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl start lufi.service
|
|
|
|
sudo systemctl enable lufi.service
|
|
|
|
fi
|
|
|
|
|
2017-02-07 22:51:47 +01:00
|
|
|
# Set right permissions on new files created at first start
|
|
|
|
sudo chown -R www-data: "$final_path"
|
|
|
|
|
|
|
|
# Add lufi as a service
|
|
|
|
sudo yunohost service add lufi -l $final_path/log/production.log
|
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
if [ "$is_public" = "No" ];
|
|
|
|
then
|
|
|
|
# Retire l'accès public
|
|
|
|
ynh_app_setting_delete $app unprotected_uris
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
fi
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
# Recharge la configuration Nginx
|
2017-04-01 16:53:29 +02:00
|
|
|
sudo service nginx reload
|