#!/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 old app settings domain=$(ynh_app_setting_get "$app" domain) path_url=$(ynh_app_setting_get "$app" path) dbpass=$(ynh_app_setting_get "$app" mysqlpwd) # Check web path availability ynh_webpath_available "$domain" "$path_url" # Install dependencies ynh_install_app_dependencies "php5-cli" # Check destination directory final_path="/var/www/$app" ynh_restore_file "$final_path" # Check whether Baïkal or Radicale is installed if yunohost app list --installed -f baikal | grep -q id ; then caldav_app="baikal" caldav_baseurl="/cal.php/" elif yunohost app list --installed -f radicale | grep -q id ; then caldav_app="radicale" caldav_baseurl="/" else ynh_die "You must install Baïkal or Radicale before" fi ynh_system_user_create "$app" "$final_path" # Protect source code against modifications chown -hR root: "$final_path" # 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 {} \; # Clean caches ynh_secure_remove "${final_path}/web/var/cache/"{profiler,twig}/* # 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%/}" conf_path="${final_path}/web/config/settings.php" sed -i "s@^\(\$app\['caldav.baseurl'\] = \).*\ @\1'${caldav_url}${caldav_baseurl}';@g" "$conf_path" sed -i "s@^\(\$app\['caldav.baseurl.public'\] = \).*\ @\1'${caldav_domain}';@g" "$conf_path" # Create log directory install -m 750 -o www-data -g adm -d "/var/log/${app}" # Create and restore the database ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql # Restore configuration files ynh_restore_file "/etc/nginx/conf.d/${domain}.d/${app}.conf" ynh_restore_file "/etc/php5/fpm/pool.d/${app}.conf" # Reload services service php5-fpm restart service nginx reload