mirror of
https://github.com/YunoHost-Apps/agendav_ynh.git
synced 2024-09-03 20:36:12 +02:00
194 lines
5.7 KiB
Bash
194 lines
5.7 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
|
|
final_path=/var/www/$app
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
# Normalize the url path syntax
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
# Register (book) web path
|
|
ynh_webpath_register $app $domain $path_url
|
|
|
|
|
|
agendav_app_check_installation() {
|
|
echo $(yunohost app list --installed -f "$1" | grep "id:")
|
|
}
|
|
|
|
# Check whether Baïkal or Radicale is installed
|
|
baikal_install=$(agendav_app_check_installation "baikal")
|
|
radicale_install=$(agendav_app_check_installation "radicale")
|
|
if [ -n "$baikal_install" ]
|
|
then
|
|
caldav_app=baikal
|
|
caldav_baseurl="/cal.php/"
|
|
elif [ -n "$radicale_install" ]
|
|
then
|
|
caldav_app=radicale
|
|
caldav_baseurl=/
|
|
else
|
|
ynh_die "Please install Baikal or Radicale before AgenDAV."
|
|
fi
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
ynh_app_setting_set $app path $path_url
|
|
ynh_app_setting_set $app language $language
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
|
|
# Install dependencies
|
|
ynh_install_app_dependencies php5-cli
|
|
|
|
#=================================================
|
|
# CREATE A MYSQL DATABASE
|
|
#=================================================
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
ynh_app_setting_set $app db_name $db_name
|
|
ynh_mysql_setup_db $db_name $db_name
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
ynh_setup_source "$final_path"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
# Copy and set nginx configuration
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
|
|
ynh_system_user_create $app
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#================================================
|
|
|
|
# Copy and set php-fpm configuration
|
|
ynh_add_fpm_config
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# CREATE SETTINGS.PHP
|
|
#=================================================
|
|
|
|
# Generate random encryption key
|
|
encryptkey=$(ynh_string_random 24)
|
|
|
|
ynh_app_setting_set $app encryptkey "$encryptkey"
|
|
|
|
# Copy and set AgenDAV configuration
|
|
timezone=$(cat /etc/timezone)
|
|
|
|
caldav_domain=$(ynh_app_setting_get $caldav_app domain)
|
|
caldav_path=$(ynh_app_setting_get $caldav_app path)
|
|
caldav_url="https://${caldav_domain}${caldav_path%/}"
|
|
|
|
conf_path="${final_path}/web/config/settings.php"
|
|
cp ../conf/settings.php "$conf_path"
|
|
|
|
logdir=/var/log/$app
|
|
|
|
ynh_replace_string "__DBUSER__" "${db_name}" "$conf_path"
|
|
ynh_replace_string "__DBPASS__" "${db_pwd}" "$conf_path"
|
|
ynh_replace_string "__DBNAME__" "${db_name}" "$conf_path"
|
|
ynh_replace_string "__ENCRYPTKEY__" "${encryptkey}" "$conf_path"
|
|
ynh_replace_string "__LOGDIR__" "${logdir}" "$conf_path"
|
|
ynh_replace_string "__TIMEZONE__" "$timezone" "$conf_path"
|
|
ynh_replace_string "__LANGUAGE__" "${language}" "$conf_path"
|
|
ynh_replace_string "__CALDAV_BASEURL__" "${caldav_url}${caldav_baseurl}" "$conf_path"
|
|
ynh_replace_string "__CALDAV_DOMAIN__" "${caldav_domain}" "$conf_path"
|
|
|
|
#=================================================
|
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
|
#=================================================
|
|
|
|
ynh_store_file_checksum "$conf_path"
|
|
|
|
#=================================================
|
|
# RUN DATABASE MIGRATIONS (INCLUDES INITIALIZATION)
|
|
#=================================================
|
|
|
|
(
|
|
cd $final_path
|
|
php agendavcli migrations:migrate --no-interaction
|
|
)
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
|
|
mkdir -p $logdir
|
|
chown -R $app: $logdir
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_use_logrotate
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
chown -R root: $final_path
|
|
|
|
# Only agendav user should write here
|
|
chown -R $app ${final_path}/web/var/cache/{profiler,twig}
|
|
|
|
# The agendav user should read here, but does not need to write
|
|
# Other users should not be able to read as it stores passwords.
|
|
chown -R root:$app ${final_path}/web/config/
|
|
chmod -R 750 ${final_path}/web/config/
|
|
|
|
#=================================================
|
|
# RELOAD NGINX and FPM
|
|
#=================================================
|
|
|
|
# Reload services
|
|
systemctl reload php5-fpm
|
|
systemctl reload nginx
|