2016-04-07 00:00:41 +02:00
#!/bin/bash
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# GENERIC START
2017-03-19 18:36:20 +01:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-06-15 23:57:31 +02:00
2017-03-20 00:17:59 +01:00
source _common.sh
2017-03-19 18:36:20 +01:00
source /usr/share/yunohost/helpers
#=================================================
2022-03-18 22:47:33 +01:00
# MANAGE SCRIPT FAILURE
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_clean_setup () {
ynh_clean_check_starting
}
2019-01-18 21:12:58 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-03-19 18:36:20 +01:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2016-06-15 23:57:31 +02:00
2016-11-08 13:38:29 +01:00
domain=$YNH_APP_ARG_DOMAIN
2017-03-19 18:36:20 +01:00
path_url=$YNH_APP_ARG_PATH
2022-03-18 22:47:33 +01:00
language=$YNH_APP_ARG_LANGUAGE
2016-11-08 13:38:29 +01:00
admin=$YNH_APP_ARG_ADMIN
infcloud=$YNH_APP_ARG_INFCLOUD
2016-05-20 00:03:02 +02:00
2016-11-08 13:38:29 +01:00
app=$YNH_APP_INSTANCE_NAME
2016-05-20 00:03:02 +02:00
2019-01-18 21:12:58 +01:00
# Retrieve the version number in the manifest file.
version=$(ynh_app_upstream_version)
2016-05-20 00:03:02 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Validating installation parameters..."
2016-04-07 00:00:41 +02:00
2017-09-05 00:34:00 +02:00
final_path=/var/www/$app
2022-03-18 22:47:33 +01:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2017-09-05 00:34:00 +02:00
# Register (book) web path
2022-03-18 22:47:33 +01:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Storing installation settings..."
2016-04-07 00:00:41 +02:00
2022-03-18 22:47:33 +01:00
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
2019-01-30 19:30:41 +01:00
2022-03-18 22:47:33 +01:00
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"
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Installing dependencies..."
2016-04-07 00:00:41 +02:00
2020-12-07 09:05:15 +01:00
ynh_install_app_dependencies $pkg_dependencies
2017-03-19 18:36:20 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Configuring system user..."
2016-04-07 00:00:41 +02:00
2022-03-18 22:47:33 +01:00
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Setting up source files..."
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2019-01-18 21:12:58 +01:00
# Create the directory and set the path in the config
2022-03-18 22:47:33 +01:00
mkdir -p "$final_path/collections"
2016-04-07 00:00:41 +02:00
# Copy files to the right place
2017-09-05 00:34:00 +02:00
cp ../conf/radicale.wsgi $final_path
2022-03-18 22:47:33 +01:00
2019-01-18 21:12:58 +01:00
# Copy extra files
2017-09-05 00:34:00 +02:00
cp -a ../sources/extra_files_radicale/. "$final_path"
2022-03-18 22:47:33 +01:00
2019-01-18 21:12:58 +01:00
# regex.py file is patched to fix the awful commit e807c3d35bea9cfcfcacac83b1b17d748ea15a39 that stop the reading of "rights" file after the first match.
2017-09-05 00:34:00 +02:00
mv "$final_path/regex.py" /opt/yunohost/$app/lib/python*/site-packages/radicale/rights/regex.py
2022-03-18 22:47:33 +01:00
2017-03-19 18:36:20 +01:00
if [ $infcloud -eq 1 ]
2019-01-18 21:12:58 +01:00
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
2022-03-18 22:47:33 +01:00
ynh_setup_source --dest_dir="$final_path"
2019-01-18 21:12:58 +01:00
# Restore the content of $final_path
final_path=$final_path_backup
2016-04-07 00:00:41 +02:00
fi
2022-03-18 22:47:33 +01:00
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
# 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 {} \;
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# ADD A CONFIGURATION
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Adding a configuration file..."
2017-03-19 18:36:20 +01:00
2017-09-05 00:34:00 +02:00
mkdir -p /etc/$app
2022-03-18 22:47:33 +01:00
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/*
2017-03-19 18:36:20 +01:00
if [ $infcloud -eq 1 ]
2019-01-18 21:12:58 +01:00
then
# InfCloud configuration
# Set language
2016-04-07 00:00:41 +02:00
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
2022-03-18 22:47:33 +01:00
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"
2016-04-07 00:00:41 +02:00
fi
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# GENERATE CALENDARS AND ADDRESS BOOKS FOR ALL USERS
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Generate calendars and address books for all users"
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
# 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-)"
2016-04-07 00:00:41 +02:00
2022-03-18 22:47:33 +01:00
#=================================================
# PREPARE THE HOOKS
#=================================================
2016-04-07 00:00:41 +02:00
2022-03-18 22:47:33 +01:00
# 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"
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# SETUP SYSTEMD
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Configuring a systemd service..."
2017-03-19 18:36:20 +01:00
2017-09-05 00:34:00 +02:00
cp ../conf/radicale.ini /etc/uwsgi/apps-available/
ln -s /etc/uwsgi/apps-available/radicale.ini /etc/uwsgi/apps-enabled/
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Configuring log rotation..."
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
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
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# INTEGRATE SERVICE IN YUNOHOST
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Integrating service in YunoHost..."
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
yunohost service add $app --log="/var/log/uwsgi/app/radicale.log"
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# START SYSTEMD SERVICE
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Starting a systemd service..."
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
# Start a systemd service
ynh_systemd_action --service_name=uwsgi --action="restart"
2017-03-19 18:36:20 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Configuring permissions..."
2017-03-19 18:36:20 +01:00
if [ $infcloud -eq 1 ]
2019-01-18 21:12:58 +01:00
then
# Add /infcloud to the path of radicale to access it from the portal
# Replace radicale by InfCloud into YunoHost portal
2022-03-18 22:47:33 +01:00
ynh_app_setting_set --app=$app --key=path --value="${path_url%/}/infcloud"
2019-01-18 21:12:58 +01:00
# Protect InfCloud access
2022-03-18 22:47:33 +01:00
ynh_app_setting_set --app=$app --key=protected_uris --value="/"
2021-07-26 07:53:15 +02:00
domain_regex=$(echo "$domain" | sed 's@-@.@g')
2019-01-18 21:12:58 +01:00
# Radicale is always accessible (For access to ressources)
2022-03-18 22:47:33 +01:00
ynh_app_setting_set --app=$app --key=skipped_regex --value="$domain_regex$path_url"
2019-01-18 21:12:58 +01:00
else
# If only radicale is installed
# Radicale is always accessible (For access to ressources)
2022-03-18 22:47:33 +01:00
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
2017-03-19 18:36:20 +01:00
fi
#=================================================
# RELOAD NGINX
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2017-12-16 23:29:00 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2019-01-21 13:22:56 +01:00
# 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"
2017-12-16 23:29:00 +01:00
if [ $infcloud -eq 1 ]
then
infcloud_config="
InfCloud has its own config file, at $final_path/infcloud/config.js
"
else
infcloud_config=""
fi
2019-01-30 19:30:41 +01:00
echo "Use the file /etc/radicale/config to change the main configuration of radicale.
2017-12-16 23:29:00 +01:00
The file /etc/radicale/logging to change the level of logging.
2019-01-18 21:12:58 +01:00
And the file /etc/radicale/rights to edit the way the calendars will be shared.
2017-12-16 23:29:00 +01:00
$infcloud_config
2019-01-30 19:30:41 +01:00
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"
2019-01-21 13:22:56 +01:00
2019-01-30 19:16:04 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2017-12-16 23:29:00 +01:00
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Installation of $app completed"