123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #!/bin/sh
  2. BASE_DIR="$(dirname -- "`readlink -f -- "$0"`")"
  3. export PATH="$BASE_DIR/node_modules/.bin":$PATH
  4. # subshell
  5. PYTHONPATH="$BASE_DIR"
  6. SEARX_DIR="$BASE_DIR/searx"
  7. ACTION="$1"
  8. cd -- "$BASE_DIR"
  9. set -e
  10. #
  11. # Python
  12. #
  13. update_packages() {
  14. pip install --upgrade pip
  15. pip install --upgrade setuptools
  16. pip install -r "$BASE_DIR/requirements.txt"
  17. }
  18. update_dev_packages() {
  19. update_packages
  20. pip install -r "$BASE_DIR/requirements-dev.txt"
  21. }
  22. install_geckodriver() {
  23. echo '[!] Checking geckodriver'
  24. # TODO : check the current geckodriver version
  25. set -e
  26. geckodriver -V > /dev/null 2>&1 || NOTFOUND=1
  27. set +e
  28. if [ -z "$NOTFOUND" ]; then
  29. return
  30. fi
  31. GECKODRIVER_VERSION="v0.19.1"
  32. PLATFORM="`python -c "import six; import platform; six.print_(platform.system().lower(), platform.architecture()[0])"`"
  33. case "$PLATFORM" in
  34. "linux 32bit" | "linux2 32bit") ARCH="linux32";;
  35. "linux 64bit" | "linux2 64bit") ARCH="linux64";;
  36. "windows 32 bit") ARCH="win32";;
  37. "windows 64 bit") ARCH="win64";;
  38. "mac 64bit") ARCH="macos";;
  39. esac
  40. GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz";
  41. if [ -z "$1" ]; then
  42. if [ -z "$VIRTUAL_ENV" ]; then
  43. printf "geckodriver can't be installed because VIRTUAL_ENV is not set, you should download it from\n %s" "$GECKODRIVER_URL"
  44. exit
  45. else
  46. GECKODRIVER_DIR="$VIRTUAL_ENV/bin"
  47. fi
  48. else
  49. GECKODRIVER_DIR="$1"
  50. mkdir -p -- "$GECKODRIVER_DIR"
  51. fi
  52. printf "Installing %s/geckodriver from\n %s" "$GECKODRIVER_DIR" "$GECKODRIVER_URL"
  53. FILE="`mktemp`"
  54. wget -qO "$FILE" -- "$GECKODRIVER_URL" && tar xz -C "$GECKODRIVER_DIR" -f "$FILE" geckodriver
  55. rm -- "$FILE"
  56. chmod 777 -- "$GECKODRIVER_DIR/geckodriver"
  57. }
  58. locales() {
  59. pybabel compile -d "$SEARX_DIR/translations"
  60. }
  61. pep8_check() {
  62. echo '[!] Running pep8 check'
  63. # ignored rules:
  64. # E402 module level import not at top of file
  65. # W503 line break before binary operator
  66. pep8 --exclude=searx/static --max-line-length=120 --ignore "E402,W503" "$SEARX_DIR" "$BASE_DIR/tests"
  67. }
  68. unit_tests() {
  69. echo '[!] Running unit tests'
  70. python -m nose2 -s "$BASE_DIR/tests/unit"
  71. }
  72. py_test_coverage() {
  73. echo '[!] Running python test coverage'
  74. PYTHONPATH="`pwd`" python -m nose2 -C --log-capture --with-coverage --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit" \
  75. && coverage report \
  76. && coverage html
  77. }
  78. robot_tests() {
  79. echo '[!] Running robot tests'
  80. PYTHONPATH="`pwd`" python "$SEARX_DIR/testing.py" robot
  81. }
  82. tests() {
  83. set -e
  84. pep8_check
  85. unit_tests
  86. install_geckodriver
  87. robot_tests
  88. set +e
  89. }
  90. #
  91. # Web
  92. #
  93. npm_packages() {
  94. echo '[!] install NPM packages'
  95. cd -- "$BASE_DIR"
  96. npm install less@2.7 less-plugin-clean-css grunt-cli
  97. echo '[!] install NPM packages for oscar theme'
  98. cd -- "$BASE_DIR/searx/static/themes/oscar"
  99. npm install
  100. echo '[!] install NPM packages for simple theme'
  101. cd -- "$BASE_DIR/searx/static/themes/simple"
  102. npm install
  103. }
  104. build_style() {
  105. lessc --clean-css="--s1 --advanced --compatibility=ie9" "$BASE_DIR/searx/static/$1" "$BASE_DIR/searx/static/$2"
  106. }
  107. styles() {
  108. echo '[!] Building legacy style'
  109. build_style themes/legacy/less/style.less themes/legacy/css/style.css
  110. build_style themes/legacy/less/style-rtl.less themes/legacy/css/style-rtl.css
  111. echo '[!] Building courgette style'
  112. build_style themes/courgette/less/style.less themes/courgette/css/style.css
  113. build_style themes/courgette/less/style-rtl.less themes/courgette/css/style-rtl.css
  114. echo '[!] Building pix-art style'
  115. build_style themes/pix-art/less/style.less themes/pix-art/css/style.css
  116. echo '[!] Building bootstrap style'
  117. build_style less/bootstrap/bootstrap.less css/bootstrap.min.css
  118. }
  119. grunt_build() {
  120. echo '[!] Grunt build : oscar theme'
  121. grunt --gruntfile "$SEARX_DIR/static/themes/oscar/gruntfile.js"
  122. echo '[!] Grunt build : simple theme'
  123. grunt --gruntfile "$SEARX_DIR/static/themes/simple/gruntfile.js"
  124. }
  125. #
  126. # Help
  127. #
  128. help() {
  129. [ -z "$1" ] || printf 'Error: %s\n' "$1"
  130. echo "Searx manage.sh help
  131. Commands
  132. ========
  133. help - This text
  134. Build requirements
  135. ------------------
  136. update_packages - Check & update production dependency changes
  137. update_dev_packages - Check & update development and production dependency changes
  138. install_geckodriver - Download & install geckodriver if not already installed (required for robot_tests)
  139. npm_packages - Download & install npm dependencies (source manage.sh to update the PATH)
  140. Build
  141. -----
  142. locales - Compile locales
  143. styles - Build less files
  144. grunt_build - Build files for themes
  145. Tests
  146. -----
  147. unit_tests - Run unit tests
  148. pep8_check - Pep8 validation
  149. robot_tests - Run selenium tests
  150. tests - Run all python tests (pep8, unit, robot_tests)
  151. py_test_coverage - Unit test coverage
  152. "
  153. }
  154. [ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
  155. && help "action not found" \
  156. || "$ACTION" "$2"