#!/bin/bash # SearXNG install hooks — wait for settings.yml, apply theme, restart. searxng_install_post_start() { local app_name="$1" local searxng_settings="$(appDir "$app_name")/searxng-data/settings.yml" local searxng_timeout=10 local searxng_counter=0 while [ ! -f "$searxng_settings" ]; do if [ "$searxng_counter" -ge "$searxng_timeout" ]; then isNotice "File not found after 10 seconds. Exiting..." return 0 fi isNotice "Waiting for the file to appear..." read -t 1 searxng_counter=$((searxng_counter + 1)) done # SearXNG validates this against a fixed set and refuses to start on anything # else, so a typo in the config would take the whole app down rather than just # look wrong. Check it here instead. local searxng_theme="${CFG_SEARXNG_THEME:-auto}" case "$searxng_theme" in auto|light|dark|black) ;; *) isNotice "CFG_SEARXNG_THEME='$searxng_theme' is not one of auto|light|dark|black — leaving the theme at SearXNG's default." return 0 ;; esac # The edit runs INSIDE the container, for two reasons the old `runFileOp sed` # on the host could not satisfy: # # 1. Ownership. The entrypoint chowns this file to searxng:searxng (uid 977) # on first start, mode 644 — so the host-side docker user cannot write to # it at all. # 2. Key path. The old sed replaced `simple_style: auto`, which only exists # in SearXNG's full bundled settings.yml. The file generated here is the # minimal `use_default_settings: true` form and has no ui: block at all, # so the substitution matched nothing and CFG_SEARXNG_THEME had never had # any effect on any install. # # The setting lives at ui.theme_args.simple_style. All three shapes are # handled so this stays correct on a reinstall over existing data (where the # key is already present) and if someone has hand-added their own ui: block — # appending a second one would be a duplicate YAML key and SearXNG would # refuse to load it. local searxng_container="${app_name}-service" local searxng_result searxng_result=$(runFileOp docker exec -i "$searxng_container" sh -s "$searxng_theme" <<'SEARXNG_THEME_EOS' set -e theme="$1" f=/etc/searxng/settings.yml [ -f "$f" ] || exit 1 if grep -qE '^[[:space:]]*simple_style:' "$f"; then # Already set (reinstall over existing data): update in place, keeping # whatever indentation it currently sits at. sed -i -E "s/^([[:space:]]*)simple_style:.*/\1simple_style: $theme/" "$f" elif grep -qE '^ui:[[:space:]]*$' "$f"; then # A ui: block exists but carries no theme_args — nest ours inside it rather # than appending a second ui:, which would be a duplicate YAML key. awk, not # `sed a\`, because busybox sed does not expand \n in appended text. awk -v t="$theme" ' /^ui:[[:space:]]*$/ { print; print " theme_args:"; print " simple_style: " t; next } { print } ' "$f" > "$f.lp.tmp" cat "$f.lp.tmp" > "$f" rm -f "$f.lp.tmp" else # The normal case for a LibrePortal install: the generated file is the # minimal use_default_settings form with no ui: block at all. printf '\nui:\n theme_args:\n simple_style: %s\n' "$theme" >> "$f" fi SEARXNG_THEME_EOS ) checkSuccess "Applying SearXNG theme '$searxng_theme'" dockerComposeRestart $app_name }