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/install
2019-01-18 21:12:58 +01:00

310 lines
9.9 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source _variables
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
infcloud=$YNH_APP_ARG_INFCLOUD
language=$YNH_APP_ARG_LANGUAGE
app=$YNH_APP_INSTANCE_NAME
# Retrieve the version number in the manifest file.
version=$(ynh_app_upstream_version)
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app infcloud $infcloud
ynh_app_setting_set $app version $version
ynh_app_setting_set $app overwrite_logging "1"
ynh_app_setting_set $app overwrite_config "1"
ynh_app_setting_set $app overwrite_infcloud "1"
ynh_app_setting_set $app overwrite_nginx "1"
ynh_app_setting_set $app overwrite_phpfpm "1"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies $app_depencencies
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_add_nginx_config
if [ $infcloud -eq 1 ]
then
# Add InfCloud in Nginx config
ynh_replace_string "#INFCLOUD#" "" /etc/nginx/conf.d/$domain.d/$app.conf
fi
ynh_store_file_checksum "$finalnginxconf"
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a dedicated system user
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL RADICALE IN A VIRTUALENV
#=================================================
# Init virtualenv
virtualenv /opt/yunohost/$app
version=$(ynh_app_setting_get $app version $version)
/opt/yunohost/$app/bin/pip install radicale==$version python-ldap
#=================================================
# COPY FILES INTO $FINAL_PATH
#=================================================
# Create the directory and set the path in the config
mkdir "$final_path"
ynh_app_setting_set $app final_path $final_path
# Copy files to the right place
mkdir -p $final_path/collections
cp ../conf/radicale.wsgi $final_path
# Copy extra files
cp -a ../sources/extra_files_radicale/. "$final_path"
# regex.py file is patched to fix the awful commit e807c3d35bea9cfcfcacac83b1b17d748ea15a39 that stop the reading of "rights" file after the first match.
mv "$final_path/regex.py" /opt/yunohost/$app/lib/python*/site-packages/radicale/rights/regex.py
if [ $infcloud -eq 1 ]
then
#Instal InfCloud
# Backup the content of $final_path
final_path_backup=$final_path
# Modify final_path for InfCloud installation
final_path=$final_path/infcloud
# Download and uncompress the source into final_path
ynh_setup_source "$final_path"
# Restore the content of $final_path
final_path=$final_path_backup
fi
#=================================================
# CONFIGURE RADICALE
#=================================================
mkdir -p /etc/$app
cp ../conf/config /etc/$app/
cp ../conf/logging /etc/$app/
cp ../conf/rights /etc/$app/
ynh_replace_string "__PATH__" "${path_url%/}" /etc/$app/config
ynh_replace_string "__FINALPATH__" "$final_path" /etc/$app/config
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "/etc/$app/config"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "/etc/$app/logging"
if [ $infcloud -eq 1 ]
then
# InfCloud configuration
# Set language
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
ynh_app_setting_set $app language $language
cp ../conf/config.js "$final_path/infcloud/"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/infcloud/config.js"
ynh_replace_string "__PATH__" "${path_url%/}" "$final_path/infcloud/config.js"
ynh_replace_string "__LANG__" "$language" "$final_path/infcloud/config.js"
ynh_replace_string "__ADMIN__" "$admin" "$final_path/infcloud/config.js"
ynh_replace_string "__TIMEZONE__" "$(cat /etc/timezone)" "$final_path/infcloud/config.js"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/infcloud/config.js"
fi
#=================================================
# SET PERMISSIONS ON RADICALE'S DIRECTORIES
#=================================================
# useradd radicale -d /opt/yunohost/$app
chown radicale: -R /opt/yunohost/$app
chown -R radicale: $final_path
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown radicale -R /var/log/$app
# Set default permissions as radicale do.
chmod 666 -R $final_path/default_collections
chmod 777 $final_path/default_collections $final_path/default_collections/USER
# Set permissions
chmod 755 /etc/$app/
find /opt/yunohost/$app/ -type d -exec chmod 2755 {} \;
find /opt/yunohost/$app/ -type f -exec chmod g+r,o+r {} \;
chmod 644 /etc/$app/*
#=================================================
# CONFIGURE UWSGI FOR RADICALE
#=================================================
cp ../conf/radicale.ini /etc/uwsgi/apps-available/
ln -s /etc/uwsgi/apps-available/radicale.ini /etc/uwsgi/apps-enabled/
#=================================================
# GENERATE CALENDARS AND ADDRESS BOOKS FOR ALL USERS
#=================================================
# Create default calendars and address books for each users
while read user
do
cp -a $final_path/default_collections/USER $final_path/collections/$user
cp -a $final_path/default_collections/USER.props $final_path/collections/$user.props
# List all users and remove the space after username
done <<< "$(yunohost user list | grep username | cut -d ":" -f 2 | cut -c 2-)"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
ynh_systemd_action --action=restart --service_name=uwsgi
yunohost service add uwsgi --log "/var/log/uwsgi/app/radicale.log"
#=================================================
# PREPARE THE HOOKS
#=================================================
# Modify the hooks for create user collections and to remove them.
ynh_replace_string "__FINALPATH__" "$final_path" ../hooks/post_user_create
ynh_replace_string "__FINALPATH__" "$final_path" ../hooks/post_user_delete
#=================================================
# GENERIC FINALISATION
#=================================================
# SETUP SSOWAT
#=================================================
if [ $infcloud -eq 1 ]
then
# Add /infcloud to the path of radicale to access it from the portal
# Replace radicale by InfCloud into YunoHost portal
ynh_app_setting_set $app path ${path_url%/}/infcloud
# Protect InfCloud access
ynh_app_setting_set $app protected_uris "/"
domain_regex=$(echo "$domain" | sed 's@-@.@g')
# Radicale is always accessible (For access to ressources)
ynh_app_setting_set $app skipped_regex "$domain_regex$path_url"
else
# If only radicale is installed
# Radicale is always accessible (For access to ressources)
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
if [ $infcloud -eq 1 ]
then
# Create a dedicated php-fpm config
ynh_add_fpm_config
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
if [ $infcloud -eq 1 ]
then
infcloud_config="
InfCloud has its own config file, at $final_path/infcloud/config.js
"
else
infcloud_config=""
fi
message="Use the file /etc/radicale/config to change the main configuration of radicale.
The file /etc/radicale/logging to change the level of logging.
And the file /etc/radicale/rights to edit the way the calendars will be shared.
$infcloud_config
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/radicale_ynh"
ynh_send_readme_to_admin --app_message="$message" --recipients="$admin"