mirror of
https://github.com/YunoHost-Apps/radicale_ynh.git
synced 2024-09-03 20:16:14 +02:00
214 lines
7.3 KiB
Bash
Executable file
214 lines
7.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Retrieve arguments
|
|
domain=$1
|
|
path=$2
|
|
admin=$3
|
|
infcloud=$4
|
|
language=$5
|
|
app=radicale
|
|
|
|
# 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
|
|
|
|
# Modifie le domaine pour qu'il passe dans une regex
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
|
|
|
if [ "$infcloud" = "Yes" ] || [ "$infcloud" = "yes" ] || [ "$infcloud" = "YES" ] || [ "$infcloud" = "Y" ] || [ "$infcloud" = "y" ]
|
|
then
|
|
infcloud=1
|
|
else
|
|
infcloud=0
|
|
fi
|
|
|
|
# Enregistre les infos dans la config YunoHost
|
|
sudo yunohost app setting $app domain -v $domain
|
|
sudo yunohost app setting $app path -v $path
|
|
sudo yunohost app setting $app admin -v $admin
|
|
sudo yunohost app setting $app infcloud -v $infcloud
|
|
|
|
|
|
# Crée le repertoire de destination et stocke son emplacement.
|
|
sudo mkdir "$final_path"
|
|
sudo yunohost app setting $app final_path -v $final_path
|
|
|
|
|
|
|
|
# Check depends installation
|
|
sudo apt-get install -y python-pip python-virtualenv python-dev libldap2-dev libsasl2-dev libssl-dev uwsgi uwsgi-plugin-python
|
|
|
|
# Init virtualenv
|
|
sudo virtualenv /opt/yunohost/$app
|
|
sudo /opt/yunohost/$app/bin/pip install radicale==1.1.1 python-ldap
|
|
|
|
|
|
# Copy files to the right place
|
|
sudo mkdir -p $final_path/collections
|
|
sudo cp ../conf/radicale.wsgi $final_path
|
|
# Copie les fichiers additionnels ou modifiés.
|
|
sudo cp -a ../sources/ajouts_radicale/. "$final_path"
|
|
# Le fichier regex.py est patché pour corrigé le commit destructeur e807c3d35bea9cfcfcacac83b1b17d748ea15a39 du 3/12/2015 qui arrête la lecture du fichier rights à la première occurence validée.
|
|
sudo mv "$final_path/regex.py" /opt/yunohost/$app/lib/python*/site-packages/radicale/rights/regex.py
|
|
sudo rm /opt/yunohost/$app/lib/python*/site-packages/radicale/rights/regex.pyc
|
|
if [ "$infcloud" = "1" ]
|
|
then #Instal InfCloud
|
|
# Décompresse la source
|
|
tar -x -f ../sources/infcloud.tar.gz
|
|
# Copie les fichiers sources
|
|
sudo cp -a infcloud "$final_path/"
|
|
# Copie les fichiers additionnels ou modifiés.
|
|
sudo cp -a ../sources/ajouts_infcloud/. "$final_path/infcloud/"
|
|
fi
|
|
|
|
#Configuration Radicale
|
|
sudo mkdir -p /etc/$app
|
|
sudo cp ../conf/config /etc/$app/
|
|
sudo cp ../conf/logging /etc/$app/
|
|
sudo cp ../conf/rights /etc/$app/
|
|
sudo sed -i "s@__PATH__@$path@g" /etc/$app/config
|
|
sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/$app/config
|
|
if [ "$infcloud" = "1" ]
|
|
then #Configuration InfCloud
|
|
# Détermine la langue
|
|
case "$language" in
|
|
"Czech") language="cs_CZ"
|
|
;;
|
|
"Danish") language="da_DK"
|
|
;;
|
|
"German") language="de_DE"
|
|
;;
|
|
"English/US") language="en_US"
|
|
;;
|
|
"Spanish") language="es_ES"
|
|
;;
|
|
"French") language="fr_FR"
|
|
;;
|
|
"Italian") language="it_IT"
|
|
;;
|
|
"Japan") language="ja_JP"
|
|
;;
|
|
"Hungarian") language="hu_HU"
|
|
;;
|
|
"Dutch") language="nl_NL"
|
|
;;
|
|
"Slovak") language="sk_SK"
|
|
;;
|
|
"Turkish") language="tr_TR"
|
|
;;
|
|
"Russian") language="ru_RU"
|
|
;;
|
|
"Ukrainian") language="uk_UA"
|
|
;;
|
|
"Chinese") language="zh_CN"
|
|
;;
|
|
esac
|
|
sudo yunohost app setting $app language -v $language
|
|
sudo cp ../conf/config.js "$final_path/infcloud/"
|
|
sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/infcloud/config.js"
|
|
sudo sed -i "s@__PATH__@$path@g" "$final_path/infcloud/config.js"
|
|
sudo sed -i "s@__LANG__@$language@g" "$final_path/infcloud/config.js"
|
|
sudo sed -i "s@__ADMIN__@$admin@g" "$final_path/infcloud/config.js"
|
|
sudo sed -i "s@__TIMEZONE__@$(cat /etc/timezone)@g" "$final_path/infcloud/config.js"
|
|
fi
|
|
|
|
# Set permissions to radicale directory
|
|
sudo useradd radicale -d /opt/yunohost/$app
|
|
sudo chown radicale: -R /opt/yunohost/$app
|
|
|
|
# Set permissions to radicale directory
|
|
sudo chown -R radicale: $final_path
|
|
sudo mkdir /var/log/$app
|
|
sudo touch /var/log/$app/$app.log
|
|
sudo chgrp radicale -R /var/log/$app
|
|
sudo chmod g+w -R /var/log/$app
|
|
# Droit par défaut des dossiers de collections utilisateurs, tels qu'ils sont créés par radicale.
|
|
sudo chmod 666 -R $final_path/default_collections
|
|
sudo chmod 777 $final_path/default_collections $final_path/default_collections/USER
|
|
|
|
# Copy uwsgi config
|
|
sudo cp ../conf/radicale.ini /etc/uwsgi/apps-available/
|
|
sudo ln -s /etc/uwsgi/apps-available/radicale.ini /etc/uwsgi/apps-enabled/
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
sudo sed -i "s@__PATH__@$path@g" ../conf/nginx.conf
|
|
sudo sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf
|
|
sudo sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/nginx.conf
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
if [ "$infcloud" = "1" ]
|
|
then # Ajoute InfCloud dans la config Nginx
|
|
sudo sed -i "s@#INFCLOUD#@@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
fi
|
|
|
|
if [ "$infcloud" = "1" ]
|
|
then
|
|
# Créer le fichier de configuration du pool php-fpm et le configure.
|
|
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
|
|
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
|
sudo cp ../conf/php-fpm.conf $finalphpconf
|
|
sudo chown root: $finalphpconf
|
|
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
|
|
sudo cp ../conf/php-fpm.ini $finalphpini
|
|
sudo chown root: $finalphpini
|
|
sudo service php5-fpm reload
|
|
fi
|
|
|
|
# Fix permission
|
|
sudo chmod 755 /etc/$app/
|
|
sudo find /opt/yunohost/$app/ -type d -exec chmod 2755 {} \;
|
|
sudo find /opt/yunohost/$app/ -type f -exec chmod g+r,o+r {} \;
|
|
sudo chmod 644 /etc/$app/*
|
|
|
|
# Créer les calendriers et carnets d'adresses par défaut des utilisateurs.
|
|
while read user #USER en majuscule est une variable système, à éviter.
|
|
do
|
|
sudo cp -a $final_path/default_collections/USER $final_path/collections/$user
|
|
sudo cp -a $final_path/default_collections/USER.props $final_path/collections/$user.props
|
|
done <<< "$(sudo yunohost user list | grep username | cut -d ":" -f 2 | cut -c 2-)" # Liste les utilisateurs et supprime l'espace après username:
|
|
# Le triple chevron <<< permet de prendre la sortie de commande en entrée de boucle.
|
|
|
|
# Configuration de logrotate
|
|
sed -i "s@__NAME__@$app@g" ../conf/logrotate
|
|
sudo cp ../conf/logrotate /etc/logrotate.d/$app
|
|
|
|
## Reload Nginx and regenerate SSOwat conf
|
|
sudo service nginx reload
|
|
sudo service uwsgi restart
|
|
sudo yunohost service add uwsgi -l /var/log/uwsgi/app/radicale.log
|
|
if [ "$infcloud" = "1" ]
|
|
then # /infcloud vient se rajouter à l'adresse de radicale pour y être associé sur le portail.
|
|
sudo yunohost app setting $app path -v $path/infcloud # Remplace radicale par InfCloud dans le portail Yunohost
|
|
sudo yunohost app setting $app protected_uris -v "/" # Protège l'accès à infcloud
|
|
sudo yunohost app setting $app unprotected_regex -v "$domain_regex$path" # Radicale est accessible librement (pour l'accès distant aux ressources)
|
|
else # Si seul radicale est installé.
|
|
sudo yunohost app setting $app unprotected_uris -v "/" # Radicale est accessible librement (pour l'accès distant aux ressources)
|
|
fi
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
# Mise en place du hook pour la création des collections par défaut des nouveaux utilisateurs.
|
|
sudo sed -i "s@__FINALPATH__@$final_path@g" ../hooks/post_user_create
|
|
sudo yunohost hook add radicale ../hooks/post_user_create
|