mirror of
https://github.com/YunoHost-Apps/lutim_ynh.git
synced 2024-09-03 19:36:24 +02:00
165 lines
5.4 KiB
Bash
165 lines
5.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Retrieve arguments
|
|
domain=$1
|
|
path=$2
|
|
admin=$3
|
|
is_public=$4
|
|
always_encrypt=$5
|
|
app=lutim
|
|
|
|
# Vérifie la validité de l'user admin
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
|
|
if [[ ! $? -eq 0 ]]; then
|
|
echo "Wrong admin"
|
|
exit 1
|
|
fi
|
|
|
|
# Vérifie la disponibilité du path et du domaine.
|
|
sudo yunohost app checkurl $domain$path -a $app
|
|
if [[ ! $? -eq 0 ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
# Vérifie que le dossier de destination n'est pas déjà utilisé.
|
|
final_path=/var/www/$app
|
|
if [ -e "$final_path" ]
|
|
then
|
|
echo "This path already contains a folder"
|
|
exit 1
|
|
fi
|
|
|
|
# Vérifie la présence du / en début de path
|
|
if [ $(echo $path | cut -c1) != "/" ]; then
|
|
path="/$path"
|
|
fi
|
|
# Vérifie l'absence du / en fin de path
|
|
pathRslash=$(echo "$path" | sed 's@/$@@')
|
|
|
|
# Modifie le domaine pour qu'il passe dans une regex
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
|
|
|
# Cherche un port libre.
|
|
port=8095
|
|
sudo yunohost app checkport $port
|
|
while [[ ! $? -eq 0 ]]; do
|
|
port=$((port+1))
|
|
sudo yunohost app checkport $port
|
|
done
|
|
|
|
# Enregistre les infos dans la config YunoHost
|
|
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
|
|
sudo yunohost app setting $app port -v $port
|
|
sudo yunohost app setting $app always_encrypt -v $always_encrypt
|
|
|
|
|
|
# Créer le repertoire de destination et stocke son emplacement.
|
|
sudo mkdir "$final_path"
|
|
sudo yunohost app setting $app final_path -v $final_path
|
|
|
|
# Décompresse la source
|
|
tar -x -f ../sources/lutim.tar.gz
|
|
# Copie les fichiers sources
|
|
sudo cp -a lutim/. "$final_path"
|
|
# Copie les fichiers additionnels ou modifiés.
|
|
sudo cp -a ../sources/ajouts/. "$final_path"
|
|
# Et copie le fichier de config nginx
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
# Installation de perlmagick, interface perl pour imagemagick et de carton, gestionnaire de dépendances perl
|
|
sudo apt-get update
|
|
sudo apt-get install carton perlmagick -qy
|
|
|
|
## Copie et configuration du fichier de conf.
|
|
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"
|
|
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')
|
|
sudo sed -i "s@__SECRET__@$secret@g" "$final_path/lutim.conf"
|
|
|
|
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
|
|
# 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
|
|
|
|
## 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
|
|
|
|
# Configuration de logrotate
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/logrotate
|
|
sudo cp ../conf/logrotate /etc/logrotate.d/$app
|
|
|
|
# Installation de lutim 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"
|
|
|
|
# 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"
|
|
fi
|
|
sudo sed -i "s@__ARCHDIR__@$arch_dir@g" "$final_path/script/lutim"
|
|
|
|
# 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
|
|
sudo yunohost app setting $app skipped_uris -v "/"
|
|
if [ "$is_public" = "No" ];
|
|
then # Si l'app est privée, seul le visionnage des images reste public
|
|
sudo yunohost app setting $app protected_regex -v "$domain_regex$pathRslash/stats$","$domain_regex$pathRslash/manifest.webapp$","$domain_regex$pathRslash/$","$domain_regex$pathRslash/d/.*$","$domain_regex$pathRslash/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 lutim
|
|
sudo service lutim start
|
|
# Set right permissions on new files created at first start
|
|
sudo chown -R www-data: "$final_path"
|
|
|
|
|
|
# Add lutim as a service
|
|
sudo yunohost service add lutim -l $final_path/log/production.log
|
|
|
|
|
|
# Recharge la configuration Nginx
|
|
sudo service nginx reload
|
|
# Régénère la configuration de SSOwat
|
|
sudo yunohost app ssowatconf
|