on master help sign in
utils/searx.sh: add cmd to (un)set option image_proxy and result_proxy

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

commitc748047e926ce6979ab07a8a3ed3d0cc96f534ba authorMarkus Heiser <markus.heiser@darmarit.de> dateSat 4 Apr 2020, 17:54 (7 years ago) parente530e20
1 file changed+74
utils/searx.sh+74
utils/searx.sh+74
@@ -238,6 +238,9 @@ main() {
238238 case $2 in
239239 debug-on) echo; enable_debug ;;
240240 debug-off) echo; disable_debug ;;
241+ result-proxy) set_result_proxy "$3" "$4" ;;
242+ image-proxy-on) enable_image_proxy ;;
243+ image-proxy-off) disable_image_proxy ;;
241244 *) usage "$_usage"; exit 42;;
242245 esac ;;
243246 apache)
@@ -522,6 +525,24 @@ deactivate_service() {
522525 uWSGI_restart "$SEARX_UWSGI_APP"
523526}
524527
528+enable_image_proxy() {
529+ info_msg "try to enable image_proxy ..."
530+ tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
531+cd ${SEARX_SRC}
532+sed -i -e "s/image_proxy : False/image_proxy : True/g" "$SEARX_SETTINGS_PATH"
533+EOF
534+ uWSGI_restart "$SEARX_UWSGI_APP"
535+}
536+
537+disable_image_proxy() {
538+ info_msg "try to enable image_proxy ..."
539+ tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
540+cd ${SEARX_SRC}
541+sed -i -e "s/image_proxy : True/image_proxy : False/g" "$SEARX_SETTINGS_PATH"
542+EOF
543+ uWSGI_restart "$SEARX_UWSGI_APP"
544+}
545+
525546enable_debug() {
526547 warn_msg "Do not enable debug in production enviroments!!"
527548 info_msg "try to enable debug mode ..."
@@ -541,6 +562,59 @@ EOF
541562 uWSGI_restart "$SEARX_UWSGI_APP"
542563}
543564
565+set_result_proxy() {
566+ info_msg "try to set result proxy ..."
567+ local line
568+ local stage=0
569+ local url=" url: $1"
570+ local key=" key: $2"
571+ if [[ -z $2 ]]; then
572+ key=
573+ fi
574+ cp "${SEARX_SETTINGS_PATH}" "${SEARX_SETTINGS_PATH}.bak"
575+ _set_result_proxy "$1" "$2" > "${SEARX_SETTINGS_PATH}"
576+}
577+
578+_set_result_proxy() {
579+ local line
580+ local stage=0
581+ local url=" url: $1"
582+ local key=" key: $2"
583+ if [[ -z $2 ]]; then
584+ key=
585+ fi
586+
587+ while IFS= read -r line
588+ do
589+ if [[ $stage = 0 ]] || [[ $stage = 2 ]] ; then
590+ if [[ $line =~ ^[[:space:]]*#*[[:space:]]*result_proxy[[:space:]]*:[[:space:]]*$ ]]; then
591+ if [[ $stage = 0 ]]; then
592+ stage=1
593+ echo "result_proxy:"
594+ continue
595+ elif [[ $stage = 2 ]]; then
596+ continue
597+ fi
598+ fi
599+ fi
600+ if [[ $stage = 1 ]] || [[ $stage = 2 ]] ; then
601+ if [[ $line =~ ^[[:space:]]*#*[[:space:]]*url[[:space:]]*:[[:space:]] ]]; then
602+ [[ $stage = 1 ]] && echo "$url"
603+ continue
604+ elif [[ $line =~ ^[[:space:]]*#*[[:space:]]*key[[:space:]]*:[[:space:]] ]]; then
605+ [[ $stage = 1 ]] && [[ -n $key ]] && echo "$key"
606+ continue
607+ elif [[ $line =~ ^[[:space:]]*$ ]]; then
608+ stage=2
609+ fi
610+ fi
611+ echo "$line"
612+ done < "${SEARX_SETTINGS_PATH}.bak"
613+}
614+
615+function has_substring() {
616+ [[ "$1" != "${2/$1/}" ]]
617+}
544618inspect_service() {
545619 rst_title "service status & log"
546620 cat <<EOF