searx.sh 23 KB

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