Skip to content

Commit

Permalink
upgrade to s6v3
Browse files Browse the repository at this point in the history
  • Loading branch information
kx1t committed Sep 27, 2023
1 parent ab231ac commit dfc4bfd
Show file tree
Hide file tree
Showing 65 changed files with 443 additions and 3 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion rootfs/etc/cont-finish.d/10-terminate-aiscatcher
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/with-contenv bash
#!/command/with-contenv bash
#shellcheck shell=bash

#---------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/10-container-init/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/10-container-init/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/10-container-init
Empty file.
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/40-sxfeeder/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/40-sxfeeder/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/40-sxfeeder
Empty file.
Empty file.
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/50-update-plugins/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/50-update-plugins/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/50-update-plugins
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/60-backup-aiscatcher_bin/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/60-backup-aiscatcher_bin
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/aiscatcher/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/aiscatcher
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/aiscatcher/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/check-about-updates/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/check-about-updates
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/check-about-updates/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/check-plugin-updates/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/check-plugin-updates
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/check-plugin-updates/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/sxfeeder/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/sxfeeder
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/sxfeeder/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions rootfs/etc/s6-overlay/scripts/10-container-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091

source /scripts/common
APPNAME="10-container-init"
s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}")

#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------------

"${s6wrap[@]}" --args echo "Starting ShipExplorer version $(cat /.CONTAINER_VERSION)"
mkdir -p /data
83 changes: 83 additions & 0 deletions rootfs/etc/s6-overlay/scripts/40-sxfeeder
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091

source /scripts/common

#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------------

# Check to make sure the correct command line arguments have been set

APPNAME="10-container-init"
s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}")

if [[ -z "${SHARING_KEY}" ]] && [[ -z "${AISCATCHER_EXTRA_OPTIONS}" ]] && [[ -z "${UDP_FEEDS}" ]]
then
"${s6wrap[@]}" --args echo "WARNING: Container is configured for Local Use Only. At least one of SHARING_KEY, AISCATCHER_EXTRA_OPTIONS, or UDP_FEEDS must be defined for this container to feed a service."
exit 0
fi

if [[ -z "${SHARING_KEY}" ]]
then
"${s6wrap[@]}" --args echo "WARNING: SHARING_KEY is not set. Feeding to ShipXplorer is disabled."
"${s6wrap[@]}" --args echo " If you are attempting to generate a new ShipXplorer sharing key and serial, you can do so by giving this command:"
"${s6wrap[@]}" --args echo " docker exec -it shipxplorer /usr/bin/getcreds"
exit 0
fi

if [[ -z "${SERIAL_NUMBER}" ]]
then
"${s6wrap[@]}" --args echo "ERROR: ShipXplorer SHARING_KEY is defined but SERIAL_NUMBER is not set. We need both to feed ShipXplorer. If you want to disable feeding ShipXplorer, make sure that SHARING_KEY is empty as well."
exit 1
fi

if [[ -z "${RTLSDR_DEVICE_SERIAL}" ]]
then
"${s6wrap[@]}" --args echo "WARNING: RTLSDR_DEVICE_SERIAL is not set. The container will run in network-only mode."
fi

# Generate /etc/sxfeeder.ini based on environment variables
echo """
[client]
pid=/var/run/sxfeeder/sxfeeder.pid
disable_log=false
log_file=/var/log/sxfeeder.log
#SHARINGKEY
#SERIALNUMBER

[network]
udp_listen_port=34995
""" > /etc/sxfeeder.ini

sed -i 's/#SHARINGKEY/key='"$SHARING_KEY"'/g' /etc/sxfeeder.ini
sed -i 's/#SERIALNUMBER/sn='"$SERIAL_NUMBER"'/g' /etc/sxfeeder.ini

# In case sxfeeder cannot be run, let's make sure that qemu exists:
if ! /usr/bin/sxfeeder --help >/dev/null 2>&1 && ! which qemu-arm-static >/dev/null 2>&1
then
"${s6wrap[@]}" --args echo "ERROR: sxfeeder cannot be run natively, and QEMU is not available. You cannot use this container"
"${s6wrap[@]}" --args echo " on this system / architecture. Feel free to file an issue at https://github.com/sdr-enthusiasts/docker-shipxplorer/issues"
"${s6wrap[@]}" --args echo "Container halted."
sleep infinity
fi

