1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/radicale_ynh.git synced 2024-09-03 20:16:14 +02:00
radicale_ynh/scripts/upgrade
2016-04-12 14:56:23 +02:00

159 lines
5.7 KiB
Bash

#!/bin/bash
app=radicale
# Get app settings
domain=$(sudo yunohost app setting $app domain)
path=$(sudo yunohost app setting $app path)
admin=$(sudo yunohost app setting $app admin)
infcloud=$(sudo yunohost app setting $app infcloud)
language=$(sudo yunohost app setting $app language)
# Check depends installation
sudo apt-get install -y python-pip python-virtualenv python-dev libldap2-dev libsasl2-dev libssl-dev uwsgi uwsgi-plugin-python
if [ -d /usr/local/radicale ];
then
sudo mkdir -p /opt/yunohost
sudo mv /usr/local/radicale /opt/yunohost/
fi
# Set permissions to radicale directory
sudo grep radicale /etc/passwd > /dev/null 2>&1
if [ $? != 0 ];
then
sudo useradd radicale -d /opt/yunohost/$app
fi
sudo chown radicale: -R /opt/yunohost/$app
# Upgrade pip packages
sudo rm -Rf /opt/yunohost/$app
sudo virtualenv /opt/yunohost/$app
sudo bash -c 'source /opt/yunohost/radicale/bin/activate && 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/. "$final_path/infcloud/"
fi
# Radicale configuration
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__@$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
# Copy uwsgi config
sudo cp ../conf/radicale.ini /etc/uwsgi/apps-available/
# Update Nginx configuration file
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
# Met à jour le fichier de configuration du pool php-fpm.
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/*
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
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
sudo service uwsgi restart
sudo service nginx reload
# 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