#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ynh_clean_check_starting } # 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 language=$YNH_APP_ARG_LANGUAGE admin=$YNH_APP_ARG_ADMIN infcloud=$YNH_APP_ARG_INFCLOUD 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 THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=admin --value=$admin ynh_app_setting_set --app=$app --key=infcloud --value=$infcloud ynh_app_setting_set --app=$app --key=version --value=$version ynh_app_setting_set --app=$app --key=overwrite_logging --value="1" ynh_app_setting_set --app=$app --key=overwrite_config --value="1" ynh_app_setting_set --app=$app --key=overwrite_infcloud --value="1" ynh_app_setting_set --app=$app --key=overwrite_nginx --value="1" ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value="1" ynh_app_setting_set --app=$app --key=admin_mail_html --value="1" #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Create the directory and set the path in the config mkdir -p "$final_path/collections" # Copy files to the right place cp ../conf/radicale.wsgi $final_path # Copy extra files cp -a ../sources/extra_files_radicale/. "$final_path" 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 --dest_dir="$final_path" # Restore the content of $final_path final_path=$final_path_backup fi chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" # Set default permissions as radicale do. chmod 666 -R $final_path/default_collections chmod 777 $final_path/default_collections $final_path/default_collections/USER #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." # Create a dedicated NGINX config ynh_add_nginx_config if [ $infcloud -eq 1 ] then # Add InfCloud in NGINX config ynh_replace_string --match_string="#INFCLOUD#" --replace_string="" --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" fi ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # PHP-FPM CONFIGURATION #================================================= if [ $infcloud -eq 1 ] then ynh_script_progression --message="Configuring PHP-FPM..." # Create a dedicated PHP-FPM config ynh_add_fpm_config phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) fi #================================================= # SPECIFIC SETUP #================================================= # INSTALL RADICALE IN A VIRTUALENV #================================================= ynh_script_progression --message="Install Radicale in a virtualenv" # Init virtualenv virtualenv /opt/yunohost/$app version=$(ynh_app_setting_get --app=$app --key=version) /opt/yunohost/$app/bin/pip install radicale==$version python-ldap # 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 # useradd radicale -d /opt/yunohost/$app chown radicale: -R /opt/yunohost/$app find /opt/yunohost/$app/ -type d -exec chmod 2755 {} \; find /opt/yunohost/$app/ -type f -exec chmod g+r,o+r {} \; #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." mkdir -p /etc/$app ynh_add_config --template="../conf/config" --destination="/etc/$app/config" ynh_add_config --template="../conf/logging" --destination="/etc/$app/logging" ynh_add_config --template="../conf/rights" --destination="/etc/$app/rights" chmod 755 /etc/$app/ chmod 644 /etc/$app/* 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=$app --key=language --value=$language timezone=$(cat /etc/timezone) ynh_add_config --template="../conf/config.js" --destination="$final_path/infcloud/config.js" chmod 400 "$final_path/infcloud/config.js" chown $app:$app "$final_path/infcloud/config.js" fi #================================================= # GENERATE CALENDARS AND ADDRESS BOOKS FOR ALL USERS #================================================= ynh_script_progression --message="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-)" #================================================= # PREPARE THE HOOKS #================================================= # Modify the hooks for create user collections and to remove them. ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../hooks/post_user_create" ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../hooks/post_user_delete" #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configuring a systemd service..." cp ../conf/radicale.ini /etc/uwsgi/apps-available/ ln -s /etc/uwsgi/apps-available/radicale.ini /etc/uwsgi/apps-enabled/ #================================================= # GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Configuring log rotation..." mkdir -p /var/log/$app touch /var/log/$app/$app.log chown radicale -R /var/log/$app # Use logrotate to manage application logfile(s) ynh_use_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --log="/var/log/uwsgi/app/radicale.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." # Start a systemd service ynh_systemd_action --service_name=uwsgi --action="restart" #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." 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=$app --key=path --value="${path_url%/}/infcloud" # Protect InfCloud access ynh_app_setting_set --app=$app --key=protected_uris --value="/" domain_regex=$(echo "$domain" | sed 's@-@.@g') # Radicale is always accessible (For access to ressources) ynh_app_setting_set --app=$app --key=skipped_regex --value="$domain_regex$path_url" else # If only radicale is installed # Radicale is always accessible (For access to ressources) ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload #================================================= # SEND A README FOR THE ADMIN #================================================= # Get main domain and buid the url of the admin panel of the app. admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" if [ $infcloud -eq 1 ] then infcloud_config=" InfCloud has its own config file, at $final_path/infcloud/config.js " else infcloud_config="" fi echo "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 You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/radicale_ynh__URL_TAG3__." > mail_to_send ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type="install" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed"