manage 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. #!/usr/bin/env bash
  2. # -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. # shellcheck disable=SC2031
  5. # shellcheck source=utils/lib.sh
  6. source "$(dirname "${BASH_SOURCE[0]}")/utils/lib.sh"
  7. # shellcheck source=utils/lib_static.sh
  8. source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_static.sh"
  9. # config
  10. PYOBJECTS="searx"
  11. PY_SETUP_EXTRAS='[test]'
  12. GECKODRIVER_VERSION="v0.28.0"
  13. # SPHINXOPTS=
  14. pylint.FILES() {
  15. # List files tagged by comment:
  16. #
  17. # # lint: pylint
  18. #
  19. # These py files are linted by test.pylint(), all other files are linted by
  20. # test.pep8()
  21. grep -l -r --include \*.py '^#[[:blank:]]*lint:[[:blank:]]*pylint' searx searx_extra tests
  22. }
  23. YAMLLINT_FILES=()
  24. while IFS= read -r line; do
  25. YAMLLINT_FILES+=("$line")
  26. done <<< "$(git ls-files './tests/*.yml' './searx/*.yml' './utils/templates/etc/searx/*.yml')"
  27. PYLINT_SEARX_DISABLE_OPTION="\
  28. I,C,R,\
  29. W0105,W0212,W0511,W0603,W0613,W0621,W0702,W0703,W1401,\
  30. E1136"
  31. PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES="supported_languages,language_aliases"
  32. PYLINT_OPTIONS="-m pylint -j 0 --rcfile .pylintrc"
  33. help() {
  34. cat <<EOF
  35. buildenv:
  36. rebuild ./utils/brand.env
  37. babel.:
  38. master.to.translations: update the translations branch from the messages of the master branch.
  39. translations.to.master: copy change from the translations branch to the master branch.
  40. data.:
  41. all : update searx/languages.py and ./data/*
  42. languages : update searx/data/engines_languages.json & searx/languages.py
  43. useragents: update searx/data/useragents.json with the most recent versions of Firefox.
  44. docs.:
  45. html : build HTML documentation
  46. live : autobuild HTML documentation while editing
  47. gh-pages : deploy on gh-pages branch
  48. prebuild : build reST include files (./${DOCS_BUILD}/includes)
  49. clean : clean documentation build
  50. docker.:
  51. build : build docker image
  52. push : build and push docker image
  53. gecko.driver:
  54. download & install geckodriver if not already installed (required for
  55. robot_tests)
  56. node.:
  57. env : download & install npm dependencies locally
  58. clean : drop npm installations
  59. py.:
  60. build : Build python packages at ./${PYDIST}
  61. clean : delete virtualenv and intermediate py files
  62. pyenv.:
  63. install : developer install of searx into virtualenv
  64. uninstall : uninstall developer installation
  65. cmd ... : run command ... in virtualenv
  66. OK : test if virtualenv is OK
  67. pypi.upload:
  68. Upload python packages to PyPi (to test use pypi.upload.test)
  69. test.:
  70. pylint : lint PYLINT_FILES, searx/engines, searx & tests
  71. pep8 : pycodestyle (pep8) for all files except PYLINT_FILES
  72. unit : run unit tests
  73. coverage : run unit tests with coverage
  74. robot : run robot test
  75. clean : clean intermediate test stuff
  76. themes.:
  77. all : build all themes
  78. oscar : build oscar theme
  79. simple : build simple theme
  80. pygments.:
  81. less : build LESS files for pygments
  82. EOF
  83. static_help
  84. }
  85. if [ "$VERBOSE" = "1" ]; then
  86. SPHINX_VERBOSE="-v"
  87. PYLINT_VERBOSE="-v"
  88. fi
  89. # needed by sphinx-docs
  90. export DOCS_BUILD
  91. buildenv() {
  92. # settings file from repository's working tree are used by default
  93. SEARX_SETTINGS_PATH="${REPO_ROOT}/searx/settings.yml"
  94. if [ -r '/etc/searx/settings.yml' ]; then
  95. if ask_yn "should settings read from: /etc/searx/settings.yml"; then
  96. SEARX_SETTINGS_PATH='/etc/searx/settings.yml'
  97. fi
  98. fi
  99. export SEARX_SETTINGS_PATH
  100. (
  101. set -e
  102. SEARX_DEBUG=1 pyenv.cmd python utils/build_env.py 2>&1 \
  103. | prefix_stdout "${_Blue}BUILDENV${_creset} "
  104. )
  105. return "${PIPESTATUS[0]}"
  106. }
  107. TRANSLATIONS_WORKTREE="$CACHE/translations"
  108. babel.setup.translations.worktree() {
  109. ( set -e
  110. if ! git remote get-url weblate 2> /dev/null; then
  111. git remote add weblate https://weblate.bubu1.eu/git/searxng/searxng/
  112. fi
  113. if [ -d "${TRANSLATIONS_WORKTREE}" ]; then
  114. pushd .
  115. cd "${TRANSLATIONS_WORKTREE}"
  116. git reset --hard HEAD
  117. git pull origin translations
  118. popd
  119. else
  120. mkdir -p "${TRANSLATIONS_WORKTREE}"
  121. git worktree add "${TRANSLATIONS_WORKTREE}" translations
  122. fi
  123. )
  124. }
  125. babel.weblate.to.translations() {
  126. ( set -e
  127. if [ "$(pyenv.cmd wlc lock-status)" != "locked: True" ]; then
  128. build_msg BABEL "weblate must be locked, currently: $(pyenv.cmd wlc lock-status)"
  129. exit 1
  130. fi
  131. # weblate: commit pending changes
  132. pyenv.cmd wlc pull
  133. pyenv.cmd wlc commit
  134. # get the translations in a worktree
  135. babel.setup.translations.worktree
  136. cd "${TRANSLATIONS_WORKTREE}"
  137. git remote update weblate
  138. git merge weblate/translations
  139. git push
  140. )
  141. dump_return $?
  142. }
  143. babel.translations.to.master() {
  144. local existing_commit_hash commit_body commit_message exitcode
  145. ( set -e
  146. pyenv.cmd wlc lock
  147. babel.setup.translations.worktree
  148. existing_commit_hash=$(cd "${TRANSLATIONS_WORKTREE}"; git log -n1 --pretty=format:'%h')
  149. # pull weblate commits
  150. babel.weblate.to.translations
  151. # copy the changes to the master branch
  152. cp -rv --preserve=mode,timestamps "${TRANSLATIONS_WORKTREE}/searx/translations" "searx"
  153. # compile translations
  154. build_msg BABEL 'compile translation catalogs into binary MO files'
  155. pyenv.cmd pybabel compile --statistics \
  156. -d "searx/translations"
  157. # git add/commit (no push)
  158. commit_body=$(cd "${TRANSLATIONS_WORKTREE}"; git log --pretty=format:'%h - %as - %aN <%ae>' "${existing_commit_hash}..HEAD")
  159. commit_message=$(echo -e "[translations] update\n${commit_body}")
  160. git add searx/translations
  161. git commit -m "${commit_message}"
  162. )
  163. exitcode=$?
  164. ( # make sure to always unlock weblate
  165. set -e
  166. pyenv.cmd wlc unlock
  167. )
  168. dump_return $exitcode
  169. }
  170. babel.master.to.translations() {
  171. local messages_pot diff_messages_pot last_commit_hash last_commit_detail last_commit_message exitcode
  172. ( set -e
  173. # lock change on weblate
  174. pyenv.cmd wlc lock
  175. # get translation branch
  176. babel.setup.translations.worktree
  177. # update messages.pot
  178. build_msg BABEL 'extract messages from source files and generate POT file'
  179. messages_pot="${TRANSLATIONS_WORKTREE}/searx/translations/messages.pot"
  180. pyenv.cmd pybabel extract -F babel.cfg \
  181. -o "${messages_pot}" \
  182. "searx/"
  183. # stop if there is no meaningful change
  184. diff_messages_pot=$(cd "${TRANSLATIONS_WORKTREE}"; git diff -- "searx/translations/messages.pot")
  185. if ! echo "$diff_messages_pot" | grep -qE "[\+\-](msgid|msgstr)"; then
  186. build_msg BABEL 'no changes detected, exiting'
  187. return 0
  188. fi
  189. # save messages.pot for later
  190. cd "${TRANSLATIONS_WORKTREE}"
  191. git stash push
  192. cd -
  193. # merge weblate commits into the translations branch
  194. babel.weblate.to.translations
  195. # restore messages.pot
  196. cd "${TRANSLATIONS_WORKTREE}"
  197. git stash pop
  198. cd -
  199. set -x
  200. # update messages.po files
  201. build_msg BABEL 'update existing message catalogs from POT file'
  202. pyenv.cmd pybabel update -N \
  203. -i "${messages_pot}" \
  204. -d "${TRANSLATIONS_WORKTREE}/searx/translations"
  205. # git add/commit/push
  206. last_commit_hash=$(git log -n1 --pretty=format:'%h')
  207. last_commit_detail=$(git log -n1 --pretty=format:'%h - %as - %aN <%ae>' "${last_commit_hash}")
  208. last_commit_message=$(echo -e "[translations] update messages.pot and messages.po files\nFrom ${last_commit_detail}")
  209. cd "${TRANSLATIONS_WORKTREE}"
  210. git add searx/translations
  211. git commit -m "${last_commit_message}"
  212. git push
  213. cd -
  214. # notify weblate
  215. pyenv.cmd wlc pull
  216. )
  217. exitcode=$?
  218. ( # make sure to always unlock weblate
  219. set -e
  220. pyenv.cmd wlc unlock
  221. )
  222. dump_return $exitcode
  223. }
  224. data.all() {
  225. data.languages
  226. data.useragents
  227. data.osm_keys_tags
  228. build_msg DATA "update searx/data/ahmia_blacklist.txt"
  229. pyenv.cmd python searx_extra/update/update_ahmia_blacklist.py
  230. build_msg DATA "update searx/data/wikidata_units.json"
  231. pyenv.cmd python searx_extra/update/update_wikidata_units.py
  232. build_msg DATA "update searx/data/currencies.json"
  233. pyenv.cmd python searx_extra/update/update_currencies.py
  234. }
  235. data.languages() {
  236. ( set -e
  237. build_msg ENGINES "fetch languages .."
  238. pyenv.cmd python searx_extra/update/update_languages.py
  239. build_msg ENGINES "update update searx/languages.py"
  240. build_msg DATA "update searx/data/engines_languages.json"
  241. )
  242. dump_return $?
  243. }
  244. data.useragents() {
  245. build_msg DATA "update searx/data/useragents.json"
  246. pyenv.cmd python searx_extra/update/update_firefox_version.py
  247. dump_return $?
  248. }
  249. data.osm_keys_tags() {
  250. build_msg DATA "update searx/data/osm_keys_tags.json"
  251. pyenv.cmd python searx_extra/update/update_osm_keys_tags.py
  252. dump_return $?
  253. }
  254. docs.prebuild() {
  255. build_msg DOCS "build ${DOCS_BUILD}/includes"
  256. (
  257. set -e
  258. [ "$VERBOSE" = "1" ] && set -x
  259. mkdir -p "${DOCS_BUILD}/includes"
  260. ./utils/searx.sh doc | cat > "${DOCS_BUILD}/includes/searx.rst"
  261. ./utils/filtron.sh doc | cat > "${DOCS_BUILD}/includes/filtron.rst"
  262. ./utils/morty.sh doc | cat > "${DOCS_BUILD}/includes/morty.rst"
  263. )
  264. dump_return $?
  265. }
  266. docker.push() {
  267. docker.build push
  268. }
  269. docker.buildx() {
  270. docker.build buildx
  271. }
  272. # shellcheck disable=SC2119
  273. docker.build() {
  274. pyenv.install
  275. local SEARX_GIT_VERSION
  276. local VERSION_GITCOMMIT
  277. local GITHUB_USER
  278. local SEARX_IMAGE_NAME
  279. local BUILD
  280. build_msg DOCKER build
  281. # run installation in a subprocess and activate pyenv
  282. # See https://www.shellcheck.net/wiki/SC1001 and others ..
  283. # shellcheck disable=SC2031,SC2230,SC2002,SC2236,SC2143,SC1001
  284. ( set -e
  285. # shellcheck source=/dev/null
  286. source "${PY_ENV_BIN}/activate"
  287. # Check if it is a git repository
  288. if [ ! -d .git ]; then
  289. die 1 "This is not Git repository"
  290. fi
  291. if [ ! -x "$(which git)" ]; then
  292. die 1 "git is not installed"
  293. fi
  294. if ! git remote get-url origin 2> /dev/null; then
  295. die 1 "there is no remote origin"
  296. fi
  297. # This is a git repository
  298. git update-index -q --refresh
  299. pyenv.cmd python -m searx.version freeze
  300. eval "$(pyenv.cmd python -m searx.version)"
  301. # Get the last git commit id
  302. VERSION_GITCOMMIT=$(echo "$VERSION_STRING" | cut -d- -f3)
  303. build_msg DOCKER "Last commit : $VERSION_GITCOMMIT"
  304. # define the docker image name
  305. GITHUB_USER=$(echo "${GIT_URL}" | sed 's/.*github\.com\/\([^\/]*\).*/\1/')
  306. SEARX_IMAGE_NAME="${SEARX_IMAGE_NAME:-${GITHUB_USER:-searxng}/searxng}"
  307. BUILD="build"
  308. if [ "$1" = "buildx" ]; then
  309. # buildx includes the push option
  310. CACHE_TAG="${SEARX_IMAGE_NAME}:latest-build-cache"
  311. BUILD="buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --push --cache-from=type=registry,ref=$CACHE_TAG --cache-to=type=registry,ref=$CACHE_TAG,mode=max"
  312. shift
  313. fi
  314. build_msg DOCKER "Build command: ${BUILD}"
  315. # build Docker image
  316. build_msg DOCKER "Building image ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}"
  317. # shellcheck disable=SC2086
  318. docker $BUILD \
  319. --build-arg BASE_IMAGE="${DEPENDENCIES_IMAGE_NAME}" \
  320. --build-arg GIT_URL="${GIT_URL}" \
  321. --build-arg SEARX_GIT_VERSION="${VERSION_STRING}" \
  322. --build-arg VERSION_GITCOMMIT="${VERSION_GITCOMMIT}" \
  323. --build-arg LABEL_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
  324. --build-arg LABEL_VCS_REF="$(git rev-parse HEAD)" \
  325. --build-arg LABEL_VCS_URL="${GIT_URL}" \
  326. --build-arg TIMESTAMP_SETTINGS="$(git log -1 --format="%cd" --date=unix -- searx/settings.yml)" \
  327. --build-arg TIMESTAMP_UWSGI="$(git log -1 --format="%cd" --date=unix -- dockerfiles/uwsgi.ini)" \
  328. -t "${SEARX_IMAGE_NAME}:latest" -t "${SEARX_IMAGE_NAME}:${VERSION_STRING}" .
  329. if [ "$1" = "push" ]; then
  330. docker push "${SEARX_IMAGE_NAME}:latest"
  331. docker push "${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}"
  332. fi
  333. )
  334. dump_return $?
  335. }
  336. # shellcheck disable=SC2119
  337. gecko.driver() {
  338. pyenv.install
  339. build_msg INSTALL "gecko.driver"
  340. # run installation in a subprocess and activate pyenv
  341. ( set -e
  342. # shellcheck source=/dev/null
  343. source "${PY_ENV_BIN}/activate"
  344. # TODO : check the current geckodriver version
  345. geckodriver -V > /dev/null 2>&1 || NOTFOUND=1
  346. set +e
  347. if [ -z "$NOTFOUND" ]; then
  348. build_msg INSTALL "geckodriver already installed"
  349. return
  350. fi
  351. PLATFORM="$(python3 -c 'import platform; print(platform.system().lower(), platform.architecture()[0])')"
  352. case "$PLATFORM" in
  353. "linux 32bit" | "linux2 32bit") ARCH="linux32";;
  354. "linux 64bit" | "linux2 64bit") ARCH="linux64";;
  355. "windows 32 bit") ARCH="win32";;
  356. "windows 64 bit") ARCH="win64";;
  357. "mac 64bit") ARCH="macos";;
  358. esac
  359. GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz";
  360. build_msg GECKO "Installing ${PY_ENV_BIN}/geckodriver from $GECKODRIVER_URL"
  361. FILE="$(mktemp)"
  362. wget -qO "$FILE" -- "$GECKODRIVER_URL" && tar xz -C "${PY_ENV_BIN}" -f "$FILE" geckodriver
  363. rm -- "$FILE"
  364. chmod 755 -- "${PY_ENV_BIN}/geckodriver"
  365. )
  366. dump_return $?
  367. }
  368. node.env() {
  369. if ! required_commands npm; then
  370. info_msg "to install build tools use::"
  371. info_msg " sudo -H ./utils/searx.sh install buildhost"
  372. die 1 "install needed build tools first"
  373. fi
  374. ( set -e
  375. build_msg INSTALL "searx/static/themes/oscar/package.json"
  376. npm --prefix searx/static/themes/oscar install
  377. build_msg INSTALL "searx/static/themes/simple/package.json"
  378. npm --prefix searx/static/themes/simple install
  379. )
  380. dump_return $?
  381. }
  382. node.clean() {
  383. if ! required_commands npm 2>/dev/null; then
  384. build_msg CLEAN "npm is not installed / ignore npm dependencies"
  385. return 0
  386. fi
  387. build_msg CLEAN "locally installed npm dependencies"
  388. ( set -e
  389. npm --prefix searx/static/themes/oscar run clean
  390. npm --prefix searx/static/themes/simple run clean
  391. )
  392. dump_return $?
  393. }
  394. pygments.less() {
  395. build_msg PYGMENTS "searx_extra/update/update_pygments.py"
  396. if ! pyenv.cmd python searx_extra/update/update_pygments.py; then
  397. build_msg PYGMENTS "building LESS files for pygments failed"
  398. return 1
  399. fi
  400. return 0
  401. }
  402. py.build() {
  403. build_msg BUILD "python package ${PYDIST}"
  404. pyenv.cmd python setup.py \
  405. sdist -d "${PYDIST}" \
  406. bdist_wheel --bdist-dir "${PYBUILD}" -d "${PYDIST}"
  407. }
  408. py.clean() {
  409. build_msg CLEAN pyenv
  410. ( set -e
  411. pyenv.drop
  412. [ "$VERBOSE" = "1" ] && set -x
  413. rm -rf "${PYDIST}" "${PYBUILD}" "${PY_ENV}" ./.tox ./*.egg-info
  414. find . -name '*.pyc' -exec rm -f {} +
  415. find . -name '*.pyo' -exec rm -f {} +
  416. find . -name __pycache__ -exec rm -rf {} +
  417. )
  418. }
  419. pyenv.check() {
  420. cat <<EOF
  421. import yaml
  422. print('import yaml --> OK')
  423. EOF
  424. }
  425. pyenv.install() {
  426. if ! pyenv.OK; then
  427. py.clean > /dev/null
  428. fi
  429. if pyenv.install.OK > /dev/null; then
  430. return 0
  431. fi
  432. ( set -e
  433. pyenv
  434. build_msg PYENV "[install] pip install -e 'searx${PY_SETUP_EXTRAS}'"
  435. "${PY_ENV_BIN}/python" -m pip install -e ".${PY_SETUP_EXTRAS}"
  436. buildenv
  437. )
  438. local exit_val=$?
  439. if [ ! $exit_val -eq 0 ]; then
  440. die 42 "error while pip install (${PY_ENV_BIN})"
  441. fi
  442. }
  443. pyenv.uninstall() {
  444. build_msg PYENV "[pyenv.uninstall] uninstall packages: ${PYOBJECTS}"
  445. pyenv.cmd python setup.py develop --uninstall 2>&1 \
  446. | prefix_stdout "${_Blue}PYENV ${_creset}[pyenv.uninstall] "
  447. }
  448. pypi.upload() {
  449. py.clean
  450. py.build
  451. # https://github.com/pypa/twine
  452. pyenv.cmd twine upload "${PYDIST}"/*
  453. }
  454. pypi.upload.test() {
  455. py.clean
  456. py.build
  457. pyenv.cmd twine upload -r testpypi "${PYDIST}"/*
  458. }
  459. test.yamllint() {
  460. build_msg TEST "[yamllint] \$YAMLLINT_FILES"
  461. pyenv.cmd yamllint --format parsable "${YAMLLINT_FILES[@]}"
  462. }
  463. test.pylint() {
  464. # shellcheck disable=SC2086
  465. ( set -e
  466. build_msg TEST "[pylint] \$PYLINT_FILES"
  467. pyenv.cmd python ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  468. "${PYLINT_FILES[@]}"
  469. build_msg TEST "[pylint] searx/engines"
  470. pyenv.cmd python ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  471. --disable="${PYLINT_SEARX_DISABLE_OPTION}" \
  472. --additional-builtins="${PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES}" \
  473. searx/engines
  474. build_msg TEST "[pylint] searx tests"
  475. pyenv.cmd python ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  476. --disable="${PYLINT_SEARX_DISABLE_OPTION}" \
  477. --ignore=searx/engines \
  478. searx tests
  479. )
  480. dump_return $?
  481. }
  482. test.pep8() {
  483. build_msg TEST 'pycodestyle (formerly pep8)'
  484. local _exclude=""
  485. printf -v _exclude '%s, ' "${PYLINT_FILES[@]}"
  486. pyenv.cmd pycodestyle \
  487. --exclude="searx/static, searx/languages.py, $_exclude " \
  488. --max-line-length=120 \
  489. --ignore "E117,E252,E402,E722,E741,W503,W504,W605" \
  490. searx tests
  491. dump_return $?
  492. }
  493. test.unit() {
  494. build_msg TEST 'tests/unit'
  495. pyenv.cmd python -m nose2 -s tests/unit
  496. dump_return $?
  497. }
  498. test.coverage() {
  499. build_msg TEST 'unit test coverage'
  500. ( set -e
  501. pyenv.cmd python -m nose2 -C --log-capture --with-coverage --coverage searx -s tests/unit
  502. pyenv.cmd coverage report
  503. pyenv.cmd coverage html
  504. )
  505. dump_return $?
  506. }
  507. test.robot() {
  508. build_msg TEST 'robot'
  509. gecko.driver
  510. PYTHONPATH=. pyenv.cmd python searx/testing.py robot
  511. dump_return $?
  512. }
  513. test.clean() {
  514. build_msg CLEAN "test stuff"
  515. rm -rf geckodriver.log .coverage coverage/
  516. dump_return $?
  517. }
  518. themes.all() {
  519. ( set -e
  520. pygments.less
  521. node.env
  522. themes.oscar
  523. themes.simple
  524. )
  525. dump_return $?
  526. }
  527. themes.oscar() {
  528. build_msg GRUNT "theme: oscar"
  529. npm --prefix searx/static/themes/oscar run build
  530. dump_return $?
  531. }
  532. themes.simple() {
  533. build_msg GRUNT "theme: simple"
  534. npm --prefix searx/static/themes/simple run build
  535. dump_return $?
  536. }
  537. PYLINT_FILES=()
  538. while IFS= read -r line; do
  539. PYLINT_FILES+=("$line")
  540. done <<< "$(pylint.FILES)"
  541. # shellcheck disable=SC2119
  542. main() {
  543. local _type
  544. local cmd="$1"; shift
  545. if [ "$cmd" == "" ]; then
  546. help
  547. err_msg "missing command"
  548. return 42
  549. fi
  550. case "$cmd" in
  551. --getenv) var="$1"; echo "${!var}";;
  552. --help) help;;
  553. --*)
  554. help
  555. err_msg "unknown option $cmd"
  556. return 42
  557. ;;
  558. *)
  559. _type="$(type -t "$cmd")"
  560. if [ "$_type" != 'function' ]; then
  561. err_msg "unknown command: $cmd / use --help"
  562. return 42
  563. else
  564. "$cmd" "$@"
  565. fi
  566. ;;
  567. esac
  568. }
  569. main "$@"