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

336 lines
11 KiB
Text
Raw Normal View History

2016-04-07 00:00:41 +02:00
#!/bin/bash
2017-03-19 18:36:20 +01:00
#=================================================
# GENERIC STARTING
#=================================================
# 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
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
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
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="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
2016-11-08 13:38:29 +01:00
admin=$YNH_APP_ARG_ADMIN
infcloud=$YNH_APP_ARG_INFCLOUD
language=$YNH_APP_ARG_LANGUAGE
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
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Check if the app can be installed"
2016-04-07 00:00:41 +02:00
2017-09-05 00:34:00 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Register (book) web path
ynh_webpath_register $app $domain $path_url
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Store settings from manifest" --weight=4
2016-04-07 00:00:41 +02:00
2016-12-14 16:13:20 +01:00
ynh_app_setting_set $app domain $domain
2017-03-19 18:36:20 +01:00
ynh_app_setting_set $app path $path_url
2016-12-14 16:13:20 +01:00
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app infcloud $infcloud
2017-03-19 18:36:20 +01:00
ynh_app_setting_set $app version $version
2019-01-30 19:30:41 +01:00
2018-09-29 23:37:05 +02:00
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"
2019-01-30 19:30:41 +01:00
ynh_app_setting_set $app admin_mail_html "1"
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Install dependencies" --weight=25
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
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-12-07 09:46:47 +01:00
ynh_script_progression --message="Configure NGINX" --weight=2
2017-03-19 18:36:20 +01:00
2017-09-05 00:34:00 +02:00
ynh_add_nginx_config
2017-03-19 18:36:20 +01:00
if [ $infcloud -eq 1 ]
2019-01-18 21:12:58 +01:00
then
2020-12-07 09:46:47 +01:00
# Add InfCloud in NGINX config
2017-06-13 22:28:52 +02:00
ynh_replace_string "#INFCLOUD#" "" /etc/nginx/conf.d/$domain.d/$app.conf
2017-03-19 18:36:20 +01:00
fi
2017-06-13 22:28:52 +02:00
ynh_store_file_checksum "$finalnginxconf"
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Create a dedicated user" --weight=2
2016-04-07 00:00:41 +02:00
2019-01-18 21:12:58 +01:00
# Create a dedicated system user
ynh_system_user_create $app
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL RADICALE IN A VIRTUALENV
#=================================================
2020-12-07 09:46:47 +01:00
ynh_script_progression --message="Install Radicale in a virtualenv" --weight=15
2016-04-07 00:00:41 +02:00
# Init virtualenv
2017-09-05 00:34:00 +02:00
virtualenv /opt/yunohost/$app
2017-12-16 23:29:00 +01:00
version=$(ynh_app_setting_get $app version $version)
2017-09-05 00:34:00 +02:00
/opt/yunohost/$app/bin/pip install radicale==$version python-ldap
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# COPY FILES INTO $FINAL_PATH
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Download, check and unpack source" --weight=2
2017-03-19 18:36:20 +01:00
2019-01-18 21:12:58 +01:00
# Create the directory and set the path in the config
2017-09-05 00:34:00 +02:00
mkdir "$final_path"
2017-03-19 18:36:20 +01:00
ynh_app_setting_set $app final_path $final_path
2016-04-07 00:00:41 +02:00
# Copy files to the right place
2017-09-05 00:34:00 +02:00
mkdir -p $final_path/collections
cp ../conf/radicale.wsgi $final_path
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"
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
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
ynh_setup_source "$final_path"
# Restore the content of $final_path
final_path=$final_path_backup
2016-04-07 00:00:41 +02:00
fi
2017-03-19 18:36:20 +01:00
#=================================================
# CONFIGURE RADICALE
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Configure Radicale" --weight=5
2017-03-19 18:36:20 +01:00
2017-09-05 00:34:00 +02:00
mkdir -p /etc/$app
cp ../conf/config /etc/$app/
cp ../conf/logging /etc/$app/
cp ../conf/rights /etc/$app/
2017-12-05 19:41:20 +01:00
ynh_replace_string "__PATH__" "${path_url%/}" /etc/$app/config
2017-06-13 22:28:52 +02:00
ynh_replace_string "__FINALPATH__" "$final_path" /etc/$app/config
2019-01-18 21:12:58 +01:00
# 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"
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
2016-12-14 16:13:20 +01:00
ynh_app_setting_set $app language $language
2017-09-05 00:34:00 +02:00
cp ../conf/config.js "$final_path/infcloud/"
2017-06-13 22:28:52 +02:00
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/infcloud/config.js"
2017-12-05 19:41:20 +01:00
ynh_replace_string "__PATH__" "${path_url%/}" "$final_path/infcloud/config.js"
2017-06-13 22:28:52 +02:00
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"
2019-01-18 21:12:58 +01:00
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/infcloud/config.js"
2016-04-07 00:00:41 +02:00
fi
2017-03-19 18:36:20 +01:00
#=================================================
# SET PERMISSIONS ON RADICALE'S DIRECTORIES
#=================================================
2017-09-05 00:34:00 +02:00
# useradd radicale -d /opt/yunohost/$app
chown radicale: -R /opt/yunohost/$app
2016-04-07 00:00:41 +02:00
2017-09-05 00:34:00 +02:00
chown -R radicale: $final_path
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown radicale -R /var/log/$app
2019-01-18 21:12:58 +01:00
# Set default permissions as radicale do.
2017-09-05 00:34:00 +02:00
chmod 666 -R $final_path/default_collections
chmod 777 $final_path/default_collections $final_path/default_collections/USER
2016-04-07 00:00:41 +02:00
2019-01-18 21:12:58 +01:00
# Set permissions
2017-09-05 00:34:00 +02:00
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/*
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# CONFIGURE UWSGI FOR RADICALE
#=================================================
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
#=================================================
# GENERATE CALENDARS AND ADDRESS BOOKS FOR ALL USERS
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Generate calendars and address books for all users" --weight=3
2017-03-19 18:36:20 +01:00
2019-01-18 21:12:58 +01:00
# Create default calendars and address books for each users
while read user
2016-04-07 00:00:41 +02:00
do
2017-09-05 00:34:00 +02:00
cp -a $final_path/default_collections/USER $final_path/collections/$user
cp -a $final_path/default_collections/USER.props $final_path/collections/$user.props
2019-01-18 21:12:58 +01:00
# 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
2017-03-19 18:36:20 +01:00
#=================================================
2019-01-18 21:12:58 +01:00
# ADVERTISE SERVICE IN ADMIN PANEL
2017-03-19 18:36:20 +01:00
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Restart Radicale" --weight=2
2017-03-19 18:36:20 +01:00
2019-01-18 21:12:58 +01:00
ynh_systemd_action --action=restart --service_name=uwsgi
2020-12-07 09:05:15 +01:00
yunohost service add uwsgi --log="/var/log/uwsgi/app/radicale.log"
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# PREPARE THE HOOKS
#=================================================
2019-01-18 21:12:58 +01:00
# Modify the hooks for create user collections and to remove them.
2017-06-13 22:28:52 +02:00
ynh_replace_string "__FINALPATH__" "$final_path" ../hooks/post_user_create
ynh_replace_string "__FINALPATH__" "$final_path" ../hooks/post_user_delete
2017-03-19 18:36:20 +01:00
#=================================================
# GENERIC FINALISATION
#=================================================
# SETUP SSOWAT
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Setup SSOwat" --weight=3
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
ynh_app_setting_set $app path ${path_url%/}/infcloud
# Protect InfCloud access
2019-01-18 21:12:58 +01:00
# Radicale is always accessible (For access to ressources)
2019-01-18 21:12:58 +01:00
else
# If only radicale is installed
# Radicale is always accessible (For access to ressources)
2016-04-07 00:00:41 +02:00
fi
2017-03-19 18:36:20 +01:00
#=================================================
# SETUP LOGROTATE
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Configure logrotate" --weight=2
2016-04-07 00:00:41 +02:00
2019-01-18 21:12:58 +01:00
# Use logrotate to manage application logfile(s)
2017-03-19 18:36:20 +01:00
ynh_use_logrotate
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
if [ $infcloud -eq 1 ]
then
2020-12-07 09:05:15 +01:00
ynh_script_progression --message="Configure PHP-FPM" --weight=4
2019-01-18 21:12:58 +01:00
# Create a dedicated php-fpm config
ynh_add_fpm_config
2020-12-07 09:05:15 +01:00
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2017-03-19 18:36:20 +01:00
fi
#=================================================
# RELOAD NGINX
#=================================================
2020-12-07 09:46:47 +01:00
ynh_script_progression --message="Reload NGINX" --weight=4
2017-03-19 18:36:20 +01:00
2019-01-18 21:12:58 +01:00
ynh_systemd_action --action=reload --service_name=nginx
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
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Installation completed" --last