| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | #!/bin/sh
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2017-01-26 23:30:57 +01:00
										 |  |  |     pip install -r "$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 | 
					
						
							| 
									
										
										
										
											2017-01-26 23:30:57 +01:00
										 |  |  |     pip install -r "$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 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  |     GECKODRIVER_VERSION="v0.19.1" | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     PLATFORM="`python -c "import six; import platform; six.print_(platform.system().lower(), platform.architecture()[0])"`" | 
					
						
							|  |  |  |     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
										 |  |  | pep8_check() { | 
					
						
							|  |  |  |     echo '[!] Running pep8 check' | 
					
						
							| 
									
										
										
										
											2016-01-18 12:47:31 +01:00
										 |  |  |     # ignored rules: | 
					
						
							|  |  |  |     #  E402 module level import not at top of file | 
					
						
							|  |  |  |     #  W503 line break before binary operator | 
					
						
							| 
									
										
										
										
											2017-02-12 15:06:01 +01:00
										 |  |  |     pep8 --exclude=searx/static --max-line-length=120 --ignore "E402,W503" "$SEARX_DIR" "$BASE_DIR/tests" | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unit_tests() { | 
					
						
							|  |  |  |     echo '[!] Running unit tests' | 
					
						
							|  |  |  |     python -m nose2 -s "$BASE_DIR/tests/unit" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | py_test_coverage() { | 
					
						
							|  |  |  |     echo '[!] Running python test coverage' | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     PYTHONPATH="`pwd`" python -m nose2 -C --log-capture --with-coverage --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit" \
 | 
					
						
							| 
									
										
										
										
											2017-09-13 22:58:52 +02:00
										 |  |  |     && coverage report \
 | 
					
						
							|  |  |  |     && coverage html | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | robot_tests() { | 
					
						
							|  |  |  |     echo '[!] Running robot tests' | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     PYTHONPATH="`pwd`" python "$SEARX_DIR/testing.py" robot | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tests() { | 
					
						
							|  |  |  |     set -e | 
					
						
							|  |  |  |     pep8_check | 
					
						
							|  |  |  |     unit_tests | 
					
						
							| 
									
										
										
										
											2017-08-13 12:17:26 +02:00
										 |  |  |     install_geckodriver | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  |     robot_tests | 
					
						
							|  |  |  |     set +e | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  | build_style() { | 
					
						
							| 
									
										
										
										
											2018-08-26 10:32:32 +02:00
										 |  |  |     npm_path_setup | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  |     lessc --clean-css="--s1 --advanced --compatibility=ie9" "$BASE_DIR/searx/static/$1" "$BASE_DIR/searx/static/$2" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | styles() { | 
					
						
							| 
									
										
										
										
											2018-08-26 10:32:32 +02:00
										 |  |  |     npm_path_setup | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  |     echo '[!] Building legacy style' | 
					
						
							|  |  |  |     build_style themes/legacy/less/style.less themes/legacy/css/style.css | 
					
						
							|  |  |  |     build_style themes/legacy/less/style-rtl.less themes/legacy/css/style-rtl.css | 
					
						
							|  |  |  |     echo '[!] Building courgette style' | 
					
						
							|  |  |  |     build_style themes/courgette/less/style.less themes/courgette/css/style.css | 
					
						
							|  |  |  |     build_style themes/courgette/less/style-rtl.less themes/courgette/css/style-rtl.css | 
					
						
							|  |  |  |     echo '[!] Building pix-art style' | 
					
						
							|  |  |  |     build_style themes/pix-art/less/style.less themes/pix-art/css/style.css | 
					
						
							|  |  |  |     echo '[!] Building bootstrap style' | 
					
						
							|  |  |  |     build_style less/bootstrap/bootstrap.less css/bootstrap.min.css | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 12:21:40 +01:00
										 |  |  | grunt_build() { | 
					
						
							| 
									
										
										
										
											2017-08-13 12:17:26 +02:00
										 |  |  |     echo '[!] Grunt build : oscar theme' | 
					
						
							|  |  |  |     grunt --gruntfile "$SEARX_DIR/static/themes/oscar/gruntfile.js" | 
					
						
							| 
									
										
										
										
											2017-10-06 20:31:19 +02:00
										 |  |  |     echo '[!] Grunt build : simple theme' | 
					
						
							| 
									
										
										
										
											2017-08-13 12:17:26 +02:00
										 |  |  |     grunt --gruntfile "$SEARX_DIR/static/themes/simple/gruntfile.js" | 
					
						
							| 
									
										
										
										
											2016-01-02 11:14:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  |     npm_packages         - Download & install npm dependencies (source manage.sh to update the PATH) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Build | 
					
						
							|  |  |  |     ----- | 
					
						
							| 
									
										
										
										
											2016-01-02 16:04:32 +01:00
										 |  |  |     locales              - Compile locales | 
					
						
							|  |  |  |     styles               - Build less files | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  |     grunt_build          - Build files for themes | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Tests | 
					
						
							|  |  |  |     ----- | 
					
						
							| 
									
										
										
										
											2016-01-02 16:04:32 +01:00
										 |  |  |     unit_tests           - Run unit tests | 
					
						
							| 
									
										
										
										
											2017-12-10 10:30:45 +01:00
										 |  |  |     pep8_check           - Pep8 validation | 
					
						
							|  |  |  |     robot_tests          - Run selenium tests | 
					
						
							|  |  |  |     tests                - Run all python tests (pep8, unit, robot_tests) | 
					
						
							|  |  |  |     py_test_coverage     - Unit test coverage | 
					
						
							| 
									
										
										
										
											2016-01-02 16:04:32 +01:00
										 |  |  | "
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-17 21:43:31 +01:00
										 |  |  | [ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
 | 
					
						
							|  |  |  |     && help "action not found" \
 | 
					
						
							| 
									
										
										
										
											2017-10-06 20:24:21 +02:00
										 |  |  |     || "$ACTION" "$2" |