mirror of
https://github.com/YunoHost-Apps/radicale_ynh.git
synced 2024-09-03 20:16:14 +02:00
338 lines
12 KiB
Bash
Executable file
338 lines
12 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
#REMOVEME? ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
#REMOVEME? ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
|
|
#REMOVEME? path=$YNH_APP_ARG_PATH
|
|
#REMOVEME? language=$YNH_APP_ARG_LANGUAGE
|
|
#REMOVEME? admin=$YNH_APP_ARG_ADMIN
|
|
#REMOVEME? infcloud=$YNH_APP_ARG_INFCLOUD
|
|
|
|
#REMOVEME? 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
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
#REMOVEME? install_dir=/var/www/$app
|
|
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
|
|
|
|
# Register (book) web path
|
|
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Storing installation settings..."
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path
|
|
#REMOVEME? 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"
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=admin_mail_html --value="1"
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Installing dependencies..."
|
|
|
|
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Configuring system user..."
|
|
|
|
# Create a system user
|
|
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
|
|
# Create the directory and set the path in the config
|
|
mkdir -p "$install_dir/collections"
|
|
|
|
# Copy files to the right place
|
|
cp ../conf/radicale.wsgi $install_dir
|
|
|
|
# Copy extra files
|
|
cp -a ../sources/extra_files_radicale/. "$install_dir"
|
|
|
|
if [ $infcloud -eq 1 ]
|
|
then
|
|
# Download and uncompress the source into install_dir
|
|
ynh_setup_source --dest_dir="$install_dir/infcloud"
|
|
fi
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
# Set default permissions as radicale do.
|
|
chmod 666 -R $install_dir/default_collections
|
|
chmod 777 $install_dir/default_collections $install_dir/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
|
|
#REMOVEME? 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
|
|
#REMOVEME? 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 "$install_dir/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="$install_dir/infcloud/config.js"
|
|
|
|
chmod 440 "$install_dir/infcloud/config.js"
|
|
chown $app:www-data "$install_dir/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 $install_dir/default_collections/USER $install_dir/collections/$user
|
|
cp -a $install_dir/default_collections/USER.props $install_dir/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="__INSTALL_DIR__" --replace_string="$install_dir" --target_file="../hooks/post_user_create"
|
|
ynh_replace_string --match_string="__INSTALL_DIR__" --replace_string="$install_dir" --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
|
|
#=================================================
|
|
#REMOVEME? 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
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value="${path%/}/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)
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=skipped_regex --value="$domain_regex$path"
|
|
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
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
#REMOVEME? 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 $install_dir/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"
|