diff --git a/Dockerfile b/Dockerfile index 9dbab45..419f95c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ ENV BEASTPORT=30005 \ HTTP_ACCESS_LOG="false" \ HTTP_ERROR_LOG="true" \ TAR1090_INSTALL_DIR=/usr/local/share/tar1090 \ + TAR1090_UPDATE_DIR=/var/globe_history/tar1090-update \ MLATPORT=30105 \ INTERVAL=8 \ HISTORY_SIZE=450 \ @@ -71,13 +72,15 @@ RUN set -x && \ # change some /run/tar1090-webroot to /run/readsb to make work with existing docker scripting sed -i -e 's#/run/tar1090-webroot/#/run/readsb/#' /usr/local/share/tar1090/nginx-tar1090-webroot.conf && \ # tar1090-db: document version - pushd "${TAR1090_INSTALL_DIR}/git-db" || exit 1 && \ + pushd "${TAR1090_UPDATE_DIR}/git-db" || exit 1 && \ bash -ec 'echo "tar1090-db $(git log | head -1 | tr -s " " "_")" >> /VERSIONS' && \ popd && \ # tar1090: document version - pushd "${TAR1090_INSTALL_DIR}/git" || exit 1 && \ + pushd "${TAR1090_UPDATE_DIR}/git" || exit 1 && \ bash -ec 'echo "tar1090 $(git log | head -1 | tr -s " " "_")" >> /VERSIONS' && \ popd && \ + # tar1090: remove tar1090-update files as they're not needed unless tar1090-update is active + rm -rf "${TAR1090_UPDATE_DIR}" && \ # tar1090: add nginx config cp -Rv /etc/nginx.tar1090/* /etc/nginx/ && \ # timelapse1090 @@ -86,9 +89,8 @@ RUN set -x && \ bash -ec 'echo "timelapse1090 $(git log | head -1 | tr -s " " "_")" >> /VERSIONS' && \ popd && \ mkdir -p /var/timelapse1090 && \ - # aircraft-db + # aircraft-db, file in TAR1090_UPDATE_DIR will be preferred when starting readsb if tar1090-update enabled curl -o "${TAR1090_INSTALL_DIR}/aircraft.csv.gz" "https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz" && \ - git ls-remote https://github.com/wiedehopf/tar1090-db | grep refs/heads/csv > "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.version" && \ # clone graphs1090 repo git clone \ -b master \ diff --git a/rootfs/etc/s6-overlay/scripts/readsb b/rootfs/etc/s6-overlay/scripts/readsb index 48db63a..ca184fd 100755 --- a/rootfs/etc/s6-overlay/scripts/readsb +++ b/rootfs/etc/s6-overlay/scripts/readsb @@ -235,8 +235,11 @@ if [[ -n "$READSB_NET_VRS_PORT" ]]; then fi # make sure the db file exists, and if it does, use it -if [[ -e $TAR1090_INSTALL_DIR/aircraft.csv.gz ]]; then - if [[ "$TAR1090_ENABLE_AC_DB" == "true" ]]; then +if [[ "$TAR1090_ENABLE_AC_DB" == "true" ]]; then + if [[ -e $TAR1090_UPDATE_DIR/aircraft.csv.gz ]]; then + READSB_CMD+=("--db-file=$TAR1090_UPDATE_DIR/aircraft.csv.gz") + elif [[ -e $TAR1090_INSTALL_DIR/aircraft.csv.gz ]]; then + # fallback to container supplied not updated csv.gz READSB_CMD+=("--db-file=$TAR1090_INSTALL_DIR/aircraft.csv.gz") fi fi diff --git a/rootfs/etc/s6-overlay/startup.d/02-tar1090-update b/rootfs/etc/s6-overlay/startup.d/02-tar1090-update index 2f7ee0a..cf12f3d 100755 --- a/rootfs/etc/s6-overlay/startup.d/02-tar1090-update +++ b/rootfs/etc/s6-overlay/startup.d/02-tar1090-update @@ -20,17 +20,17 @@ fi # aircraft-db if [[ "$TAR1090_ENABLE_AC_DB" == "true" ]]; then git ls-remote https://github.com/wiedehopf/tar1090-db | grep refs/heads/csv > "/run/aircraft.csv.gz.version.new" - if ! diff -q "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.version" "/run/aircraft.csv.gz.version.new" &>/dev/null; then + if ! diff -q "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.version" "/run/aircraft.csv.gz.version.new" &>/dev/null; then echo "Downloading https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz" - if curl --silent --show-error -o "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.tmp" "https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz"; then - mv -f "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.tmp" "${TAR1090_INSTALL_DIR}/aircraft.csv.gz" - mv -f "/run/aircraft.csv.gz.version.new" "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.version" + if curl --silent --show-error -o "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.tmp" "https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz"; then + mv -f "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.tmp" "${TAR1090_UPDATE_DIR}/aircraft.csv.gz" + mv -f "/run/aircraft.csv.gz.version.new" "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.version" fi fi fi # Print tar1090 version -pushd "${TAR1090_INSTALL_DIR}/git" >/dev/null || exit 1 +pushd "${TAR1090_UPDATE_DIR}/git" >/dev/null || exit 1 if [[ -z "$TAR1090_VERSION" ]]; then TAR1090_VERSION=$(git rev-parse --short HEAD) fi diff --git a/rootfs/tar1090-install.sh b/rootfs/tar1090-install.sh index 552601f..c9e7ade 100755 --- a/rootfs/tar1090-install.sh +++ b/rootfs/tar1090-install.sh @@ -24,7 +24,11 @@ lighttpd=no nginx=no function useSystemd () { command -v systemd &>/dev/null; } +gpath="$TAR1090_UPDATE_DIR" +if [[ -z "$gpath" ]]; then gpath="$ipath"; fi + mkdir -p "$ipath" +mkdir -p "$gpath" if useSystemd && ! id -u tar1090 &>/dev/null then @@ -85,8 +89,8 @@ fi dir=$(pwd) -if (( $( { du -s "$ipath/git-db" 2>/dev/null || echo 0; } | cut -f1) > 150000 )); then - rm -rf "$ipath/git-db" +if (( $( { du -s "$gpath/git-db" 2>/dev/null || echo 0; } | cut -f1) > 150000 )); then + rm -rf "$gpath/git-db" fi function getGIT() { @@ -106,11 +110,11 @@ function revision() { git rev-parse --short HEAD 2>/dev/null || echo "$RANDOM-$RANDOM" } -if ! { [[ "$1" == "test" ]] && cd "$ipath/git-db"; }; then - getGIT "$db_repo" "master" "$ipath/git-db" || true +if ! { [[ "$1" == "test" ]] && cd "$gpath/git-db"; }; then + getGIT "$db_repo" "master" "$gpath/git-db" || true fi -if ! cd "$ipath/git-db" +if ! cd "$gpath/git-db" then echo "Unable to download files, exiting! (Maybe try again?)" exit 1 @@ -121,17 +125,17 @@ DB_VERSION=$(revision) cd "$dir" if [[ "$1" == "test" ]] || [[ -n "$git_source" ]]; then - mkdir -p "$ipath/git" - rm -rf "$ipath/git"/* || true + mkdir -p "$gpath/git" + rm -rf "$gpath/git"/* || true if [[ -n "$git_source" ]]; then - cp -r "$git_source"/* "$ipath/git" + cp -r "$git_source"/* "$gpath/git" else - cp -r ./* "$ipath/git" + cp -r ./* "$gpath/git" fi - cd "$ipath/git" + cd "$gpath/git" TAR_VERSION="$(date +%s)_${RANDOM}${RANDOM}" else - if ! getGIT "$repo" "master" "$ipath/git" || ! cd "$ipath/git" + if ! getGIT "$repo" "master" "$gpath/git" || ! cd "$gpath/git" then echo "Unable to download files, exiting! (Maybe try again?)" exit 1 @@ -274,7 +278,7 @@ do sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?${service}?g" tar1090.service cp -r -T html "$TMP" - cp -r -T "$ipath/git-db/db" "$TMP/db-$DB_VERSION" + cp -r -T "$gpath/git-db/db" "$TMP/db-$DB_VERSION" sed -i -e "s/let databaseFolder = .*;/let databaseFolder = \"db-$DB_VERSION\";/" "$TMP/index.html" echo "{ \"tar1090Version\": \"$TAR_VERSION\", \"databaseVersion\": \"$DB_VERSION\" }" > "$TMP/version.json" @@ -306,7 +310,7 @@ do sed -i -e "s/tar1090 on github/tar1090 on github ($(date +%y%m%d))/" index.html - "$ipath/git/cachebust.sh" "$ipath/git/cachebust.list" "$TMP" + "$gpath/git/cachebust.sh" "$gpath/git/cachebust.list" "$TMP" rm -rf "$html_path" mv "$TMP" "$html_path"