# Create log dirs
mkdir -p /var/run/sxfeeder
chmod a+rwx /var/run/sxfeeder
touch /var/log/rbfeeder.log
chmod a+rwx /var/log/rbfeeder.log
truncate --size=0 /var/log/rbfeeder.log
chmod a+rw /etc/sxfeeder.ini
32 changes: 32 additions & 0 deletions rootfs/etc/s6-overlay/scripts/50-update-plugins
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091,SC2164

source /scripts/common

#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------------

# Update JavaScript plugins on container start

export APPNAME="50-plugin-updates"

#shellcheck disable=SC2076
if chk_disabled "${PLUGIN_UPDATE_INTERVAL,,}"; then
s6wrap --quiet --timestamps --prepend="${APPNAME}" --args echo "Plugins Updating is disabled"
exit 0
fi

exec /scripts/update-plugins
30 changes: 30 additions & 0 deletions rootfs/etc/s6-overlay/scripts/60-backup-aiscatcher_bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091,SC2164

source /scripts/common

#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------------

# Back up the aiscatcher.bin file

# Copy plugin file if it's newer but leave a backup in place
if [[ -f /data/aiscatcher.bin ]]; then
cp --backup=numbered -u /data/aiscatcher.bin /data/aiscatcher.bin.bkup
fi

# remove any backups older than BACKUP_RETENTION_TIME (or 30 days if undefined)
find /data -maxdepth 1 -name '*.~*~' -mtime +"${BACKUP_RETENTION_TIME:-30}" -exec rm {} \;
107 changes: 107 additions & 0 deletions rootfs/etc/s6-overlay/scripts/aiscatcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091,SC2016,SC2068,SC2076,SC2086,SC2015

source /scripts/common
APPNAME="aiscatcher"
s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}")

#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------------


# check if logging is verbose:
if [[ -n "$VERBOSE_LOGGING" ]]
then
[[ $VERBOSE_LOGGING =~ ^[0-5]{1}$ ]] && SHOWLOGS="-o $VERBOSE_LOGGING" || SHOWLOGS=""
else
SHOWLOGS="-q -v 60"
fi

# Interpret additional feed targets, if defined
FEEDSTRING=()
if [[ -n "$UDP_FEEDS" ]]
then
readarray -d "," -t feedsarray <<< "$UDP_FEEDS"
for feeds in "${feedsarray[@]}"
do
[[ -n "$feeds" ]] && FEEDSTRING+=("-u ${feeds//:/ }")
done
fi

# get gain
VALID_GAINS=(0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6)
# if the gain isn't defined, default to 33.8 (middle of the scale)
RTLSDR_DEVICE_GAIN="${RTLSDR_DEVICE_GAIN:-33.8}"
# if the gain isn't a number and it isn't "auto", then default to 33.8 (middle of the scale)
if [[ "${RTLSDR_DEVICE_GAIN,,}" != "auto" ]] && [[ ! $RTLSDR_DEVICE_GAIN =~ ^[+-]?[0-9.]+$ ]]
then
RTLSDR_DEVICE_GAIN="33.8"
fi
# Now make sure that the gain is in the valid gains range, and if it isn't, pick the nearest higher one
if [[ ! " ${VALID_GAINS[*]} " =~ " ${RTLSDR_DEVICE_GAIN} " ]] && [[ "${RTLSDR_DEVICE_GAIN,,}" != "auto" ]]
then
for GAIN in "${VALID_GAINS[@]}"
do
if [[ "$(awk "BEGIN {print int($GAIN * 10);}")" -ge "$(awk "BEGIN {print int($RTLSDR_DEVICE_GAIN * 10);}")" ]]
then
RTLSDR_DEVICE_GAIN="$GAIN"
"${s6wrap[@]}" --args echo "Gain rounded to ${RTLSDR_DEVICE_GAIN}"
break
fi
done
fi
# If the number is still larger than the largest allowed number, then default to that one
[[ "$(awk "BEGIN {print int($RTLSDR_DEVICE_GAIN * 10);}")" -gt "$(awk "BEGIN {print int(${VALID_GAINS[-1]} * 10);}")" ]] && RTLSDR_DEVICE_GAIN="${VALID_GAINS[-1]}"

