searx.sh 22 KB

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