| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | #!/bin/sh
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 14:36:47 +02:00
										 |  |  | export LANG=C | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  | BASE_DIR="$(dirname -- "`readlink -f -- "$0"`")" | 
					
						
							| 
									
										
										
										
											2018-08-01 11:53:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | cd -- "$BASE_DIR" | 
					
						
							|  |  |  | set -e | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | # subshell | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  | PYTHONPATH="$BASE_DIR" | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | SEARX_DIR="$BASE_DIR/searx" | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  | ACTION="$1" | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-29 11:41:59 +02:00
										 |  |  | . "${BASE_DIR}/utils/brand.env" | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Python | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2017-08-13 12:17:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | update_packages() { | 
					
						
							| 
									
										
										
										
											2017-07-20 20:51:39 +02:00
										 |  |  |     pip install --upgrade pip | 
					
						
							|  |  |  |     pip install --upgrade setuptools | 
					
						
							| 
									
										
										
										
											2018-12-05 18:52:36 +01:00
										 |  |  |     pip install -Ur "$BASE_DIR/requirements.txt" | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | update_dev_packages() { | 
					
						
							| 
									
										
										
										
											2016-01-07 19:56:59 +01:00
										 |  |  |     update_packages | 
					
						
							| 
									
										
										
										
											2018-12-05 18:52:36 +01:00
										 |  |  |     pip install -Ur "$BASE_DIR/requirements-dev.txt" | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 12:17:26 +02:00
										 |  |  | install_geckodriver() { | 
					
						
							| 
									
										
										
										
											2017-01-03 19:25:04 +01:00
										 |  |  |     echo '[!] Checking geckodriver' | 
					
						
							| 
									
										
										
										
											2017-08-16 18:14:07 +02:00
										 |  |  |     # TODO : check the current geckodriver version | 
					
						
							| 
									
										
										
										
											2017-01-03 19:25:04 +01:00
										 |  |  |     set -e | 
					
						
							| 
									
										
										
										
											2017-10-06 20:43:15 +02:00
										 |  |  |     geckodriver -V > /dev/null 2>&1 || NOTFOUND=1 | 
					
						
							| 
									
										
										
										
											2017-01-03 19:25:04 +01:00
										 |  |  |     set +e | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     if [ -z "$NOTFOUND" ]; then | 
					
						
							| 
									
										
										
										
											2017-10-06 20:31:19 +02:00
										 |  |  |         return | 
					
						
							| 
									
										
										
										
											2017-01-03 19:25:04 +01:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2020-12-28 09:04:39 +01:00
										 |  |  |     GECKODRIVER_VERSION="v0.28.0" | 
					
						
							| 
									
										
										
										
											2020-08-06 17:42:46 +02:00
										 |  |  |     PLATFORM="`python3 -c "import platform; print(platform.system().lower(), platform.architecture()[0])"`" | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     case "$PLATFORM" in | 
					
						
							| 
									
										
										
										
											2017-10-06 20:31:19 +02:00
										 |  |  |         "linux 32bit" | "linux2 32bit") ARCH="linux32";; | 
					
						
							|  |  |  |         "linux 64bit" | "linux2 64bit") ARCH="linux64";; | 
					
						
							|  |  |  |         "windows 32 bit") ARCH="win32";; | 
					
						
							|  |  |  |         "windows 64 bit") ARCH="win64";; | 
					
						
							|  |  |  |         "mac 64bit") ARCH="macos";; | 
					
						
							| 
									
										
										
										
											2017-01-03 19:25:04 +01:00
										 |  |  |     esac | 
					
						
							|  |  |  |     GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz"; | 
					
						
							| 
									
										
										
										
											2017-08-13 13:45:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-16 18:14:07 +02:00
										 |  |  |     if [ -z "$1" ]; then | 
					
						
							| 
									
										
										
										
											2017-10-06 20:31:19 +02:00
										 |  |  |         if [ -z "$VIRTUAL_ENV" ]; then | 
					
						
							| 
									
										
										
										
											2018-02-21 20:46:24 +01:00
										 |  |  |             printf "geckodriver can't be installed because VIRTUAL_ENV is not set, you should download it from\n  %s" "$GECKODRIVER_URL" | 
					
						
							| 
									
										
										
										
											2017-10-06 20:31:19 +02:00
										 |  |  |             exit | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             GECKODRIVER_DIR="$VIRTUAL_ENV/bin" | 
					
						
							|  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2017-01-03 19:25:04 +01:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-10-06 20:31:19 +02:00
										 |  |  |         GECKODRIVER_DIR="$1" | 
					
						
							|  |  |  |         mkdir -p -- "$GECKODRIVER_DIR" | 
					
						
							| 
									
										
										
										
											2017-01-03 19:25:04 +01:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2017-08-13 13:45:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 20:46:24 +01:00
										 |  |  |     printf "Installing %s/geckodriver from\n  %s" "$GECKODRIVER_DIR" "$GECKODRIVER_URL" | 
					
						
							| 
									
										
										
										
											2017-10-06 20:31:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     FILE="`mktemp`" | 
					
						
							|  |  |  |     wget -qO "$FILE" -- "$GECKODRIVER_URL" && tar xz -C "$GECKODRIVER_DIR" -f "$FILE" geckodriver | 
					
						
							|  |  |  |     rm -- "$FILE" | 
					
						
							|  |  |  |     chmod 777 -- "$GECKODRIVER_DIR/geckodriver" | 
					
						
							| 
									
										
										
										
											2017-01-03 19:25:04 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | locales() { | 
					
						
							|  |  |  |     pybabel compile -d "$SEARX_DIR/translations" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | # | 
					
						
							|  |  |  | # Web | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2017-08-13 12:17:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-26 10:32:32 +02:00
										 |  |  | npm_path_setup() { | 
					
						
							|  |  |  |     which npm || (printf 'Error: npm is not found\n'; exit 1) | 
					
						
							|  |  |  |     export PATH="$(npm bin)":$PATH | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 13:45:02 +02:00
										 |  |  | npm_packages() { | 
					
						
							| 
									
										
										
										
											2018-08-26 10:32:32 +02:00
										 |  |  |     npm_path_setup | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  |     echo '[!] install NPM packages' | 
					
						
							|  |  |  |     cd -- "$BASE_DIR" | 
					
						
							|  |  |  |     npm install less@2.7 less-plugin-clean-css grunt-cli | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 13:45:02 +02:00
										 |  |  |     echo '[!] install NPM packages for oscar theme' | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     cd -- "$BASE_DIR/searx/static/themes/oscar" | 
					
						
							| 
									
										
										
										
											2017-08-13 12:17:26 +02:00
										 |  |  |     npm install | 
					
						
							| 
									
										
										
										
											2017-08-13 13:45:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-06 20:31:19 +02:00
										 |  |  |     echo '[!] install NPM packages for simple theme' | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     cd -- "$BASE_DIR/searx/static/themes/simple" | 
					
						
							| 
									
										
										
										
											2017-08-13 12:17:26 +02:00
										 |  |  |     npm install | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-29 11:59:13 +02:00
										 |  |  | docker_build() { | 
					
						
							|  |  |  |     # Check if it is a git repository | 
					
						
							|  |  |  |     if [ ! -d .git ]; then | 
					
						
							|  |  |  | 	echo "This is not Git repository" | 
					
						
							|  |  |  | 	exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if [ ! -x "$(which git)" ]; then | 
					
						
							|  |  |  | 	echo "git is not installed" | 
					
						
							|  |  |  | 	exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if [ ! git remote get-url origin 2> /dev/null ]; then | 
					
						
							|  |  |  | 	echo "there is no remote origin" | 
					
						
							|  |  |  | 	exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # This is a git repository | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # "git describe" to get the Docker version (for example : v0.15.0-89-g0585788e) | 
					
						
							|  |  |  |     # awk to remove the "v" and the "g" | 
					
						
							| 
									
										
										
										
											2020-09-09 11:35:18 +02:00
										 |  |  |     SEARX_GIT_VERSION=$(git describe --match "v[0-9]*\.[0-9]*\.[0-9]*" HEAD 2>/dev/null | awk -F'-' '{OFS="-"; $1=substr($1, 2); if ($3) { $3=substr($3, 2); }  print}') | 
					
						
							| 
									
										
										
										
											2019-06-29 11:59:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # add the suffix "-dirty" if the repository has uncommited change | 
					
						
							| 
									
										
										
										
											2020-12-27 14:39:48 +01:00
										 |  |  |     # /!\ HACK for searx/searx: ignore utils/brand.env | 
					
						
							| 
									
										
										
										
											2019-06-29 11:59:13 +02:00
										 |  |  |     git update-index -q --refresh | 
					
						
							| 
									
										
										
										
											2020-12-27 14:39:48 +01:00
										 |  |  |     if [ ! -z "$(git diff-index --name-only HEAD -- | grep -v 'utils/brand.env')" ]; then | 
					
						
							| 
									
										
										
										
											2019-06-29 11:59:13 +02:00
										 |  |  | 	SEARX_GIT_VERSION="${SEARX_GIT_VERSION}-dirty" | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Get the last git commit id, will be added to the Searx version (see Dockerfile) | 
					
						
							|  |  |  |     VERSION_GITCOMMIT=$(echo $SEARX_GIT_VERSION | cut -d- -f2-4) | 
					
						
							|  |  |  |     echo "Last commit : $VERSION_GITCOMMIT" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Check consistency between the git tag and the searx/version.py file | 
					
						
							|  |  |  |     # /!\ HACK : parse Python file with bash /!\ | 
					
						
							|  |  |  |     # otherwise it is not possible build the docker image without all Python dependencies ( version.py loads __init__.py ) | 
					
						
							| 
									
										
										
										
											2020-08-06 17:42:46 +02:00
										 |  |  |     # SEARX_PYTHON_VERSION=$(python3 -c "import six; import searx.version; six.print_(searx.version.VERSION_STRING)") | 
					
						
							| 
									
										
										
										
											2019-06-29 11:59:13 +02:00
										 |  |  |     SEARX_PYTHON_VERSION=$(cat searx/version.py | grep "\(VERSION_MAJOR\|VERSION_MINOR\|VERSION_BUILD\) =" | cut -d\= -f2 | sed -e 's/^[[:space:]]*//' | paste -sd "." -) | 
					
						
							|  |  |  |     if [ $(echo "$SEARX_GIT_VERSION" | cut -d- -f1) != "$SEARX_PYTHON_VERSION" ]; then | 
					
						
							|  |  |  | 	echo "Inconsistency between the last git tag and the searx/version.py file" | 
					
						
							|  |  |  | 	echo "git tag:          $SEARX_GIT_VERSION" | 
					
						
							|  |  |  | 	echo "searx/version.py: $SEARX_PYTHON_VERSION" | 
					
						
							|  |  |  | 	exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # define the docker image name | 
					
						
							| 
									
										
										
										
											2020-03-25 14:50:39 +01:00
										 |  |  |     GITHUB_USER=$(echo "${GIT_URL}" | sed 's/.*github\.com\/\([^\/]*\).*/\1/') | 
					
						
							| 
									
										
										
										
											2021-04-22 20:14:16 +02:00
										 |  |  |     SEARX_IMAGE_NAME="${SEARX_IMAGE_NAME:-${GITHUB_USER:-searxng}/searxng}" | 
					
						
							| 
									
										
										
										
											2019-06-29 11:59:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # build Docker image | 
					
						
							|  |  |  |     echo "Building image ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}" | 
					
						
							|  |  |  |     sudo docker build \
 | 
					
						
							| 
									
										
										
										
											2020-03-25 14:50:39 +01:00
										 |  |  |          --build-arg GIT_URL="${GIT_URL}" \
 | 
					
						
							| 
									
										
										
										
											2019-06-29 11:59:13 +02:00
										 |  |  |          --build-arg SEARX_GIT_VERSION="${SEARX_GIT_VERSION}" \
 | 
					
						
							|  |  |  |          --build-arg VERSION_GITCOMMIT="${VERSION_GITCOMMIT}" \
 | 
					
						
							|  |  |  |          --build-arg LABEL_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
 | 
					
						
							|  |  |  |          --build-arg LABEL_VCS_REF=$(git rev-parse HEAD) \
 | 
					
						
							| 
									
										
										
										
											2020-03-25 15:17:11 +01:00
										 |  |  |          --build-arg LABEL_VCS_URL="${GIT_URL}" \
 | 
					
						
							| 
									
										
										
										
											2019-06-29 11:59:13 +02:00
										 |  |  | 	 --build-arg TIMESTAMP_SETTINGS=$(git log -1 --format="%cd" --date=unix -- searx/settings.yml) \
 | 
					
						
							|  |  |  | 	 --build-arg TIMESTAMP_UWSGI=$(git log -1 --format="%cd" --date=unix -- dockerfiles/uwsgi.ini) \
 | 
					
						
							|  |  |  |          -t ${SEARX_IMAGE_NAME}:latest -t ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION} . | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if [ "$1" = "push" ]; then | 
					
						
							|  |  |  | 	sudo docker push ${SEARX_IMAGE_NAME}:latest | 
					
						
							|  |  |  | 	sudo docker push ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION} | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | # | 
					
						
							|  |  |  | # Help | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 16:04:32 +01:00
										 |  |  | help() { | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     [ -z "$1" ] || printf 'Error: %s\n' "$1" | 
					
						
							| 
									
										
										
										
											2016-01-02 16:04:32 +01:00
										 |  |  |     echo "Searx manage.sh help
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Commands | 
					
						
							|  |  |  | ======== | 
					
						
							|  |  |  |     help                 - This text | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Build requirements | 
					
						
							|  |  |  |     ------------------ | 
					
						
							|  |  |  |     update_packages      - Check & update production dependency changes | 
					
						
							|  |  |  |     update_dev_packages  - Check & update development and production dependency changes | 
					
						
							|  |  |  |     install_geckodriver  - Download & install geckodriver if not already installed (required for robot_tests) | 
					
						
							| 
									
										
										
										
											2019-07-23 14:10:10 +02:00
										 |  |  |     npm_packages         - Download & install npm dependencies | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Build | 
					
						
							|  |  |  |     ----- | 
					
						
							| 
									
										
										
										
											2016-01-02 16:04:32 +01:00
										 |  |  |     locales              - Compile locales | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-29 11:41:59 +02:00
										 |  |  | Environment: | 
					
						
							|  |  |  |     GIT_URL:          ${GIT_URL} | 
					
						
							|  |  |  |     ISSUE_URL:        ${ISSUE_URL} | 
					
						
							|  |  |  |     SEARX_URL:        ${SEARX_URL} | 
					
						
							|  |  |  |     DOCS_URL:         ${DOCS_URL} | 
					
						
							|  |  |  |     PUBLIC_INSTANCES: ${PUBLIC_INSTANCES} | 
					
						
							| 
									
										
										
										
											2016-01-02 16:04:32 +01:00
										 |  |  | "
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 14:33:47 +02:00
										 |  |  | [ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
 | 
					
						
							| 
									
										
										
										
											2016-03-17 21:43:31 +01:00
										 |  |  |     && help "action not found" \
 | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     || "$ACTION" "$2" |