From 2d89c36679dcd3e33bc2c0990050017378e1cc8b Mon Sep 17 00:00:00 2001 From: 76rhodan Date: Mon, 19 Feb 2024 08:30:35 +0000 Subject: [PATCH] next try of s6 migrate --- rootfs/back/cont-init.d/50-vrs | 129 +++++++ rootfs/back/cont-init.d/60-marker | 77 +++++ rootfs/back/cont-init.d/61-layer | 106 ++++++ rootfs/back/services.d/autoupdate/run | 324 ++++++++++++++++++ rootfs/back/services.d/vrs/run | 19 + rootfs/etc/s6-overlay/s6-rc.d/50-vrs/type | 1 + rootfs/etc/s6-overlay/s6-rc.d/50-vrs/up | 2 + .../s6-rc.d/60-marker/dependencies.d/50-vrs | 0 rootfs/etc/s6-overlay/s6-rc.d/60-marker/type | 1 + rootfs/etc/s6-overlay/s6-rc.d/60-marker/up | 2 + .../s6-rc.d/61-layer/dependencies.d/50-vrs | 0 .../s6-rc.d/61-layer/dependencies.d/60-marker | 0 rootfs/etc/s6-overlay/s6-rc.d/61-layer/type | 1 + rootfs/etc/s6-overlay/s6-rc.d/61-layer/up | 2 + .../s6-rc.d/autoupdate/dependencies.d/50-vrs | 0 .../autoupdate/dependencies.d/60-marker | 0 .../autoupdate/dependencies.d/61-layer | 0 rootfs/etc/s6-overlay/s6-rc.d/autoupdate/run | 2 + rootfs/etc/s6-overlay/s6-rc.d/autoupdate/type | 1 + .../s6-overlay/s6-rc.d/user/contents.d/50-vrs | 0 .../s6-rc.d/user/contents.d/60-marker | 0 .../s6-rc.d/user/contents.d/61-layer | 0 .../s6-rc.d/user/contents.d/autoupdate | 0 .../s6-overlay/s6-rc.d/user/contents.d/vrs | 0 .../s6-rc.d/vrs/dependencies.d/50-vrs | 0 .../s6-rc.d/vrs/dependencies.d/60-marker | 0 .../s6-rc.d/vrs/dependencies.d/61-layer | 0 rootfs/etc/s6-overlay/s6-rc.d/vrs/run | 2 + rootfs/etc/s6-overlay/s6-rc.d/vrs/type | 1 + rootfs/etc/s6-overlay/scripts/50-vrs | 129 +++++++ rootfs/etc/s6-overlay/scripts/60-marker | 77 +++++ rootfs/etc/s6-overlay/scripts/61-layer | 106 ++++++ rootfs/etc/s6-overlay/scripts/autoupdate | 324 ++++++++++++++++++ rootfs/etc/s6-overlay/scripts/vrs | 19 + 34 files changed, 1325 insertions(+) create mode 100755 rootfs/back/cont-init.d/50-vrs create mode 100755 rootfs/back/cont-init.d/60-marker create mode 100755 rootfs/back/cont-init.d/61-layer create mode 100644 rootfs/back/services.d/autoupdate/run create mode 100755 rootfs/back/services.d/vrs/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/50-vrs/type create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/50-vrs/up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/60-marker/dependencies.d/50-vrs create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/60-marker/type create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/60-marker/up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/61-layer/dependencies.d/50-vrs create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/61-layer/dependencies.d/60-marker create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/61-layer/type create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/61-layer/up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/50-vrs create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/60-marker create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/61-layer create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/autoupdate/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/autoupdate/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/50-vrs create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/60-marker create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/61-layer create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/autoupdate create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vrs create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/50-vrs create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/60-marker create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/61-layer create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/vrs/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/vrs/type create mode 100755 rootfs/etc/s6-overlay/scripts/50-vrs create mode 100755 rootfs/etc/s6-overlay/scripts/60-marker create mode 100755 rootfs/etc/s6-overlay/scripts/61-layer create mode 100755 rootfs/etc/s6-overlay/scripts/autoupdate create mode 100755 rootfs/etc/s6-overlay/scripts/vrs diff --git a/rootfs/back/cont-init.d/50-vrs b/rootfs/back/cont-init.d/50-vrs new file mode 100755 index 0000000..96270bf --- /dev/null +++ b/rootfs/back/cont-init.d/50-vrs @@ -0,0 +1,129 @@ +#!/usr/bin/with-contenv bash +#shellcheck shell=bash disable=SC2034,SC2164,SC2015 + +APPNAME="$(hostname)/vrs-init" +VRS_DIR="/opt/vrs" +VRS_EXEC="mono VirtualRadar.exe" +VRS_CMDLINE=() +VRS_CMDLINE+=("-nogui") +VRS_CMDLINE+=("-createAdmin:${VRS_ADMIN_USERNAME}") +VRS_CMDLINE+=("-password:${VRS_ADMIN_PASSWORD}") +VRS_CONFIG_DIR="/root/.local/share/VirtualRadar" +VRS_EXTENSION_DIR="/root/.local/share/VirtualRadar/CustomContent/CustomInjectedFiles" +#Silhouettes, OpFlags and DB +FLAGSDB_LINK="https://github.com/rikgale/VRSData/raw/main/BaseStation.zip" + +#max runtime in seconds for VRS init +MAXTIME=15 + +#helper files for updatechecks +ACTUALFILE="$VRS_CONFIG_DIR/commitid" +ACTUALFILE_CM="$VRS_CONFIG_DIR/commitid_cm" +ACTUALFILE_SQB="$VRS_CONFIG_DIR/commitid_sqb" + +#We need that for the update-after-fresh-install prevention +WHICHREPO_SQB="https://api.github.com/repos/rikgale/VRSData/branches" +WHICHBRANCH_SQB="main" + +#if the helper file to store the commit ID isn't there, create it empty +touch $ACTUALFILE +#and the same for the custom markers +touch $ACTUALFILE_CM +#for the database +touch $ACTUALFILE_SQB + +#debugging stuff +#echo $ACTUAL +#echo $PROBE +BUILD_DATE=$(cat "${VRS_DIR}"/builddate) + +echo "[$APPNAME][$(date)] Initializing Virtual Radar Server, build ${BUILD_DATE}..." + +mkdir -p "${VRS_CONFIG_DIR}/flags" +mkdir -p "${VRS_CONFIG_DIR}/silhouettes" +mkdir -p "${VRS_CONFIG_DIR}/photos" +mkdir -p "${VRS_CONFIG_DIR}/db" +mkdir -p "${VRS_CONFIG_DIR}/CustomContent/CustomInjectedFiles" + +#download and install pre-filled DB for operator flags. As this should only happen once, no commit id check needed +if [ ! -e "${VRS_CONFIG_DIR}/db/BaseStation.sqb" ] +then + echo "[$APPNAME][$(date)] Downloading database for Operator Flags" + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/BaseStation.zip" ${FLAGSDB_LINK} && unzip -qq -o -d "${VRS_CONFIG_DIR}/db" "${VRS_CONFIG_DIR}/BaseStation.zip" + then + echo "[$APPNAME][$(date)] Database for Operator Flags installed successfully" + #that should prevent a DB update right after a fresh download + PROBE_SQB=$(curl -sH "Accept: application/vnd.github.v3+json" $WHICHREPO_SQB | awk "c&&!--c;/$WHICHBRANCH_SQB/{c=2}" | awk '/"sha"/ { print $2}' | sed 's/"//g;s/.$//g') + echo "$PROBE_SQB" > $ACTUALFILE_SQB + echo "[$APPNAME][$(date)] Updated $ACTUALFILE_SQB to commit ID $PROBE_SQB" + else + echo "[$APPNAME][$(date)] Database for Operator Flags not installed - failure" + fi +else + echo "[$APPNAME][$(date)] Found an existing DB in $VRS_CONFIG_DIR, not touching anything!" +fi + +#copy PluginsConfig into place if it's not there +if [ ! -e "${VRS_CONFIG_DIR}/PluginsConfiguration.txt" ] + then + echo "[$APPNAME][$(date)] PluginsConfiguration.txt not found, adding template" + if cp -f /opt/vrs/PluginsConfiguration.txt "${VRS_CONFIG_DIR}/PluginsConfiguration.txt" + then + echo "[$APPNAME][$(date)] PluginsConfiguration.txt not found, adding template - OK" + else + echo "[$APPNAME][$(date)] PluginsConfiguration.txt not found, adding template - Failure" + fi + else + echo "[$APPNAME][$(date)] PluginsConfiguration.txt found, not touching anything" +fi + +# Starting VRS temporarily to create a username and password if none exist +# If VRS has been initialized previously this step will be skipped. +# If it hasn't, a username / password and a bunch of other files will be created... +# ...and VRS will actually stay up and run. We will shut it down after a max runtime of $MAXTIME secs. +if [ ! -e "${VRS_CONFIG_DIR}/Configuration.xml" ] +then + echo "[$APPNAME][$(date)] No Configuration.xml found, doing first run initialization." + cd "${VRS_DIR}" + # shellcheck disable=SC2068,SC2086 + timeout "$MAXTIME" exec ${VRS_EXEC} ${VRS_CMDLINE[@]} #>/dev/null 2>&1 + echo "[$APPNAME][$(date)] Virtual Radar Server has been initialized." +else + echo "[$APPNAME][$(date)] Configuration.xml found, skipping initialization." +fi + +# Replace 127.0.0.1 With ReadSB +sed -i "s#
127.0.0.1
#
${VRS_SBSHOST:-readsb}
#g" "${VRS_CONFIG_DIR}/Configuration.xml" +sed -i "s#30003#${VRS_SBSPORT:-30003}#g" "${VRS_CONFIG_DIR}/Configuration.xml" + +#Injecting settings for silhouettes, OpFlags and DB into Configuration.xml +if ! grep -q "" "${VRS_CONFIG_DIR}/Configuration.xml" +then + sed -i "/^ .*/a \ \/root/.local/share/VirtualRadar/db/BaseStation.sqb" "${VRS_CONFIG_DIR}/Configuration.xml" + echo "[$APPNAME][$(date)] Added database filename to Configuration.xml" +else + echo "[$APPNAME][$(date)] DatabaseFileName found, not touching config." +fi + +if ! grep -q "" "${VRS_CONFIG_DIR}/Configuration.xml" +then + sed -i "/^ .*/a \ \/root/.local/share/VirtualRadar/flags" "${VRS_CONFIG_DIR}/Configuration.xml" + echo "[$APPNAME][$(date)] Added Operator Flags folder to Configuration.xml" +else + echo "[$APPNAME][$(date)] OperatorFlagsFolder found, not touching config." +fi + +if ! grep -q "" "${VRS_CONFIG_DIR}/Configuration.xml" +then + sed -i "/^ .*/a \ \/root/.local/share/VirtualRadar/silhouettes" "${VRS_CONFIG_DIR}/Configuration.xml" + echo "[$APPNAME][$(date)] Added Silhouettes folder to Configuration.xml" +else + echo "[$APPNAME][$(date)] SilhouettesFolder found, not touching config." +fi + +#cleanup and exit +[[ -f "${VRS_CONFIG_DIR}/BaseStation.zip" ]] && rm -f "${VRS_CONFIG_DIR}/BaseStation.zip" || true +echo "[$APPNAME][$(date)] Cleaned up downloaded files." +echo "[$APPNAME][$(date)] Finished basic configuration." + +exit 0 diff --git a/rootfs/back/cont-init.d/60-marker b/rootfs/back/cont-init.d/60-marker new file mode 100755 index 0000000..5cb8049 --- /dev/null +++ b/rootfs/back/cont-init.d/60-marker @@ -0,0 +1,77 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +APPNAME="$(hostname)/vrs-ccmarker" +#VRS_DIR="/opt/vrs" +VRS_CONFIG_DIR="/root/.local/share/VirtualRadar" +VRS_EXTENSION_DIR="/root/.local/share/VirtualRadar/CustomContent/CustomInjectedFiles" + +#PluginConfig Settings (escaped) +CCMARKER_DISABLED="%3cInjectSettings%3e%0a++++%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3etrue%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fMyMarkers1\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +CCMARKER_ENABLED="%3cInjectSettings%3e%0a++++%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3etrue%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fMyMarkers1\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" + +#Downloadlinks +EXT_MARKERS_LINK="https://raw.githubusercontent.com/rikgale/VRSCustomMarkers/main/MyMarkers1.html" +EXT_HFDLMARKERS_LINK="https://raw.githubusercontent.com/rikgale/VRSCustomMarkers/main/MyMarkers1HFDL.html" + +echo "[$APPNAME][$(date)] Starting CustomContent Markers script..." + +#Create the directory in case it's not there +mkdir -p "${VRS_CONFIG_DIR}/CustomContent/CustomInjectedFiles" + +if [[ -n "${VRS_ENHANCED_MARKERS}" ]] + then + echo "[$APPNAME][$(date)] Downloading and installing Custom Markers" + #normal markers + if [[ "${VRS_ENHANCED_MARKERS}" == "normal" ]] + then + echo "[$APPNAME][$(date)] Normal Custom markers" + if curl --fail -s -L -o "${VRS_EXTENSION_DIR}/MyMarkers1.html" ${EXT_MARKERS_LINK} + then + echo "[$APPNAME][$(date)] Normal Custom marker file download - OK" + echo "[$APPNAME][$(date)] Injecting custom marker config into PluginsConfiguration.txt" + if sed -i -e "s/$CCMARKER_DISABLED/$CCMARKER_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Custom marker config enabled - OK" + else + echo "[$APPNAME][$(date)] Custom marker config enabled - Failure" + fi + else + echo "[$APPNAME][$(date)] Normal Custom marker file download - Failure" + fi + #HFDL markers + elif [[ "${VRS_ENHANCED_MARKERS}" == "HFDL" ]] || [[ "${VRS_ENHANCED_MARKERS}" == "hfdl" ]] + then + echo "[$APPNAME][$(date)] HFDL Custom markers" + if curl --fail -s -L -o "${VRS_EXTENSION_DIR}/MyMarkers1.html" ${EXT_HFDLMARKERS_LINK} + then + echo "[$APPNAME][$(date)] HFDL Custom marker file download - OK" + echo "[$APPNAME][$(date)] Injecting custom marker config into PluginsConfiguration.txt" + if sed -i -e "s/$CCMARKER_DISABLED/$CCMARKER_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Custom marker config enabled - OK" + else + echo "[$APPNAME][$(date)] Custom marker config enabled - Failure" + fi + else + echo "[$APPNAME][$(date)] HFDL Custom marker file download - Failure" + fi + #disabled + elif [[ "${VRS_ENHANCED_MARKERS}" == "disabled" ]] || [[ "${VRS_ENHANCED_MARKERS}" == "false" ]] + then + echo "[$APPNAME][$(date)] HFDL Custom markers disabled" + if sed -i -e "s/$CCMARKER_ENABLED/$CCMARKER_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Custom marker config disabled - OK" + else + echo "[$APPNAME][$(date)] Custom marker config disabled - Failure" + fi + + else echo "[$APPNAME][$(date)] yaml setting unkown. Check readme." + fi + else + echo "[$APPNAME][$(date)] Custom Markers not enabled" +fi + +#cleanup and exit +exit 0 diff --git a/rootfs/back/cont-init.d/61-layer b/rootfs/back/cont-init.d/61-layer new file mode 100755 index 0000000..3f0379b --- /dev/null +++ b/rootfs/back/cont-init.d/61-layer @@ -0,0 +1,106 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +APPNAME="$(hostname)/vrs-cclayer" +#VRS_DIR="/opt/vrs" +VRS_CONFIG_DIR="/root/.local/share/VirtualRadar" +VRS_EXTENSION_DIR="/root/.local/share/VirtualRadar/CustomContent/CustomInjectedFiles" + +#PluginConfig Settings (escaped) +LAYER_EOB_DISABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fEndOfBody\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_EOB_ENABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fEndOfBody\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_EOH_DISABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eHead%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fEndOfHead\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_EOH_ENABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eHead%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fEndOfHead\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_SCALE_DISABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e%2fdesktop\.html%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fScale\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_SCALE_ENABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e%2fdesktop\.html%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fScale\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_FULLSCREEN_DISABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e%2fdesktop\.html%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fFullScreen\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_FULLSCREEN_ENABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e%2fdesktop\.html%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fFullScreen\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" + +#Downloadlinks +EXT_LAYERS_LINK="https://github.com/rikgale/VRSCustomLayers/raw/main/VRSCustomLayers.zip" + +echo "[$APPNAME][$(date)] Starting CustomContent Layers script..." + +#Create the directory in case it's not there +[ -d "${VRS_EXTENSION_DIR}" ] && mkdir -p "${VRS_CONFIG_DIR}/CustomContent/CustomInjectedFiles" + +if [[ -n "${VRS_ENHANCED_LAYERS_COUNTRY}" ]] + then + #cleaning up first + cd "${VRS_EXTENSION_DIR}" || exit + rm "${VRS_CONFIG_DIR}/CustomContent/CustomInjectedFiles"/*.geojson + echo "[$APPNAME][$(date)] Downloading and installing Enhanced Layers" + if curl --fail --compressed -s -L -o "${VRS_EXTENSION_DIR}/enhancedlayers.zip" ${EXT_LAYERS_LINK} &&\ + unzip -q -o "${VRS_EXTENSION_DIR}/enhancedlayers.zip" &&\ + rm "${VRS_EXTENSION_DIR}/enhancedlayers.zip" &&\ + cp -r "${VRS_EXTENSION_DIR}"/VRSCustomLayers/* "${VRS_EXTENSION_DIR}" &&\ + cp -r "${VRS_EXTENSION_DIR}"/'Put these files in VRS root folder'/* "${VRS_EXTENSION_DIR}" &&\ + rm -r 'Put these files in VRS root folder' + then + echo "[$APPNAME][$(date)] Enhanced Layers archive download and uncompress - OK" + case "${VRS_ENHANCED_LAYERS_COUNTRY,,}" in + (uk) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/UK//' -- *.geojson + ;; + (de) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/DE//' -- *.geojson + ;; + (usa1) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/USA1//' -- *.geojson + ;; + (usaaz) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/USAAZ//' -- *.geojson + ;; + (se) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/SE//' -- *.geojson + ;; + (au) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/AU//' -- *.geojson + ;; + (*) echo "[$APPNAME][$(date)] Unknown or wrong country, default set to UK" + ;; + esac + if sed -i -e "s/$LAYER_EOB_DISABLED/$LAYER_EOB_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_EOH_DISABLED/$LAYER_EOH_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_SCALE_DISABLED/$LAYER_SCALE_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_FULLSCREEN_DISABLED/$LAYER_FULLSCREEN_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Enhanced Layers config enabled - OK" + else + echo "[$APPNAME][$(date)] Enhanced Layers config enabled - Failure" + fi + if ! [[ -n "${VRS_ENHANCED_LAYERS_OPENAIP_APIKEY}" || "${VRS_ENHANCED_LAYERS_OPENWX_APIKEY}" ]] + then + echo "[$APPNAME][$(date)] VRS_ENHANCED_LAYERS_OPENAIP_APIKEY and VRS_ENHANCED_LAYERS_OPENWX_APIKEY not set. Expect those layers not to work." + else + if sed -i -e "s/##OPENWXAPIKEY##/${VRS_ENHANCED_LAYERS_OPENWX_APIKEY}/g" ${VRS_EXTENSION_DIR}/EndOfBody.html &&\ + sed -i -e "s/##OPENAIPKEY##/${VRS_ENHANCED_LAYERS_OPENAIP_APIKEY}/g" ${VRS_EXTENSION_DIR}/EndOfBody.html + then + echo "[$APPNAME][$(date)] Enhanced Layers API Keys config injection - OK" + else + echo "[$APPNAME][$(date)] Enhanced Layers API Keys config injection - Failure" + fi + fi + if [[ -n "${VRS_ENHANCED_LAYERS_CONFIG}" ]] + then + #shellcheck disable=SC2001 + sed -i "s|##EXTERNALCONFIG##|$(sed -e 's|/\*[^*]*\*/||g' <<< "${VRS_ENHANCED_LAYERS_CONFIG//[[:space:]]/}")|g" "${VRS_EXTENSION_DIR}"/EndOfBody.html + fi + else + echo "[$APPNAME][$(date)] Enhanced Layers archive download and uncompress - Failure" + fi + else + echo "[$APPNAME][$(date)] Enhanced Layers not set in the yaml. Exiting." + if sed -i -e "s/$LAYER_EOB_ENABLED/$LAYER_EOB_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_EOH_ENABLED/$LAYER_EOH_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_SCALE_ENABLED/$LAYER_SCALE_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_FULLSCREEN_ENABLED/$LAYER_FULLSCREEN_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Enhanced Layers config enabled - OK" + else + echo "[$APPNAME][$(date)] Enhanced Layers config enabled - Failure" + fi + exit 0 +fi +#cleanup and exit +exit 0 diff --git a/rootfs/back/services.d/autoupdate/run b/rootfs/back/services.d/autoupdate/run new file mode 100644 index 0000000..f03aecd --- /dev/null +++ b/rootfs/back/services.d/autoupdate/run @@ -0,0 +1,324 @@ +#!/usr/bin/with-contenv bash +#shellcheck shell=bash disable=SC2128 + +APPNAME="$(hostname)/autoupdate" +VRS_CONFIG_DIR="/root/.local/share/VirtualRadar" +VRS_EXTENSION_DIR="/root/.local/share/VirtualRadar/CustomContent/CustomInjectedFiles" +export VRS_CONFIG_DIR + +#Silhouettes, OpFlags and DB +SILH_LINK="https://github.com/rikgale/VRSOperatorFlags/raw/main/Silhouettes.zip" +SILH_DV_LINK="https://github.com/rikgale/VRSOperatorFlags/raw/main/DVSilhouettes.zip" +FLAGS_LINK="https://github.com/rikgale/VRSOperatorFlags/raw/main/OperatorFlags.zip" +#we need a permanent variable to reset if the sils are changed +SILH_FILE="$VRS_CONFIG_DIR/silh" + +#rickgales extras +#LocalAircraft.txt +EXT_LOCALAC_LINK="https://raw.githubusercontent.com/rikgale/LocalAircraft/main/LocalAircraft.txt" +#ExtraMarkers +EXT_MARKERS_LINK="https://raw.githubusercontent.com/rikgale/VRSCustomMarkers/main/MyMarkers1.html" +EXT_HFDLMARKERS_LINK="https://raw.githubusercontent.com/rikgale/VRSCustomMarkers/main/MyMarkers1HFDL.html" + +#sqb update link +FULLAIRCRAFT_LINK="https://github.com/rikgale/VRSData/raw/main/FullAircraft.zip" +INCREMENTAL_UPD_LINK="https://raw.githubusercontent.com/rikgale/VRSData/main/DailyUpdates/" + +#Variables for optimized downloads +WHICHREPO="https://api.github.com/repos/rikgale/VRSOperatorFlags/branches" +WHICHBRANCH="main" +ACTUALFILE="$VRS_CONFIG_DIR/commitid" +#the same for CustomMarkers +WHICHREPO_CM="https://api.github.com/repos/rikgale/VRSCustomMarkers/branches" +WHICHBRANCH_CM="main" +ACTUALFILE_CM="$VRS_CONFIG_DIR/commitid_cm" +#and the sqb +WHICHREPO_SQB="https://api.github.com/repos/rikgale/VRSData/branches" +WHICHBRANCH_SQB="main" +ACTUALFILE_SQB="$VRS_CONFIG_DIR/commitid_sqb" + +#Tine of the updatecheck. Changed from 02:20 to 03:30 to hopefully prevent any daylightsavings mishaps +UPDATETIME="03:20" + +#Failsetting for the SQB Backup +SQBFAIL=0 + +#Give VRS a bit of time to start +sleep 5 + +#Who we are and what we are doing +echo "[$APPNAME][$(date)] Autoupdate service started." + +#mopping up first because of some changes - incremental updates +[[ -f "${VRS_CONFIG_DIR}/db/FullAircraft.csv" ]] && rm -f "${VRS_CONFIG_DIR}/db/FullAircraft.csv" + +if [[ -n "${VRS_DEBUG_NOAUTOUPDATE}" ]] + then + echo "[$APPNAME][$(date)] debugging set, exited" + sleep infinity +fi + +#Let's go +while true +do + #lets reset this variable first + export FULLAIRCRAFT_NAME="none" + #we need these in the loop, otherwise they will never get updated + ACTUAL=$(<"$ACTUALFILE") + PROBE=$(curl -sH "Accept: application/vnd.github.v3+json" $WHICHREPO | awk "c&&!--c;/$WHICHBRANCH/{c=2}" | awk '/"sha"/ { print $2}' | sed 's/"//g;s/.$//g') + #The same check as above but for the custom markers + ACTUAL_CM=$(<"$ACTUALFILE_CM") + PROBE_CM=$(curl -sH "Accept: application/vnd.github.v3+json" $WHICHREPO_CM | awk "c&&!--c;/$WHICHBRANCH_CM/{c=2}" | awk '/"sha"/ { print $2}' | sed 's/"//g;s/.$//g') + #and the database + ACTUAL_SQB=$(<"$ACTUALFILE_SQB") + PROBE_SQB=$(curl -sH "Accept: application/vnd.github.v3+json" $WHICHREPO_SQB | awk "c&&!--c;/$WHICHBRANCH_SQB/{c=2}" | awk '/"sha"/ { print $2}' | sed 's/"//g;s/.$//g') + #Here are some files we're gonna update anyway, no matter of repo updates + echo "[$APPNAME][$(date)] Updating LocalAircraft.txt" + if curl --fail -s -L -o "${VRS_CONFIG_DIR}/LocalAircraft.txt" ${EXT_LOCALAC_LINK} + then + echo "[$APPNAME][$(date)] LocalAircraft.txt downloaded and installed successfully" + else + echo "[$APPNAME][$(date)] LocalAircraft.txt - failure" + fi + + #if there is a change in the commit ID, download and install sil/opflags + echo "[$APPNAME][$(date)] ----------------------------------------" + echo "[$APPNAME][$(date)] Looking for Sil / Operator Flags updates" + #following is some logic to force a download of the silh files if the dv envar is changed + SILH_PROBE=$(<"$SILH_FILE") + [ -n "${VRS_SILHOUETTES_DUALVIEW}" ] && echo "dv" > $SILH_FILE || echo "sv" > $SILH_FILE + ACTUAL_SILH=$(<"$SILH_FILE") + if [[ "$SILH_PROBE" != "$ACTUAL_SILH" ]] + then + ACTUAL="reset" + fi + if [[ "$ACTUAL" != "$PROBE" ]] + then + echo "[$APPNAME][$(date)] Looks like there was an update for Sil /Operator Flags. Going to download the files" + echo "$PROBE" > $ACTUALFILE + echo "[$APPNAME][$(date)] Updated $ACTUALFILE to commit ID $PROBE" + if [[ -n "${VRS_SILHOUETTES_DUALVIEW}" ]] + then + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/silhouettesDV.zip" ${SILH_DV_LINK} && rm ${VRS_CONFIG_DIR}/silhouettes/* && unzip -u -qq -d "${VRS_CONFIG_DIR}/silhouettes" "${VRS_CONFIG_DIR}/silhouettesDV.zip" + then + echo "[$APPNAME][$(date)] Dual View Silhouettes installed successfully" + else + echo "[$APPNAME][$(date)] Dual View Silhouettes not installed - failure" + fi + fi + if [[ -n "${VRS_SILHOUETTES_DUALVIEW}" ]] + then + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/silhouettes.zip" ${SILH_LINK} && unzip -u -qq -n -d "${VRS_CONFIG_DIR}/silhouettes" "${VRS_CONFIG_DIR}/silhouettes.zip" + then + echo "[$APPNAME][$(date)] Silhouettes installed successfully - DV Setup" + else + echo "[$APPNAME][$(date)] Silhouettes not installed - DV Setup - failure" + fi + else + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/silhouettes.zip" ${SILH_LINK} && unzip -u -qq -o -d "${VRS_CONFIG_DIR}/silhouettes" "${VRS_CONFIG_DIR}/silhouettes.zip" + then + echo "[$APPNAME][$(date)] Silhouettes installed successfully" + else + echo "[$APPNAME][$(date)] Silhouettes not installed - failure" + fi + fi + #download and install operator flags + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/OperatorFlags.zip" ${FLAGS_LINK} && unzip -u -qq -o -d "${VRS_CONFIG_DIR}/flags" "${VRS_CONFIG_DIR}/OperatorFlags.zip" + then + echo "[$APPNAME][$(date)] Operator Flags installed successfully" + else + echo "[$APPNAME][$(date)] Operator Flags not installed - failure" + fi + else + echo "[$APPNAME][$(date)] No changes found, nothing was downloaded." + fi + #looking for updates of the custom markers html file + echo "[$APPNAME][$(date)] ----------------------------------------" + echo "[$APPNAME][$(date)] Looking for updates for the custom markers file" + if [[ "$ACTUAL_CM" != "$PROBE_CM" ]] + then + echo "[$APPNAME][$(date)] Looks like there was an update for the custom markers. Going to download the file" + echo "$PROBE_CM" > $ACTUALFILE_CM + echo "[$APPNAME][$(date)] Updated $ACTUALFILE_CM to commit ID $PROBE_CM" + if [[ "${VRS_ENHANCED_MARKERS}" == "normal" ]] + then + if curl --fail -s -L -o "${VRS_EXTENSION_DIR}/MyMarkers1.html" ${EXT_MARKERS_LINK} + then + echo "[$APPNAME][$(date)] New ADSB custom marker file installed successfully" + else + echo "[$APPNAME][$(date)] New ADSB custom marker file not installed - failure" + fi + elif [[ "${VRS_ENHANCED_MARKERS}" == "HFDL" ]] || [[ "${VRS_ENHANCED_MARKERS}" == "hfdl" ]] + then + if curl --fail -s -L -o "${VRS_EXTENSION_DIR}/MyMarkers1.html" ${EXT_HFDLMARKERS_LINK} + then + echo "[$APPNAME][$(date)] New HFDL custom marker file installed successfully" + else + echo "[$APPNAME][$(date)] New HFDL custom marker file not installed - failure" + fi + else + echo "[$APPNAME][$(date)] No custom markers downloaded, not set in the yaml." + fi + else + echo "[$APPNAME][$(date)] No changes found, nothing was downloaded." + fi + #BaseSation SQB Update + if [[ -n "${VRS_DB_UPDATE_POLICY_FULLAUTO}" ]] + then + echo "[$APPNAME][$(date)] ----------------------------------------" + echo "[$APPNAME][$(date)] Looking for updates for the BaseStation.sqb" + if [[ "$ACTUAL_SQB" != "$PROBE_SQB" ]] + then + echo "[$APPNAME][$(date)] Looks like there was an update for the database. Going to download the updatefile" + #date of yesterday portion for the filename + DATE_YESTERDAY=$(date -d "yesterday" -I) + INCREMENTAL_UPD_FILENAME="Updates_${DATE_YESTERDAY}.zip" + INCREMENTAL_UPD_DL_LINK="${INCREMENTAL_UPD_LINK}${INCREMENTAL_UPD_FILENAME}" + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/db/${INCREMENTAL_UPD_FILENAME}" "${INCREMENTAL_UPD_DL_LINK}" && FULLAIRCRAFT_NAME=$(unzip -o "${VRS_CONFIG_DIR}/db/${INCREMENTAL_UPD_FILENAME}" -d "${VRS_CONFIG_DIR}/db/" | grep inflating | awk -F "/" '{print $NF}') + then + echo "[$APPNAME][$(date)] Incremental Update file ${INCREMENTAL_UPD_DL_LINK} downloaded" + echo "[$APPNAME][$(date)] Filename extrated from the zip: ${FULLAIRCRAFT_NAME}" + export FULLAIRCRAFT_NAME + else + echo "[$APPNAME][$(date)] no incremental update file found, going to download the full update" + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/db/FullAircraft.zip" ${FULLAIRCRAFT_LINK} && FULLAIRCRAFT_NAME=$(unzip -o "${VRS_CONFIG_DIR}/db/FullAircraft.zip" -d "${VRS_CONFIG_DIR}/db/" | grep inflating | awk -F "/" '{print $NF}') + then + echo "[$APPNAME][$(date)] Download of the latest FullAircraft update file - OK" + echo "[$APPNAME][$(date)] Filename extrated from the zip: ${FULLAIRCRAFT_NAME}" + export FULLAIRCRAFT_NAME + else + echo "[$APPNAME][$(date)] Download of the latest FullAircraft update file - FAIL!" + SQBFAIL=1 + fi + fi + #shutting down VRS for the DB backup and update +# echo "[$APPNAME][$(date)] Shutting down VRS temporarily as we are going to deal with the database." +# s6-svc -wD -d -T 5000 /run/s6/services/vrs/ +# echo "[$APPNAME][$(date)] It's dead, Jim" + sleep 1 + #delete the prior backup +# if [ -e "${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb" ] +# then +# mv -f "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb.1 +# echo "[$APPNAME][$(date)] Prior backup moved to secondary." +# else +# echo "[$APPNAME][$(date)] No prior backup found." +# fi + echo "[$APPNAME][$(date)] Create a backup of the BaseStation.sqb" + if [[ -n "${VRS_DB_UPDATE_BACKUP_UNCOMPRESSED}" ]] + then + if [ -e "${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb" ] + then + mv -f "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb.1 + echo "[$APPNAME][$(date)] Prior backup moved to secondary." + else + echo "[$APPNAME][$(date)] No prior backup found." + fi + #uncompressed backup + if /opt/vrs/scripts/db_backup + then + echo "[$APPNAME][$(date)] Uncompressed Backup of BaseStation.sqb - OK" + else + echo "[$APPNAME][$(date)] Uncompressed Backup of BaseStation.sqb - FAIL!" + SQBFAIL=1 + fi + else + if [ -e "${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb.gz" ] + then + mv -f "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb.gz "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb.gz.1 + echo "[$APPNAME][$(date)] Prior backup moved to secondary." + else + echo "[$APPNAME][$(date)] No prior backup found." + fi + #compressed backup + if /opt/vrs/scripts/db_backup && gzip -f ${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb + then + echo "[$APPNAME][$(date)] Compressed Backup of BaseStation.sqb - OK" + else + echo "[$APPNAME][$(date)] Compressed Backup of BaseStation.sqb - FAIL!" + SQBFAIL=1 + fi + fi + #Starting the merge process - but check for any fails first. If one is found, we'll nope out here + if ! [[ $SQBFAIL == 0 ]] + then + echo "[$APPNAME][$(date)] Something went wrong with the Updatefile or the backup. Merge will be skipped" + else + echo "[$APPNAME][$(date)] Merging updates into BaseStation.sqb - this might take a few moments" + #we want to see how long this takes... + sleep 2 + if TIMEFORMAT='Runtime of the update: %R seconds.' + time { + if [[ -n "${VRS_DB_UPDATE_WITH_VACUUM}" ]] + then + echo "[$APPNAME][$(date)] Started script with vacuum" + /opt/vrs/scripts/update_with_vacuum + else + echo "[$APPNAME][$(date)] Started script without vacuum" + /opt/vrs/scripts/update_without_vacuum + fi + } + then + echo "[$APPNAME][$(date)] Merging updates into BaseStation.sqb - OK" + echo "$PROBE_SQB" > $ACTUALFILE_SQB + echo "[$APPNAME][$(date)] Updated $ACTUALFILE_SQB to commit ID $PROBE_SQB" + else + echo "[$APPNAME][$(date)] Merging updates into BaseStation.sqb - FAIL!" + echo "[$APPNAME][$(date)] Restoring Backup." + if [[ -n "${VRS_DB_UPDATE_BACKUP_UNCOMPRESSED}" ]] + then + #uncompressed restore + echo "[$APPNAME][$(date)] Sleeping for 2 Seconds to let VRS do it's thing with the db" + sleep 2 + if /opt/vrs/scripts/db_restore + then + echo "[$APPNAME][$(date)] Uncompressed Restore of BaseStation.sqb - OK" + else + echo "[$APPNAME][$(date)] Uncompressed Restore of BaseStation.sqb - FAIL!" + fi + else + #compressed restore + echo "[$APPNAME][$(date)] Sleeping for 2 Seconds to let VRS do it's thing with the db" + sleep 2 + if gunzip -f -k ${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb.gz && /opt/vrs/scripts/db_restore + then + echo "[$APPNAME][$(date)] Compressed Restore of BaseStation.sqb - OK" + else + echo "[$APPNAME][$(date)] Compressed Restore of BaseStation.sqb - FAIL!" + fi + fi + fi + fi + #Restarting VRS after we're finished with the DB thingies + echo "[$APPNAME][$(date)] DB maintenance finished" +# s6-svc -u /run/s6/services/vrs/ + else + echo "[$APPNAME][$(date)] No update for the database found" + fi + else + echo "[$APPNAME][$(date)] VRS_DB_UPDATE_POLICY_FULLAUTO not set, skipped DB updates" + fi + + #cleaning up downloaded files + [[ -f "${VRS_CONFIG_DIR}/silhouettes.zip" ]] && rm -f "${VRS_CONFIG_DIR}/silhouettes.zip" + [[ -f "${VRS_CONFIG_DIR}/OperatorFlags.zip" ]] && rm -f "${VRS_CONFIG_DIR}/OperatorFlags.zip" + #deleting any left over .csv files in the db folder + DBUPDATECSVFILES=("${VRS_CONFIG_DIR}/db/*.csv") + for CSVUPD in $DBUPDATECSVFILES + do +# echo "[$APPNAME][$(date)] Deleting file: ${CSVUPD}" + rm -f "${CSVUPD}" + done + [[ -f "${VRS_CONFIG_DIR}/db/${INCREMENTAL_UPD_FILENAME}" ]] && rm -f "${VRS_CONFIG_DIR}/db/${INCREMENTAL_UPD_FILENAME}" + [[ -d "${VRS_EXTENSION_DIR}/VRSCustomLayers" ]] && rm -r -f "${VRS_EXTENSION_DIR}/VRSCustomLayers" + echo "[$APPNAME][$(date)] Cleaned up downloaded files - if any" + #calculationg the next run + NEXTRUN_SECONDS=$((($(date -f - +%s- <<<${UPDATETIME}$' tomorrow\nnow')0)%86400)) + TIMENOW=$(date +%s) + SECONDS_TO_NEXT=$((TIMENOW+NEXTRUN_SECONDS)) + NEXTRUN_TIME=$(date --date @$SECONDS_TO_NEXT) + echo "[$APPNAME][$(date)] Finished. Next run in $NEXTRUN_TIME" + echo "[$APPNAME][$(date)] ----------------------------------------" + #sleep a bit until the next run + sleep $NEXTRUN_SECONDS +done diff --git a/rootfs/back/services.d/vrs/run b/rootfs/back/services.d/vrs/run new file mode 100755 index 0000000..ab231a1 --- /dev/null +++ b/rootfs/back/services.d/vrs/run @@ -0,0 +1,19 @@ +#!/usr/bin/with-contenv bash +#shellcheck shell=bash disable=SC2015 + +APPNAME="$(hostname)/vrs-runtime" +VRS_DIR="/opt/vrs" +VRS_EXEC="mono VirtualRadar.exe" +VRS_CMDLINE=() +VRS_CMDLINE+=("-nogui") +[[ -n "${VRS_CULTURE}" ]] && VRS_CMDLINE+=("-culture:${VRS_CULTURE}") || true + +# start VRS and keep it in the foreground: +cd "${VRS_DIR}" || exit +echo "[$APPNAME][$(date)] Starting ${VRS_DIR}/${VRS_EXEC} ${VRS_CMDLINE[*]}" +#exec ${VRS_EXEC} ${VRS_CMDLINE[@]} | stdbuf -o0 awk -v label=${APPNAME} '{print "[" label "][" strftime("%F %T%z", systime()) "] " $0}' +exec ${VRS_EXEC} "${VRS_CMDLINE[@]}" + +#by wiedehopf. Trying to fix the s6-svc pipe trouble +#trap 'kill 0' TERM +#( ${VRS_EXEC} ${VRS_CMDLINE[@]} | stdbuf -o0 awk -v label=${APPNAME} '{print "[" label "][" strftime("%F %T%z", systime()) "] " $0}' ) diff --git a/rootfs/etc/s6-overlay/s6-rc.d/50-vrs/type b/rootfs/etc/s6-overlay/s6-rc.d/50-vrs/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/50-vrs/type @@ -0,0 +1 @@ +oneshot diff --git a/rootfs/etc/s6-overlay/s6-rc.d/50-vrs/up b/rootfs/etc/s6-overlay/s6-rc.d/50-vrs/up new file mode 100755 index 0000000..b7a5a54 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/50-vrs/up @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/50-vrs diff --git a/rootfs/etc/s6-overlay/s6-rc.d/60-marker/dependencies.d/50-vrs b/rootfs/etc/s6-overlay/s6-rc.d/60-marker/dependencies.d/50-vrs new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/60-marker/type b/rootfs/etc/s6-overlay/s6-rc.d/60-marker/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/60-marker/type @@ -0,0 +1 @@ +oneshot diff --git a/rootfs/etc/s6-overlay/s6-rc.d/60-marker/up b/rootfs/etc/s6-overlay/s6-rc.d/60-marker/up new file mode 100755 index 0000000..4d2cad6 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/60-marker/up @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/60-marker diff --git a/rootfs/etc/s6-overlay/s6-rc.d/61-layer/dependencies.d/50-vrs b/rootfs/etc/s6-overlay/s6-rc.d/61-layer/dependencies.d/50-vrs new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/61-layer/dependencies.d/60-marker b/rootfs/etc/s6-overlay/s6-rc.d/61-layer/dependencies.d/60-marker new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/61-layer/type b/rootfs/etc/s6-overlay/s6-rc.d/61-layer/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/61-layer/type @@ -0,0 +1 @@ +oneshot diff --git a/rootfs/etc/s6-overlay/s6-rc.d/61-layer/up b/rootfs/etc/s6-overlay/s6-rc.d/61-layer/up new file mode 100755 index 0000000..22fe889 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/61-layer/up @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/61-layer diff --git a/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/50-vrs b/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/50-vrs new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/60-marker b/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/60-marker new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/61-layer b/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/dependencies.d/61-layer new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/run b/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/run new file mode 100755 index 0000000..4c2ff34 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/autoupdate diff --git a/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/type b/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/autoupdate/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/50-vrs b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/50-vrs new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/60-marker b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/60-marker new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/61-layer b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/61-layer new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/autoupdate b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/autoupdate new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vrs b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vrs new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/50-vrs b/rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/50-vrs new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/60-marker b/rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/60-marker new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/61-layer b/rootfs/etc/s6-overlay/s6-rc.d/vrs/dependencies.d/61-layer new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vrs/run b/rootfs/etc/s6-overlay/s6-rc.d/vrs/run new file mode 100755 index 0000000..18c9c83 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/vrs/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/vrs diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vrs/type b/rootfs/etc/s6-overlay/s6-rc.d/vrs/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/vrs/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/scripts/50-vrs b/rootfs/etc/s6-overlay/scripts/50-vrs new file mode 100755 index 0000000..76c6e74 --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/50-vrs @@ -0,0 +1,129 @@ +#!/command/with-contenv bash +#shellcheck shell=bash disable=SC2034,SC2164,SC2015 + +APPNAME="$(hostname)/vrs-init" +VRS_DIR="/opt/vrs" +VRS_EXEC="mono VirtualRadar.exe" +VRS_CMDLINE=() +VRS_CMDLINE+=("-nogui") +VRS_CMDLINE+=("-createAdmin:${VRS_ADMIN_USERNAME}") +VRS_CMDLINE+=("-password:${VRS_ADMIN_PASSWORD}") +VRS_CONFIG_DIR="/root/.local/share/VirtualRadar" +VRS_EXTENSION_DIR="/root/.local/share/VirtualRadar/CustomContent/CustomInjectedFiles" +#Silhouettes, OpFlags and DB +FLAGSDB_LINK="https://github.com/rikgale/VRSData/raw/main/BaseStation.zip" + +#max runtime in seconds for VRS init +MAXTIME=15 + +#helper files for updatechecks +ACTUALFILE="$VRS_CONFIG_DIR/commitid" +ACTUALFILE_CM="$VRS_CONFIG_DIR/commitid_cm" +ACTUALFILE_SQB="$VRS_CONFIG_DIR/commitid_sqb" + +#We need that for the update-after-fresh-install prevention +WHICHREPO_SQB="https://api.github.com/repos/rikgale/VRSData/branches" +WHICHBRANCH_SQB="main" + +#if the helper file to store the commit ID isn't there, create it empty +touch $ACTUALFILE +#and the same for the custom markers +touch $ACTUALFILE_CM +#for the database +touch $ACTUALFILE_SQB + +#debugging stuff +#echo $ACTUAL +#echo $PROBE +BUILD_DATE=$(cat "${VRS_DIR}"/builddate) + +echo "[$APPNAME][$(date)] Initializing Virtual Radar Server, build ${BUILD_DATE}..." + +mkdir -p "${VRS_CONFIG_DIR}/flags" +mkdir -p "${VRS_CONFIG_DIR}/silhouettes" +mkdir -p "${VRS_CONFIG_DIR}/photos" +mkdir -p "${VRS_CONFIG_DIR}/db" +mkdir -p "${VRS_CONFIG_DIR}/CustomContent/CustomInjectedFiles" + +#download and install pre-filled DB for operator flags. As this should only happen once, no commit id check needed +if [ ! -e "${VRS_CONFIG_DIR}/db/BaseStation.sqb" ] +then + echo "[$APPNAME][$(date)] Downloading database for Operator Flags" + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/BaseStation.zip" ${FLAGSDB_LINK} && unzip -qq -o -d "${VRS_CONFIG_DIR}/db" "${VRS_CONFIG_DIR}/BaseStation.zip" + then + echo "[$APPNAME][$(date)] Database for Operator Flags installed successfully" + #that should prevent a DB update right after a fresh download + PROBE_SQB=$(curl -sH "Accept: application/vnd.github.v3+json" $WHICHREPO_SQB | awk "c&&!--c;/$WHICHBRANCH_SQB/{c=2}" | awk '/"sha"/ { print $2}' | sed 's/"//g;s/.$//g') + echo "$PROBE_SQB" > $ACTUALFILE_SQB + echo "[$APPNAME][$(date)] Updated $ACTUALFILE_SQB to commit ID $PROBE_SQB" + else + echo "[$APPNAME][$(date)] Database for Operator Flags not installed - failure" + fi +else + echo "[$APPNAME][$(date)] Found an existing DB in $VRS_CONFIG_DIR, not touching anything!" +fi + +#copy PluginsConfig into place if it's not there +if [ ! -e "${VRS_CONFIG_DIR}/PluginsConfiguration.txt" ] + then + echo "[$APPNAME][$(date)] PluginsConfiguration.txt not found, adding template" + if cp -f /opt/vrs/PluginsConfiguration.txt "${VRS_CONFIG_DIR}/PluginsConfiguration.txt" + then + echo "[$APPNAME][$(date)] PluginsConfiguration.txt not found, adding template - OK" + else + echo "[$APPNAME][$(date)] PluginsConfiguration.txt not found, adding template - Failure" + fi + else + echo "[$APPNAME][$(date)] PluginsConfiguration.txt found, not touching anything" +fi + +# Starting VRS temporarily to create a username and password if none exist +# If VRS has been initialized previously this step will be skipped. +# If it hasn't, a username / password and a bunch of other files will be created... +# ...and VRS will actually stay up and run. We will shut it down after a max runtime of $MAXTIME secs. +if [ ! -e "${VRS_CONFIG_DIR}/Configuration.xml" ] +then + echo "[$APPNAME][$(date)] No Configuration.xml found, doing first run initialization." + cd "${VRS_DIR}" + # shellcheck disable=SC2068,SC2086 + timeout "$MAXTIME" exec ${VRS_EXEC} ${VRS_CMDLINE[@]} #>/dev/null 2>&1 + echo "[$APPNAME][$(date)] Virtual Radar Server has been initialized." +else + echo "[$APPNAME][$(date)] Configuration.xml found, skipping initialization." +fi + +# Replace 127.0.0.1 With ReadSB +sed -i "s#
127.0.0.1
#
${VRS_SBSHOST:-readsb}
#g" "${VRS_CONFIG_DIR}/Configuration.xml" +sed -i "s#30003#${VRS_SBSPORT:-30003}#g" "${VRS_CONFIG_DIR}/Configuration.xml" + +#Injecting settings for silhouettes, OpFlags and DB into Configuration.xml +if ! grep -q "" "${VRS_CONFIG_DIR}/Configuration.xml" +then + sed -i "/^ .*/a \ \/root/.local/share/VirtualRadar/db/BaseStation.sqb" "${VRS_CONFIG_DIR}/Configuration.xml" + echo "[$APPNAME][$(date)] Added database filename to Configuration.xml" +else + echo "[$APPNAME][$(date)] DatabaseFileName found, not touching config." +fi + +if ! grep -q "" "${VRS_CONFIG_DIR}/Configuration.xml" +then + sed -i "/^ .*/a \ \/root/.local/share/VirtualRadar/flags" "${VRS_CONFIG_DIR}/Configuration.xml" + echo "[$APPNAME][$(date)] Added Operator Flags folder to Configuration.xml" +else + echo "[$APPNAME][$(date)] OperatorFlagsFolder found, not touching config." +fi + +if ! grep -q "" "${VRS_CONFIG_DIR}/Configuration.xml" +then + sed -i "/^ .*/a \ \/root/.local/share/VirtualRadar/silhouettes" "${VRS_CONFIG_DIR}/Configuration.xml" + echo "[$APPNAME][$(date)] Added Silhouettes folder to Configuration.xml" +else + echo "[$APPNAME][$(date)] SilhouettesFolder found, not touching config." +fi + +#cleanup and exit +[[ -f "${VRS_CONFIG_DIR}/BaseStation.zip" ]] && rm -f "${VRS_CONFIG_DIR}/BaseStation.zip" || true +echo "[$APPNAME][$(date)] Cleaned up downloaded files." +echo "[$APPNAME][$(date)] Finished basic configuration." + +exit 0 diff --git a/rootfs/etc/s6-overlay/scripts/60-marker b/rootfs/etc/s6-overlay/scripts/60-marker new file mode 100755 index 0000000..cadd043 --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/60-marker @@ -0,0 +1,77 @@ +#!/command/with-contenv bash +# shellcheck shell=bash + +APPNAME="$(hostname)/vrs-ccmarker" +#VRS_DIR="/opt/vrs" +VRS_CONFIG_DIR="/root/.local/share/VirtualRadar" +VRS_EXTENSION_DIR="/root/.local/share/VirtualRadar/CustomContent/CustomInjectedFiles" + +#PluginConfig Settings (escaped) +CCMARKER_DISABLED="%3cInjectSettings%3e%0a++++%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3etrue%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fMyMarkers1\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +CCMARKER_ENABLED="%3cInjectSettings%3e%0a++++%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3etrue%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fMyMarkers1\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" + +#Downloadlinks +EXT_MARKERS_LINK="https://raw.githubusercontent.com/rikgale/VRSCustomMarkers/main/MyMarkers1.html" +EXT_HFDLMARKERS_LINK="https://raw.githubusercontent.com/rikgale/VRSCustomMarkers/main/MyMarkers1HFDL.html" + +echo "[$APPNAME][$(date)] Starting CustomContent Markers script..." + +#Create the directory in case it's not there +mkdir -p "${VRS_CONFIG_DIR}/CustomContent/CustomInjectedFiles" + +if [[ -n "${VRS_ENHANCED_MARKERS}" ]] + then + echo "[$APPNAME][$(date)] Downloading and installing Custom Markers" + #normal markers + if [[ "${VRS_ENHANCED_MARKERS}" == "normal" ]] + then + echo "[$APPNAME][$(date)] Normal Custom markers" + if curl --fail -s -L -o "${VRS_EXTENSION_DIR}/MyMarkers1.html" ${EXT_MARKERS_LINK} + then + echo "[$APPNAME][$(date)] Normal Custom marker file download - OK" + echo "[$APPNAME][$(date)] Injecting custom marker config into PluginsConfiguration.txt" + if sed -i -e "s/$CCMARKER_DISABLED/$CCMARKER_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Custom marker config enabled - OK" + else + echo "[$APPNAME][$(date)] Custom marker config enabled - Failure" + fi + else + echo "[$APPNAME][$(date)] Normal Custom marker file download - Failure" + fi + #HFDL markers + elif [[ "${VRS_ENHANCED_MARKERS}" == "HFDL" ]] || [[ "${VRS_ENHANCED_MARKERS}" == "hfdl" ]] + then + echo "[$APPNAME][$(date)] HFDL Custom markers" + if curl --fail -s -L -o "${VRS_EXTENSION_DIR}/MyMarkers1.html" ${EXT_HFDLMARKERS_LINK} + then + echo "[$APPNAME][$(date)] HFDL Custom marker file download - OK" + echo "[$APPNAME][$(date)] Injecting custom marker config into PluginsConfiguration.txt" + if sed -i -e "s/$CCMARKER_DISABLED/$CCMARKER_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Custom marker config enabled - OK" + else + echo "[$APPNAME][$(date)] Custom marker config enabled - Failure" + fi + else + echo "[$APPNAME][$(date)] HFDL Custom marker file download - Failure" + fi + #disabled + elif [[ "${VRS_ENHANCED_MARKERS}" == "disabled" ]] || [[ "${VRS_ENHANCED_MARKERS}" == "false" ]] + then + echo "[$APPNAME][$(date)] HFDL Custom markers disabled" + if sed -i -e "s/$CCMARKER_ENABLED/$CCMARKER_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Custom marker config disabled - OK" + else + echo "[$APPNAME][$(date)] Custom marker config disabled - Failure" + fi + + else echo "[$APPNAME][$(date)] yaml setting unkown. Check readme." + fi + else + echo "[$APPNAME][$(date)] Custom Markers not enabled" +fi + +#cleanup and exit +exit 0 diff --git a/rootfs/etc/s6-overlay/scripts/61-layer b/rootfs/etc/s6-overlay/scripts/61-layer new file mode 100755 index 0000000..06e6f1d --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/61-layer @@ -0,0 +1,106 @@ +#!/command/with-contenv bash +# shellcheck shell=bash + +APPNAME="$(hostname)/vrs-cclayer" +#VRS_DIR="/opt/vrs" +VRS_CONFIG_DIR="/root/.local/share/VirtualRadar" +VRS_EXTENSION_DIR="/root/.local/share/VirtualRadar/CustomContent/CustomInjectedFiles" + +#PluginConfig Settings (escaped) +LAYER_EOB_DISABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fEndOfBody\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_EOB_ENABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fEndOfBody\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_EOH_DISABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eHead%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fEndOfHead\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_EOH_ENABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e\*%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eHead%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fEndOfHead\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_SCALE_DISABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e%2fdesktop\.html%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fScale\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_SCALE_ENABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e%2fdesktop\.html%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fScale\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_FULLSCREEN_DISABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3efalse%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e%2fdesktop\.html%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fFullScreen\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" +LAYER_FULLSCREEN_ENABLED="%3cInjectSettings%3e%0a++++++%3cEnabled%3etrue%3c%2fEnabled%3e%0a++++++%3cPathAndFile%3e%2fdesktop\.html%3c%2fPathAndFile%3e%0a++++++%3cInjectionLocation%3eBody%3c%2fInjectionLocation%3e%0a++++++%3cStart%3efalse%3c%2fStart%3e%0a++++++%3cFile%3e%2froot%2f\.local%2fshare%2fVirtualRadar%2fCustomContent%2fCustomInjectedFiles%2fFullScreen\.html%3c%2fFile%3e%0a++++%3c%2fInjectSettings%3e%0a" + +#Downloadlinks +EXT_LAYERS_LINK="https://github.com/rikgale/VRSCustomLayers/raw/main/VRSCustomLayers.zip" + +echo "[$APPNAME][$(date)] Starting CustomContent Layers script..." + +#Create the directory in case it's not there +[ -d "${VRS_EXTENSION_DIR}" ] && mkdir -p "${VRS_CONFIG_DIR}/CustomContent/CustomInjectedFiles" + +if [[ -n "${VRS_ENHANCED_LAYERS_COUNTRY}" ]] + then + #cleaning up first + cd "${VRS_EXTENSION_DIR}" || exit + rm "${VRS_CONFIG_DIR}/CustomContent/CustomInjectedFiles"/*.geojson + echo "[$APPNAME][$(date)] Downloading and installing Enhanced Layers" + if curl --fail --compressed -s -L -o "${VRS_EXTENSION_DIR}/enhancedlayers.zip" ${EXT_LAYERS_LINK} &&\ + unzip -q -o "${VRS_EXTENSION_DIR}/enhancedlayers.zip" &&\ + rm "${VRS_EXTENSION_DIR}/enhancedlayers.zip" &&\ + cp -r "${VRS_EXTENSION_DIR}"/VRSCustomLayers/* "${VRS_EXTENSION_DIR}" &&\ + cp -r "${VRS_EXTENSION_DIR}"/'Put these files in VRS root folder'/* "${VRS_EXTENSION_DIR}" &&\ + rm -r 'Put these files in VRS root folder' + then + echo "[$APPNAME][$(date)] Enhanced Layers archive download and uncompress - OK" + case "${VRS_ENHANCED_LAYERS_COUNTRY,,}" in + (uk) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/UK//' -- *.geojson + ;; + (de) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/DE//' -- *.geojson + ;; + (usa1) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/USA1//' -- *.geojson + ;; + (usaaz) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/USAAZ//' -- *.geojson + ;; + (se) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/SE//' -- *.geojson + ;; + (au) echo "[$APPNAME][$(date)] Enhanced Layers renaming country files for: ${VRS_ENHANCED_LAYERS_COUNTRY}" + rename -f 's/AU//' -- *.geojson + ;; + (*) echo "[$APPNAME][$(date)] Unknown or wrong country, default set to UK" + ;; + esac + if sed -i -e "s/$LAYER_EOB_DISABLED/$LAYER_EOB_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_EOH_DISABLED/$LAYER_EOH_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_SCALE_DISABLED/$LAYER_SCALE_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_FULLSCREEN_DISABLED/$LAYER_FULLSCREEN_ENABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Enhanced Layers config enabled - OK" + else + echo "[$APPNAME][$(date)] Enhanced Layers config enabled - Failure" + fi + if ! [[ -n "${VRS_ENHANCED_LAYERS_OPENAIP_APIKEY}" || "${VRS_ENHANCED_LAYERS_OPENWX_APIKEY}" ]] + then + echo "[$APPNAME][$(date)] VRS_ENHANCED_LAYERS_OPENAIP_APIKEY and VRS_ENHANCED_LAYERS_OPENWX_APIKEY not set. Expect those layers not to work." + else + if sed -i -e "s/##OPENWXAPIKEY##/${VRS_ENHANCED_LAYERS_OPENWX_APIKEY}/g" ${VRS_EXTENSION_DIR}/EndOfBody.html &&\ + sed -i -e "s/##OPENAIPKEY##/${VRS_ENHANCED_LAYERS_OPENAIP_APIKEY}/g" ${VRS_EXTENSION_DIR}/EndOfBody.html + then + echo "[$APPNAME][$(date)] Enhanced Layers API Keys config injection - OK" + else + echo "[$APPNAME][$(date)] Enhanced Layers API Keys config injection - Failure" + fi + fi + if [[ -n "${VRS_ENHANCED_LAYERS_CONFIG}" ]] + then + #shellcheck disable=SC2001 + sed -i "s|##EXTERNALCONFIG##|$(sed -e 's|/\*[^*]*\*/||g' <<< "${VRS_ENHANCED_LAYERS_CONFIG//[[:space:]]/}")|g" "${VRS_EXTENSION_DIR}"/EndOfBody.html + fi + else + echo "[$APPNAME][$(date)] Enhanced Layers archive download and uncompress - Failure" + fi + else + echo "[$APPNAME][$(date)] Enhanced Layers not set in the yaml. Exiting." + if sed -i -e "s/$LAYER_EOB_ENABLED/$LAYER_EOB_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_EOH_ENABLED/$LAYER_EOH_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_SCALE_ENABLED/$LAYER_SCALE_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt &&\ + sed -i -e "s/$LAYER_FULLSCREEN_ENABLED/$LAYER_FULLSCREEN_DISABLED/g" ${VRS_CONFIG_DIR}/PluginsConfiguration.txt + then + echo "[$APPNAME][$(date)] Enhanced Layers config enabled - OK" + else + echo "[$APPNAME][$(date)] Enhanced Layers config enabled - Failure" + fi + exit 0 +fi +#cleanup and exit +exit 0 diff --git a/rootfs/etc/s6-overlay/scripts/autoupdate b/rootfs/etc/s6-overlay/scripts/autoupdate new file mode 100755 index 0000000..be27f04 --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/autoupdate @@ -0,0 +1,324 @@ +#!/command/with-contenv bash +#shellcheck shell=bash disable=SC2128 + +APPNAME="$(hostname)/autoupdate" +VRS_CONFIG_DIR="/root/.local/share/VirtualRadar" +VRS_EXTENSION_DIR="/root/.local/share/VirtualRadar/CustomContent/CustomInjectedFiles" +export VRS_CONFIG_DIR + +#Silhouettes, OpFlags and DB +SILH_LINK="https://github.com/rikgale/VRSOperatorFlags/raw/main/Silhouettes.zip" +SILH_DV_LINK="https://github.com/rikgale/VRSOperatorFlags/raw/main/DVSilhouettes.zip" +FLAGS_LINK="https://github.com/rikgale/VRSOperatorFlags/raw/main/OperatorFlags.zip" +#we need a permanent variable to reset if the sils are changed +SILH_FILE="$VRS_CONFIG_DIR/silh" + +#rickgales extras +#LocalAircraft.txt +EXT_LOCALAC_LINK="https://raw.githubusercontent.com/rikgale/LocalAircraft/main/LocalAircraft.txt" +#ExtraMarkers +EXT_MARKERS_LINK="https://raw.githubusercontent.com/rikgale/VRSCustomMarkers/main/MyMarkers1.html" +EXT_HFDLMARKERS_LINK="https://raw.githubusercontent.com/rikgale/VRSCustomMarkers/main/MyMarkers1HFDL.html" + +#sqb update link +FULLAIRCRAFT_LINK="https://github.com/rikgale/VRSData/raw/main/FullAircraft.zip" +INCREMENTAL_UPD_LINK="https://raw.githubusercontent.com/rikgale/VRSData/main/DailyUpdates/" + +#Variables for optimized downloads +WHICHREPO="https://api.github.com/repos/rikgale/VRSOperatorFlags/branches" +WHICHBRANCH="main" +ACTUALFILE="$VRS_CONFIG_DIR/commitid" +#the same for CustomMarkers +WHICHREPO_CM="https://api.github.com/repos/rikgale/VRSCustomMarkers/branches" +WHICHBRANCH_CM="main" +ACTUALFILE_CM="$VRS_CONFIG_DIR/commitid_cm" +#and the sqb +WHICHREPO_SQB="https://api.github.com/repos/rikgale/VRSData/branches" +WHICHBRANCH_SQB="main" +ACTUALFILE_SQB="$VRS_CONFIG_DIR/commitid_sqb" + +#Tine of the updatecheck. Changed from 02:20 to 03:30 to hopefully prevent any daylightsavings mishaps +UPDATETIME="03:20" + +#Failsetting for the SQB Backup +SQBFAIL=0 + +#Give VRS a bit of time to start +sleep 5 + +#Who we are and what we are doing +echo "[$APPNAME][$(date)] Autoupdate service started." + +#mopping up first because of some changes - incremental updates +[[ -f "${VRS_CONFIG_DIR}/db/FullAircraft.csv" ]] && rm -f "${VRS_CONFIG_DIR}/db/FullAircraft.csv" + +if [[ -n "${VRS_DEBUG_NOAUTOUPDATE}" ]] + then + echo "[$APPNAME][$(date)] debugging set, exited" + sleep infinity +fi + +#Let's go +while true +do + #lets reset this variable first + export FULLAIRCRAFT_NAME="none" + #we need these in the loop, otherwise they will never get updated + ACTUAL=$(<"$ACTUALFILE") + PROBE=$(curl -sH "Accept: application/vnd.github.v3+json" $WHICHREPO | awk "c&&!--c;/$WHICHBRANCH/{c=2}" | awk '/"sha"/ { print $2}' | sed 's/"//g;s/.$//g') + #The same check as above but for the custom markers + ACTUAL_CM=$(<"$ACTUALFILE_CM") + PROBE_CM=$(curl -sH "Accept: application/vnd.github.v3+json" $WHICHREPO_CM | awk "c&&!--c;/$WHICHBRANCH_CM/{c=2}" | awk '/"sha"/ { print $2}' | sed 's/"//g;s/.$//g') + #and the database + ACTUAL_SQB=$(<"$ACTUALFILE_SQB") + PROBE_SQB=$(curl -sH "Accept: application/vnd.github.v3+json" $WHICHREPO_SQB | awk "c&&!--c;/$WHICHBRANCH_SQB/{c=2}" | awk '/"sha"/ { print $2}' | sed 's/"//g;s/.$//g') + #Here are some files we're gonna update anyway, no matter of repo updates + echo "[$APPNAME][$(date)] Updating LocalAircraft.txt" + if curl --fail -s -L -o "${VRS_CONFIG_DIR}/LocalAircraft.txt" ${EXT_LOCALAC_LINK} + then + echo "[$APPNAME][$(date)] LocalAircraft.txt downloaded and installed successfully" + else + echo "[$APPNAME][$(date)] LocalAircraft.txt - failure" + fi + + #if there is a change in the commit ID, download and install sil/opflags + echo "[$APPNAME][$(date)] ----------------------------------------" + echo "[$APPNAME][$(date)] Looking for Sil / Operator Flags updates" + #following is some logic to force a download of the silh files if the dv envar is changed + SILH_PROBE=$(<"$SILH_FILE") + [ -n "${VRS_SILHOUETTES_DUALVIEW}" ] && echo "dv" > $SILH_FILE || echo "sv" > $SILH_FILE + ACTUAL_SILH=$(<"$SILH_FILE") + if [[ "$SILH_PROBE" != "$ACTUAL_SILH" ]] + then + ACTUAL="reset" + fi + if [[ "$ACTUAL" != "$PROBE" ]] + then + echo "[$APPNAME][$(date)] Looks like there was an update for Sil /Operator Flags. Going to download the files" + echo "$PROBE" > $ACTUALFILE + echo "[$APPNAME][$(date)] Updated $ACTUALFILE to commit ID $PROBE" + if [[ -n "${VRS_SILHOUETTES_DUALVIEW}" ]] + then + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/silhouettesDV.zip" ${SILH_DV_LINK} && rm ${VRS_CONFIG_DIR}/silhouettes/* && unzip -u -qq -d "${VRS_CONFIG_DIR}/silhouettes" "${VRS_CONFIG_DIR}/silhouettesDV.zip" + then + echo "[$APPNAME][$(date)] Dual View Silhouettes installed successfully" + else + echo "[$APPNAME][$(date)] Dual View Silhouettes not installed - failure" + fi + fi + if [[ -n "${VRS_SILHOUETTES_DUALVIEW}" ]] + then + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/silhouettes.zip" ${SILH_LINK} && unzip -u -qq -n -d "${VRS_CONFIG_DIR}/silhouettes" "${VRS_CONFIG_DIR}/silhouettes.zip" + then + echo "[$APPNAME][$(date)] Silhouettes installed successfully - DV Setup" + else + echo "[$APPNAME][$(date)] Silhouettes not installed - DV Setup - failure" + fi + else + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/silhouettes.zip" ${SILH_LINK} && unzip -u -qq -o -d "${VRS_CONFIG_DIR}/silhouettes" "${VRS_CONFIG_DIR}/silhouettes.zip" + then + echo "[$APPNAME][$(date)] Silhouettes installed successfully" + else + echo "[$APPNAME][$(date)] Silhouettes not installed - failure" + fi + fi + #download and install operator flags + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/OperatorFlags.zip" ${FLAGS_LINK} && unzip -u -qq -o -d "${VRS_CONFIG_DIR}/flags" "${VRS_CONFIG_DIR}/OperatorFlags.zip" + then + echo "[$APPNAME][$(date)] Operator Flags installed successfully" + else + echo "[$APPNAME][$(date)] Operator Flags not installed - failure" + fi + else + echo "[$APPNAME][$(date)] No changes found, nothing was downloaded." + fi + #looking for updates of the custom markers html file + echo "[$APPNAME][$(date)] ----------------------------------------" + echo "[$APPNAME][$(date)] Looking for updates for the custom markers file" + if [[ "$ACTUAL_CM" != "$PROBE_CM" ]] + then + echo "[$APPNAME][$(date)] Looks like there was an update for the custom markers. Going to download the file" + echo "$PROBE_CM" > $ACTUALFILE_CM + echo "[$APPNAME][$(date)] Updated $ACTUALFILE_CM to commit ID $PROBE_CM" + if [[ "${VRS_ENHANCED_MARKERS}" == "normal" ]] + then + if curl --fail -s -L -o "${VRS_EXTENSION_DIR}/MyMarkers1.html" ${EXT_MARKERS_LINK} + then + echo "[$APPNAME][$(date)] New ADSB custom marker file installed successfully" + else + echo "[$APPNAME][$(date)] New ADSB custom marker file not installed - failure" + fi + elif [[ "${VRS_ENHANCED_MARKERS}" == "HFDL" ]] || [[ "${VRS_ENHANCED_MARKERS}" == "hfdl" ]] + then + if curl --fail -s -L -o "${VRS_EXTENSION_DIR}/MyMarkers1.html" ${EXT_HFDLMARKERS_LINK} + then + echo "[$APPNAME][$(date)] New HFDL custom marker file installed successfully" + else + echo "[$APPNAME][$(date)] New HFDL custom marker file not installed - failure" + fi + else + echo "[$APPNAME][$(date)] No custom markers downloaded, not set in the yaml." + fi + else + echo "[$APPNAME][$(date)] No changes found, nothing was downloaded." + fi + #BaseSation SQB Update + if [[ -n "${VRS_DB_UPDATE_POLICY_FULLAUTO}" ]] + then + echo "[$APPNAME][$(date)] ----------------------------------------" + echo "[$APPNAME][$(date)] Looking for updates for the BaseStation.sqb" + if [[ "$ACTUAL_SQB" != "$PROBE_SQB" ]] + then + echo "[$APPNAME][$(date)] Looks like there was an update for the database. Going to download the updatefile" + #date of yesterday portion for the filename + DATE_YESTERDAY=$(date -d "yesterday" -I) + INCREMENTAL_UPD_FILENAME="Updates_${DATE_YESTERDAY}.zip" + INCREMENTAL_UPD_DL_LINK="${INCREMENTAL_UPD_LINK}${INCREMENTAL_UPD_FILENAME}" + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/db/${INCREMENTAL_UPD_FILENAME}" "${INCREMENTAL_UPD_DL_LINK}" && FULLAIRCRAFT_NAME=$(unzip -o "${VRS_CONFIG_DIR}/db/${INCREMENTAL_UPD_FILENAME}" -d "${VRS_CONFIG_DIR}/db/" | grep inflating | awk -F "/" '{print $NF}') + then + echo "[$APPNAME][$(date)] Incremental Update file ${INCREMENTAL_UPD_DL_LINK} downloaded" + echo "[$APPNAME][$(date)] Filename extrated from the zip: ${FULLAIRCRAFT_NAME}" + export FULLAIRCRAFT_NAME + else + echo "[$APPNAME][$(date)] no incremental update file found, going to download the full update" + if curl --fail --compressed -s -L -o "${VRS_CONFIG_DIR}/db/FullAircraft.zip" ${FULLAIRCRAFT_LINK} && FULLAIRCRAFT_NAME=$(unzip -o "${VRS_CONFIG_DIR}/db/FullAircraft.zip" -d "${VRS_CONFIG_DIR}/db/" | grep inflating | awk -F "/" '{print $NF}') + then + echo "[$APPNAME][$(date)] Download of the latest FullAircraft update file - OK" + echo "[$APPNAME][$(date)] Filename extrated from the zip: ${FULLAIRCRAFT_NAME}" + export FULLAIRCRAFT_NAME + else + echo "[$APPNAME][$(date)] Download of the latest FullAircraft update file - FAIL!" + SQBFAIL=1 + fi + fi + #shutting down VRS for the DB backup and update +# echo "[$APPNAME][$(date)] Shutting down VRS temporarily as we are going to deal with the database." +# s6-svc -wD -d -T 5000 /run/s6/services/vrs/ +# echo "[$APPNAME][$(date)] It's dead, Jim" + sleep 1 + #delete the prior backup +# if [ -e "${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb" ] +# then +# mv -f "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb.1 +# echo "[$APPNAME][$(date)] Prior backup moved to secondary." +# else +# echo "[$APPNAME][$(date)] No prior backup found." +# fi + echo "[$APPNAME][$(date)] Create a backup of the BaseStation.sqb" + if [[ -n "${VRS_DB_UPDATE_BACKUP_UNCOMPRESSED}" ]] + then + if [ -e "${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb" ] + then + mv -f "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb.1 + echo "[$APPNAME][$(date)] Prior backup moved to secondary." + else + echo "[$APPNAME][$(date)] No prior backup found." + fi + #uncompressed backup + if /opt/vrs/scripts/db_backup + then + echo "[$APPNAME][$(date)] Uncompressed Backup of BaseStation.sqb - OK" + else + echo "[$APPNAME][$(date)] Uncompressed Backup of BaseStation.sqb - FAIL!" + SQBFAIL=1 + fi + else + if [ -e "${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb.gz" ] + then + mv -f "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb.gz "${VRS_CONFIG_DIR}"/db/Basestation_Backup.sqb.gz.1 + echo "[$APPNAME][$(date)] Prior backup moved to secondary." + else + echo "[$APPNAME][$(date)] No prior backup found." + fi + #compressed backup + if /opt/vrs/scripts/db_backup && gzip -f ${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb + then + echo "[$APPNAME][$(date)] Compressed Backup of BaseStation.sqb - OK" + else + echo "[$APPNAME][$(date)] Compressed Backup of BaseStation.sqb - FAIL!" + SQBFAIL=1 + fi + fi + #Starting the merge process - but check for any fails first. If one is found, we'll nope out here + if ! [[ $SQBFAIL == 0 ]] + then + echo "[$APPNAME][$(date)] Something went wrong with the Updatefile or the backup. Merge will be skipped" + else + echo "[$APPNAME][$(date)] Merging updates into BaseStation.sqb - this might take a few moments" + #we want to see how long this takes... + sleep 2 + if TIMEFORMAT='Runtime of the update: %R seconds.' + time { + if [[ -n "${VRS_DB_UPDATE_WITH_VACUUM}" ]] + then + echo "[$APPNAME][$(date)] Started script with vacuum" + /opt/vrs/scripts/update_with_vacuum + else + echo "[$APPNAME][$(date)] Started script without vacuum" + /opt/vrs/scripts/update_without_vacuum + fi + } + then + echo "[$APPNAME][$(date)] Merging updates into BaseStation.sqb - OK" + echo "$PROBE_SQB" > $ACTUALFILE_SQB + echo "[$APPNAME][$(date)] Updated $ACTUALFILE_SQB to commit ID $PROBE_SQB" + else + echo "[$APPNAME][$(date)] Merging updates into BaseStation.sqb - FAIL!" + echo "[$APPNAME][$(date)] Restoring Backup." + if [[ -n "${VRS_DB_UPDATE_BACKUP_UNCOMPRESSED}" ]] + then + #uncompressed restore + echo "[$APPNAME][$(date)] Sleeping for 2 Seconds to let VRS do it's thing with the db" + sleep 2 + if /opt/vrs/scripts/db_restore + then + echo "[$APPNAME][$(date)] Uncompressed Restore of BaseStation.sqb - OK" + else + echo "[$APPNAME][$(date)] Uncompressed Restore of BaseStation.sqb - FAIL!" + fi + else + #compressed restore + echo "[$APPNAME][$(date)] Sleeping for 2 Seconds to let VRS do it's thing with the db" + sleep 2 + if gunzip -f -k ${VRS_CONFIG_DIR}/db/Basestation_Backup.sqb.gz && /opt/vrs/scripts/db_restore + then + echo "[$APPNAME][$(date)] Compressed Restore of BaseStation.sqb - OK" + else + echo "[$APPNAME][$(date)] Compressed Restore of BaseStation.sqb - FAIL!" + fi + fi + fi + fi + #Restarting VRS after we're finished with the DB thingies + echo "[$APPNAME][$(date)] DB maintenance finished" +# s6-svc -u /run/s6/services/vrs/ + else + echo "[$APPNAME][$(date)] No update for the database found" + fi + else + echo "[$APPNAME][$(date)] VRS_DB_UPDATE_POLICY_FULLAUTO not set, skipped DB updates" + fi + + #cleaning up downloaded files + [[ -f "${VRS_CONFIG_DIR}/silhouettes.zip" ]] && rm -f "${VRS_CONFIG_DIR}/silhouettes.zip" + [[ -f "${VRS_CONFIG_DIR}/OperatorFlags.zip" ]] && rm -f "${VRS_CONFIG_DIR}/OperatorFlags.zip" + #deleting any left over .csv files in the db folder + DBUPDATECSVFILES=("${VRS_CONFIG_DIR}/db/*.csv") + for CSVUPD in $DBUPDATECSVFILES + do +# echo "[$APPNAME][$(date)] Deleting file: ${CSVUPD}" + rm -f "${CSVUPD}" + done + [[ -f "${VRS_CONFIG_DIR}/db/${INCREMENTAL_UPD_FILENAME}" ]] && rm -f "${VRS_CONFIG_DIR}/db/${INCREMENTAL_UPD_FILENAME}" + [[ -d "${VRS_EXTENSION_DIR}/VRSCustomLayers" ]] && rm -r -f "${VRS_EXTENSION_DIR}/VRSCustomLayers" + echo "[$APPNAME][$(date)] Cleaned up downloaded files - if any" + #calculationg the next run + NEXTRUN_SECONDS=$((($(date -f - +%s- <<<${UPDATETIME}$' tomorrow\nnow')0)%86400)) + TIMENOW=$(date +%s) + SECONDS_TO_NEXT=$((TIMENOW+NEXTRUN_SECONDS)) + NEXTRUN_TIME=$(date --date @$SECONDS_TO_NEXT) + echo "[$APPNAME][$(date)] Finished. Next run in $NEXTRUN_TIME" + echo "[$APPNAME][$(date)] ----------------------------------------" + #sleep a bit until the next run + sleep $NEXTRUN_SECONDS +done diff --git a/rootfs/etc/s6-overlay/scripts/vrs b/rootfs/etc/s6-overlay/scripts/vrs new file mode 100755 index 0000000..9315ade --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/vrs @@ -0,0 +1,19 @@ +#!/command/with-contenv bash +#shellcheck shell=bash disable=SC2015 + +APPNAME="$(hostname)/vrs-runtime" +VRS_DIR="/opt/vrs" +VRS_EXEC="mono VirtualRadar.exe" +VRS_CMDLINE=() +VRS_CMDLINE+=("-nogui") +[[ -n "${VRS_CULTURE}" ]] && VRS_CMDLINE+=("-culture:${VRS_CULTURE}") || true + +# start VRS and keep it in the foreground: +cd "${VRS_DIR}" || exit +echo "[$APPNAME][$(date)] Starting ${VRS_DIR}/${VRS_EXEC} ${VRS_CMDLINE[*]}" +#exec ${VRS_EXEC} ${VRS_CMDLINE[@]} | stdbuf -o0 awk -v label=${APPNAME} '{print "[" label "][" strftime("%F %T%z", systime()) "] " $0}' +exec ${VRS_EXEC} "${VRS_CMDLINE[@]}" + +#by wiedehopf. Trying to fix the s6-svc pipe trouble +#trap 'kill 0' TERM +#( ${VRS_EXEC} ${VRS_CMDLINE[@]} | stdbuf -o0 awk -v label=${APPNAME} '{print "[" label "][" strftime("%F %T%z", systime()) "] " $0}' )