on fce2d49 help sign in
searx/dockerfiles/docker-entrypoint.sh
132 lines 4.0 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 " INSTANCE_NAME settings.yml : general.instance_name\n"
33 printf " AUTOCOMPLETE settings.yml : search.autocomplete\n"
34 printf " BASE_URL settings.yml : server.base_url\n"
35 printf " MORTY_URL settings.yml : result_proxy.url\n"
36 printf " MORTY_KEY settings.yml : result_proxy.key\n"
37 printf " BIND_ADDRESS where uwsgi will accept HTTP request (format : host:port)\n"
38 exit 0
39 esac
40done
42# helpers to update the configuration files
43patch_uwsgi_settings() {
44 CONF="$1"
46 # Nothing
49patch_searx_settings() {
50 CONF="$1"
52 # Make sure that there is trailing slash at the end of BASE_URL
53 # see http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion
54 export BASE_URL="${BASE_URL%/}/"
56 # update settings.yml
57 sed -i -e "s|base_url : False|base_url : ${BASE_URL}|g" \
58 -e "s/instance_name : \"searx\"/instance_name : \"${INSTANCE_NAME}\"/g" \
59 -e "s/autocomplete : \"\"/autocomplete : \"${AUTOCOMPLETE}\"/g" \
60 -e "s/ultrasecretkey/$(openssl rand -hex 32)/g" \
61 "${CONF}"
63 # Morty configuration
64 if [ ! -z "${MORTY_KEY}" -a ! -z "${MORTY_URL}" ]; then
65 sed -i -e "s/image_proxy : False/image_proxy : True/g" \
66 "${CONF}"
67 cat >> "${CONF}" <<-EOF
69# Morty configuration
70result_proxy:
71 url : ${MORTY_URL}
72 key : !!binary "${MORTY_KEY}"
73EOF
74 fi
77update_conf() {
78 FORCE_CONF_UPDATE=$1
79 CONF="$2"
80 NEW_CONF="${2}.new"
81 OLD_CONF="${2}.old"
82 REF_CONF="$3"
83 PATCH_REF_CONF="$4"
85 if [ -f "${CONF}" ]; then
86 if [ "${REF_CONF}" -nt "${CONF}" ]; then
87 # There is a new version
88 if [ $FORCE_CONF_UPDATE -ne 0 ]; then
89 # Replace the current configuration
90 printf '⚠️ Automaticaly update %s to the new version\n' "${CONF}"
91 if [ ! -f "${OLD_CONF}" ]; then
92 printf 'The previous configuration is saved to %s\n' "${OLD_CONF}"
93 mv "${CONF}" "${OLD_CONF}"
94 fi
95 cp "${REF_CONF}" "${CONF}"
96 $PATCH_REF_CONF "${CONF}"
97 else
98 # Keep the current configuration
99 printf '⚠️ Check new version %s to make sure searx is working properly\n' "${NEW_CONF}"
100 cp "${REF_CONF}" "${NEW_CONF}"
101 $PATCH_REF_CONF "${NEW_CONF}"
102 fi
103 else
104 printf 'Use existing %s\n' "${CONF}"
105 fi
106 else
107 printf 'Create %s\n' "${CONF}"
108 cp "${REF_CONF}" "${CONF}"
109 $PATCH_REF_CONF "${CONF}"
110 fi
113# make sure there are uwsgi settings
114update_conf ${FORCE_CONF_UPDATE} "${UWSGI_SETTINGS_PATH}" "/usr/local/searx/dockerfiles/uwsgi.ini" "patch_uwsgi_settings"
116# make sure there are searx settings
117update_conf "${FORCE_CONF_UPDATE}" "${SEARX_SETTINGS_PATH}" "/usr/local/searx/searx/settings.yml" "patch_searx_settings"
119# dry run (to update configuration files, then inspect them)
120if [ $DRY_RUN -eq 1 ]; then
121 printf 'Dry run\n'
122 exit
123fi
126touch /var/run/uwsgi-logrotate
127chown -R searx:searx /var/log/uwsgi /var/run/uwsgi-logrotate
128unset MORTY_KEY
130# Start uwsgi
131printf 'Listen on %s\n' "${BIND_ADDRESS}"
132exec su-exec searx:searx uwsgi --master --http-socket "${BIND_ADDRESS}" "${UWSGI_SETTINGS_PATH}"