searx.sh 22 KB

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