#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # 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 #================================================= ynh_script_progression --message="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 #================================================= ynh_script_progression --message="Check if the app can be installed" 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_script_progression --message="Store settings from manifest" --weight=4 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" ynh_app_setting_set $app admin_mail_html "1" #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Install dependencies" --weight=25 ynh_install_app_dependencies $pkg_dependencies #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configure nginx" --weight=2 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 #================================================= ynh_script_progression --message="Create a dedicated user" --weight=2 # Create a dedicated system user ynh_system_user_create $app #================================================= # SPECIFIC SETUP #================================================= # INSTALL RADICALE IN A VIRTUALENV #================================================= ynh_script_progression --message="Install radicale in a virtualenv" --weight=15 # 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 #================================================= ynh_script_progression --message="Download, check and unpack source" --weight=2 # 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 #================================================= ynh_script_progression --message="Configure Radicale" --weight=5 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 #================================================= ynh_script_progression --message="Generate calendars and address books for all users" --weight=3 # 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_script_progression --message="Restart Radicale" --weight=2 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 #================================================= ynh_script_progression --message="Setup SSOwat" --weight=3 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 #================================================= ynh_script_progression --message="Configure logrotate" --weight=2 # Use logrotate to manage application logfile(s) ynh_use_logrotate #================================================= # PHP-FPM CONFIGURATION #================================================= if [ $infcloud -eq 1 ] then ynh_script_progression --message="Configure PHP-FPM" --weight=4 # Create a dedicated php-fpm config ynh_add_fpm_config phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) fi #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reload nginx" --weight=4 ynh_systemd_action --action=reload --service_name=nginx #================================================= # 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 completed" --last