on update_data_update_firefox_version.py help sign in
searx/dockerfiles/docker-entrypoint.sh
145 lines 4.3 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
27# Parse special command line
28# see docs/admin/installation-docker.rst
29# display the help message without the version
30if [ "$1" = "help" ]; then
31 help
32fi
34# Version
35export SEARX_VERSION=$(su searx -c 'python3 -c "import six; import searx.version; six.print_(searx.version.VERSION_STRING)"' 2>/dev/null)
36printf 'searx version %s\n\n' "${SEARX_VERSION}"
38# Parse command line
39FORCE_CONF_UPDATE=0
40DRY_RUN=0
41while getopts "fdh" option
42do
43 case $option in
44 f)
45 FORCE_CONF_UPDATE=1
46 ;;
47 d)
48 DRY_RUN=1
49 ;;
50 h)
51 help
52 esac
53done
55# helpers to update the configuration files
56patch_uwsgi_settings() {
57 CONF="$1"
59 # Nothing
62patch_searx_settings() {
63 CONF="$1"
65 # Make sure that there is trailing slash at the end of BASE_URL
66 # see https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion
67 export BASE_URL="${BASE_URL%/}/"
69 # update settings.yml
70 sed -i -e "s|base_url : False|base_url : ${BASE_URL}|g" \
71 -e "s/instance_name : \"searx\"/instance_name : \"${INSTANCE_NAME}\"/g" \
72 -e "s/autocomplete : \"\"/autocomplete : \"${AUTOCOMPLETE}\"/g" \
73 -e "s/ultrasecretkey/$(openssl rand -hex 32)/g" \
74 "${CONF}"
76 # Morty configuration
77 if [ ! -z "${MORTY_KEY}" -a ! -z "${MORTY_URL}" ]; then
78 sed -i -e "s/image_proxy : False/image_proxy : True/g" \
79 "${CONF}"
80 cat >> "${CONF}" <<-EOF
82# Morty configuration
83result_proxy:
84 url : ${MORTY_URL}
85 key : !!binary "${MORTY_KEY}"
86EOF
87 fi
90update_conf() {
91 FORCE_CONF_UPDATE=$1
92 CONF="$2"
93 NEW_CONF="${2}.new"
94 OLD_CONF="${2}.old"
95 REF_CONF="$3"
96 PATCH_REF_CONF="$4"
98 if [ -f "${CONF}" ]; then
99 if [ "${REF_CONF}" -nt "${CONF}" ]; then
100 # There is a new version
101 if [ $FORCE_CONF_UPDATE -ne 0 ]; then
102 # Replace the current configuration
103 printf '⚠️ Automaticaly update %s to the new version\n' "${CONF}"
104 if [ ! -f "${OLD_CONF}" ]; then
105 printf 'The previous configuration is saved to %s\n' "${OLD_CONF}"
106 mv "${CONF}" "${OLD_CONF}"
107 fi
108 cp "${REF_CONF}" "${CONF}"
109 $PATCH_REF_CONF "${CONF}"
110 else
111 # Keep the current configuration
112 printf '⚠️ Check new version %s to make sure searx is working properly\n' "${NEW_CONF}"
113 cp "${REF_CONF}" "${NEW_CONF}"
114 $PATCH_REF_CONF "${NEW_CONF}"
115 fi
116 else
117 printf 'Use existing %s\n' "${CONF}"
118 fi
119 else
120 printf 'Create %s\n' "${CONF}"
121 cp "${REF_CONF}" "${CONF}"
122 $PATCH_REF_CONF "${CONF}"
123 fi
126# make sure there are uwsgi settings
127update_conf ${FORCE_CONF_UPDATE} "${UWSGI_SETTINGS_PATH}" "/usr/local/searx/dockerfiles/uwsgi.ini" "patch_uwsgi_settings"
129# make sure there are searx settings
130update_conf "${FORCE_CONF_UPDATE}" "${SEARX_SETTINGS_PATH}" "/usr/local/searx/searx/settings.yml" "patch_searx_settings"
132# dry run (to update configuration files, then inspect them)
133if [ $DRY_RUN -eq 1 ]; then
134 printf 'Dry run\n'
135 exit
136fi
139touch /var/run/uwsgi-logrotate
140chown -R searx:searx /var/log/uwsgi /var/run/uwsgi-logrotate
141unset MORTY_KEY
143# Start uwsgi
144printf 'Listen on %s\n' "${BIND_ADDRESS}"
145exec su-exec searx:searx uwsgi --master --http-socket "${BIND_ADDRESS}" "${UWSGI_SETTINGS_PATH}"