#!/bin/bash set -eu # Get multi-instances specific variables app=$YNH_APP_INSTANCE_NAME # Set app specific variables dbname=$app dbuser=$app # Source app helpers source /usr/share/yunohost/helpers # Retrieve old app settings domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) dbpass=$(ynh_app_setting_get "$app" mysqlpwd) # TODO: Check domain/path availability with app helper # Temporarily conditioned, see https://dev.yunohost.org/issues/593 if [ ${#path} -gt 1 ]; then sudo yunohost app checkurl "${domain}${path}" -a "$app" \ || ynh_die "The path ${domain}${path} is not available for app installation." fi # Check destination directory DESTDIR="/var/www/$app" [[ -d $DESTDIR ]] && ynh_die \ "The destination directory '$DESTDIR' already exists.\ You should safely delete it before restoring this app." # Define app's data directory DATADIR="/home/yunohost.app/${app}/data" # Check configuration files nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" [[ -f $nginx_conf ]] && ynh_die \ "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app." phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" [[ -f $phpfpm_conf ]] && ynh_die \ "The PHP FPM configuration already exists at '${phpfpm_conf}'. You should safely delete it before restoring this app." # Install dependencies ynh_package_install_from_equivs ./nextcloud-deps.control \ || ynh_die "Unable to install dependencies" # Create a system account for Nextcloud sudo useradd -c "$app system account" \ -d /var/lib/$app --system --user-group $app \ || ynh_die "Unable to create $app system account" # Restore the app files sudo cp -a ./www "$DESTDIR" sudo mkdir -p "$DATADIR" if [ -d ./data ] # Le dossier data est restauré seulement si il existe. Si le backup a été fait avec l'option backup_core_only, ce dossier n'a pas été sauvegardé. then sudo cp -a ./data/. "$DATADIR" fi ynh_app_setting_delete $app backup_core_only # Retire l'option backup_core_only du fichier settings.yml le cas échéant # Create and restore the database ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql # Iterate over users to extend their home folder permissions - for the external # storage plugin usage - and create relevant Nextcloud directories for u in $(ynh_user_list); do sudo mkdir -p "${DATADIR}/${u}" sudo setfacl -m g:$app:rwx "/home/$u" || true done # Fix app ownerships & permissions sudo chown -R $app: "$DESTDIR" "$DATADIR" sudo find ${DESTDIR}/ -type f -print0 | sudo xargs -0 chmod 0644 sudo find ${DESTDIR}/ -type d -print0 | sudo xargs -0 chmod 0755 sudo find ${DATADIR}/ -type f -print0 | sudo xargs -0 chmod 0640 sudo find ${DATADIR}/ -type d -print0 | sudo xargs -0 chmod 0750 sudo chmod 640 "${DESTDIR}/config/config.php" sudo chmod 755 /home/yunohost.app # Restore configuration files sudo cp -a ./conf/nginx.conf "$nginx_conf" sudo cp -a ./conf/php-fpm.conf "$phpfpm_conf" # Restore cron job sudo cp -a ./conf/cron "/etc/cron.d/${app}" # Reload services sudo service php5-fpm restart || true sudo service nginx reload || true