mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-09-18 07:39:08 +02:00
* fix(filebrowser_quantum): repair direct access on port 8071 1.5.1.1 published the port but direct access still did not work, in two ways measured against a running instance: 1. The root redirect was absolute, so nginx built it from $server_port and sent the browser to :8072 — the container-internal port, not the published one. `absolute_redirect off` keeps the redirect relative. 2. The page served under /filebrowser_quantum/ referenced its assets under the app's own baseURL (the ingress entry path), which that vhost did not route: GET /api/hassio_ingress/<hash>/public/static/favicon.svg returned 404 while the same file under /filebrowser_quantum/ returned 200. The page loaded and every asset on it failed. Rather than translating paths, the vhost now passes requests through unchanged and redirects only the bare root to the app's baseURL, which is what its own links already point at. Asset, API and websocket URLs then work without any response rewriting. Ingress is untouched. * docs(filebrowser_quantum): describe the legacy redirects accurately The comments, CHANGELOG and README still said only the bare root was redirected, which stopped being true when the two /filebrowser_quantum compatibility redirects were added. Raised by CodeRabbit and Codex.
171 lines
6.0 KiB
Bash
Executable File
171 lines
6.0 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="/ssl/$(bashio::config 'certfile')"
|
|
KEYFILE="/ssl/$(bashio::config 'keyfile')"
|
|
else
|
|
CERTFILE=""
|
|
KEYFILE=""
|
|
fi
|
|
export CERTFILE KEYFILE
|
|
|
|
#################
|
|
# NGINX SETTING #
|
|
#################
|
|
|
|
#declare port
|
|
#declare certfile
|
|
declare ingress_interface
|
|
declare ingress_port
|
|
#declare keyfile
|
|
|
|
# The app's own baseURL is the Supervisor ingress-entry path, unchanged from
|
|
# before: FileBrowser emits that prefix as absolute links in its HTML and JS,
|
|
# so it is also the path direct ip:port access has to use (see direct.conf).
|
|
FB_BASEURL=$(bashio::addon.ingress_entry)
|
|
export FB_BASEURL
|
|
|
|
declare ADDON_PROTOCOL=http
|
|
# Generate Ingress configuration
|
|
if bashio::config.true 'ssl'; then
|
|
ADDON_PROTOCOL=https
|
|
fi
|
|
|
|
#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_BASEURL}/|g" /etc/nginx/servers/ingress.conf
|
|
|
|
# --- Direct ip:port access (separate vhost, ingress untouched) ---
|
|
# Listens on 8072, published to the host as 8071 by config.yaml's `ports:`.
|
|
# Requests are passed through unchanged; the bare root and the two legacy
|
|
# /filebrowser_quantum paths are redirected to the app's baseURL, which is what
|
|
# its own links already point at.
|
|
sed -i "s|%%protocol%%|${ADDON_PROTOCOL}|g" /etc/nginx/servers/direct.conf
|
|
sed -i "s|%%subpath%%|${FB_BASEURL}/|g" /etc/nginx/servers/direct.conf
|
|
|
|
mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
|
|
|
|
############################
|
|
# FILEBROWSER CONFIGURATION #
|
|
############################
|
|
|
|
mkdir -p /config /cache
|
|
|
|
# Copy default config if not existing
|
|
if [ ! -f "$FILEBROWSER_CONFIG" ]; then
|
|
cp /home/filebrowser/data/config.yaml "$FILEBROWSER_CONFIG"
|
|
fi
|
|
|
|
bashio::log.info "Updating FileBrowser config..."
|
|
|
|
# --- Server (hardcoded values) ---
|
|
bashio::log.info "... set server"
|
|
yq e -i ".server.port = 8080" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".server.listen = \"0.0.0.0\"" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".server.database = \"/config/database.db\"" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".server.cacheDir = \"/cache\"" "$FILEBROWSER_CONFIG"
|
|
|
|
# --- Default user scope / source path ---
|
|
bashio::log.info "... set default user scope"
|
|
DEFAULT_USER_SCOPE=$(bashio::config 'default_user_scope' '/')
|
|
|
|
# Validate: must start with /
|
|
if [[ "$DEFAULT_USER_SCOPE" != /* ]]; then
|
|
bashio::log.fatal "default_user_scope '${DEFAULT_USER_SCOPE}' is not a valid absolute path (must start with /). Stopping."
|
|
exit 1
|
|
fi
|
|
|
|
# Validate: path must exist
|
|
if [ ! -d "$DEFAULT_USER_SCOPE" ]; then
|
|
bashio::log.fatal "default_user_scope '${DEFAULT_USER_SCOPE}' does not exist or is not a directory. Stopping."
|
|
exit 1
|
|
fi
|
|
|
|
bashio::log.info "... set source path and defaultUserScope to ${DEFAULT_USER_SCOPE}"
|
|
yq e -i ".server.sources[0].path = \"${DEFAULT_USER_SCOPE}\"" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".server.sources[0].name = \"Default\"" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".server.sources[0].config.defaultUserScope = \"${DEFAULT_USER_SCOPE}\"" "$FILEBROWSER_CONFIG"
|
|
|
|
# --- Base URL (from env or config) ---
|
|
bashio::log.info "... set base URL to allow ingress"
|
|
BASE_URL=$(bashio::config 'base_url' "${FB_BASEURL:-/}")
|
|
yq e -i ".server.baseURL = \"${BASE_URL}\"" "$FILEBROWSER_CONFIG"
|
|
|
|
# --- Auth method ---
|
|
AUTH_METHOD=$(bashio::config 'auth_method' 'password')
|
|
bashio::log.info "... authentication method set to $AUTH_METHOD"
|
|
case "$AUTH_METHOD" in
|
|
noauth)
|
|
yq e -i ".auth.methods.noauth = true" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.password.enabled = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.proxy.enabled = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.oidc.enabled = false" "$FILEBROWSER_CONFIG"
|
|
;;
|
|
password)
|
|
yq e -i ".auth.methods.noauth = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.password.enabled = true" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.proxy.enabled = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.oidc.enabled = false" "$FILEBROWSER_CONFIG"
|
|
;;
|
|
proxy)
|
|
yq e -i ".auth.methods.noauth = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.password.enabled = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.proxy.enabled = true" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.oidc.enabled = false" "$FILEBROWSER_CONFIG"
|
|
;;
|
|
oidc)
|
|
yq e -i ".auth.methods.noauth = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.password.enabled = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.proxy.enabled = false" "$FILEBROWSER_CONFIG"
|
|
yq e -i ".auth.methods.oidc.enabled = true" "$FILEBROWSER_CONFIG"
|
|
;;
|
|
*)
|
|
bashio::log.fatal "Unknown auth_method: $AUTH_METHOD"
|
|
;;
|
|
esac
|
|
|
|
######################
|
|
# LAUNCH FILEBROWSER #
|
|
######################
|
|
|
|
# Prevent conflicts
|
|
for folders in /etc/services.d /etc/s6-overlay; do
|
|
[[ -d "$folders" ]] && rm -r "$folders"
|
|
done
|
|
|
|
bashio::log.info "Starting..."
|
|
|
|
cd /home/filebrowser
|
|
./filebrowser &
|
|
bashio::net.wait_for 8080 localhost 900 || true
|
|
bashio::log.info "Started !"
|
|
nginx || bashio::log.fatal "Nginx failed"
|