@@ -1,5 +1,5 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2−# -*- coding: utf-8; mode: sh -*-
2+# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
3# shellcheck disable=SC2119
3# shellcheck disable=SC2119
5# shellcheck source=utils/lib.sh
5# shellcheck source=utils/lib.sh
@@ -15,8 +15,11 @@ SERVICE_USER="${SERVICE_NAME}"
15SERVICE_GROUP="${SERVICE_USER}"
15SERVICE_GROUP="${SERVICE_USER}"
16SERVICE_HOME="/home/${SERVICE_USER}"
16SERVICE_HOME="/home/${SERVICE_USER}"
18+# shellcheck disable=SC2034
19+SEARX_URL="127.0.0.1:8888"
18SEARX_GIT_URL="https://github.com/asciimoo/searx.git"
21SEARX_GIT_URL="https://github.com/asciimoo/searx.git"
19−SEARX_GIT_BRANCH="origin/master"
22+SEARX_GIT_BRANCH="master"
21# FIXME: Arch Linux & RHEL should be added
24# FIXME: Arch Linux & RHEL should be added
@@ -25,8 +28,8 @@ libapache2-mod-uwsgi uwsgi uwsgi-plugin-python3 \
25 git build-essential libxslt-dev python3-dev python3-babel zlib1g-dev \
28 git build-essential libxslt-dev python3-dev python3-babel zlib1g-dev \
26 libffi-dev libssl-dev"
29 libffi-dev libssl-dev"
28−SEARX_VENV="${SEARX_HOME}/searx-venv"
31+SEARX_PYENV="${SERVICE_HOME}/searx-pyenv"
29−SEARX_SRC="${SEARX_HOME}/searx-src"
32+SEARX_SRC="${SERVICE_HOME}/searx-src"
30SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
33SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
31SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(uname -n)}"
34SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(uname -n)}"
32SEARX_UWSGI_APP="${uWSGI_SETUP}/apps-available/searx.ini"
35SEARX_UWSGI_APP="${uWSGI_SETUP}/apps-available/searx.ini"
@@ -51,25 +54,26 @@ usage(){
53 $(basename "$0") shell
56 $(basename "$0") shell
54− $(basename "$0") install [all|user]
57+ $(basename "$0") install [all|user|pyenv|searx-src]
55 $(basename "$0") update [searx]
58 $(basename "$0") update [searx]
56− $(basename "$0") remove [all]
59+ $(basename "$0") remove [all|user|pyenv|searx-src]
57 $(basename "$0") activate [service]
60 $(basename "$0") activate [service]
58 $(basename "$0") deactivate [service]
61 $(basename "$0") deactivate [service]
59 $(basename "$0") show [service]
62 $(basename "$0") show [service]
62 start interactive shell from user ${SERVICE_USER}
65 start interactive shell from user ${SERVICE_USER}
63−install / remove all
66+install / remove
64− complete setup of searx service
67+ all: complete (de-) installation of searx service
68+ user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
69+ searx-src: clone $SEARX_GIT_URL
70+ pyenv: create/remove virtualenv (python) in $SEARX_PYENV
65update searx
71update searx
66 Update searx installation of user ${SERVICE_USER}
72 Update searx installation of user ${SERVICE_USER}
68 activate and start service daemon (systemd unit)
74 activate and start service daemon (systemd unit)
69deactivate service
75deactivate service
70 stop and deactivate service daemon (systemd unit)
76 stop and deactivate service daemon (systemd unit)
72− add service user '$SERVICE_USER' at $SERVICE_HOME
73show service
77show service
74 show service status and log
78 show service status and log
@@ -102,6 +106,8 @@ main(){
102 case $2 in
106 case $2 in
103 all) install_all ;;
107 all) install_all ;;
104 user) assert_user ;;
108 user) assert_user ;;
109+ pyenv) create_pyenv ;;
110+ searx-src) clone_searx ;;
105 *) usage "$_usage"; exit 42;;
111 *) usage "$_usage"; exit 42;;
@@ -115,6 +121,8 @@ main(){
115 case $2 in
121 case $2 in
116 all) remove_all;;
122 all) remove_all;;
117 user) remove_user ;;
123 user) remove_user ;;
124+ pyenv) remove_pyenv ;;
125+ searx-src) remove_searx ;;
118 *) usage "$_usage"; exit 42;;
126 *) usage "$_usage"; exit 42;;
120 activate)
128 activate)
@@ -143,7 +151,7 @@ install_all() {
144 clone_searx
152 clone_searx
146− create_venv
154+ create_pyenv
148 configure_searx
156 configure_searx
@@ -167,7 +175,7 @@ update_searx() {
167cd ${SEARX_SRC}
175cd ${SEARX_SRC}
168cp -f ${SEARX_SETTINGS} ${SEARX_SETTINGS}.backup
176cp -f ${SEARX_SETTINGS} ${SEARX_SETTINGS}.backup
169git stash push -m "BACKUP -- 'update server' at ($(date))"
177git stash push -m "BACKUP -- 'update server' at ($(date))"
170−git checkout -b "$(basename "$SEARX_GIT_BRANCH")" --track "$SEARX_GIT_BRANCH"
178+git checkout -b $SEARX_GIT_BRANCH" --track "$SEARX_GIT_BRANCH"
171git pull "$SEARX_GIT_BRANCH"
179git pull "$SEARX_GIT_BRANCH"
172${SEARX_SRC}/manage.sh update_packages
180${SEARX_SRC}/manage.sh update_packages
@@ -185,16 +193,16 @@ EOF
185 "start interactiv shell"
193 "start interactiv shell"
186 case $action in
194 case $action in
187 "keep new configuration")
195 "keep new configuration")
188− info_msg "continue using new settings file"
196+ info_msg "continue using new settings file"
190 "revert to the old configuration (backup file)")
198 "revert to the old configuration (backup file)")
191 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
199 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
192cp -f ${SEARX_SETTINGS}.backup ${SEARX_SETTINGS}
200cp -f ${SEARX_SETTINGS}.backup ${SEARX_SETTINGS}
195− "start interactiv shell")
203+ "start interactiv shell")
196− interactive_shell
204+ interactive_shell
199 chown "${SERVICE_USER}:${SERVICE_USER}" "${SEARX_SETTINGS}"
207 chown "${SERVICE_USER}:${SERVICE_USER}" "${SEARX_SETTINGS}"
@@ -208,7 +216,10 @@ EOF
209remove_all() {
217remove_all() {
210 rst_title "De-Install $SERVICE_NAME (service)"
218 rst_title "De-Install $SERVICE_NAME (service)"
211− remove_service
219+ if ! ask_yn "Do you really want to deinstall $SERVICE_NAME?"; then
213 remove_user
224 remove_user
@@ -240,35 +251,71 @@ remove_user() {
240clone_searx(){
251clone_searx(){
241 rst_title "Clone searx sources" section
252 rst_title "Clone searx sources" section
254+ SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME 2>/dev/null)"
255+ if [[ ! "${SERVICE_HOME}" ]]; then
256+ err_msg "to clone searx sources, user $SERVICE_USER hast to be created first"
243 git_clone "$SEARX_GIT_URL" "$SEARX_SRC" \
261 git_clone "$SEARX_GIT_URL" "$SEARX_SRC" \
244− "$SEARX_GIT_BRANCH" "$SERVICE_USER"
262+ "$SEARX_GIT_BRANCH" "$SERVICE_USER"
246 pushd "${SEARX_SRC}" > /dev/null
264 pushd "${SEARX_SRC}" > /dev/null
247 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
265 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
248cd "${SEARX_SRC}"
266cd "${SEARX_SRC}"
249git config user.email "$ADMIN_EMAIL"
267git config user.email "$ADMIN_EMAIL"
250git config user.name "$ADMIN_NAME"
268git config user.name "$ADMIN_NAME"
251−git checkout "$SEARX_GIT_BRANCH"
269+git config --list
253 popd > /dev/null
271 popd > /dev/null
256−create_venv(){
274+remove_searx() {
257− rst_title "Create virtualenv (python)" section
275+ rst_title "Drop searx sources" section
276+ if ask_yn "Do you really want to drop searx sources ($SEARX_SRC)?"; then
279+ rst_para "Leave searx sources unchanged."
259− rst_para "Create venv in ${SEARX_VENV} and install needed python packages."
283+create_pyenv(){
284+ rst_title "Create virtualenv (python)" section
286+ if [[ ! -f "${SEARX_SRC}/manage.sh" ]]; then
287+ err_msg "to create pyenv for searx, searx has to be cloned first"
290+ info_msg "create pyenv in ${SEARX_PYENV}"
261 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
291 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
262−rm -rf "${SEARX_VENV}"
292+rm -rf "${SEARX_PYENV}"
263−python3 -m venv "${SEARX_VENV}"
293+python3 -m venv "${SEARX_PYENV}"
264−. ${SEARX_VENV}/bin/activate
294+grep -qFs -- 'source ${SEARX_PYENV}/bin/activate' ~/.profile \
265−${SEARX_SRC}/manage.sh update_packages
295+ || echo 'source ${SEARX_PYENV}/bin/activate' >> ~/.profile
297+ info_msg "inspect python's virtual environment"
298+ tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
299+command -v python && python --version
302+ info_msg "install needed python packages"
267 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
303 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
268−grep -qFs -- 'source ${SEARX_VENV}/bin/activate' ~/.profile \
304+${SEARX_SRC}/manage.sh update_packages
269− || echo 'source ${SEARX_VENV}/bin/activate' >> ~/.profile
309+ rst_title "Remove virtualenv (python)" section
310+ if ! ask_yn "Do you really want to drop ${SEARX_PYENV} ?"; then
313+ info_msg "remove pyenv activation from ~/.profile"
314+ tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
315+grep -v 'source ${SEARX_PYENV}/bin/activate' ~/.profile > ~/.profile.##
316+mv ~/.profile.## ~/.profile
318+ rm -rf "${SEARX_PYENV}"
274configure_searx(){
321configure_searx(){
@@ -283,7 +330,7 @@ EOF
285test_local_searx(){
332test_local_searx(){
286− rstHeading "Testing searx instance localy" section
333+ rst_title "Testing searx instance localy" section
288 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
335 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
289cd ${SEARX_SRC}
336cd ${SEARX_SRC}
@@ -293,7 +340,6 @@ sleep 1
293curl --location --verbose --head --insecure http://127.0.0.1:8888/
340curl --location --verbose --head --insecure http://127.0.0.1:8888/
294sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
341sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
299install_searx_uwsgi() {
345install_searx_uwsgi() {