on update_data_update_languages.py help sign in
searx/manage.sh
205 lines 6.4 kB history raw
1#!/bin/sh
3export LANG=C
5BASE_DIR="$(dirname -- "`readlink -f -- "$0"`")"
7cd -- "$BASE_DIR"
8set -e
10# subshell
11PYTHONPATH="$BASE_DIR"
12SEARX_DIR="$BASE_DIR/searx"
13ACTION="$1"
15. "${BASE_DIR}/utils/brand.env"
18# Python
21update_packages() {
22 pip install --upgrade pip
23 pip install --upgrade setuptools
24 pip install -Ur "$BASE_DIR/requirements.txt"
27update_dev_packages() {
28 update_packages
29 pip install -Ur "$BASE_DIR/requirements-dev.txt"
32install_geckodriver() {
33 echo '[!] Checking geckodriver'
34 # TODO : check the current geckodriver version
35 set -e
36 geckodriver -V > /dev/null 2>&1 || NOTFOUND=1
37 set +e
38 if [ -z "$NOTFOUND" ]; then
39 return
40 fi
41 GECKODRIVER_VERSION="v0.28.0"
42 PLATFORM="`python3 -c "import platform; print(platform.system().lower(), platform.architecture()[0])"`"
43 case "$PLATFORM" in
44 "linux 32bit" | "linux2 32bit") ARCH="linux32";;
45 "linux 64bit" | "linux2 64bit") ARCH="linux64";;
46 "windows 32 bit") ARCH="win32";;
47 "windows 64 bit") ARCH="win64";;
48 "mac 64bit") ARCH="macos";;
49 esac
50 GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz";
52 if [ -z "$1" ]; then
53 if [ -z "$VIRTUAL_ENV" ]; then
54 printf "geckodriver can't be installed because VIRTUAL_ENV is not set, you should download it from\n %s" "$GECKODRIVER_URL"
55 exit
56 else
57 GECKODRIVER_DIR="$VIRTUAL_ENV/bin"
58 fi
59 else
60 GECKODRIVER_DIR="$1"
61 mkdir -p -- "$GECKODRIVER_DIR"
62 fi
64 printf "Installing %s/geckodriver from\n %s" "$GECKODRIVER_DIR" "$GECKODRIVER_URL"
66 FILE="`mktemp`"
67 wget -qO "$FILE" -- "$GECKODRIVER_URL" && tar xz -C "$GECKODRIVER_DIR" -f "$FILE" geckodriver
68 rm -- "$FILE"
69 chmod 777 -- "$GECKODRIVER_DIR/geckodriver"
72locales() {
73 pybabel compile -d "$SEARX_DIR/translations"
78# Web
81npm_path_setup() {
82 which npm || (printf 'Error: npm is not found\n'; exit 1)
83 export PATH="$(npm bin)":$PATH
86npm_packages() {
87 npm_path_setup
89 echo '[!] install NPM packages'
90 cd -- "$BASE_DIR"
91 npm install less@2.7 less-plugin-clean-css grunt-cli
93 echo '[!] install NPM packages for oscar theme'
94 cd -- "$BASE_DIR/searx/static/themes/oscar"
95 npm install
97 echo '[!] install NPM packages for simple theme'
98 cd -- "$BASE_DIR/searx/static/themes/simple"
99 npm install
102docker_build() {
103 # Check if it is a git repository
104 if [ ! -d .git ]; then
105 echo "This is not Git repository"
106 exit 1
107 fi
109 if [ ! -x "$(which git)" ]; then
110 echo "git is not installed"
111 exit 1
112 fi
114 if [ ! git remote get-url origin 2> /dev/null ]; then
115 echo "there is no remote origin"
116 exit 1
117 fi
119 # This is a git repository
121 # "git describe" to get the Docker version (for example : v0.15.0-89-g0585788e)
122 # awk to remove the "v" and the "g"
123 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}')
125 # add the suffix "-dirty" if the repository has uncommited change
126 # /!\ HACK for searx/searx: ignore utils/brand.env
127 git update-index -q --refresh
128 if [ ! -z "$(git diff-index --name-only HEAD -- | grep -v 'utils/brand.env')" ]; then
129 SEARX_GIT_VERSION="${SEARX_GIT_VERSION}-dirty"
130 fi
132 # Get the last git commit id, will be added to the Searx version (see Dockerfile)
133 VERSION_GITCOMMIT=$(echo $SEARX_GIT_VERSION | cut -d- -f2-4)
134 echo "Last commit : $VERSION_GITCOMMIT"
136 # Check consistency between the git tag and the searx/version.py file
137 # /!\ HACK : parse Python file with bash /!\
138 # otherwise it is not possible build the docker image without all Python dependencies ( version.py loads __init__.py )
139 # SEARX_PYTHON_VERSION=$(python3 -c "import six; import searx.version; six.print_(searx.version.VERSION_STRING)")
140 SEARX_PYTHON_VERSION=$(cat searx/version.py | grep "\(VERSION_MAJOR\|VERSION_MINOR\|VERSION_BUILD\) =" | cut -d\= -f2 | sed -e 's/^[[:space:]]*//' | paste -sd "." -)
141 if [ $(echo "$SEARX_GIT_VERSION" | cut -d- -f1) != "$SEARX_PYTHON_VERSION" ]; then
142 echo "Inconsistency between the last git tag and the searx/version.py file"
143 echo "git tag: $SEARX_GIT_VERSION"
144 echo "searx/version.py: $SEARX_PYTHON_VERSION"
145 exit 1
146 fi
148 # define the docker image name
149 GITHUB_USER=$(echo "${GIT_URL}" | sed 's/.*github\.com\/\([^\/]*\).*/\1/')
150 SEARX_IMAGE_NAME="${GITHUB_USER:-searx}/searx"
152 # build Docker image
153 echo "Building image ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}"
154 sudo docker build \
155 --build-arg GIT_URL="${GIT_URL}" \
156 --build-arg SEARX_GIT_VERSION="${SEARX_GIT_VERSION}" \
157 --build-arg VERSION_GITCOMMIT="${VERSION_GITCOMMIT}" \
158 --build-arg LABEL_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
159 --build-arg LABEL_VCS_REF=$(git rev-parse HEAD) \
160 --build-arg LABEL_VCS_URL="${GIT_URL}" \
161 --build-arg TIMESTAMP_SETTINGS=$(git log -1 --format="%cd" --date=unix -- searx/settings.yml) \
162 --build-arg TIMESTAMP_UWSGI=$(git log -1 --format="%cd" --date=unix -- dockerfiles/uwsgi.ini) \
163 -t ${SEARX_IMAGE_NAME}:latest -t ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION} .
165 if [ "$1" = "push" ]; then
166 sudo docker push ${SEARX_IMAGE_NAME}:latest
167 sudo docker push ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}
168 fi
172# Help
175help() {
176 [ -z "$1" ] || printf 'Error: %s\n' "$1"
177 echo "Searx manage.sh help
179Commands
180========
181 help - This text
183 Build requirements
184 ------------------
185 update_packages - Check & update production dependency changes
186 update_dev_packages - Check & update development and production dependency changes
187 install_geckodriver - Download & install geckodriver if not already installed (required for robot_tests)
188 npm_packages - Download & install npm dependencies
190 Build
191 -----
192 locales - Compile locales
194Environment:
195 GIT_URL: ${GIT_URL}
196 ISSUE_URL: ${ISSUE_URL}
197 SEARX_URL: ${SEARX_URL}
198 DOCS_URL: ${DOCS_URL}
199 PUBLIC_INSTANCES: ${PUBLIC_INSTANCES}
203[ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
204 && help "action not found" \
205 || "$ACTION" "$2"