Files

127 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2025-05-16 11:16:41 +02:00
#!/bin/sh
# shellcheck shell=dash
2025-05-21 14:06:14 +02:00
set -u
2025-05-16 11:16:41 +02:00
# Check if it's a valid file
2025-05-16 11:16:41 +02:00
check_file() {
local target="$1"
if [ ! -f "$target" ]; then
cat <<EOF
!!!
!!! ERROR
!!! "$target" is not a valid file, exiting...
!!!
EOF
exit 127
fi
}
# Check if it's a valid directory
2025-05-16 11:16:41 +02:00
check_directory() {
local target="$1"
if [ ! -d "$target" ]; then
cat <<EOF
!!!
!!! ERROR
!!! "$target" is not a valid directory, exiting...
!!!
EOF
exit 127
fi
}
setup_ownership() {
local target="$1"
local type="$2"
case "$type" in
file | directory) ;;
*)
cat <<EOF
2025-05-16 11:16:41 +02:00
!!!
!!! ERROR
!!! "$type" is not a valid type, exiting...
!!!
EOF
exit 1
;;
2025-05-16 11:16:41 +02:00
esac
target_ownership=$(stat -c %U:%G "$target")
if [ "$target_ownership" != "searxng:searxng" ]; then
if [ "${FORCE_OWNERSHIP:-true}" = true ] && [ "$(id -u)" -eq 0 ]; then
2025-05-16 11:16:41 +02:00
chown -R searxng:searxng "$target"
else
cat <<EOF
!!!
!!! WARNING
!!! "$target" $type is not owned by "searxng:searxng"
2025-05-16 11:16:41 +02:00
!!! This may cause issues when running SearXNG
!!!
!!! Expected "searxng:searxng"
!!! Got "$target_ownership"
2025-05-16 11:16:41 +02:00
!!!
EOF
fi
fi
}
# Handle volume mounts
volume_handler() {
local target="$1"
check_directory "$target"
setup_ownership "$target" "directory"
}
2026-06-16 15:32:47 +02:00
setup() {
local template_settings="/usr/local/searxng/settings.template.yml"
local target_settings="$__SEARXNG_CONFIG_PATH/settings.yml"
2025-05-16 11:16:41 +02:00
2026-06-16 15:32:47 +02:00
if [ ! -f "$target_settings" ]; then
2025-05-16 11:16:41 +02:00
cat <<EOF
...
... INFORMATION
2026-06-16 15:32:47 +02:00
... "$target_settings" does not exist, creating from template...
2025-05-16 11:16:41 +02:00
...
EOF
2026-06-16 15:32:47 +02:00
cp -pfT "$template_settings" "$target_settings"
2026-06-16 15:32:47 +02:00
sed -i "s/ultrasecretkey/$(head -c 24 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9')/g" "$target_settings"
2025-05-16 11:16:41 +02:00
fi
2026-06-16 15:32:47 +02:00
check_file "$target_settings"
2025-05-16 11:16:41 +02:00
}
cat <<EOF
2026-03-28 16:45:06 +01:00
SearXNG $__SEARXNG_VERSION
EOF
2025-05-16 11:16:41 +02:00
# Check for volume mounts
2026-03-28 16:45:06 +01:00
volume_handler "$__SEARXNG_CONFIG_PATH"
volume_handler "$__SEARXNG_DATA_PATH"
2025-05-16 11:16:41 +02:00
2026-06-16 15:32:47 +02:00
setup
2025-05-16 11:16:41 +02:00
2026-03-28 16:45:06 +01:00
# root only features
if [ "$(id -u)" -eq 0 ]; then
update-ca-certificates
fi
# ENVs aliases
# https://github.com/searxng/searxng/issues/5934
case "${SEARXNG_PORT:-}" in
'') ;;
*[!0-9]*)
unset SEARXNG_PORT
;;
*)
export GRANIAN_PORT="$SEARXNG_PORT"
;;
esac
2025-08-07 10:46:26 +02:00
exec /usr/local/searxng/.venv/bin/granian searx.webapp:app