HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: //var/packages/StorageManager/scripts/postupgrade
#!/bin/sh
# Copyright (C) 2000-2023 Synology Inc. All rights reserved.

### This script will be executed ONLY at package upgraded.
### Actions after package upgraded.
### ex. restore user settings.
PKG_RUN_PATH="/run/smpkg"

log() {
	echo "$(date +"%Y/%m/%d %T") $1"
	return 0
}
is_upgrade_from_pkg_center()
{
	[ -f /var/.UpgradeBootup ] && return 1
	return 0
}
upgrade_passive_smpkg() {
	local resp=""
	resp=$(/usr/local/bin/synoharequest --synopkg show StorageManager)
	if [[ $? -ne 0 ]]; then
		log "failed to show smpkg details"
		return 1
	fi
	local link=$(/bin/echo $resp | jq --raw-output '.link')
	local spk_name=$(/bin/basename $link)
	local spk_path="/var/tmp/${spk_name}"
	/bin/curl -o $spk_path $link
	if [[ $? -ne 0 ]]; then
		log "failed to curl spk"
		return 1
	fi
	resp=$(/usr/local/bin/synohaupgrade --install-remote-pkg -P=$spk_path)
	if [[ $? -ne 0 ]]; then
		log "failed to request remote to install smpkg"
		return 1
	fi
	/bin/rm $spk_path
	local success=$(/bin/echo $resp | jq --raw-output '.success')
	if [[ "$success" == "true" ]]; then
		return 0
	else
		log "failed to install passive smpkg"
		return 1
	fi
}

clear_smpkg_upgrading_flag()
{
	rm -f "${PKG_RUN_PATH}/upgrading"
}

if [ "yes" != "$(/usr/syno/sbin/synohacore --is_ha_running)" ]; then
	clear_smpkg_upgrading_flag
	exit 0
fi
if [ "Active" != "$(/usr/local/bin/synoha --local-role)" ]; then
	clear_smpkg_upgrading_flag
	exit 0
fi
if ! is_upgrade_from_pkg_center; then
	clear_smpkg_upgrading_flag
	exit 0
fi

upgrade_passive_smpkg
if [[ $? -ne 0 ]]; then
	log "failed to upgrade passive smpkg"
fi
clear_smpkg_upgrading_flag
exit 0