#!/bin/bash
. /usr/syno/bin/jsoncmd

WEBSTATION_CONFIG_PATH="/usr/syno/etc/packages/WebStation"
WEBSTATION_JSON_FILES="WebStation.json VirtualHost.json"
PHP56_CONFIG_PATH="/usr/local/etc/php56/conf.d"
PHP56_INI_FILES="user-settings.ini extensions.ini apcu.ini opcache.ini"
BIN_PATH="/var/packages/WebStation/target/tools"

exportPath=$(jget "${SYNOPKG_BKP_INPUT}" ".temp_path")
if [ $? -ne 0 ];then
	msg="WebStation backup failed"
	error=$(printf "%s(%s)" "${msg}" "0x01")
	jerr "$error"
	exit 1
fi

# backup WebStation Json config
for file in ${WEBSTATION_JSON_FILES}; do
	if [ -e "${WEBSTATION_CONFIG_PATH}/${file}" ]; then
		cp -f "${WEBSTATION_CONFIG_PATH}/${file}" "${exportPath}/"
	fi
done

# backup PHP56 ini
for file in ${PHP56_INI_FILES}; do
	if [ -e "${PHP56_CONFIG_PATH}/${file}" ]; then
		cp -f "${PHP56_CONFIG_PATH}/${file}" "${exportPath}/"
	fi
done

# backup userdatacollection
"${BIN_PATH}"/synouserdata_webstation > "${exportPath}"/usercollection.json

jout_begin
joutstr "app_data_version" "1.0"
jout_end
