1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 20:17:45 +01:00

[mod] utils/searx.sh - add command 'inspect settings'

Inspect YAML setting <key> from SearXNG instance (${SEARX_SRC})::

  utils/searx.sh inspect settings server.base_url

utils/lib_install.sh
  should not log on stdout which is used for the output of function
  prompt_installation_setting().  Turned build_msg (stdout) into
  info_msg (stderr).

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2021-07-12 16:51:36 +02:00
parent 28c874bf3f
commit 57b8f340a6
2 changed files with 61 additions and 12 deletions

View File

@ -55,18 +55,18 @@ source_dot_config() {
SEARX_PYENV=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_PYENV) SEARX_PYENV=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_PYENV)
SEARX_SETTINGS_PATH=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_SETTINGS_PATH) SEARX_SETTINGS_PATH=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_SETTINGS_PATH)
if [ ! -r "${SEARX_SRC}" ]; then if [ ! -r "${SEARX_SRC}" ]; then
build_msg INSTANCE "not yet cloned: ${SEARX_SRC}" info_msg "not yet cloned: ${SEARX_SRC}"
orig_source_dot_config orig_source_dot_config
return 0 return 0
fi fi
build_msg INSTANCE "using instance at: ${SEARX_SRC}" info_msg "using instance at: ${SEARX_SRC}"
# set and log DOT_CONFIG # set and log DOT_CONFIG
if [ -r "${SEARX_SRC}/.config.sh" ]; then if [ -r "${SEARX_SRC}/.config.sh" ]; then
build_msg INSTANCE "switching to ${SEARX_SRC}/.config.sh" info_msg "switching to ${SEARX_SRC}/.config.sh"
DOT_CONFIG="${SEARX_SRC}/.config.sh" DOT_CONFIG="${SEARX_SRC}/.config.sh"
else else
build_msg INSTANCE "using local config: ${DOT_CONFIG}" info_msg "using local config: ${DOT_CONFIG}"
fi fi
init_SEARX_SRC_INIT_FILES init_SEARX_SRC_INIT_FILES
fi fi
@ -104,12 +104,12 @@ init_SEARX_SRC_INIT_FILES(){
# diff "${REPO_ROOT}/${fname}" "${SEARX_SRC}/${fname}" # diff "${REPO_ROOT}/${fname}" "${SEARX_SRC}/${fname}"
if ! cmp --silent "${REPO_ROOT}/${fname}" "${SEARX_SRC}/${fname}"; then if ! cmp --silent "${REPO_ROOT}/${fname}" "${SEARX_SRC}/${fname}"; then
SEARX_SRC_INIT_FILES+=("${fname}") SEARX_SRC_INIT_FILES+=("${fname}")
build_msg INSTANCE "local clone (workingtree), modified file: ./$fname" info_msg "local clone (workingtree), modified file: ./$fname"
msg="to update use: sudo -H ./utils/searx.sh install init-src" msg="to update use: sudo -H ./utils/searx.sh install init-src"
fi fi
fi fi
done <<< "$(git diff --name-only)" done <<< "$(git diff --name-only)"
[ -n "$msg" ] && build_msg INSTANCE "$msg" [ -n "$msg" ] && info_msg "$msg"
} }
install_log_searx_instance() { install_log_searx_instance() {

View File

@ -146,7 +146,7 @@ usage::
$(basename "$0") remove [all|user|pyenv|searx-src] $(basename "$0") remove [all|user|pyenv|searx-src]
$(basename "$0") activate [service] $(basename "$0") activate [service]
$(basename "$0") deactivate [service] $(basename "$0") deactivate [service]
$(basename "$0") inspect [service] $(basename "$0") inspect [service|settings <key>]
$(basename "$0") option [debug-[on|off]|image-proxy-[on|off]|result-proxy <url> <key>] $(basename "$0") option [debug-[on|off]|image-proxy-[on|off]|result-proxy <url> <key>]
$(basename "$0") apache [install|remove] $(basename "$0") apache [install|remove]
@ -169,8 +169,9 @@ activate service
activate and start service daemon (systemd unit) activate and start service daemon (systemd unit)
deactivate service deactivate service
stop and deactivate service daemon (systemd unit) stop and deactivate service daemon (systemd unit)
inspect service inspect
run some small tests and inspect service's status and log :service: run some small tests and inspect service's status and log
:settings: inspect YAML setting <key> from SearXNG instance (${SEARX_SRC})
option option
set one of the available options set one of the available options
apache apache
@ -205,6 +206,10 @@ main() {
sudo_or_exit sudo_or_exit
inspect_service inspect_service
;; ;;
settings)
prompt_installation_setting "$3"
dump_return $?
;;
*) usage "$_usage"; exit 42;; *) usage "$_usage"; exit 42;;
esac ;; esac ;;
install) install)
@ -425,9 +430,14 @@ EOF
} }
prompt_installation_status(){ prompt_installation_status(){
local _state
_state="$(install_searx_get_state)" local state branch remote remote_url instance_setting
case $_state in state="$(install_searx_get_state)"
branch="$(git name-rev --name-only HEAD)"
remote="$(git config branch."${branch}".remote)"
remote_url="$(git config remote."${remote}".url)"
case $state in
missing-searx-clone) missing-searx-clone)
info_msg "${_BBlue}(status: $(install_searx_get_state))${_creset}" info_msg "${_BBlue}(status: $(install_searx_get_state))${_creset}"
return 0 return 0
@ -435,6 +445,16 @@ prompt_installation_status(){
*) *)
warn_msg "SearXNG instance already installed at: $SEARX_SRC" warn_msg "SearXNG instance already installed at: $SEARX_SRC"
warn_msg "status: ${_BBlue}$(install_searx_get_state)${_creset} " warn_msg "status: ${_BBlue}$(install_searx_get_state)${_creset} "
instance_setting="$(prompt_installation_setting brand.git_url)"
if ! [ "$instance_setting" = "$remote_url" ]; then
warn_msg "instance's brand.git_url: '${instance_setting}'" \
"differs from local clone's remote URL: ${remote_url}"
fi
instance_setting="$(prompt_installation_setting brand.git_branch)"
if ! [ "$instance_setting" = "$branch" ]; then
warn_msg "instance brand.git_branch: ${instance_setting}" \
"differs from local clone's branch: ${branch}"
fi
return 42 return 42
;; ;;
esac esac
@ -447,6 +467,35 @@ verify_continue_install(){
fi fi
} }
prompt_installation_setting(){
# usage: prompt_installation_setting brand.git_url
#
# Prompts the value of the (YAML) setting in the SearXNG instance.
local _state
_state="$(install_searx_get_state)"
case $_state in
python-installed|installer-modified)
sudo -H -u "${SERVICE_USER}" "${SEARX_PYENV}/bin/python" <<EOF
import sys
from searx import get_setting
name = "${1}"
unset = object()
value = get_setting(name, unset)
if value is unset:
sys.stderr.write("error: setting '%s' does not exists\n" % name)
sys.exit(42)
print(value)
sys.exit(0)
EOF
;;
*)
return 42
;;
esac
}
init_SEARX_SRC(){ init_SEARX_SRC(){
rst_title "Update instance: ${SEARX_SRC}/" section rst_title "Update instance: ${SEARX_SRC}/" section