1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/agendav_ynh.git synced 2024-09-03 20:36:12 +02:00
agendav_ynh/scripts/upgrade
2017-10-20 17:55:20 +02:00

129 lines
3.7 KiB
Bash

#!/bin/bash
# Source local helpers
source ./_common.sh
# Source app helpers
source /usr/share/yunohost/helpers
# Abort script if errors
ynh_abort_if_errors
# Set app specific variables
app="$YNH_APP_INSTANCE_NAME"
dbname=$app
dbuser=$app
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
encryptkey=$(ynh_app_setting_get "$app" encryptkey)
language=$(ynh_app_setting_get "$app" language)
is_public=$(ynh_app_setting_get "$app" is_public)
# Set and store language
if [[ -z "$language" ]]; then
# retrieve language the old way
lang=${LANG/.*/}
[[ ${LANGUAGES[$lang]+_} ]] || lang="en"
# retrieve and store the relevant language
language=${LANGUAGES[$lang]}
ynh_app_setting_set "$app" language "$language"
fi
# Define LOGDIR (create it later when user is created)
LOGDIR=/var/log/$app
# Check destination directory
final_path=/var/www/$app
# 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 "Baikal or Radicale is mandatory"
fi
# Install dependencies
ynh_install_app_dependencies php5-cli
ynh_setup_source "$final_path"
# Copy and set AgenDAV configuration
conf_path="${final_path}/web/config/settings.php"
cp ../conf/settings.php "$conf_path"
sed -i "s/{DBUSER}/${dbuser}/g" "$conf_path"
sed -i "s/{DBPASS}/${dbpass}/g" "$conf_path"
sed -i "s/{DBNAME}/${dbname}/g" "$conf_path"
sed -i "s/{ENCRYPTKEY}/${encryptkey}/g" "$conf_path"
sed -i "s@{LOGDIR}@${LOGDIR}@g" "$conf_path"
sed -i "s@{TIMEZONE}@$(cat /etc/timezone)@g" "$conf_path"
sed -i "s@{LANGUAGE}@${language}@g" "$conf_path"
# CalDAV config
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%/}"
sed -i "s@{CALDAV_BASEURL}@${caldav_url}${caldav_baseurl}@g" "$conf_path"
sed -i "s@{CALDAV_DOMAIN}@${caldav_domain}@g" "$conf_path"
ynh_system_user_create "$app" "$final_path"
# Protect source code against modifications
find "${final_path}" -type f -exec chown root:root {} \; -exec chmod 644 {} \;
find "${final_path}" -type d -exec chown root:root {} \; -exec chmod 755 {} \;
# Only agendav user should write here
chown -hR $app: "${final_path}/web/var/cache/"{profiler,twig}
chmod -R 750 "${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.
find "${final_path}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \;
find "${final_path}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \;
# Create log directory
install -m 750 -o $app -g adm -d "$LOGDIR"
# Run database migrations
(
cd $final_path
php agendavcli migrations:migrate --no-interaction
)
# Copy and set nginx configuration
ynh_add_nginx_config
# Copy and set php-fpm configuration
ynh_add_fpm_config
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set "$app" unprotected_uris "/"
# ynh panel is not needed
ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf"
ynh_store_file_checksum "$finalnginxconf"
fi
# Reload services
service php5-fpm restart
service nginx reload