1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lutim_ynh.git synced 2024-09-03 19:36:24 +02:00
lutim_ynh/scripts/install

173 lines
5.9 KiB
Text
Raw Normal View History

2015-03-19 20:49:50 +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
YNH_VERSION # Récupère le numéro de version de Yunohost.
CLEAN_SETUP () {
# Nettoyage des résidus d'installation non pris en charge par le script remove.
# Pas de nettoyage supplémentaire nécessaire ici...
echo ""
}
TRAP_ON # Active trap pour arrêter le script si une erreur est détectée.
2015-03-19 20:49:50 +01:00
# Retrieve arguments
2016-05-20 00:01:21 +02:00
if [ $ynh_version = "2.4" ]
then
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
always_encrypt=$YNH_APP_ARG_ALWAYS_ENCRYPT
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
2016-06-04 23:09:27 +02:00
source /usr/share/yunohost/helpers
2016-05-20 00:01:21 +02:00
else
domain=$1
path=$2
admin=$3
is_public=$4
always_encrypt=$5
app=lutim
fi
script_dir=$PWD
2016-06-15 23:56:45 +02:00
# Vérifie que les variables ne sont pas vides.
CHECK_VAR "$app" "app name not set"
CHECK_VAR "$script_dir" "script_dir not set"
2015-03-19 20:49:50 +01:00
2016-06-15 23:56:45 +02:00
CHECK_USER "$admin" # Vérifie la validité de l'user admin
2015-11-18 00:28:42 +01:00
2016-06-15 23:56:45 +02:00
CHECK_PATH # Vérifie et corrige la syntaxe du path.
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
2015-11-18 00:28:42 +01:00
2016-06-15 23:56:45 +02:00
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
2015-03-19 20:49:50 +01:00
2015-03-27 23:20:31 +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
CHECK_VAR "$domain_regex" "domain_regex empty"
2015-03-27 23:20:31 +01:00
2016-06-15 23:56:45 +02:00
FIND_PORT 8095 # Cherche un port libre.
2015-03-19 20:49:50 +01:00
2015-11-18 00:28:42 +01:00
# Enregistre les infos dans la config YunoHost
2015-03-19 20:49:50 +01:00
sudo yunohost app setting $app admin -v $admin
sudo yunohost app setting $app domain -v $domain
sudo yunohost app setting $app is_public -v $is_public
2015-03-26 13:07:01 +01:00
sudo yunohost app setting $app port -v $port
sudo yunohost app setting $app always_encrypt -v $always_encrypt
2015-03-19 20:49:50 +01:00
2015-11-18 00:28:42 +01:00
# Créer le repertoire de destination et stocke son emplacement.
sudo mkdir "$final_path"
sudo yunohost app setting $app final_path -v $final_path
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
# Copie le fichier de config nginx
2015-03-19 20:49:50 +01:00
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2015-11-18 00:28:42 +01:00
2015-04-17 13:26:47 +02:00
# Installation de perlmagick, interface perl pour imagemagick et de carton, gestionnaire de dépendances perl
2015-05-02 13:33:03 +02:00
sudo apt-get update
2015-04-15 12:44:58 +02:00
sudo apt-get install carton perlmagick -qy
2015-03-19 20:49:50 +01:00
## Copie et configuration du fichier de conf.
2015-03-19 23:15:38 +01:00
sudo cp ../conf/lutim.conf.template "$final_path/lutim.conf"
sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/lutim.conf"
2015-03-27 21:33:54 +01:00
sudo sed -i "s@__PATH__@$path@g" "$final_path/lutim.conf"
2015-03-19 23:15:38 +01:00
sudo sed -i "s@__PORT__@$port@g" "$final_path/lutim.conf"
2015-03-27 20:28:32 +01:00
if [ "$always_encrypt" = "No" ]; then
2015-03-26 13:07:01 +01:00
always_encrypt=0
else
always_encrypt=1
fi
sudo sed -i "s@__ENCRYPT__@$always_encrypt@g" "$final_path/lutim.conf"
2015-03-19 20:49:50 +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')
2016-06-15 23:56:45 +02:00
CHECK_VAR "$secret" "secret empty"
2015-03-19 23:15:38 +01:00
sudo sed -i "s@__SECRET__@$secret@g" "$final_path/lutim.conf"
2016-06-15 23:56:45 +02:00
STORE_MD5_CONFIG "lutim.conf" "$final_path/lutim.conf" # Enregistre la somme de contrôle du fichier de config
2016-06-05 00:53:04 +02:00
2015-03-19 20:49:50 +01:00
2016-03-31 22:41:54 +02:00
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
2016-06-15 23:56:45 +02:00
CHECK_VAR "$codename" "codename empty"
2016-03-31 22:41:54 +02:00
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
# Mise en place du script systemd
sudo cp ../conf/lutim.service /etc/systemd/system/lutim.service
sudo chown 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
fi
2015-03-19 20:49:50 +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
sudo chmod +x $final_path/script/lutim
2015-03-19 20:49:50 +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-03-19 20:49:50 +01:00
# Installation de lutim via carton
2015-04-17 13:26:47 +02:00
sudo mkdir -p /var/log/$app/
2015-03-19 20:49:50 +01:00
cd $final_path
2015-03-26 13:07:01 +01:00
sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
2015-03-19 20:49:50 +01:00
2015-08-19 21:33:40 +02: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"
2016-06-15 23:56:45 +02:00
false
2015-08-19 21:33:40 +02:00
fi
2016-06-15 23:56:45 +02:00
CHECK_VAR "$arch_dir" "arch_dir empty"
2015-08-19 21:33:40 +02:00
sudo sed -i "s@__ARCHDIR__@$arch_dir@g" "$final_path/script/lutim"
2015-03-19 20:49:50 +01:00
# Change variables in nginx configuration
2015-03-27 21:33:54 +01:00
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
2015-03-19 20:49:50 +01:00
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
# Make app public or private
sudo yunohost app setting $app skipped_uris -v "/"
if [ "$is_public" = "No" ];
2015-03-20 18:27:58 +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-19 20:49:50 +01:00
fi
2015-03-26 13:07:01 +01:00
# 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"
2015-11-18 00:28:42 +01:00
# Configure les droits d'accès au fichiers
2015-03-19 20:49:50 +01:00
sudo chown -R www-data: $final_path
2016-03-31 22:41:54 +02:00
2015-03-19 20:49:50 +01:00
# Start lutim
2016-03-31 22:41:54 +02:00
sudo service lutim start
2015-03-19 20:49:50 +01:00
# Set right permissions on new files created at first start
2015-03-19 23:15:38 +01:00
sudo chown -R www-data: "$final_path"
2015-03-19 20:49:50 +01:00
2015-11-18 00:28:42 +01:00
2015-03-26 13:07:01 +01:00
# Add lutim as a service
sudo yunohost service add lutim -l $final_path/log/production.log
2015-11-18 00:28:42 +01:00
# Recharge la configuration Nginx
2015-03-19 20:49:50 +01:00
sudo service nginx reload
2015-11-18 00:28:42 +01:00
# Régénère la configuration de SSOwat
2015-03-19 20:49:50 +01:00
sudo yunohost app ssowatconf