#!/bin/sh

# Script Environment Variables
# -------------------------------------------------------------------------------------
# SYNOPKG_PKGNAME               =   Package identify which is defined in INFO
# SYNOPKG_PKGVER                =   Package version which is defined in INFO
# SYNOPKG_PKGDEST               =   Package destination path
#                                   /volume[x]/@appstore/[Package Name]
# SYNOPKG_TEMP_UPGRADE_FOLDER   =   Temporary upgrade folder
#                                   /volume1/@tmp/synopkg.tmp/[Package Name]
# -------------------------------------------------------------------------------------


# Important Paths, soft links and variables
# -------------------------------------------------------------------------------------
# DSM WebGUI folder
# /usr/syno/synoman/webman/3rdparty/[Package Name] -> /var/packages/[Package Name]/target
WEBGUI_FOLDER="/usr/syno/synoman/webman/3rdparty/${SYNOPKG_PKGNAME}"

# Soft link
# /var/packages/[Package Name]/target -> /volume1/@appstore/[Package Name]
PACKAGE_FOLDER="/var/packages/${SYNOPKG_PKGNAME}/target/ui"

# Timestamp - Formatting the Timestamp to terminate log entries
TIMESTAMP=$(date +%Y-%m-%d%t%H:%M:%S)
# -------------------------------------------------------------------------------------

# Action...
# -------------------------------------------------------------------------------------

# um unseren Platzhalter auf / zu bringen
rm -rf $SYNOPKG_PKGDEST/ocr_docker
ln -s / $SYNOPKG_PKGDEST/ocr_docker

# DSM 7: postinst runs as package user (not root). If DSM already applied the
# privilege "tool" setuid bit, heal docker/administrators immediately so the
# user never needs a manual root start. If the bit is not set yet, first GUI
# or package start of synOCR-start.sh will call the helper.
HELPER=""
case "$(uname -m)" in
    x86_64)  HELPER="${SYNOPKG_PKGDEST}/bin/helper/synocr-helper-x86_64" ;;
    aarch64|arm64) HELPER="${SYNOPKG_PKGDEST}/bin/helper/synocr-helper-aarch64" ;;
esac
if [ -n "${HELPER}" ] && [ -u "${HELPER}" ]; then
    "${HELPER}" selfheal >/tmp/synOCR.postinst.selfheal 2>&1 || true
fi

exit 0