Files
hassio-addons/filebrowser/rootfs/etc/cont-init.d/99-run.sh
alexbelgium 278818970f filebrowser: fix healthcheck protocol detection with ssl enabled
The HEALTHCHECK branched on "$ssl", but that variable is never present
in the container environment: Supervisor only injects the environment:
block from config.yaml (FB_BASEURL, PGID, PUID) plus TZ/SUPERVISOR_TOKEN.
The ssl option lives in /data/options.json and is read via bashio inside
cont-init, and HEALTHCHECK CMD is spawned by dockerd, so no export from
that shell can ever reach it.

The test was therefore always false and the healthcheck kept probing
http:// against the TLS listener, producing the

  http: TLS handshake error ... client sent an HTTP request to an HTTPS server

spam reported in #2881.

Write the resolved protocol to /run/health_protocol from 99-run.sh and
read it back in the healthcheck, matching the pattern already used by
the gitea addon. Also corrects the 127.0.01 typo (missing octet).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-26 07:57:09 +02:00

130 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bashio
# shellcheck shell=bash
set -e
############
# TIMEZONE #
############
if bashio::config.has_value 'TZ'; then
TIMEZONE=$(bashio::config 'TZ')
bashio::log.info "Setting timezone to $TIMEZONE"
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
echo "$TIMEZONE" > /etc/timezone
else
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
fi
fi
###################
# SSL CONFIG v1.0 #
###################
bashio::config.require.ssl
if bashio::config.true 'ssl'; then
bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths"
#set variables
CERTFILE="-t /ssl/$(bashio::config 'certfile')"
KEYFILE="-k /ssl/$(bashio::config 'keyfile')"
else
CERTFILE=""
KEYFILE=""
fi
#################
# NGINX SETTING #
#################
#declare port
#declare certfile
declare ingress_interface
declare ingress_port
#declare keyfile
FB_BASE_URL=$(bashio::addon.ingress_entry)
export FB_BASE_URL
declare ADDON_PROTOCOL=http
# Generate Ingress configuration
if bashio::config.true 'ssl'; then
ADDON_PROTOCOL=https
fi
# Expose the protocol to the docker HEALTHCHECK, which runs outside this
# shell and therefore cannot read the addon options
echo -n "${ADDON_PROTOCOL}" > /run/health_protocol
#port=$(bashio::addon.port 80)
ingress_port=$(bashio::addon.ingress_port)
ingress_interface=$(bashio::addon.ip_address)
sed -i "s|%%protocol%%|${ADDON_PROTOCOL}|g" /etc/nginx/servers/ingress.conf
sed -i "s|%%port%%|${ingress_port}|g" /etc/nginx/servers/ingress.conf
sed -i "s|%%interface%%|${ingress_interface}|g" /etc/nginx/servers/ingress.conf
sed -i "s|%%subpath%%|${FB_BASE_URL}/|g" /etc/nginx/servers/ingress.conf
mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
######################
# LAUNCH FILEBROWSER #
######################
NOAUTH=""
# Prevent conflicts
for folders in /etc/services.d /etc/s6-overlay; do
[[ -d "$folders" ]] && rm -r "$folders"
done
# Disable authentification
if bashio::config.true 'NoAuth'; then
if ! bashio::fs.file_exists "/data/noauth"; then
rm /data/auth &> /dev/null || true
rm /config/filebrowser.dB &> /dev/null || true
touch /data/noauth
bashio::log.warning "Auth method change, database reset"
fi
NOAUTH="--noauth"
bashio::log.info "NoAuth option selected"
else
if ! bashio::fs.file_exists "/data/auth"; then
rm /data/noauth &> /dev/null || true
rm /config/filebrowser.dB &> /dev/null || true
touch /data/auth
bashio::log.warning "Auth method change, database reset"
fi
bashio::log.info "Default username/password : admin/admin"
fi
# Set base folder
if bashio::config.has_value 'base_folder'; then
BASE_FOLDER=$(bashio::config 'base_folder')
else
BASE_FOLDER=/
fi
# Disable thumbnails
if bashio::config.true 'disable_thumbnails'; then
DISABLE_THUMBNAILS="--disableThumbnails"
else
DISABLE_THUMBNAILS=""
fi
# Disable thumbnails
if bashio::config.true 'follow_external_symlinks'; then
FOLLOW_SYMLINKS="--followExternalSymlinks"
else
FOLLOW_SYMLINKS=""
fi
# Remove configuration file
if [ -f /.filebrowser.json ]; then
rm /.filebrowser.json
fi
bashio::log.info "Starting..."
# shellcheck disable=SC2086
/./bin/filebrowser --disablePreviewResize --disableTypeDetectionByHeader --cacheDir="/cache" $CERTFILE $KEYFILE --root="$BASE_FOLDER" --address=0.0.0.0 --port=8080 --database=/config/filebrowser.dB ${FOLLOW_SYMLINKS:+$FOLLOW_SYMLINKS} ${NOAUTH:+$NOAUTH} ${DISABLE_THUMBNAILS:+$DISABLE_THUMBNAILS} &
bashio::net.wait_for 8080 localhost 900 || true
bashio::log.info "Started !"
nginx || bashio::log.fatal "Nginx failed"