# check if STATION_NAME and STATION_LINK is defined. If it is not, add the ShipXplorer URL
[[ -z "$STATION_NAME" ]] && [[ -n "$SERIAL_NUMBER" ]] && STATION_NAME="${SERIAL_NUMBER}" || true
[[ -z "$STATION_LINK" ]] && [[ -n "$SERIAL_NUMBER" ]] && STATION_LINK="https://www.shipxplorer.com/stations/${SERIAL_NUMBER}" || true

aiscatcher_command=()
aiscatcher_command+=("/usr/local/bin/AIS-catcher")
# set the web site parameters:
if ! chk_enabled "${DISABLE_WEBSITE}"; then
aiscatcher_command+=("-N 80 REUSE_PORT on FILE /data/aiscatcher.bin")
chk_enabled "${DISABLE_SHIPSJSON_COMPRESS}" && aiscatcher_command+=("ZLIB off") || true
[[ -d "/data/plugins" ]] && aiscatcher_command+=("PLUGIN_DIR /data/plugins") || true
[[ -f "/data/about.md" ]] && aiscatcher_command+=("ABOUT /data/about.md") || true
[[ -n "${BACKUP_INTERVAL}" ]] && aiscatcher_command+=("BACKUP ${BACKUP_INTERVAL}") || true
[[ -n "${STATION_HISTORY}" ]] && aiscatcher_command+=("HISTORY ${STATION_HISTORY}") || true
chk_enabled "${PROMETHEUS_ENABLE}" && aiscatcher_command+=("PROME on") || true
[[ -n "${STATION_NAME}" ]] && aiscatcher_command+=("STATION $STATION_NAME") || true
[[ -n "${STATION_LINK}" ]] && aiscatcher_command+=("STATION_LINK $STATION_LINK") || true
if [[ -n "$SXFEEDER_LAT" ]] && [[ -n "$SXFEEDER_LON" ]]
then
aiscatcher_command+=("LAT $SXFEEDER_LAT LON $SXFEEDER_LON")
chk_enabled "${SITESHOW}" && aiscatcher_command+=("SHARE_LOC on") || true
fi
chk_enabled "${DISABLE_SHOWLASTMSG}" && true || aiscatcher_command+=("MESSAGE on")
chk_enabled "${REALTIME}" && aiscatcher_command+=("REALTIME on") || true
fi
aiscatcher_command+=("-u 127.0.0.1 34994")
aiscatcher_command+=("-u 127.0.0.1 34995")
aiscatcher_command+=("${FEEDSTRING[*]}")
aiscatcher_command+=("$SHOWLOGS")
[[ -n "${RTLSDR_DEVICE_SERIAL}" ]] && aiscatcher_command+=("-d ${RTLSDR_DEVICE_SERIAL}") || true
[[ -n "${RTLSDR_DEVICE_SERIAL}" ]] && aiscatcher_command+=("-gr tuner ${RTLSDR_DEVICE_GAIN} rtlagc ON")
aiscatcher_command+=("$AISCATCHER_EXTRA_OPTIONS")

aiscommand="$(echo ${aiscatcher_command[@]} | xargs)"

"${s6wrap[@]}" --args echo "Starting: ${aiscommand}"

# shellcheck disable=SC2048
exec "${s6wrap[@]}" --args ${aiscommand}
48 changes: 48 additions & 0 deletions rootfs/etc/s6-overlay/scripts/check-about-updates
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/command/with-contenv bash
#shellcheck shell=bash disable=SC1091,SC2164

source /scripts/common
APPNAME="check-about-updates"
s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}")

#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------------

# Check if about.md has been updated by comparing its MD5 hash every 30 seconds; restart
# the aiscatcher service

filename="/data/about.md"

# determine the initial MD5 of about.md, or set it to "none" if the file doesn't exist:
m1=$(md5sum "$filename" 2>/dev/null) || m1="none"

while true
do
# md5sum is computationally expensive, so check only once every 30 seconds
sleep 30

# determine the current MD5 of about.md, or set it to "none" if the file doesn't exist:
m2=$(md5sum "$filename" 2>/dev/null) || m2="none"

# restart AIS-catcher if the newly calculated MD5 is different from the old MD5, indicating
# that about.md has changed:
if [[ "$m1" != "$m2" ]]
then
"${s6wrap[@]}" --args echo "about.md has changed, restarting AIS-Catcher to ensure about file is re-read..."
pkill AIS-catcher >/dev/null 2>&1
m1="$m2"
fi
done
Loading

0 comments on commit dfc4bfd

Please sign in to comment.