on master help sign in
searx.sh: install settings at /etc/searx/settings.yml

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit59e4026762a809fe2a5b5a5a949d7d671f4d989b authorMarkus Heiser <markus.heiser@darmarit.de> dateMon 17 Feb 2020, 18:58 (7 years ago) parentde58f02
5 files changed+84−64
.config.mk+3−3 Makefile+5 utils/filtron.sh+2 utils/searx.sh+71−61 utils/templates/etc/uwsgi/apps-available/searx.ini+3
.config.mk+3−3
@@ -6,8 +6,8 @@
66# Compare your settings here with file .config.sh used by the toolboxing in
77# utils.
88
9−export SEARX_URL=https://searx.me
9+export SEARX_URL:=$(or ${SEARX_URL},https://searx.me)
1010
11−export GIT_URL=https://github.com/asciimoo/searx
12−export DOCS_URL=https://asciimoo.github.io/searx
11+export DOCS_URL:=$(or ${DOCS_URL},https://asciimoo.github.io/searx)
12+export GIT_URL:=$(or ${GIT_URL},https://github.com/asciimoo/searx)
1313
Makefile+5
@@ -26,6 +26,11 @@ help:
2626 @echo ' gh-pages - build docs & deploy on gh-pages branch'
2727 @echo ' clean - drop builds and environments'
2828 @echo ''
29+ @echo 'environment'
30+ @echo ' SEARX_URL = $(SEARX_URL)'
31+ @echo ' GIT_URL = $(GIT_URL)'
32+ @echo ' DOCS_URL = $(DOCS_URL)'
33+ @echo ''
2934 @$(MAKE) -s -f utils/makefile.include make-help
3035 @echo ''
3136 @$(MAKE) -s -f utils/makefile.python python-help
utils/filtron.sh+2
@@ -87,6 +87,8 @@ apache : ${PUBLIC_URL}
8787 :install: apache site with a reverse proxy (ProxyPass)
8888 :remove: apache site ${APACHE_FILTRON_SITE}
8989
90+filtron rules: ${FILTRON_RULES}
91+
9092If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
9193
9294 PUBLIC_URL : ${PUBLIC_URL}
utils/searx.sh+71−61
@@ -30,7 +30,7 @@ SEARX_GIT_URL="${SEARX_GIT_URL:-https://github.com/asciimoo/searx.git}"
3030SEARX_GIT_BRANCH="${SEARX_GIT_BRANCH:-master}"
3131SEARX_PYENV="${SERVICE_HOME}/searx-pyenv"
3232SEARX_SRC="${SERVICE_HOME}/searx-src"
33−SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
33+SEARX_SETTINGS_PATH="/etc/searx/settings.yml"
3434SEARX_UWSGI_APP="searx.ini"
3535# shellcheck disable=SC2034
3636SEARX_UWSGI_SOCKET="/run/uwsgi/app/searx/socket"
@@ -59,7 +59,7 @@ CONFIG_FILES=(
5959
6060# shellcheck disable=SC2034
6161CONFIG_BACKUP_ENCRYPTED=(
62− "${SEARX_SETTINGS}"
62+ "${SEARX_SETTINGS_PATH}"
6363)
6464
6565# ----------------------------------------------------------------------------
@@ -88,6 +88,7 @@ install / remove
8888 :user: add/remove service user '$SERVICE_USER' ($SERVICE_HOME)
8989 :searx-src: clone $SEARX_GIT_URL
9090 :pyenv: create/remove virtualenv (python) in $SEARX_PYENV
91+ :settings: reinstall settings from ${REPO_ROOT}/searx/settings.yml
9192update searx
9293 Update searx installation ($SERVICE_HOME)
9394activate service
@@ -102,6 +103,8 @@ apache
102103 :install: apache site with the searx uwsgi app
103104 :remove: apache site ${APACHE_FILTRON_SITE}
104105
106+searx settings: ${SEARX_SETTINGS_PATH}
107+
105108If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
106109
107110 PUBLIC_URL : ${PUBLIC_URL}
@@ -145,6 +148,7 @@ main() {
145148 user) assert_user ;;
146149 pyenv) create_pyenv ;;
147150 searx-src) clone_searx ;;
151+ settings) install_settings ;;
148152 *) usage "$_usage"; exit 42;;
149153 esac ;;
150154 update)
@@ -206,7 +210,7 @@ install_all() {
206210 wait_key
207211 create_pyenv
208212 wait_key
209− configure_searx
213+ install_settings
210214 wait_key
211215 test_local_searx
212216 wait_key
@@ -217,7 +221,6 @@ install_all() {
217221 if ask_yn "Do you want to inspect the installation?" Yn; then
218222 inspect_service
219223 fi
220−
221224}
222225
223226update_searx() {
@@ -226,45 +229,11 @@ update_searx() {
226229 echo
227230 tee_stderr 0.3 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
228231cd ${SEARX_SRC}
229−cp -f ${SEARX_SETTINGS} ${SEARX_SETTINGS}.backup
230−git stash push -m "BACKUP -- 'update server' at ($(date))"
231232git checkout -B "$SEARX_GIT_BRANCH"
232233git pull
233−cd ${SEARX_SRC}
234234${SEARX_SRC}/manage.sh update_packages
235235EOF
236− configure_searx
237−
238− rst_title "${SEARX_SETTINGS}" section
239− rst_para 'Diff between new setting file (<) and backup (>):'
240− echo
241− $DIFF_CMD "${SEARX_SETTINGS}" "${SEARX_SETTINGS}.backup"
242−
243− local action
244− choose_one action "What should happen to the settings file? " \
245− "keep new configuration" \
246− "revert to the old configuration (backup file)" \
247− "start interactiv shell"
248− case $action in
249− "keep new configuration")
250− info_msg "continue using new settings file"
251− ;;
252− "revert to the old configuration (backup file)")
253− tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
254−cp -f ${SEARX_SETTINGS}.backup ${SEARX_SETTINGS}
255−EOF
256− ;;
257− "start interactiv shell")
258− interactive_shell "${SERVICE_USER}"
259− ;;
260− esac
261− chown "${SERVICE_USER}:${SERVICE_USER}" "${SEARX_SETTINGS}"
262−
263− # shellcheck disable=SC2016
264− rst_para 'Diff between local modified settings (<) and $SEARX_GIT_BRANCH branch (>):'
265− echo
266− git_diff
267− wait_key
236+ install_settings
268237 uWSGI_restart
269238}
270239
@@ -279,8 +248,9 @@ installations that were installed with this script."
279248 return
280249 fi
281250 remove_searx_uwsgi
282− wait_key
283251 drop_service_account "${SERVICE_USER}"
252+ remove_settings
253+ wait_key
284254 if service_is_available "${PUBLIC_URL}"; then
285255 MSG="** Don't forgett to remove your public site! (${PUBLIC_URL}) **" wait_key 10
286256 fi
@@ -301,7 +271,7 @@ EOF
301271}
302272
303273clone_is_available() {
304− [[ -f "$SEARX_SETTINGS" ]]
274+ [[ -f "$SEARX_SRC/.git/config" ]]
305275}
306276
307277# shellcheck disable=SC2164
@@ -314,13 +284,13 @@ clone_searx() {
314284 return 42
315285 fi
316286 export SERVICE_HOME
317−
318− git_clone "$SEARX_GIT_URL" "$SEARX_SRC" \
287+ git_clone "$REPO_ROOT" "$SEARX_SRC" \
319288 "$SEARX_GIT_BRANCH" "$SERVICE_USER"
320289
321290 pushd "${SEARX_SRC}" > /dev/null
322291 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
323292cd "${SEARX_SRC}"
293+git remote set-url origin ${SEARX_GIT_URL}
324294git config user.email "$ADMIN_EMAIL"
325295git config user.name "$ADMIN_NAME"
326296git config --list
@@ -328,6 +298,52 @@ EOF
328298 popd > /dev/null
329299}
330300
301+install_settings() {
302+ rst_title "${SEARX_SETTINGS_PATH}" section
303+ if ! clone_is_available; then
304+ err_msg "you have to install searx first"
305+ exit 42
306+ fi
307+ mkdir -p "$(dirname ${SEARX_SETTINGS_PATH})"
308+
309+ if [[ ! -f ${SEARX_SETTINGS_PATH} ]]; then
310+ info_msg "install settings ${REPO_ROOT}/searx/settings.yml"
311+ info_msg " --> ${SEARX_SETTINGS_PATH}"
312+ cp "${REPO_ROOT}/searx/settings.yml" "${SEARX_SETTINGS_PATH}"
313+ configure_searx
314+ return
315+ fi
316+
317+ rst_para "Diff between origin's setting file (-) and current (+):"
318+ echo
319+ $DIFF_CMD "${SEARX_SRC}/searx/settings.yml" "${SEARX_SETTINGS_PATH}"
320+
321+ local action
322+ choose_one action "What should happen to the settings file? " \
323+ "keep new configuration" \
324+ "start interactiv shell"
325+ case $action in
326+ "keep new configuration")
327+ info_msg "continue using new settings file"
328+ ;;
329+ "start interactiv shell")
330+ echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
331+ sudo -H -i
332+ rst_para 'Diff between new setting file (-) and current (+):'
333+ echo
334+ $DIFF_CMD "${SEARX_SRC}/searx/settings.yml" "${SEARX_SETTINGS_PATH}"
335+ wait_key
336+ ;;
337+ esac
338+}
339+
340+remove_settings() {
341+ rst_title "remove searx settings" section
342+ echo
343+ info_msg "delete ${SEARX_SETTINGS_PATH}"
344+ rm -f "${SEARX_SETTINGS_PATH}"
345+}
346+
331347remove_searx() {
332348 rst_title "Drop searx sources" section
333349 if ask_yn "Do you really want to drop searx sources ($SEARX_SRC)?"; then
@@ -381,12 +397,12 @@ EOF
381397
382398configure_searx() {
383399 rst_title "Configure searx" section
384− rst_para "Setup searx config located at $SEARX_SETTINGS"
400+ rst_para "Setup searx config located at $SEARX_SETTINGS_PATH"
385401 echo
386− tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
402+ tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
387403cd ${SEARX_SRC}
388−sed -i -e "s/ultrasecretkey/$(openssl rand -hex 16)/g" "$SEARX_SETTINGS"
389−sed -i -e "s/{instance_name}/${SEARX_INSTANCE_NAME}/g" "$SEARX_SETTINGS"
404+sed -i -e "s/ultrasecretkey/$(openssl rand -hex 16)/g" "$SEARX_SETTINGS_PATH"
405+sed -i -e "s/{instance_name}/${SEARX_INSTANCE_NAME}/g" "$SEARX_SETTINGS_PATH"
390406EOF
391407}
392408
@@ -401,14 +417,15 @@ test_local_searx() {
401417 return
402418 fi
403419 fi
420+ sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS_PATH"
404421 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
422+export SEARX_SETTINGS_PATH="${SEARX_SETTINGS_PATH}"
405423cd ${SEARX_SRC}
406−sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS"
407424timeout 10 python3 searx/webapp.py &
408425sleep 3
409426curl --location --verbose --head --insecure $SEARX_INTERNAL_URL
410−sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
411427EOF
428+ sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS_PATH"
412429}
413430
414431install_searx_uwsgi() {
@@ -437,28 +454,21 @@ deactivate_service() {
437454 uWSGI_restart
438455}
439456
440−git_diff() {
441− sudo -H -u "${SERVICE_USER}" -i <<EOF
442−cd ${SEARX_SRC}
443−git --no-pager diff
444−EOF
445−}
446−
447457enable_debug() {
448458 warn_msg "Do not enable debug in production enviroments!!"
449459 info_msg "try to enable debug mode ..."
450− tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
460+ tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
451461cd ${SEARX_SRC}
452−sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS"
462+sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS_PATH"
453463EOF
454464 uWSGI_restart
455465}
456466
457467disable_debug() {
458468 info_msg "try to disable debug mode ..."
459− tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
469+ tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
460470cd ${SEARX_SRC}
461−sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
471+sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS_PATH"
462472EOF
463473 uWSGI_restart
464474}
@@ -513,7 +523,7 @@ EOF
513523 fi
514524
515525 if ! service_is_available "${PUBLIC_URL}"; then
516− err_msg "Public service at ${PUBLIC_URL} is not available!"
526+ warn_msg "Public service at ${PUBLIC_URL} is not available!"
517527 fi
518528
519529 local _debug_on
utils/templates/etc/uwsgi/apps-available/searx.ini+3
@@ -12,6 +12,9 @@ gid = ${SERVICE_GROUP}
1212# chdir to specified directory before apps loading
1313chdir = ${SEARX_SRC}/searx
1414
15+# searx configuration (settings.yml)
16+env = SEARX_SETTINGS_PATH=${SEARX_SETTINGS_PATH}
17+
1518# disable logging for privacy
1619disable-logging = true
1720