mirror of
https://github.com/YunoHost-Apps/radicale_ynh.git
synced 2024-09-03 20:16:14 +02:00
253 lines
8.6 KiB
Bash
Executable file
253 lines
8.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
|
|
# Retrieve arguments
|
|
if [ $ynh_version = "2.4" ]
|
|
then
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path=$YNH_APP_ARG_PATH
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
infcloud=$YNH_APP_ARG_INFCLOUD
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Source app helpers
|
|
. /usr/share/yunohost/helpers
|
|
else
|
|
domain=$1
|
|
path=$2
|
|
admin=$3
|
|
infcloud=$4
|
|
language=$5
|
|
app=radicale
|
|
fi
|
|
|
|
# Delete files and db if exit with an error
|
|
EXIT_PROPERLY () {
|
|
trap '' ERR
|
|
echo -e "\e[91m \e[1m" # Shell in light red bold
|
|
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!"
|
|
|
|
if [ $ynh_version = "2.2" ]; then
|
|
/bin/bash ./remove # Appel le script remove. En 2.2, ce comportement n'est pas automatique.
|
|
fi
|
|
exit 1
|
|
}
|
|
TRAP_ON () { # Activate signal capture
|
|
trap EXIT_PROPERLY ERR # Capturing exit signals on error
|
|
}
|
|
TRAP_OFF () { # Ignoring signal capture until TRAP_ON
|
|
# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien.
|
|
# Mais pas la fonction TRAP_OFF...
|
|
# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction.
|
|
trap '' ERR # Ignoring exit signals
|
|
}
|
|
TRAP_ON
|
|
|
|
|
|
# Vérifie la validité de l'user admin
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
|
|
if [[ ! $? -eq 0 ]]; then
|
|
echo "Wrong admin"
|
|
touch /force_stop
|
|
fi
|
|
|
|
# Vérifie la disponibilité du path et du domaine.
|
|
sudo yunohost app checkurl $domain$path -a $app
|
|
if [[ ! $? -eq 0 ]]; then
|
|
touch /force_stop
|
|
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"
|
|
touch /force_stop
|
|
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 -p /var/log/$app
|
|
sudo touch /var/log/$app/$app.log
|
|
sudo chown radicale -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 des hook pour la création des collections par défaut des nouveaux utilisateurs. Et leur suppression
|
|
sudo sed -i "s@__FINALPATH__@$final_path@g" ../hooks/post_user_create
|
|
sudo yunohost hook add radicale ../hooks/post_user_create
|
|
sudo sed -i "s@__FINALPATH__@$final_path@g" ../hooks/post_user_delete
|
|
sudo yunohost hook add radicale ../hooks/post_user_delete
|