HEX
Server: Apache/2.4.63 (Unix)
System: Linux Synopilou92 4.4.302+ #72806 SMP Mon Jul 21 23:16:00 CST 2025 x86_64
User: pilou92 (1026)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: //var/packages/SynologyApplicationService/scripts/utils
#!/bin/sh

SynoSettingsGet()
{
	synogetkeyvalue /var/packages/SynologyApplicationService/etc/settings.conf $1
}

SynoSettingsSet()
{
	synosetkeyvalue /var/packages/SynologyApplicationService/etc/settings.conf $1 $2
}

SynoService()
{
	SynoSystemdService "$@"
	return $?;
}

SynoUpstartService()
{
	if (( $# < 2 )); then
		echo "Fatal, Wrong params." > $SYNOPKG_TEMP_LOGFILE
		return 2
	fi

	NEED_GREP=$( [ $1 == 'stop' ] && echo 'stop' || echo 'running' )
	if [ "$1" != "status" ]; then
		initctl $1 $2
		sleep 1
	fi

	if (( $# > 2 )); then
		initctl status $2 | grep $NEED_GREP;
		while (( $? == 0 )); do
			result=true
			for (( idx = 3 ; $idx <= $# ; ++idx )); do
				if ! ${!idx}; then
					result=false
					break;
				fi
			done
			if $result; then
				return 0
			fi
			sleep 0.5
			initctl status $2 | grep $NEED_GREP >/dev/null 2>&1;
		done
		echo "Service \"$2\" $1 failed." > $SYNOPKG_TEMP_LOGFILE
		return 1
	fi
	initctl status $2 | grep $NEED_GREP >/dev/null 2>&1;
	return $?
}

SynoSystemdService()
{
	if (( $# < 2 )); then
		echo "Fatal, Wrong params." > $SYNOPKG_TEMP_LOGFILE
		return 2
	fi

	NEED_GREP=$( [ $1 == 'stop' ] && echo 'inactive' || echo 'active' )
	if [ "$1" != "status" ]; then
		/usr/syno/bin/synosystemctl "$1" "$2"
		sleep 3
	fi

	if (( $# > 2 )); then
		/usr/syno/bin/synosystemctl get-active-status "$2" | grep -w "${NEED_GREP}"
		while (( $? == 0 )); do
			result=true
			for (( idx = 3 ; $idx <= $# ; ++idx )); do
				if ! ${!idx}; then
					result=false
					break;
				fi
			done
			if $result; then
				return 0
			fi
			sleep 0.5
			/usr/syno/bin/synosystemctl get-active-status "$2" | grep -w "${NEED_GREP}" >/dev/null 2>&1;
		done
		echo "Service \"$2\" $1 failed." > $SYNOPKG_TEMP_LOGFILE
		return 1
	fi
	/usr/syno/bin/synosystemctl get-active-status "$2" | grep -w "${NEED_GREP}" >/dev/null 2>&1;
	return $?
}

SynoSetVolume()
{
	volume="$(SynoSettingsGet volume)"

	volume_name=$(realpath /var/packages/SynologyApplicationService/target | /usr/bin/cut -d'/' -f2)
	install_volume="/$volume_name/@SynologyApplicationService"

	if [ ! -d ${install_volume} ]; then
		/bin/mkdir -p ${install_volume}
	fi

	if [[ "" != ${volume} && -d ${volume} && ${volume} != ${install_volume} ]]; then
		/bin/rm -rf ${install_volume}
		/bin/mv -f ${volume} ${install_volume}
	fi

	if [ ! -L /usr/local/SynologyApplicationService ]; then
		/bin/rm -rf /usr/local/SynologyApplicationService
	fi

	/bin/unlink /usr/local/SynologyApplicationService
	/bin/ln -s ${install_volume} /usr/local/SynologyApplicationService

	SynoSettingsSet volume ${install_volume}
}

FSDNIsSupported()
{
	if [[ ! -f "/usr/syno/sbin/syno_feature_check.sh" ]]; then
		return 1
	fi
	if [[ -z "$G_FSDN_IS_SUPPORT" ]];then
		if /usr/syno/sbin/syno_feature_check.sh SYNO_PRODUCT_FSDN ; then
			G_FSDN_IS_SUPPORT=0
		else
			G_FSDN_IS_SUPPORT=1
		fi
	fi
	return $G_FSDN_IS_SUPPORT
}

FSDNIsAdminNode()
{
	if [[ "$(/usr/syno/bin/aacore is-admin-node)" == "yes" ]]; then
		return 0
	fi
	return 1
}

IsSASServiceRunningNode()
{
	# PAM non-admin node
	if FSDNIsSupported && ! FSDNIsAdminNode; then
		return 1
	fi
	return 0
}