mirror of
https://github.com/YunoHost-Apps/nextcloud_ynh.git
synced 2024-09-03 19:55:57 +02:00
parent
09219ab72d
commit
e509d3766d
1 changed files with 149 additions and 143 deletions
292
scripts/upgrade
292
scripts/upgrade
|
@ -3,6 +3,8 @@
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
upgrade_type=$(ynh_check_app_version_changed)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ENSURE DOWNWARD COMPATIBILITY
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -146,173 +148,177 @@ then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_script_progression --message="Upgrading $app..." --weight=3
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
then
|
||||||
# Set write access for the following commands
|
ynh_script_progression --message="Upgrading $app..." --weight=3
|
||||||
chown -R $app: "$install_dir" "$data_dir"
|
|
||||||
|
|
||||||
# Print the current version number of Nextcloud
|
|
||||||
exec_occ -V
|
|
||||||
|
|
||||||
|
|
||||||
# Upgrade may fail if this app is enabled
|
|
||||||
# Take all apps enabled, and check if mail is one of them
|
|
||||||
# Then temporary disable the mail app
|
|
||||||
mail_app_must_be_reactived=0
|
|
||||||
|
|
||||||
if exec_occ app:list | awk '/Enabled/{f=1;next} /Disabled/{f=0} f' | grep -q -w mail; then
|
|
||||||
exec_occ app:disable mail
|
|
||||||
mail_app_must_be_reactived=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# While the current version is not the last version, do an upgrade
|
|
||||||
while [ "$last_version" != "$current_version" ]
|
|
||||||
do
|
|
||||||
next_major_version="$(( $current_major_version + 1 ))"
|
|
||||||
if [[ "$next_major_version" -ge "$last_major_version" ]]; then
|
|
||||||
ynh_print_info --message="Upgrading to Nextcloud $last_version"
|
|
||||||
cp -a ../sources/patches_last_version/* ../sources/patches
|
|
||||||
source_id="main"
|
|
||||||
else
|
|
||||||
ynh_print_info --message="Upgrading to Nextcloud $next_major_version"
|
|
||||||
source_id="$next_major_version"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create a temporary directory
|
|
||||||
tmpdir="${install_dir}__tmp_upgrade"
|
|
||||||
|
|
||||||
ynh_setup_source --dest_dir="$tmpdir" --source_id="$source_id"
|
|
||||||
|
|
||||||
# Backup the config file in the temp dir
|
|
||||||
cp -a "$install_dir/config/config.php" "$tmpdir/config/config.php"
|
|
||||||
|
|
||||||
# Enable maintenance mode
|
|
||||||
exec_occ maintenance:mode --on
|
|
||||||
|
|
||||||
# Backup 3rd party applications from the current Nextcloud
|
|
||||||
# But do not overwrite if there is any upgrade
|
|
||||||
# (apps directory already exists in Nextcloud archive)
|
|
||||||
(
|
|
||||||
cd $install_dir/apps
|
|
||||||
for nc_app_dir in */
|
|
||||||
do
|
|
||||||
if [ ! -d "$tmpdir/apps/$nc_app_dir" ]
|
|
||||||
then
|
|
||||||
cp -a "$nc_app_dir" "$tmpdir/apps/$nc_app_dir"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
)
|
|
||||||
|
|
||||||
# Replace the old Nextcloud by the new one
|
|
||||||
ynh_secure_remove --file="$install_dir"
|
|
||||||
mv "$tmpdir" "$install_dir"
|
|
||||||
|
|
||||||
# Set write access for the following commands
|
# Set write access for the following commands
|
||||||
chown -R $app: "$install_dir" "$data_dir"
|
chown -R $app: "$install_dir" "$data_dir"
|
||||||
|
|
||||||
# Upgrade Nextcloud (SUCCESS = 0, UP_TO_DATE = 3)
|
|
||||||
exec_occ maintenance:mode --off
|
|
||||||
exec_occ upgrade \
|
|
||||||
|| [ $? -eq 3 ] || ynh_die --message="Unable to upgrade $app"
|
|
||||||
|
|
||||||
# Get the new current version number
|
|
||||||
current_version=$(grep OC_VersionString "$install_dir/version.php" | cut -d\' -f2)
|
|
||||||
current_major_version=${current_version%%.*}
|
|
||||||
|
|
||||||
# Print the current version number of Nextcloud
|
# Print the current version number of Nextcloud
|
||||||
exec_occ -V
|
exec_occ -V
|
||||||
done
|
|
||||||
|
|
||||||
exec_occ db:add-missing-indices -n
|
|
||||||
exec_occ db:add-missing-columns -n
|
|
||||||
exec_occ db:add-missing-primary-keys -n
|
|
||||||
exec_occ db:convert-filecache-bigint -n
|
|
||||||
|
|
||||||
#=================================================
|
# Upgrade may fail if this app is enabled
|
||||||
# CONFIGURE NEXTCLOUD
|
# Take all apps enabled, and check if mail is one of them
|
||||||
#=================================================
|
# Then temporary disable the mail app
|
||||||
ynh_script_progression --message="Reconfiguring $app..." --weight=9
|
mail_app_must_be_reactived=0
|
||||||
|
|
||||||
# Verify the checksum and backup the file if it's different
|
if exec_occ app:list | awk '/Enabled/{f=1;next} /Disabled/{f=0} f' | grep -q -w mail; then
|
||||||
ynh_backup_if_checksum_is_different --file="$install_dir/config/config.php"
|
exec_occ app:disable mail
|
||||||
|
mail_app_must_be_reactived=1
|
||||||
|
fi
|
||||||
|
|
||||||
nc_conf="${install_dir}/config.json"
|
# While the current version is not the last version, do an upgrade
|
||||||
ynh_add_config --template="config.json" --destination="$nc_conf"
|
while [ "$last_version" != "$current_version" ]
|
||||||
|
do
|
||||||
|
|
||||||
# Reneable the mail app
|
next_major_version="$(( $current_major_version + 1 ))"
|
||||||
if [ $mail_app_must_be_reactived -eq 1 ]; then
|
if [[ "$next_major_version" -ge "$last_major_version" ]]; then
|
||||||
exec_occ app:enable mail
|
ynh_print_info --message="Upgrading to Nextcloud $last_version"
|
||||||
fi
|
cp -a ../sources/patches_last_version/* ../sources/patches
|
||||||
|
source_id="main"
|
||||||
|
else
|
||||||
|
ynh_print_info --message="Upgrading to Nextcloud $next_major_version"
|
||||||
|
source_id="$next_major_version"
|
||||||
|
fi
|
||||||
|
|
||||||
# Ensure that UpdateNotification app is disabled
|
# Create a temporary directory
|
||||||
exec_occ app:disable updatenotification
|
tmpdir="${install_dir}__tmp_upgrade"
|
||||||
|
|
||||||
# Enable LDAP plugin
|
ynh_setup_source --dest_dir="$tmpdir" --source_id="$source_id"
|
||||||
exec_occ app:enable user_ldap
|
|
||||||
|
|
||||||
# Update all installed apps
|
# Backup the config file in the temp dir
|
||||||
exec_occ app:update --all
|
cp -a "$install_dir/config/config.php" "$tmpdir/config/config.php"
|
||||||
|
|
||||||
# move the logs from the data_dir to the standard /var/log
|
# Enable maintenance mode
|
||||||
# it would be better in the ENSURE DOWNWARD COMPATIBILITY section
|
exec_occ maintenance:mode --on
|
||||||
# but it must be after the exec_occ() definition, so it's here
|
|
||||||
if [ -f "$data_dir/data/nextcloud.log" ]; then
|
|
||||||
mkdir -p "/var/log/$app"
|
|
||||||
chmod 750 "/var/log/$app"
|
|
||||||
mv "$data_dir"/data/nextcloud.log* "/var/log/$app"
|
|
||||||
# adapt the nextcloud config
|
|
||||||
exec_occ config:system:set logfile --value="/var/log/$app/nextcloud.log"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Load the config file in nextcloud
|
# Backup 3rd party applications from the current Nextcloud
|
||||||
exec_occ config:import "$nc_conf"
|
# But do not overwrite if there is any upgrade
|
||||||
|
# (apps directory already exists in Nextcloud archive)
|
||||||
|
(
|
||||||
|
cd $install_dir/apps
|
||||||
|
for nc_app_dir in */
|
||||||
|
do
|
||||||
|
if [ ! -d "$tmpdir/apps/$nc_app_dir" ]
|
||||||
|
then
|
||||||
|
cp -a "$nc_app_dir" "$tmpdir/apps/$nc_app_dir"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
)
|
||||||
|
|
||||||
# Then remove the config file
|
# Replace the old Nextcloud by the new one
|
||||||
ynh_secure_remove --file="$nc_conf"
|
ynh_secure_remove --file="$install_dir"
|
||||||
|
mv "$tmpdir" "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
# Set write access for the following commands
|
||||||
# ALLOW USERS TO DISCONNECT FROM NEXTCLOUD
|
chown -R $app: "$install_dir" "$data_dir"
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Add dynamic logout URL to the config
|
# Upgrade Nextcloud (SUCCESS = 0, UP_TO_DATE = 3)
|
||||||
exec_occ config:system:get logout_url >/dev/null 2>&1 \
|
exec_occ maintenance:mode --off
|
||||||
|| echo "
|
exec_occ upgrade \
|
||||||
//-YunoHost-
|
|| [ $? -eq 3 ] || ynh_die --message="Unable to upgrade $app"
|
||||||
// set logout_url according to main domain
|
|
||||||
\$main_domain = exec('cat /etc/yunohost/current_host');
|
|
||||||
\$CONFIG['logout_url'] = 'https://'.\$main_domain.'/yunohost/sso/?action=logout';
|
|
||||||
//-YunoHost-
|
|
||||||
" >> "$install_dir/config/config.php"
|
|
||||||
|
|
||||||
#=================================================
|
# Get the new current version number
|
||||||
# CHANGE HOSTNAME FOR ACTIVITY NOTIFICATIONS
|
current_version=$(grep OC_VersionString "$install_dir/version.php" | cut -d\' -f2)
|
||||||
#=================================================
|
current_major_version=${current_version%%.*}
|
||||||
|
|
||||||
exec_occ config:system:set overwrite.cli.url --value="https://${domain}${path}"
|
# Print the current version number of Nextcloud
|
||||||
|
exec_occ -V
|
||||||
#=================================================
|
|
||||||
# MOUNT HOME FOLDERS AS EXTERNAL STORAGE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Enable External Storage and create local mount to home folder as needed
|
|
||||||
if [ $user_home -eq 1 ]; then
|
|
||||||
exec_occ app:enable files_external
|
|
||||||
exec_occ files_external:list --output=json \
|
|
||||||
| grep -q '"storage":"\\\\OC\\\\Files\\\\Storage\\\\Local"' \
|
|
||||||
|| create_external_storage "/home/\$user" "Home"
|
|
||||||
# Iterate over users to extend their home folder permissions
|
|
||||||
for u in $(ynh_user_list); do
|
|
||||||
setfacl --modify g:$app:rwx "/home/$u" || true
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
exec_occ db:add-missing-indices -n
|
||||||
|
exec_occ db:add-missing-columns -n
|
||||||
|
exec_occ db:add-missing-primary-keys -n
|
||||||
|
exec_occ db:convert-filecache-bigint -n
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CONFIGURE NEXTCLOUD
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reconfiguring $app..." --weight=9
|
||||||
|
|
||||||
|
# Verify the checksum and backup the file if it's different
|
||||||
|
ynh_backup_if_checksum_is_different --file="$install_dir/config/config.php"
|
||||||
|
|
||||||
|
nc_conf="${install_dir}/config.json"
|
||||||
|
ynh_add_config --template="config.json" --destination="$nc_conf"
|
||||||
|
|
||||||
|
# Reneable the mail app
|
||||||
|
if [ $mail_app_must_be_reactived -eq 1 ]; then
|
||||||
|
exec_occ app:enable mail
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure that UpdateNotification app is disabled
|
||||||
|
exec_occ app:disable updatenotification
|
||||||
|
|
||||||
|
# Enable LDAP plugin
|
||||||
|
exec_occ app:enable user_ldap
|
||||||
|
|
||||||
|
# Update all installed apps
|
||||||
|
exec_occ app:update --all
|
||||||
|
|
||||||
|
# move the logs from the data_dir to the standard /var/log
|
||||||
|
# it would be better in the ENSURE DOWNWARD COMPATIBILITY section
|
||||||
|
# but it must be after the exec_occ() definition, so it's here
|
||||||
|
if [ -f "$data_dir/data/nextcloud.log" ]; then
|
||||||
|
mkdir -p "/var/log/$app"
|
||||||
|
chmod 750 "/var/log/$app"
|
||||||
|
mv "$data_dir"/data/nextcloud.log* "/var/log/$app"
|
||||||
|
# adapt the nextcloud config
|
||||||
|
exec_occ config:system:set logfile --value="/var/log/$app/nextcloud.log"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Load the config file in nextcloud
|
||||||
|
exec_occ config:import "$nc_conf"
|
||||||
|
|
||||||
|
# Then remove the config file
|
||||||
|
ynh_secure_remove --file="$nc_conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ALLOW USERS TO DISCONNECT FROM NEXTCLOUD
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Add dynamic logout URL to the config
|
||||||
|
exec_occ config:system:get logout_url >/dev/null 2>&1 \
|
||||||
|
|| echo "
|
||||||
|
//-YunoHost-
|
||||||
|
// set logout_url according to main domain
|
||||||
|
\$main_domain = exec('cat /etc/yunohost/current_host');
|
||||||
|
\$CONFIG['logout_url'] = 'https://'.\$main_domain.'/yunohost/sso/?action=logout';
|
||||||
|
//-YunoHost-
|
||||||
|
" >> "$install_dir/config/config.php"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHANGE HOSTNAME FOR ACTIVITY NOTIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
exec_occ config:system:set overwrite.cli.url --value="https://${domain}${path}"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MOUNT HOME FOLDERS AS EXTERNAL STORAGE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Enable External Storage and create local mount to home folder as needed
|
||||||
|
if [ $user_home -eq 1 ]; then
|
||||||
|
exec_occ app:enable files_external
|
||||||
|
exec_occ files_external:list --output=json \
|
||||||
|
| grep -q '"storage":"\\\\OC\\\\Files\\\\Storage\\\\Local"' \
|
||||||
|
|| create_external_storage "/home/\$user" "Home"
|
||||||
|
# Iterate over users to extend their home folder permissions
|
||||||
|
for u in $(ynh_user_list); do
|
||||||
|
setfacl --modify g:$app:rwx "/home/$u" || true
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Calculate and store the config file checksum into the app settings
|
||||||
|
ynh_store_file_checksum --file="${install_dir}/config/config.php"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# STORE THE CHECKSUM OF THE CONFIG FILE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Calculate and store the config file checksum into the app settings
|
|
||||||
ynh_store_file_checksum --file="${install_dir}/config/config.php"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REGEN PERMISSIONS
|
# REGEN PERMISSIONS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue