From 575a2355231fe0b54d699f611dd6999fc7c61e36 Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Mon, 19 Aug 2024 00:03:13 +0200 Subject: [PATCH] tree: do more rework Signed-off-by: AuxXxilium --- sspatch/all/usr/bin/sspatch.sh | 88 ++++++++++++++++++++++++++++++++++ sspatch/install.sh | 88 +++++++++++----------------------- 2 files changed, 115 insertions(+), 61 deletions(-) create mode 100755 sspatch/all/usr/bin/sspatch.sh diff --git a/sspatch/all/usr/bin/sspatch.sh b/sspatch/all/usr/bin/sspatch.sh new file mode 100755 index 0000000..1276453 --- /dev/null +++ b/sspatch/all/usr/bin/sspatch.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +if [ -d /var/packages/SurveillanceStation ]; then + # Define the entries to be added + ENTRIES=("0.0.0.0 synosurveillance.synology.com") + + # Loop over each entry + for ENTRY in "${ENTRIES[@]}" + do + if [ -f /tmpRoot/etc/hosts ]; then + # Check if the entry is already in the file + if grep -Fxq "$ENTRY" /tmpRoot/etc/hosts; then + echo "Entry $ENTRY already exists" + else + echo "Entry $ENTRY does not exist, adding now" + echo "$ENTRY" >> /tmpRoot/etc/hosts + fi + fi + if [ -f /tmpRoot/etc.defaults/hosts ]; then + if grep -Fxq "$ENTRY" /tmpRoot/etc.defaults/hosts; then + echo "Entry $ENTRY already exists" + else + echo "Entry $ENTRY does not exist, adding now" + echo "$ENTRY" >> /tmpRoot/etc.defaults/hosts + fi + fi + done + + SSPATH="/var/packages/SurveillanceStation" + PATHSCRIPTS="${SSPATH}/target/scripts" + SPATCHBIN="/usr/bin" + + SO_FILE="${SSPATH}/target/lib/libssutils.so" + if [ ! -f "${SO_FILE}" ]; then + echo "SSPatch: libssutils.so does not exist" + exit 1 + fi + + /usr/syno/bin/synopkg stop SurveillanceStation + sleep 5 + + # Check Sha256sum + if [ "$(sha256sum "${SO_FILE}" | cut -d' ' -f1)" = "81b64d65f4a2a65626f9280ba43ea43f031a239af3152b859b79e1b5124cc6e3" ]; then + PATCH="8548ffffff41be43000000e93dffffff/8548ffffff41be7b000000e93dffffff" + cp -f "${SO_FILE}" "${SO_FILE}.bak" + cp -f "${SO_FILE}" "${SO_FILE}.tmp" + xxd -c $(xxd -p "${SO_FILE}.tmp" 2>/dev/null | wc -c) -p "${SO_FILE}.tmp" 2>/dev/null | + sed "s/${PATCH}/" | + xxd -r -p >"${SO_FILE}" 2>/dev/null + rm -f "${SO_FILE}.tmp" + echo "SSPatch: libssutils.so is patched" + elif [ "$(sha256sum "${SO_FILE}" | cut -d' ' -f1)" = "b0fafefe820aa8ecd577313dff2ae22cf41a6ddf44051f01670c3b92ee04224d" ]; then + PATCH="850b010000e8b684e5ff83f80141bc43/850b010000e8b684e5ff83f80141bc7b" + cp -f "${SO_FILE}" "${SO_FILE}.bak" + cp -f "${SO_FILE}" "${SO_FILE}.tmp" + xxd -c $(xxd -p "${SO_FILE}.tmp" 2>/dev/null | wc -c) -p "${SO_FILE}.tmp" 2>/dev/null | + sed "s/${PATCH}/" | + xxd -r -p >"${SO_FILE}" 2>/dev/null + rm -f "${SO_FILE}.tmp" + echo "SSPatch: libssutils.so is patched" + else + if [ -f "${SO_FILE}.bak" ]; then + echo "SSPatch: libssutils.so is already patched" + exit 0 + else + echo "SSPatch: version not supported" + exit 1 + fi + fi + chown SurveillanceStation:SurveillanceStation "${SO_FILE}" + chmod 0644 "${SO_FILE}" + + rm -f "${PATHSCRIPTS}/S82surveillance.sh" + cp -f "${SPATCHBIN}/S82surveillance.sh" "${PATHSCRIPTS}/S82surveillance.sh" + chown SurveillanceStation:SurveillanceStation "${PATHSCRIPTS}/S82surveillance.sh" + chmod 0755 "${PATHSCRIPTS}/S82surveillance.sh" + + rm -f "${PATHSCRIPTS}/license.sh" + cp -f "${SPATCHBIN}/license.sh" "${PATHSCRIPTS}/license.sh" + chown SurveillanceStation:SurveillanceStation "${PATHSCRIPTS}/license.sh" + chmod 0777 "${PATHSCRIPTS}/license.sh" + + echo -e "Surveillance Patch: Successfull!" + + sleep 5 + /usr/syno/bin/synopkg start SurveillanceStation +fi +exit 0 \ No newline at end of file diff --git a/sspatch/install.sh b/sspatch/install.sh index 1081a2b..54490ed 100755 --- a/sspatch/install.sh +++ b/sspatch/install.sh @@ -1,71 +1,37 @@ #!/usr/bin/env ash if [ "${1}" = "late" ]; then - if [ -d /tmpRoot/var/packages/SurveillanceStation ]; then - echo "Installing addon sspatch - ${1}" - mkdir -p "/tmpRoot/usr/arc/addons/" - cp -vf "${0}" "/tmpRoot/usr/arc/addons/" + echo "Installing addon sspatch - ${1}" + mkdir -p "/tmpRoot/usr/arc/addons/" + cp -vf "${0}" "/tmpRoot/usr/arc/addons/" - SO_FILE="/tmpRoot/var/packages/SurveillanceStation/target/lib/libssutils.so" - if [ ! -f "${SO_FILE}" ]; then - echo "SSPatch: libssutils.so does not exist" - exit 0 - fi + cp -vf /usr/bin/sspatch.sh /tmpRoot/usr/bin/sspatch.sh + cp -vf /usr/bin/license.sh /tmpRoot/usr/bin/license.sh + cp -vf /usr/bin/S82surveillance.sh /tmpRoot/usr/bin/S82surveillance.sh + + mkdir -p "/tmpRoot/usr/lib/systemd/system" + DEST="/tmpRoot/usr/lib/systemd/system/sspatch.service" + cat << EOF > ${DEST} +[Unit] +Description=addon amepatch +After=multi-user.target - # Define the entries to be added - ENTRIES=("0.0.0.0 synosurveillance.synology.com") +[Service] +Type=simple +Restart=on-failure +RestartSec=5s +ExecStart=/usr/bin/sspatch.sh - # Loop over each entry - for ENTRY in "${ENTRIES[@]}" - do - if [ -f /tmpRoot/etc/hosts ]; then - # Check if the entry is already in the file - if grep -Fxq "$ENTRY" /tmpRoot/etc/hosts; then - echo "Entry $ENTRY already exists" - else - echo "Entry $ENTRY does not exist, adding now" - echo "$ENTRY" >> /tmpRoot/etc/hosts - fi - fi - if [ -f /tmpRoot/etc.defaults/hosts ]; then - if grep -Fxq "$ENTRY" /tmpRoot/etc.defaults/hosts; then - echo "Entry $ENTRY already exists" - else - echo "Entry $ENTRY does not exist, adding now" - echo "$ENTRY" >> /tmpRoot/etc.defaults/hosts - fi - fi - done +[Install] +WantedBy=multi-user.target - # Check Sha256sum - if [ "$(sha256sum "${SO_FILE}" | cut -d' ' -f1)" = "81b64d65f4a2a65626f9280ba43ea43f031a239af3152b859b79e1b5124cc6e3" ]; then - PATCH="8548ffffff41be43000000e93dffffff/8548ffffff41be7b000000e93dffffff" - cp -vf "${SO_FILE}" "${SO_FILE}.bak" - cp -f "${SO_FILE}" "${SO_FILE}.tmp" - xxd -c $(xxd -p "${SO_FILE}.tmp" 2>/dev/null | wc -c) -p "${SO_FILE}.tmp" 2>/dev/null | - sed "s/${PATCH}/" | - xxd -r -p >"${SO_FILE}" 2>/dev/null - rm -f "${SO_FILE}.tmp" - echo "SSPatch: libssutils.so is patched" - elif [ "$(sha256sum "${SO_FILE}" | cut -d' ' -f1)" = "b0fafefe820aa8ecd577313dff2ae22cf41a6ddf44051f01670c3b92ee04224d" ]; then - PATCH="850b010000e8b684e5ff83f80141bc43/850b010000e8b684e5ff83f80141bc7b" - cp -vf "${SO_FILE}" "${SO_FILE}.bak" - cp -f "${SO_FILE}" "${SO_FILE}.tmp" - xxd -c $(xxd -p "${SO_FILE}.tmp" 2>/dev/null | wc -c) -p "${SO_FILE}.tmp" 2>/dev/null | - sed "s/${PATCH}/" | - xxd -r -p >"${SO_FILE}" 2>/dev/null - rm -f "${SO_FILE}.tmp" - echo "SSPatch: libssutils.so is patched" - else - if [ -f "${SO_FILE}.bak" ]; then - echo "SSPatch: libssutils.so is already patched" - else - echo "SSPatch: version not supported" - fi - fi - cp -vf /usr/bin/license.sh /tmpRoot/usr/bin/license.sh - cp -vf /usr/bin/S82surveillance.sh /tmpRoot/usr/bin/S82surveillance.sh - fi +[X-Synology] +Author=Virtualization Team +EOF + + mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants + ln -vsf /usr/lib/systemd/system/sspatch.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/sspatch.service +fi elif [ "${1}" = "uninstall" ]; then echo "Installing addon sspatch - ${1}" # To-Do