on update_data_update_languages.py help sign in
searx/dockerfiles/docker-entrypoint.sh
148 lines 4.4 kB history raw
1#!/bin/sh
3help() {
4 printf "Command line:\n\n"
5 printf " -h Display this help\n"
6 printf " -d Dry run to update the configuration files.\n"
7 printf " -f Always update on the configuration files (existing files are renamed with the .old suffix)\n"
8 printf " Without this option, the new configuration files are copied with the .new suffix\n"
9 printf "\nEnvironment variables:\n\n"
10 printf " INSTANCE_NAME settings.yml : general.instance_name\n"
11 printf " AUTOCOMPLETE settings.yml : search.autocomplete\n"
12 printf " BASE_URL settings.yml : server.base_url\n"
13 printf " MORTY_URL settings.yml : result_proxy.url\n"
14 printf " MORTY_KEY settings.yml : result_proxy.key\n"
15 printf " BIND_ADDRESS uwsgi bind to the specified TCP socket using HTTP protocol. Default value: \"${DEFAULT_BIND_ADDRESS}\"\n"
16 printf "\nVolume:\n\n"
17 printf " /etc/searx the docker entry point copies settings.yml and uwsgi.ini in this directory (see the -f command line option)\n"
18 echo
19 exit 0
22export DEFAULT_BIND_ADDRESS="0.0.0.0:8080"
23if [ -z "${BIND_ADDRESS}" ]; then
24 export BIND_ADDRESS="${DEFAULT_BIND_ADDRESS}"
25fi
27export UWSGI_SETTINGS_PATH=/etc/searx/uwsgi.ini
28export SEARX_SETTINGS_PATH=/etc/searx/settings.yml
30# Parse special command line
31# see docs/admin/installation-docker.rst
32# display the help message without the version
33if [ "$1" = "help" ]; then
34 help
35fi
37# Version
38export SEARX_VERSION=$(su searx -c 'python3 -c "import six; import searx.version; six.print_(searx.version.VERSION_STRING)"' 2>/dev/null)
39printf 'searx version %s\n\n' "${SEARX_VERSION}"
41# Parse command line
42FORCE_CONF_UPDATE=0
43DRY_RUN=0
44while getopts "fdh" option
45do
46 case $option in
47 f)
48 FORCE_CONF_UPDATE=1
49 ;;
50 d)
51 DRY_RUN=1
52 ;;
53 h)
54 help
55 esac
56done
58# helpers to update the configuration files
59patch_uwsgi_settings() {
60 CONF="$1"
62 # Nothing
65patch_searx_settings() {
66 CONF="$1"
68 # Make sure that there is trailing slash at the end of BASE_URL
69 # see https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion
70 export BASE_URL="${BASE_URL%/}/"
72 # update settings.yml
73 sed -i -e "s|base_url : False|base_url : ${BASE_URL}|g" \
74 -e "s/instance_name : \"searx\"/instance_name : \"${INSTANCE_NAME}\"/g" \
75 -e "s/autocomplete : \"\"/autocomplete : \"${AUTOCOMPLETE}\"/g" \
76 -e "s/ultrasecretkey/$(openssl rand -hex 32)/g" \
77 "${CONF}"
79 # Morty configuration
80 if [ ! -z "${MORTY_KEY}" -a ! -z "${MORTY_URL}" ]; then
81 sed -i -e "s/image_proxy : False/image_proxy : True/g" \
82 "${CONF}"
83 cat >> "${CONF}" <<-EOF
85# Morty configuration
86result_proxy:
87 url : ${MORTY_URL}
88 key : !!binary "${MORTY_KEY}"
89EOF
90 fi
93update_conf() {
94 FORCE_CONF_UPDATE=$1
95 CONF="$2"
96 NEW_CONF="${2}.new"
97 OLD_CONF="${2}.old"
98 REF_CONF="$3"
99 PATCH_REF_CONF="$4"
101 if [ -f "${CONF}" ]; then
102 if [ "${REF_CONF}" -nt "${CONF}" ]; then
103 # There is a new version
104 if [ $FORCE_CONF_UPDATE -ne 0 ]; then
105 # Replace the current configuration
106 printf '⚠️ Automaticaly update %s to the new version\n' "${CONF}"
107 if [ ! -f "${OLD_CONF}" ]; then
108 printf 'The previous configuration is saved to %s\n' "${OLD_CONF}"
109 mv "${CONF}" "${OLD_CONF}"
110 fi
111 cp "${REF_CONF}" "${CONF}"
112 $PATCH_REF_CONF "${CONF}"
113 else
114 # Keep the current configuration
115 printf '⚠️ Check new version %s to make sure searx is working properly\n' "${NEW_CONF}"
116 cp "${REF_CONF}" "${NEW_CONF}"
117 $PATCH_REF_CONF "${NEW_CONF}"
118 fi
119 else
120 printf 'Use existing %s\n' "${CONF}"
121 fi
122 else
123 printf 'Create %s\n' "${CONF}"
124 cp "${REF_CONF}" "${CONF}"
125 $PATCH_REF_CONF "${CONF}"
126 fi
129# make sure there are uwsgi settings
130update_conf ${FORCE_CONF_UPDATE} "${UWSGI_SETTINGS_PATH}" "/usr/local/searx/dockerfiles/uwsgi.ini" "patch_uwsgi_settings"
132# make sure there are searx settings
133update_conf "${FORCE_CONF_UPDATE}" "${SEARX_SETTINGS_PATH}" "/usr/local/searx/searx/settings.yml" "patch_searx_settings"
135# dry run (to update configuration files, then inspect them)
136if [ $DRY_RUN -eq 1 ]; then
137 printf 'Dry run\n'
138 exit
139fi
142touch /var/run/uwsgi-logrotate
143chown -R searx:searx /var/log/uwsgi /var/run/uwsgi-logrotate
144unset MORTY_KEY
146# Start uwsgi
147printf 'Listen on %s\n' "${BIND_ADDRESS}"
148exec su-exec searx:searx uwsgi --master --http-socket "${BIND_ADDRESS}" "${UWSGI_SETTINGS_PATH}"