searx.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. #!/usr/bin/env bash
  2. # -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. # shellcheck disable=SC2001
  5. # shellcheck source=utils/lib.sh
  6. source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
  7. source_dot_config
  8. source "${REPO_ROOT}/utils/lxc.env"
  9. # ----------------------------------------------------------------------------
  10. # config
  11. # ----------------------------------------------------------------------------
  12. SEARX_INTERNAL_URL="${SEARX_INTERNAL_URL:-127.0.0.1:8888}"
  13. SEARX_URL_PATH="${SEARX_URL_PATH:-$(echo "${PUBLIC_URL}" \
  14. | sed -e 's,^.*://[^/]*\(/.*\),\1,g')}"
  15. [[ "${SEARX_URL_PATH}" == "${PUBLIC_URL}" ]] && SEARX_URL_PATH=/
  16. SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(echo "$PUBLIC_URL" \
  17. | sed -e 's,^.*://\([^\:/]*\).*,\1,g') }"
  18. SERVICE_NAME="searx"
  19. SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
  20. SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"
  21. SERVICE_HOME="${SERVICE_HOME_BASE}/${SERVICE_USER}"
  22. # shellcheck disable=SC2034
  23. SERVICE_GROUP="${SERVICE_USER}"
  24. SEARX_GIT_URL="${SEARX_GIT_URL:-https://github.com/asciimoo/searx.git}"
  25. SEARX_GIT_BRANCH="${SEARX_GIT_BRANCH:-master}"
  26. SEARX_PYENV="${SERVICE_HOME}/searx-pyenv"
  27. SEARX_SRC="${SERVICE_HOME}/searx-src"
  28. SEARX_SETTINGS_PATH="/etc/searx/settings.yml"
  29. SEARX_UWSGI_APP="searx.ini"
  30. # shellcheck disable=SC2034
  31. SEARX_UWSGI_SOCKET="/run/uwsgi/app/searx/socket"
  32. # apt packages
  33. SEARX_PACKAGES_debian="\
  34. python3-dev python3-babel python3-venv
  35. uwsgi uwsgi-plugin-python3
  36. git build-essential libxslt-dev zlib1g-dev libffi-dev libssl-dev"
  37. # pacman packages
  38. SEARX_PACKAGES_arch="\
  39. python python-pip python-lxml python-babel
  40. uwsgi uwsgi-plugin-python
  41. git base-devel libxml2"
  42. # dnf packages
  43. SEARX_PACKAGES_fedora="\
  44. python python-pip python-lxml python-babel
  45. uwsgi uwsgi-plugin-python3
  46. git @development-tools libxml2"
  47. case $DIST_ID in
  48. ubuntu|debian) SEARX_PACKAGES="${SEARX_PACKAGES_debian}" ;;
  49. arch) SEARX_PACKAGES="${SEARX_PACKAGES_arch}" ;;
  50. fedora) SEARX_PACKAGES="${SEARX_PACKAGES_fedora}" ;;
  51. esac
  52. # Apache Settings
  53. APACHE_APT_PACKAGES="\
  54. libapache2-mod-uwsgi \
  55. "
  56. APACHE_SEARX_SITE="searx.conf"
  57. # shellcheck disable=SC2034
  58. CONFIG_FILES=(
  59. "${uWSGI_APPS_AVAILABLE}/${SEARX_UWSGI_APP}"
  60. )
  61. # shellcheck disable=SC2034
  62. CONFIG_BACKUP_ENCRYPTED=(
  63. "${SEARX_SETTINGS_PATH}"
  64. )
  65. # ----------------------------------------------------------------------------
  66. usage() {
  67. # ----------------------------------------------------------------------------
  68. # shellcheck disable=SC1117
  69. cat <<EOF
  70. usage::
  71. $(basename "$0") shell
  72. $(basename "$0") install [all|user|searx-src|pyenv|apache]
  73. $(basename "$0") update [searx]
  74. $(basename "$0") remove [all|user|pyenv|searx-src]
  75. $(basename "$0") activate [service]
  76. $(basename "$0") deactivate [service]
  77. $(basename "$0") inspect [service]
  78. $(basename "$0") option [debug-on|debug-off]
  79. $(basename "$0") apache [install|remove]
  80. shell
  81. start interactive shell from user ${SERVICE_USER}
  82. install / remove
  83. :all: complete (de-) installation of searx service
  84. :user: add/remove service user '$SERVICE_USER' ($SERVICE_HOME)
  85. :searx-src: clone $SEARX_GIT_URL
  86. :pyenv: create/remove virtualenv (python) in $SEARX_PYENV
  87. :settings: reinstall settings from ${REPO_ROOT}/searx/settings.yml
  88. update searx
  89. Update searx installation ($SERVICE_HOME)
  90. activate service
  91. activate and start service daemon (systemd unit)
  92. deactivate service
  93. stop and deactivate service daemon (systemd unit)
  94. inspect service
  95. run some small tests and inspect service's status and log
  96. option
  97. set one of the available options
  98. apache
  99. :install: apache site with the searx uwsgi app
  100. :remove: apache site ${APACHE_FILTRON_SITE}
  101. searx settings: ${SEARX_SETTINGS_PATH}
  102. If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
  103. PUBLIC_URL : ${PUBLIC_URL}
  104. PUBLIC_HOST : ${PUBLIC_HOST}
  105. SEARX_INSTANCE_NAME : ${SEARX_INSTANCE_NAME}
  106. SERVICE_USER : ${SERVICE_USER}
  107. EOF
  108. [[ -n ${1} ]] && err_msg "$1"
  109. }
  110. main() {
  111. rst_title "$SEARX_INSTANCE_NAME" part
  112. required_commands \
  113. sudo systemctl install git wget curl \
  114. || exit
  115. local _usage="unknown or missing $1 command $2"
  116. case $1 in
  117. --source-only) ;;
  118. -h|--help) usage; exit 0;;
  119. shell)
  120. sudo_or_exit
  121. interactive_shell "${SERVICE_USER}"
  122. ;;
  123. inspect)
  124. case $2 in
  125. service)
  126. sudo_or_exit
  127. inspect_service
  128. ;;
  129. *) usage "$_usage"; exit 42;;
  130. esac ;;
  131. install)
  132. sudo_or_exit
  133. case $2 in
  134. all) install_all ;;
  135. user) assert_user ;;
  136. pyenv) create_pyenv ;;
  137. searx-src) clone_searx ;;
  138. settings) install_settings ;;
  139. *) usage "$_usage"; exit 42;;
  140. esac ;;
  141. update)
  142. sudo_or_exit
  143. case $2 in
  144. searx) update_searx;;
  145. *) usage "$_usage"; exit 42;;
  146. esac ;;
  147. remove)
  148. sudo_or_exit
  149. case $2 in
  150. all) remove_all;;
  151. user) drop_service_account "${SERVICE_USER}";;
  152. pyenv) remove_pyenv ;;
  153. searx-src) remove_searx ;;
  154. *) usage "$_usage"; exit 42;;
  155. esac ;;
  156. activate)
  157. sudo_or_exit
  158. case $2 in
  159. service)
  160. activate_service ;;
  161. *) usage "$_usage"; exit 42;;
  162. esac ;;
  163. deactivate)
  164. sudo_or_exit
  165. case $2 in
  166. service) deactivate_service ;;
  167. *) usage "$_usage"; exit 42;;
  168. esac ;;
  169. option)
  170. sudo_or_exit
  171. case $2 in
  172. debug-on) echo; enable_debug ;;
  173. debug-off) echo; disable_debug ;;
  174. *) usage "$_usage"; exit 42;;
  175. esac ;;
  176. apache)
  177. sudo_or_exit
  178. case $2 in
  179. install) install_apache_site ;;
  180. remove) remove_apache_site ;;
  181. *) usage "$_usage"; exit 42;;
  182. esac ;;
  183. doc) rst-doc;;
  184. *) usage "unknown or missing command $1"; exit 42;;
  185. esac
  186. }
  187. _service_prefix=" ${_Yellow}|$SERVICE_USER|${_creset} "
  188. install_all() {
  189. rst_title "Install $SEARX_INSTANCE_NAME (service)"
  190. pkg_install "$SEARX_PACKAGES"
  191. wait_key
  192. assert_user
  193. wait_key
  194. clone_searx
  195. wait_key
  196. create_pyenv
  197. wait_key
  198. install_settings
  199. wait_key
  200. test_local_searx
  201. wait_key
  202. install_searx_uwsgi
  203. if ! service_is_available "http://$SEARX_INTERNAL_URL"; then
  204. err_msg "URL http://$SEARX_INTERNAL_URL not available, check searx & uwsgi setup!"
  205. fi
  206. if ask_yn "Do you want to inspect the installation?" Ny; then
  207. inspect_service
  208. fi
  209. }
  210. update_searx() {
  211. rst_title "Update searx instance"
  212. echo
  213. tee_stderr 0.3 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
  214. cd ${SEARX_SRC}
  215. git checkout -B "$SEARX_GIT_BRANCH"
  216. git pull
  217. ${SEARX_SRC}/manage.sh update_packages
  218. EOF
  219. install_settings
  220. uWSGI_restart "$SEARX_UWSGI_APP"
  221. }
  222. remove_all() {
  223. rst_title "De-Install $SEARX_INSTANCE_NAME (service)"
  224. rst_para "\
  225. It goes without saying that this script can only be used to remove
  226. installations that were installed with this script."
  227. if ! ask_yn "Do you really want to deinstall $SEARX_INSTANCE_NAME?"; then
  228. return
  229. fi
  230. remove_searx_uwsgi
  231. drop_service_account "${SERVICE_USER}"
  232. remove_settings
  233. wait_key
  234. if service_is_available "${PUBLIC_URL}"; then
  235. MSG="** Don't forgett to remove your public site! (${PUBLIC_URL}) **" wait_key 10
  236. fi
  237. }
  238. assert_user() {
  239. rst_title "user $SERVICE_USER" section
  240. echo
  241. tee_stderr 1 <<EOF | bash | prefix_stdout
  242. useradd --shell /bin/bash --system \
  243. --home-dir "$SERVICE_HOME" \
  244. --comment 'Privacy-respecting metasearch engine' $SERVICE_USER
  245. mkdir "$SERVICE_HOME"
  246. chown -R "$SERVICE_GROUP:$SERVICE_GROUP" "$SERVICE_HOME"
  247. groups $SERVICE_USER
  248. EOF
  249. #SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME)"
  250. #export SERVICE_HOME
  251. #echo "export SERVICE_HOME=$SERVICE_HOME"
  252. }
  253. clone_is_available() {
  254. [[ -f "$SEARX_SRC/.git/config" ]]
  255. }
  256. # shellcheck disable=SC2164
  257. clone_searx() {
  258. rst_title "Clone searx sources" section
  259. echo
  260. SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME 2>/dev/null)"
  261. if [[ ! "${SERVICE_HOME}" ]]; then
  262. err_msg "to clone searx sources, user $SERVICE_USER hast to be created first"
  263. return 42
  264. fi
  265. export SERVICE_HOME
  266. git_clone "$REPO_ROOT" "$SEARX_SRC" \
  267. "$SEARX_GIT_BRANCH" "$SERVICE_USER"
  268. pushd "${SEARX_SRC}" > /dev/null
  269. tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
  270. cd "${SEARX_SRC}"
  271. git remote set-url origin ${SEARX_GIT_URL}
  272. git config user.email "$ADMIN_EMAIL"
  273. git config user.name "$ADMIN_NAME"
  274. git config --list
  275. EOF
  276. popd > /dev/null
  277. }
  278. install_settings() {
  279. rst_title "${SEARX_SETTINGS_PATH}" section
  280. if ! clone_is_available; then
  281. err_msg "you have to install searx first"
  282. exit 42
  283. fi
  284. mkdir -p "$(dirname ${SEARX_SETTINGS_PATH})"
  285. if [[ ! -f ${SEARX_SETTINGS_PATH} ]]; then
  286. info_msg "install settings ${REPO_ROOT}/searx/settings.yml"
  287. info_msg " --> ${SEARX_SETTINGS_PATH}"
  288. cp "${REPO_ROOT}/searx/settings.yml" "${SEARX_SETTINGS_PATH}"
  289. configure_searx
  290. return
  291. fi
  292. rst_para "Diff between origin's setting file (+) and current (-):"
  293. echo
  294. $DIFF_CMD "${SEARX_SETTINGS_PATH}" "${SEARX_SRC}/searx/settings.yml"
  295. local action
  296. choose_one action "What should happen to the settings file? " \
  297. "keep configuration unchanged" \
  298. "use origin settings" \
  299. "start interactiv shell"
  300. case $action in
  301. "keep configuration unchanged")
  302. info_msg "leave settings file unchanged"
  303. ;;
  304. "use origin settings")
  305. backup_file "${SEARX_SETTINGS_PATH}"
  306. info_msg "install origin settings"
  307. cp "${SEARX_SRC}/searx/settings.yml" "${SEARX_SETTINGS_PATH}"
  308. ;;
  309. "start interactiv shell")
  310. backup_file "${SEARX_SETTINGS_PATH}"
  311. echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
  312. sudo -H -i
  313. rst_para 'Diff between new setting file (-) and current (+):'
  314. echo
  315. $DIFF_CMD "${SEARX_SRC}/searx/settings.yml" "${SEARX_SETTINGS_PATH}"
  316. wait_key
  317. ;;
  318. esac
  319. }
  320. remove_settings() {
  321. rst_title "remove searx settings" section
  322. echo
  323. info_msg "delete ${SEARX_SETTINGS_PATH}"
  324. rm -f "${SEARX_SETTINGS_PATH}"
  325. }
  326. remove_searx() {
  327. rst_title "Drop searx sources" section
  328. if ask_yn "Do you really want to drop searx sources ($SEARX_SRC)?"; then
  329. rm -rf "$SEARX_SRC"
  330. else
  331. rst_para "Leave searx sources unchanged."
  332. fi
  333. }
  334. pyenv_is_available() {
  335. [[ -f "${SEARX_PYENV}/bin/activate" ]]
  336. }
  337. create_pyenv() {
  338. rst_title "Create virtualenv (python)" section
  339. echo
  340. if [[ ! -f "${SEARX_SRC}/manage.sh" ]]; then
  341. err_msg "to create pyenv for searx, searx has to be cloned first"
  342. return 42
  343. fi
  344. info_msg "create pyenv in ${SEARX_PYENV}"
  345. tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
  346. rm -rf "${SEARX_PYENV}"
  347. python3 -m venv "${SEARX_PYENV}"
  348. grep -qFs -- 'source ${SEARX_PYENV}/bin/activate' ~/.profile \
  349. || echo 'source ${SEARX_PYENV}/bin/activate' >> ~/.profile
  350. EOF
  351. info_msg "inspect python's virtual environment"
  352. tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
  353. command -v python && python --version
  354. EOF
  355. wait_key
  356. info_msg "install needed python packages"
  357. tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
  358. ${SEARX_SRC}/manage.sh update_packages
  359. EOF
  360. }
  361. remove_pyenv() {
  362. rst_title "Remove virtualenv (python)" section
  363. if ! ask_yn "Do you really want to drop ${SEARX_PYENV} ?"; then
  364. return
  365. fi
  366. info_msg "remove pyenv activation from ~/.profile"
  367. tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
  368. grep -v 'source ${SEARX_PYENV}/bin/activate' ~/.profile > ~/.profile.##
  369. mv ~/.profile.## ~/.profile
  370. EOF
  371. rm -rf "${SEARX_PYENV}"
  372. }
  373. configure_searx() {
  374. rst_title "Configure searx" section
  375. rst_para "Setup searx config located at $SEARX_SETTINGS_PATH"
  376. echo
  377. tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
  378. cd ${SEARX_SRC}
  379. sed -i -e "s/ultrasecretkey/$(openssl rand -hex 16)/g" "$SEARX_SETTINGS_PATH"
  380. sed -i -e "s/{instance_name}/${SEARX_INSTANCE_NAME}/g" "$SEARX_SETTINGS_PATH"
  381. EOF
  382. }
  383. test_local_searx() {
  384. rst_title "Testing searx instance localy" section
  385. echo
  386. if service_is_available "http://$SEARX_INTERNAL_URL" &>/dev/null; then
  387. err_msg "URL/port http://$SEARX_INTERNAL_URL is already in use, you"
  388. err_msg "should stop that service before starting local tests!"
  389. if ! ask_yn "Continue with local tests?"; then
  390. return
  391. fi
  392. fi
  393. sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS_PATH"
  394. tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
  395. export SEARX_SETTINGS_PATH="${SEARX_SETTINGS_PATH}"
  396. cd ${SEARX_SRC}
  397. timeout 10 python searx/webapp.py &
  398. sleep 3
  399. curl --location --verbose --head --insecure $SEARX_INTERNAL_URL
  400. EOF
  401. sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS_PATH"
  402. }
  403. install_searx_uwsgi() {
  404. rst_title "Install searx's uWSGI app (searx.ini)" section
  405. echo
  406. uWSGI_install_app "$SEARX_UWSGI_APP"
  407. }
  408. remove_searx_uwsgi() {
  409. rst_title "Remove searx's uWSGI app (searx.ini)" section
  410. echo
  411. uWSGI_remove_app "$SEARX_UWSGI_APP"
  412. }
  413. activate_service() {
  414. rst_title "Activate $SEARX_INSTANCE_NAME (service)" section
  415. echo
  416. uWSGI_enable_app "$SEARX_UWSGI_APP"
  417. uWSGI_restart "$SEARX_UWSGI_APP"
  418. }
  419. deactivate_service() {
  420. rst_title "De-Activate $SEARX_INSTANCE_NAME (service)" section
  421. echo
  422. uWSGI_disable_app "$SEARX_UWSGI_APP"
  423. uWSGI_restart "$SEARX_UWSGI_APP"
  424. }
  425. enable_debug() {
  426. warn_msg "Do not enable debug in production enviroments!!"
  427. info_msg "try to enable debug mode ..."
  428. tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
  429. cd ${SEARX_SRC}
  430. sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS_PATH"
  431. EOF
  432. uWSGI_restart "$SEARX_UWSGI_APP"
  433. }
  434. disable_debug() {
  435. info_msg "try to disable debug mode ..."
  436. tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
  437. cd ${SEARX_SRC}
  438. sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS_PATH"
  439. EOF
  440. uWSGI_restart "$SEARX_UWSGI_APP"
  441. }
  442. inspect_service() {
  443. rst_title "service status & log"
  444. cat <<EOF
  445. sourced ${DOT_CONFIG#"$REPO_ROOT/"} :
  446. PUBLIC_URL : ${PUBLIC_URL}
  447. PUBLIC_HOST : ${PUBLIC_HOST}
  448. SEARX_URL_PATH : ${SEARX_URL_PATH}
  449. SEARX_INSTANCE_NAME : ${SEARX_INSTANCE_NAME}
  450. SEARX_INTERNAL_URL : ${SEARX_INTERNAL_URL}
  451. EOF
  452. apache_is_installed && info_msg "Apache is installed."
  453. if service_account_is_available "$SERVICE_USER"; then
  454. info_msg "Service account $SERVICE_USER exists."
  455. else
  456. err_msg "Service account $SERVICE_USER does not exists!"
  457. fi
  458. if pyenv_is_available; then
  459. info_msg "~$SERVICE_USER: python environment is available."
  460. else
  461. err_msg "~$SERVICE_USER: python environment is not available!"
  462. fi
  463. if clone_is_available; then
  464. info_msg "~$SERVICE_USER: Searx software is installed."
  465. else
  466. err_msg "~$SERVICE_USER: Missing searx software!"
  467. fi
  468. if uWSGI_app_enabled "$SEARX_UWSGI_APP"; then
  469. info_msg "uWSGI app $SEARX_UWSGI_APP is enabled."
  470. else
  471. err_msg "uWSGI app $SEARX_UWSGI_APP not enabled!"
  472. fi
  473. uWSGI_app_available "$SEARX_UWSGI_APP" \
  474. || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
  475. if is_container; then
  476. warn_msg "runnning inside container ..."
  477. for ip in $(hostname -I); do
  478. if [[ $ip =~ .*:.* ]]; then
  479. info_msg " public HTTP service (IPv6) --> http://[$ip]"
  480. else
  481. info_msg " public HTTP service (IPv4) --> http://$ip"
  482. fi
  483. done
  484. warn_msg "SEARX_INTERNAL_URL not available from outside"
  485. fi
  486. if ! service_is_available "http://${SEARX_INTERNAL_URL}"; then
  487. err_msg "uWSGI app (service) at http://${SEARX_INTERNAL_URL} is not available!"
  488. echo -e "${_Green}stop with [${_BCyan}CTRL-C${_Green}] or .."
  489. wait_key
  490. fi
  491. if ! service_is_available "${PUBLIC_URL}"; then
  492. warn_msg "Public service at ${PUBLIC_URL} is not available!"
  493. if is_container; then
  494. warn_msg "Check if public name is correct and routed or use the public IP from above."
  495. fi
  496. fi
  497. local _debug_on
  498. if ask_yn "Enable searx debug mode?"; then
  499. enable_debug
  500. _debug_on=1
  501. fi
  502. echo
  503. systemctl --no-pager -l status "${SERVICE_NAME}"
  504. echo
  505. info_msg "public URL --> ${PUBLIC_URL}"
  506. info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
  507. # shellcheck disable=SC2059
  508. printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
  509. read -r -s -n1 -t 2
  510. echo
  511. while true; do
  512. trap break 2
  513. #journalctl -f -u "${SERVICE_NAME}"
  514. tail -f /var/log/uwsgi/app/searx.log
  515. done
  516. if [[ $_debug_on == 1 ]]; then
  517. disable_debug
  518. fi
  519. return 0
  520. }
  521. install_apache_site() {
  522. rst_title "Install Apache site $APACHE_SEARX_SITE"
  523. rst_para "\
  524. This installs the searx uwsgi app as apache site. If your server ist public to
  525. the internet you should instead use a reverse proxy (filtron) to block
  526. excessively bot queries."
  527. ! apache_is_installed && err_msg "Apache is not installed."
  528. if ! ask_yn "Do you really want to install apache site for searx-uwsgi?"; then
  529. return
  530. fi
  531. pkg_install "$APACHE_APT_PACKAGES"
  532. a2enmod uwsgi
  533. echo
  534. apache_install_site --variant=uwsgi "${APACHE_SEARX_SITE}"
  535. if ! service_is_available "${PUBLIC_URL}"; then
  536. err_msg "Public service at ${PUBLIC_URL} is not available!"
  537. fi
  538. }
  539. remove_apache_site() {
  540. rst_title "Remove Apache site ${APACHE_SEARX_SITE}"
  541. rst_para "\
  542. This removes apache site ${APACHE_SEARX_SITE}."
  543. ! apache_is_installed && err_msg "Apache is not installed."
  544. if ! ask_yn "Do you really want to continue?"; then
  545. return
  546. fi
  547. apache_remove_site "${APACHE_SEARX_SITE}"
  548. }
  549. rst-doc() {
  550. local debian="${SEARX_PACKAGES_debian}"
  551. local arch="${SEARX_PACKAGES_arch}"
  552. local fedora="${SEARX_PACKAGES_fedora}"
  553. debian="$(echo "${debian}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
  554. arch="$(echo "${arch}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
  555. fedora="$(echo "${fedora}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
  556. eval "echo \"$(< ${REPO_ROOT}/docs/build-templates/searx.rst)\""
  557. # I use ubuntu-20.04 here to demonstrate that versions are also suported,
  558. # normaly debian-* and ubuntu-* are most the same.
  559. for DIST_NAME in ubuntu-20.04 arch fedora; do
  560. (
  561. DIST_ID=${DIST_NAME%-*}
  562. DIST_VERS=${DIST_NAME#*-}
  563. [[ $DIST_VERS =~ $DIST_ID ]] && DIST_VERS=
  564. uWSGI_distro_setup
  565. echo -e "\n.. START searx uwsgi-description $DIST_NAME"
  566. echo "location: ${uWSGI_APPS_ENABLED}/${SEARX_UWSGI_APP}"
  567. case $DIST_ID-$DIST_VERS in
  568. ubuntu-*|debian-*)
  569. echo "restart: sudo -H service uwsgi restart ${SEARX_UWSGI_APP%.*}" ;;
  570. arch-*)
  571. echo "restart: sudo -H systemctl restart uwsgi@${SEARX_UWSGI_APP%.*}" ;;
  572. fedora-*)
  573. echo "restart: sudo -H touch ${uWSGI_APPS_ENABLED}/${SEARX_UWSGI_APP}";;
  574. esac
  575. echo -e ".. END searx uwsgi-description $DIST_NAME"
  576. echo -e "\n.. START searx uwsgi-appini $DIST_NAME"
  577. eval "echo \"$(< ${TEMPLATES}/${uWSGI_APPS_AVAILABLE}/${SEARX_UWSGI_APP})\""
  578. echo -e "\n.. END searx uwsgi-appini $DIST_NAME"
  579. )
  580. done
  581. }
  582. # ----------------------------------------------------------------------------
  583. main "$@"
  584. # ----------------------------------------------------------------------------