Calculate time difference

This commit is contained in:
Kroese 2023-04-17 15:50:49 +02:00 committed by GitHub
parent 1ed99ab73d
commit a039eb859d

View File

@ -2,6 +2,7 @@
set -u set -u
# Functions # Functions
HEADER="VirtualDSM Agent:"
function checkNMI { function checkNMI {
@ -10,7 +11,7 @@ function checkNMI {
if [ "$nmi" != "" ]; then if [ "$nmi" != "" ]; then
echo "Received shutdown request through NMI.." echo "$HEADER Received shutdown request through NMI.."
/usr/syno/sbin/synoshutdown -s > /dev/null /usr/syno/sbin/synoshutdown -s > /dev/null
exit exit
@ -21,7 +22,7 @@ function checkNMI {
finish() { finish() {
echo "Shutting down guest agent.." echo "$HEADER Shutting down.."
exit exit
} }
@ -32,7 +33,7 @@ ts=$(date +%s%N)
checkNMI checkNMI
VERSION="4" VERSION="4"
echo "Starting agent v$VERSION.." echo "$HEADER starting v$VERSION.."
# Install packages # Install packages
@ -51,11 +52,10 @@ if [ "$first_run" = true ]; then
BASE=$(basename "$filename" .spk) BASE=$(basename "$filename" .spk)
BASE="${BASE%%-*}" BASE="${BASE%%-*}"
echo "Installing package ${BASE}.." echo "$HEADER Installing package ${BASE}.."
/usr/syno/bin/synopkg install "$filename" > /dev/null
#echo "Activating package ${BASE}.." /usr/syno/bin/synopkg install "$filename" > /dev/null
/usr/syno/bin/synopkg start "$BASE" & /usr/syno/bin/synopkg start "$BASE" > /dev/null &
rm "$filename" rm "$filename"
@ -73,22 +73,32 @@ else
line=$(head -1 "${TMP}") line=$(head -1 "${TMP}")
if [ "$line" == "#!/usr/bin/env bash" ]; then if [ "$line" == "#!/usr/bin/env bash" ]; then
SCRIPT=$(readlink -f ${BASH_SOURCE[0]}) SCRIPT=$(readlink -f ${BASH_SOURCE[0]})
mv -f "${TMP}" "${SCRIPT}" if ! cmp --silent -- "${TMP}" "${SCRIPT}"; then
chmod +x "${SCRIPT}" mv -f "${TMP}" "${SCRIPT}"
chmod +x "${SCRIPT}"
echo "$HEADER succesfully installed update."
else
echo "$HEADER Update not needed."
fi
else else
echo "Update error, invalid header: $line" echo "$HEADER update error, invalid header: $line"
fi fi
else else
echo "Update error, file not found.." echo "$HEADER update error, file not found.."
fi fi
else else
echo "Update error, curl error: $?" echo "$HEADER update error, curl error: $?"
fi fi
fi fi
elapsed=$((($(date +%s%N) - $ts)/1000000)) elapsed=$((($(date +%s%N) - $ts)/1000000))
echo "Elapsed time: $elapsed" difference=$(((5000-elapsed)*0.001))
if (( difference > 0 )); then
echo "Elapsed time: $elapsed, difference: $difference"
sleep $difference
fi
# Display message in docker log output # Display message in docker log output