@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
#=================================================
# LOAD SETTINGS
# LOAD SETTINGS
#=================================================
#=================================================
ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
app=$YNH_APP_INSTANCE_NAME
@ -25,6 +26,7 @@ user_home=$(ynh_app_setting_get $app user_home)
#=================================================
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
#=================================================
ynh_print_info "Ensuring downward compatibility..."
# If db_name doesn't exist, create it
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
if [ -z $db_name ]; then
@ -38,22 +40,22 @@ if [ -z $final_path ]; then
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set $app final_path $final_path
fi
fi
# Remove the option backup_core_only if it's in the settings.yml file
ynh_app_setting_delete $app backup_core_only
#=================================================
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
#=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..."
# Made a backup only after the version 11.0.0
# Made a backup only after the version 11.0.0
# Before, the datas will be always saved.
# Before, the datas will be always saved.
# Get the current version number of nextcloud/owncloud
# Get the current version number of nextcloud/owncloud
current_version=$(grep OC_VersionString "$final_path/version.php" | cut -d\' -f2)
current_version=$(grep OC_VersionString "$final_path/version.php" | cut -d\' -f2)
current_major_version=${current_version%%.*}
current_major_version=${current_version%%.*}
if [ $current_major_version -gt 11 ]
if [ $current_major_version -gt 11 ]
then
then
# Inform the backup/restore process that it should not save the data directory
ynh_app_setting_set $app backup_core_only 1
# Backup the current version of the app
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_setup () {
@ -65,7 +67,7 @@ then
}
}
fi
fi
# Exit if an error occurs during the script execution
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_abort_if_errors
#=================================================
#=================================================
@ -75,7 +77,7 @@ ynh_abort_if_errors
ynh_handle_app_migration "owncloud" "owncloud_migration"
ynh_handle_app_migration "owncloud" "owncloud_migration"
if [ $migration_process -eq 1 ]
if [ $migration_process -eq 1 ]
then
then
# If a migration has been perform
# If a migration has been performed
# Reload some values changed by the migration process
# Reload some values changed by the migration process
final_path=$(ynh_app_setting_get $app final_path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
db_name=$(ynh_app_setting_get $app db_name)
@ -105,34 +107,35 @@ path_url=$(ynh_normalize_url_path $path_url)
#=================================================
#=================================================
# NGINX CONFIGURATION
# NGINX CONFIGURATION
#=================================================
#=================================================
ynh_print_info "Upgrading nginx web server configuration..."
ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf"
# Delete current nginx configuration to be able to check if .well-known is already served.
# Delete current nginx configuration to be able to check if .well-known is already served.
ynh_remove_nginx_config
ynh_remove_nginx_config
ynh_app_setting_delete $app "checksum__etc_nginx_conf.d_$domain.d_$app.conf" || true
ynh_app_setting_delete $app "checksum__etc_nginx_conf.d_$domain.d_$app.conf" || true
# Do not serve .well-known if it's already served on the domain
# Do not serve .well-known if it's already served on the domain
if is_url_handled "https://${ domain} /.well-known/caldav" ; then
if is_url_handled "https://$domain/.well-known/caldav" ; then
sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
"../conf/nginx.conf"
"../conf/nginx.conf"
fi
fi
# Handle root path, avoid double slash.
# Temporary fix, in waiting for an upgrade of the helper. (#361)
path_url_slash_less=${path_url%/}
ynh_replace_string "__PATH__/" "$path_url_slash_less/" "../conf/nginx.conf"
# Create a dedicated nginx config
# Create a dedicated nginx config
ynh_add_nginx_config
ynh_add_nginx_config
#=================================================
#=================================================
# CREATE DEDICATED USER
# CREATE DEDICATED USER
#=================================================
#=================================================
ynh_print_info "Making sure dedicated system user exists..."
# Create a system user
# Create a dedicated user (if not existing)
ynh_system_user_create $app
ynh_system_user_create $app
#=================================================
#=================================================
# PHP-FPM CONFIGURATION
# PHP-FPM CONFIGURATION
#=================================================
#=================================================
ynh_print_info "Upgrading php-fpm configuration..."
# Create a dedicated php-fpm config
# Create a dedicated php-fpm config
ynh_add_fpm_config
ynh_add_fpm_config
@ -140,6 +143,7 @@ ynh_add_fpm_config
#=================================================
#=================================================
# UPGRADE DEPENDENCIES
# UPGRADE DEPENDENCIES
#=================================================
#=================================================
ynh_print_info "Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
ynh_install_app_dependencies $pkg_dependencies
@ -149,13 +153,20 @@ ynh_install_app_dependencies $pkg_dependencies
# MAKE SEQUENTIAL UPGRADES FROM EACH MAJOR
# MAKE SEQUENTIAL UPGRADES FROM EACH MAJOR
# VERSION TO THE NEXT ONE
# VERSION TO THE NEXT ONE
#=================================================
#=================================================
ynh_print_info "Upgrading nextcloud..."
# Define a function to execute commands with `occ`
exec_occ() {
(cd "$final_path" && exec_as "$app" \
php occ --no-interaction --no-ansi "$@")
}
# Load the last available version
# Load the last available version
source upgrade.d/upgrade.last.sh
source upgrade.d/upgrade.last.sh
last_version=$next_version
last_version=$next_version
# Define app's data directory
# Define app's data directory
datadir="/home/yunohost.app/${app}/data"
datadir="/home/yunohost.app/$app/data"
# Set write access for the following commands
# Set write access for the following commands
chown -R $app: "$final_path" "$datadir"
chown -R $app: "$final_path" "$datadir"
@ -183,7 +194,7 @@ do
# Load the value for this version
# Load the value for this version
source upgrade.d/upgrade.$current_major_version.sh
source upgrade.d/upgrade.$current_major_version.sh
echo -e "\nUpgrade to nextcloud $next_version" >&2
ynh_print_info "Upgrade to nextcloud $next_version"
# Create an app.src for this version of nextcloud
# Create an app.src for this version of nextcloud
cp ../conf/app.src.default ../conf/app.src
cp ../conf/app.src.default ../conf/app.src
@ -218,7 +229,7 @@ do
# Upgrade Nextcloud (SUCCESS = 0, UP_TO_DATE = 3)
# Upgrade Nextcloud (SUCCESS = 0, UP_TO_DATE = 3)
exec_occ maintenance:mode --off
exec_occ maintenance:mode --off
exec_occ upgrade \
exec_occ upgrade \
|| ([[ $? -eq 3 ] ] || ynh_die "Unable to upgrade Nextcloud")
|| ([ $? -eq 3 ] || ynh_die "Unable to upgrade Nextcloud")
# Get the new current version number
# Get the new current version number
current_version=$(grep OC_VersionString "$final_path/version.php" | cut -d\' -f2)
current_version=$(grep OC_VersionString "$final_path/version.php" | cut -d\' -f2)
@ -231,14 +242,16 @@ done
#=================================================
#=================================================
# CONFIGURE NEXTCLOUD
# CONFIGURE NEXTCLOUD
#=================================================
#=================================================
ynh_print_info "Reconfiguring nextcloud..."
# Verify the checksum and backup the file if it's different
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "${ final_path} /config/config.php"
ynh_backup_if_checksum_is_different "$final_path/config/config.php"
nc_conf="${final_path}/config.json"
nc_conf="${final_path}/config.json"
cp ../conf/config.json "$nc_conf"
cp ../conf/config.json "$nc_conf"
ynh_replace_string "#DOMAIN#" "$domain" "$nc_conf"
ynh_replace_string "#DATADIR#" "$datadir" "$nc_conf"
ynh_replace_string "__DOMAIN__" "$domain" "$nc_conf"
ynh_replace_string "__DATADIR__" "$datadir" "$nc_conf"
# Ensure that UpdateNotification app is disabled
# Ensure that UpdateNotification app is disabled
exec_occ app:disable updatenotification
exec_occ app:disable updatenotification
@ -248,7 +261,8 @@ exec_occ app:enable user_ldap
# Load the config file in nextcloud
# Load the config file in nextcloud
exec_occ config:import "$nc_conf"
exec_occ config:import "$nc_conf"
# Then remove it
# Then remove the config file
rm -f "$nc_conf"
rm -f "$nc_conf"
#=================================================
#=================================================
@ -263,7 +277,7 @@ exec_occ config:system:get logout_url >/dev/null 2>&1 \
\$main_domain = exec('cat /etc/yunohost/current_host');
\$main_domain = exec('cat /etc/yunohost/current_host');
\$CONFIG['logout_url'] = 'https://'.\$main_domain.'/yunohost/sso/?action=logout';
\$CONFIG['logout_url'] = 'https://'.\$main_domain.'/yunohost/sso/?action=logout';
//-YunoHost-
//-YunoHost-
" >> "${ final_path} /config/config.php"
" >> "$final_path/config/config.php"
#=================================================
#=================================================
# CHANGE HOSTNAME FOR ACTIVITY NOTIFICATIONS
# CHANGE HOSTNAME FOR ACTIVITY NOTIFICATIONS
@ -275,6 +289,18 @@ ynh_replace_string "'overwrite.cli.url' => 'http://localhost'," "'overwrite.cli.
# MOUNT HOME FOLDERS AS EXTERNAL STORAGE
# MOUNT HOME FOLDERS AS EXTERNAL STORAGE
#=================================================
#=================================================
# Define a function to add an external storage
# Create the external storage for the given folders and enable sharing
create_external_storage() {
local datadir="$1"
local mount_name="$2"
local mount_id=`exec_occ files_external:create --output=json \
"$mount_name" 'local' 'null::null' -c "datadir=$datadir" || true`
! [[ $mount_id =~ ^[0-9]+$ ]] \
&& echo "Unable to create external storage" >&2 \
|| exec_occ files_external:option "$mount_id" enable_sharing true
}
# Enable External Storage and create local mount to home folder as needed
# Enable External Storage and create local mount to home folder as needed
if [ $user_home -eq 1 ]; then
if [ $user_home -eq 1 ]; then
exec_occ app:enable files_external
exec_occ app:enable files_external
@ -283,7 +309,7 @@ if [ $user_home -eq 1 ]; then
|| create_external_storage "/home/\$user" "Home"
|| create_external_storage "/home/\$user" "Home"
# Iterate over users to extend their home folder permissions
# Iterate over users to extend their home folder permissions
for u in $(ynh_user_list); do
for u in $(ynh_user_list); do
setfacl -m g:$app:rwx "/home/$u" || true
setfacl -- modify g:$app:rwx "/home/$u" || true
done
done
fi
fi
@ -303,8 +329,8 @@ cp -a ../conf/nextcloud.cron "$cron_path"
chown root: "$cron_path"
chown root: "$cron_path"
chmod 644 "$cron_path"
chmod 644 "$cron_path"
ynh_replace_string "#USER# " "$app" "$cron_path"
ynh_replace_string "#DESTDIR# " "$final_path" "$cron_path"
ynh_replace_string "__USER__ " "$app" "$cron_path"
ynh_replace_string "__DESTDIR__ " "$final_path" "$cron_path"
exec_occ background:cron
exec_occ background:cron
@ -313,11 +339,12 @@ exec_occ background:cron
#=================================================
#=================================================
# Set system group in hooks
# Set system group in hooks
ynh_replace_string "#GROUP# " "$app" ../hooks/post_user_create
ynh_replace_string "__GROUP__ " "$app" ../hooks/post_user_create
#=================================================
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
#=================================================
ynh_print_info "Updating multimedia directories..."
# Build YunoHost multimedia directories
# Build YunoHost multimedia directories
ynh_multimedia_build_main_dir
ynh_multimedia_build_main_dir
@ -336,11 +363,11 @@ ynh_multimedia_addaccess $app
# Fix app ownerships & permissions
# Fix app ownerships & permissions
chown -R $app: "$final_path" "$datadir"
chown -R $app: "$final_path" "$datadir"
find ${ final_path} / -type f -print0 | xargs -0 chmod 0644
find ${ final_path} / -type d -print0 | xargs -0 chmod 0755
find ${ datadir} / -type f -print0 | xargs -0 chmod 0640
find ${ datadir} / -type d -print0 | xargs -0 chmod 0750
chmod 640 "${ final_path} /config/config.php"
find $final_path/ -type f -print0 | xargs -0 chmod 0644
find $final_path/ -type d -print0 | xargs -0 chmod 0755
find $datadir/ -type f -print0 | xargs -0 chmod 0640
find $datadir/ -type d -print0 | xargs -0 chmod 0750
chmod 640 "$final_path/config/config.php"
chmod 755 /home/yunohost.app
chmod 755 /home/yunohost.app
#=================================================
#=================================================
@ -348,12 +375,13 @@ chmod 755 /home/yunohost.app
#=================================================
#=================================================
# Warn about possible disabled apps
# Warn about possible disabled apps
echo "Note that if you've installed some third-parties Nextcloud applications, \
they are probably disabled and you'll have to manually enable them again." >&2
ynh_print_warn "Note that if you've installed some third-parties Nextcloud applications, \
they are probably disabled and you'll have to manually enable them again."
#=================================================
#=================================================
# SETUP LOGROTATE
# SETUP LOGROTATE
#=================================================
#=================================================
ynh_print_info "Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s)
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
ynh_use_logrotate --non-append
@ -363,6 +391,7 @@ ynh_use_logrotate --non-append
#=================================================
#=================================================
# SETUP SSOWAT
# SETUP SSOWAT
#=================================================
#=================================================
ynh_print_info "Upgrading SSOwat configuration..."
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set $app skipped_regex \
ynh_app_setting_set $app skipped_regex \
@ -371,6 +400,7 @@ ynh_app_setting_set $app skipped_regex \
#=================================================
#=================================================
# RELOAD NGINX
# RELOAD NGINX
#=================================================
#=================================================
ynh_print_info "Reloading nginx web server..."
systemctl reload nginx
systemctl reload nginx
@ -380,10 +410,10 @@ systemctl reload nginx
if [ $migration_process -eq 1 ]
if [ $migration_process -eq 1 ]
then
then
ech o "ownCloud has been successfully migrated to Nextcloud! \
ynh_print_inf o "ownCloud has been successfully migrated to Nextcloud! \
A last scheduled operation will run in a couple of minutes to finish the \
A last scheduled operation will run in a couple of minutes to finish the \
migration in YunoHost side. Do not proceed any application operation while \
migration in YunoHost side. Do not proceed any application operation while \
you don't see Nextcloud as installed." >&2
you don't see Nextcloud as installed."
# Execute a post migration script after the end of this upgrade.
# Execute a post migration script after the end of this upgrade.
# Mainly for some cleaning
# Mainly for some cleaning
@ -394,3 +424,9 @@ you don't see Nextcloud as installed." >&2
chmod +x /tmp/$script_post_migration
chmod +x /tmp/$script_post_migration
(cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes)
(cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes)
fi
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Upgrade of $app completed"