on eb182df help sign in
searx/dockerfiles/docker-entrypoint.sh
128 lines 3.7 kB history raw
1#!/bin/sh
3export SEARX_VERSION=$(su searx -c 'python3 -c "import six; import searx.version; six.print_(searx.version.VERSION_STRING)"')
4printf 'searx version %s\n\n' "${SEARX_VERSION}"
6export UWSGI_SETTINGS_PATH=/etc/searx/uwsgi.ini
7export SEARX_SETTINGS_PATH=/etc/searx/settings.yml
9if [ -z "${BIND_ADDRESS}" ]; then
10 export BIND_ADDRESS=":8080"
11fi
13# Parse command line
14FORCE_CONF_UPDATE=0
15DRY_RUN=0
16while getopts "fdh" option
17do
18 case $option in
19 f)
20 FORCE_CONF_UPDATE=1
21 ;;
22 d)
23 DRY_RUN=1
24 ;;
25 h)
26 printf "Command line:\n\n"
27 printf " -h Display this help\n"
28 printf " -d Dry run to update the configuration files.\n"
29 printf " -f Always update on the configuration files (existing files are renamed with the .old suffix)\n"
30 printf " Without this option, new configuration files are copied with the .new suffix\n"
31 printf "\nEnvironment variables:\n\n"
32 printf " BASE_URL settings.yml : server.base_url\n"
33 printf " MORTY_URL settings.yml : result_proxy.url\n"
34 printf " MORTY_KEY settings.yml : result_proxy.key\n"
35 printf " BIND_ADDRESS where uwsgi will accept HTTP request (format : host:port)\n"
36 exit 0
37 esac
38done
40# helpers to update the configuration files
41patch_uwsgi_settings() {
42 CONF="$1"
44 # Nothing
47patch_searx_settings() {
48 CONF="$1"
50 # Make sure that there is trailing slash at the end of BASE_URL
51 # see http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion
52 export BASE_URL="${BASE_URL%/}/"
54 # update settings.yml
55 sed -i -e "s|base_url : False|base_url : ${BASE_URL}|g" \
56 -e "s/ultrasecretkey/$(openssl rand -hex 32)/g" \
57 "${CONF}"
59 # Morty configuration
60 if [ ! -z "${MORTY_KEY}" -a ! -z "${MORTY_URL}" ]; then
61 sed -i -e "s/image_proxy : False/image_proxy : True/g" \
62 "${CONF}"
63 cat >> "${CONF}" <<-EOF
65# Morty configuration
66result_proxy:
67 url : ${MORTY_URL}
68 key : !!binary "${MORTY_KEY}"
69EOF
70 fi
73update_conf() {
74 FORCE_CONF_UPDATE="$1"
75 CONF="$2"
76 NEW_CONF="${2}.new"
77 OLD_CONF="${2}.old"
78 REF_CONF="$3"
79 PATCH_REF_CONF="$4"
81 if [ -f "${CONF}" ]; then
82 if [ "${REF_CONF}" -nt "${CONF}" ]; then
83 # There is a new version
84 if [ $FORCE_CONF_UPDATE ]; then
85 # Replace the current configuration
86 printf '⚠️ Automaticaly update %s to the new version\n' "${CONF}"
87 if [ ! -f "${OLD_CONF}" ]; then
88 printf 'The previous configuration is saved to %s\n' "${OLD_CONF}"
89 mv "${CONF}" "${OLD_CONF}"
90 fi
91 cp "${REF_CONF}" "${CONF}"
92 $PATCH_REF_CONF "${CONF}"
93 else
94 # Keep the current configuration
95 printf '⚠️ Check new version %s to make sure searx is working properly\n' "${NEW_CONF}"
96 cp "${REF_CONF}" "${NEW_CONF}"
97 $PATCH_REF_CONF "${NEW_CONF}"
98 fi
99 else
100 printf 'Use existing %s\n' "${CONF}"
101 fi
102 else
103 printf 'Create %s\n' "${CONF}"
104 cp "${REF_CONF}" "${CONF}"
105 $PATCH_REF_CONF "${CONF}"
106 fi
109# make sure there are uwsgi settings
110update_conf "${FORCE_CONF_UPDATE}" "${UWSGI_SETTINGS_PATH}" "/usr/local/searx/dockerfiles/uwsgi.ini" "patch_uwsgi_settings"
112# make sure there are searx settings
113update_conf "${FORCE_CONF_UPDATE}" "${SEARX_SETTINGS_PATH}" "/usr/local/searx/searx/settings.yml" "patch_searx_settings"
115# dry run (to update configuration files, then inspect them)
116if [ $DRY_RUN -eq 1 ]; then
117 printf 'Dry run\n'
118 exit
119fi
122touch /var/run/uwsgi-logrotate
123chown -R searx:searx /var/log/uwsgi /var/run/uwsgi-logrotate
124unset MORTY_KEY
126# Start uwsgi
127printf 'Listen on %s\n' "${BIND_ADDRESS}"
128exec su-exec searx:searx uwsgi --master --http-socket "${BIND_ADDRESS}" "${UWSGI_SETTINGS_PATH}"