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

315 lines
10 KiB
Text
Raw Normal View History

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 () {
2022-11-22 13:40:41 +01:00
ynh_clean_check_starting
2022-03-18 22:47:33 +01:00
}
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)
2022-11-22 13:40:41 +01:00
ynh_print_warn $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_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"
2022-11-22 13:40:41 +01:00
ynh_app_setting_set --app=$app --key=overwrite_systemd --value="1"
2022-03-18 22:47:33 +01:00
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
2022-11-22 13:40:41 +01:00
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Configuring firewall..."
# Find a free port
port=$(ynh_find_port --port=5232)
ynh_app_setting_set --app=$app --key=port --value=$port
2017-03-19 18:36:20 +01:00
#=================================================
# 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
2017-03-19 18:36:20 +01:00
if [ $infcloud -eq 1 ]
2019-01-18 21:12:58 +01:00
then
2022-11-22 13:40:41 +01:00
# Download and uncompress the source into final_path
ynh_setup_source --dest_dir="$final_path/infcloud"
2016-04-07 00:00:41 +02:00
fi
2022-11-22 13:40:41 +01:00
chmod 750 -R "$final_path"
2022-03-18 22:47:33 +01:00
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config
ynh_add_nginx_config
if [ $infcloud -eq 1 ]
then
2022-11-22 13:40:41 +01:00
# Add InfCloud in NGINX config
ynh_replace_string --match_string="#INFCLOUD#" --replace_string="" --target_file="/etc/nginx/conf.d/$domain.d/$app.conf"
2022-03-18 22:47:33 +01:00
fi
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
if [ $infcloud -eq 1 ]
then
2022-11-22 13:40:41 +01:00
ynh_script_progression --message="Configuring PHP-FPM..."
2022-03-18 22:47:33 +01:00
2022-11-22 13:40:41 +01:00
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2022-03-18 22:47:33 +01:00
fi
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL RADICALE IN A VIRTUALENV
#=================================================
ynh_script_progression --message="Install Radicale in a virtualenv"
# Init virtualenv
2022-11-22 13:40:41 +01:00
virtualenv -p python3 /opt/yunohost/$app
version=$(ynh_app_upstream_version)
ynh_app_setting_set --app=$app --key=version --value="$version"
/opt/yunohost/$app/bin/python3 -m pip install radicale==$version passlib bcrypt
2022-03-18 22:47:33 +01:00
2022-11-22 13:40:41 +01:00
# Add LDAP plugin
# (cd /opt/yunohost/$app
# set +u; source bin/activate
# # git clone https://github.com/marcoh00/radicale-auth-ldap
# git clone https://github.com/cloudron-io/radicale-auth-ldap
# cd radicale-auth-ldap
# python3 -m pip install .)
# Use htpasswd instead of ldap
touch /etc/radicale/users
# sudo htpasswd -B -c /etc/radicale/users username
2022-03-19 12:28:19 +01:00
2022-03-18 22:47:33 +01:00
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/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
2022-11-22 13:40:41 +01:00
# 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 440 "$final_path/infcloud/config.js"
chown $app:www-data "$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
# 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
2022-11-22 13:40:41 +01:00
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
# Create a dedicated systemd config
ynh_add_systemd_config
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-11-22 13:40:41 +01:00
yunohost service add $app --log="/var/log/$app"
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
2022-11-22 13:40:41 +01:00
ynh_systemd_action --service_name=$app --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
2022-11-22 13:40:41 +01:00
ynh_permission_create --permission="infcloud" --url="${path_url%/}/infcloud" --allowed="$admin" --show_tile=true
2017-03-19 18:36:20 +01:00
fi
2022-11-22 13:40:41 +01:00
ynh_permission_update --permission="main" --add="visitors" --show_tile=false
2017-03-19 18:36:20 +01:00
#=================================================
# 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
2022-11-22 13:40:41 +01:00
infcloud_config="
2017-12-16 23:29:00 +01:00
InfCloud has its own config file, at $final_path/infcloud/config.js
"
else
2022-11-22 13:40:41 +01:00
infcloud_config=""
2017-12-16 23:29:00 +01:00
fi
2019-01-30 19:30:41 +01:00
echo "Use the file /etc/radicale/config to change the main configuration of radicale.
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"