mirror of
https://github.com/YunoHost-Apps/radicale_ynh.git
synced 2024-09-03 20:16:14 +02:00
314 lines
10 KiB
Bash
Executable file
314 lines
10 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path_url=$YNH_APP_ARG_PATH
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
infcloud=$YNH_APP_ARG_INFCLOUD
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Retrieve the version number in the manifest file.
|
|
version=$(ynh_app_upstream_version)
|
|
ynh_print_warn $version
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
final_path=/var/www/$app
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
# Register (book) web path
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
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
|
|
|
|
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_systemd --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"
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# 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
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
# Create a system user
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
# Create the directory and set the path in the config
|
|
mkdir -p "$final_path/collections"
|
|
|
|
if [ $infcloud -eq 1 ]
|
|
then
|
|
# Download and uncompress the source into final_path
|
|
ynh_setup_source --dest_dir="$final_path/infcloud"
|
|
fi
|
|
|
|
chmod 750 -R "$final_path"
|
|
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
|
|
# 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 -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
|
|
|
|
# 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
|
|
|
|
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/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="$final_path/infcloud/config.js"
|
|
|
|
chmod 440 "$final_path/infcloud/config.js"
|
|
chown $app:www-data "$final_path/infcloud/config.js"
|
|
fi
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# 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/$app"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=$app --action="restart"
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring permissions..."
|
|
|
|
if [ $infcloud -eq 1 ]
|
|
then
|
|
ynh_permission_create --permission="infcloud" --url="${path_url%/}/infcloud" --allowed="$admin" --show_tile=true
|
|
fi
|
|
ynh_permission_update --permission="main" --add="visitors" --show_tile=false
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
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 $final_path/infcloud/config.js
|
|
"
|
|
else
|
|
infcloud_config=""
|
|
fi
|
|
|
|
echo "Use the file /etc/radicale/config to change the main configuration of radicale.
|
|
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"
|