freedombone-app-searx 35KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Searx engine application
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. VARIANTS='full full-vim'
  29. IN_DEFAULT_INSTALL=0
  30. SHOW_ON_ABOUT=1
  31. SHOW_ICANN_ADDRESS_ON_ABOUT=0
  32. SEARX_REPO="https://github.com/asciimoo/searx"
  33. SEARX_COMMIT='80460be8f69cea5f15c9d5ddbb63e4e48fde2dd0'
  34. SEARX_PATH=/etc
  35. SEARX_PORT=8888
  36. SEARX_ONION_PORT=8094
  37. SEARX_ONION_HOSTNAME=
  38. SEARX_LOGIN_TEXT=$"Search engine login"
  39. SEARX_PASSWORD=
  40. SEARX_BACKGROUND_IMAGE_URL=
  41. searx_variables=(SEARX_LOGIN_TEXT
  42. MY_USERNAME
  43. SEARX_BACKGROUND_IMAGE_URL
  44. SYSTEM_TYPE)
  45. function logging_on_searx {
  46. echo -n ''
  47. }
  48. function logging_off_searx {
  49. echo -n ''
  50. }
  51. function searx_set_default_background {
  52. if [ -f "$HOME/${PROJECT_NAME}/img/backgrounds/searx.jpg" ]; then
  53. cp "$HOME/${PROJECT_NAME}/img/backgrounds/searx.jpg" /etc/searx/searx/static/themes/courgette/img/bg-body-index.jpg
  54. chown -R searx:searx ${SEARX_PATH}/searx
  55. else
  56. if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/backgrounds/searx.jpg" ]; then
  57. cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/backgrounds/searx.jpg" "/etc/searx/searx/static/themes/courgette/img/bg-body-index.jpg"
  58. chown -R searx:searx ${SEARX_PATH}/searx
  59. fi
  60. fi
  61. # remove the github ribbon icon
  62. if [ -f /etc/searx/searx/static/themes/courgette/img/github_ribbon.png ]; then
  63. mv /etc/searx/searx/static/themes/courgette/img/github_ribbon.png /etc/searx/searx/static/themes/courgette/img/github_ribbon.png.old
  64. fi
  65. }
  66. function searx_set_background_image_from_url {
  67. url="$1"
  68. ext=
  69. if [ ${#url} -gt 0 ]; then
  70. if [[ "$url" == *".jpeg" || "$url" == *".jpg" ]]; then
  71. ext="jpg"
  72. fi
  73. if [[ "$url" == *".png" ]]; then
  74. ext="png"
  75. fi
  76. if [[ "$url" == *".gif" ]]; then
  77. ext="gif"
  78. fi
  79. fi
  80. if [ ${#ext} -gt 0 ]; then
  81. if [ -d /etc/searx/searx/static/themes/courgette/img ]; then
  82. cd "/etc/searx/searx/static/themes/courgette/img" || exit 37853539539
  83. # remove any existing image
  84. if [ -f bg-body-index.jpg ]; then
  85. rm bg-body-index.jpg
  86. fi
  87. # get the new image
  88. if [[ "$ext" != 'jpg' ]]; then
  89. if [ -f bg-body-index.${ext} ]; then
  90. rm bg-body-index.${ext}
  91. fi
  92. wget "$url" -O bg-body-index.${ext}
  93. convert bg-body-index.${ext} bg-body-index.jpg
  94. else
  95. wget "$url" -O bg-body-index.jpg
  96. fi
  97. if [ ! -f bg-body-index.jpg ]; then
  98. echo "$url"
  99. echo $'Custom background image for SearX could not be downloaded'
  100. echo "1"
  101. return
  102. fi
  103. chown -R searx:searx ${SEARX_PATH}/searx
  104. fi
  105. else
  106. echo "2"
  107. return
  108. fi
  109. echo "0"
  110. }
  111. function searx_set_background_image {
  112. data=$(mktemp 2>/dev/null)
  113. dialog --title $"SearX Metasearch" \
  114. --backtitle $"Freedombone Control Panel" \
  115. --inputbox $'Set a background image URL' 10 60 2>"$data"
  116. sel=$?
  117. case $sel in
  118. 0)
  119. temp_background=$(<"$data")
  120. if [ ${#temp_background} -gt 0 ]; then
  121. SEARX_BACKGROUND_IMAGE_URL="$temp_background"
  122. write_config_param "SEARX_BACKGROUND_IMAGE_URL" "$SEARX_BACKGROUND_IMAGE_URL"
  123. if [[ $(searx_set_background_image_from_url "$SEARX_BACKGROUND_IMAGE_URL" | tail -n 1) == "0" ]]; then
  124. dialog --title $"Set SearX background" \
  125. --msgbox $"The background image has been set" 6 60
  126. fi
  127. fi
  128. ;;
  129. esac
  130. rm -f "$data"
  131. }
  132. function searx_enable_login {
  133. dialog --title $"Enable Searx login" \
  134. --backtitle $"Freedombone Control Panel" \
  135. --defaultno \
  136. --yesno $"\\nDo you want to add a login so that random web users can't use your metasearch engine?" 10 60
  137. sel=$?
  138. case $sel in
  139. 0) if grep -q '#auth_basic' /etc/nginx/sites-available/searx; then
  140. sed -i 's|#auth_basic|auth_basic|g' /etc/nginx/sites-available/searx
  141. systemctl restart nginx
  142. fi
  143. read_config_param "$MY_USERNAME"
  144. SEARX_LOGIN_PASS=$("${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a searx)
  145. dialog --title $"Enable Searx login" \
  146. --msgbox $"Searx logins are now enabled with the password $SEARX_LOGIN_PASS" 6 65
  147. SEARX_LOGIN_PASS=
  148. ;;
  149. 1) if ! grep -q '#auth_basic' /etc/nginx/sites-available/searx; then
  150. sed -i 's|auth_basic|#auth_basic|g' /etc/nginx/sites-available/searx
  151. systemctl restart nginx
  152. fi
  153. dialog --title $"Disable Searx login" \
  154. --msgbox $"Searx logins are now disabled. Anyone can access your metasearch engine." 6 65
  155. ;;
  156. esac
  157. }
  158. function configure_interactive_searx {
  159. W=(1 $"Set a background image"
  160. 2 $"Enable login")
  161. while true
  162. do
  163. # shellcheck disable=SC2068
  164. selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"SearX" --menu $"Choose an operation, or ESC to exit:" 10 60 2 "${W[@]}" 3>&2 2>&1 1>&3)
  165. if [ ! "$selection" ]; then
  166. break
  167. fi
  168. case $selection in
  169. 1) searx_set_background_image;;
  170. 2) searx_enable_login;;
  171. esac
  172. done
  173. }
  174. function remove_user_searx {
  175. remove_username="$1"
  176. "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp searx
  177. if grep -q "$remove_username:" /etc/nginx/.htpasswd; then
  178. sed -i "/$remove_username:/d" /etc/nginx/.htpasswd
  179. fi
  180. }
  181. function add_user_searx {
  182. if [[ $(app_is_installed searx) == "0" ]]; then
  183. echo '0'
  184. return
  185. fi
  186. new_username="$1"
  187. new_user_password="$2"
  188. "${PROJECT_NAME}-pass" -u "$new_username" -a searx -p "$new_user_password"
  189. if grep -q "$new_username:" /etc/nginx/.htpasswd; then
  190. sed -i "/$new_username:/d" /etc/nginx/.htpasswd
  191. fi
  192. echo "$new_user_password" | htpasswd -i -s -c /etc/nginx/.htpasswd "$new_username"
  193. echo '0'
  194. }
  195. function install_interactive_searx {
  196. echo -n ''
  197. APP_INSTALLED=1
  198. }
  199. function change_password_searx {
  200. new_username="$1"
  201. new_user_password="$2"
  202. if grep -q "$new_username:" /etc/nginx/.htpasswd; then
  203. sed -i "/$new_username:/d" /etc/nginx/.htpasswd
  204. echo "$new_user_password" | htpasswd -i -s -c /etc/nginx/.htpasswd "$new_username"
  205. "${PROJECT_NAME}-pass" -u "$new_username" -a searx -p "$new_user_password"
  206. echo '0'
  207. fi
  208. echo '1'
  209. }
  210. function reconfigure_searx {
  211. echo -n ''
  212. }
  213. function create_searx_config {
  214. settings_file=${SEARX_PATH}/searx/searx/settings.yml
  215. SEARX_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_searx/hostname)
  216. SEARX_SECRET_KEY=$(get_completion_param "searx key")
  217. { echo 'general:';
  218. echo ' debug : False';
  219. echo ' instance_name : "Freedombone Metasearch"';
  220. echo '';
  221. echo 'search:';
  222. echo ' safe_search : 0 # Filter results. 0: None, 1: Moderate, 2: Strict';
  223. echo ' autocomplete : "" # Existing autocomplete backends: "dbpedia", "duckduckgo", "startpage", "wikipedia" - leave blank to turn it off by default';
  224. echo ' language : "all"';
  225. echo '';
  226. echo 'server:';
  227. echo " port : ${SEARX_PORT}";
  228. echo ' bind_address : "127.0.0.1" # address to listen on';
  229. echo " secret_key : \"${SEARX_SECRET_KEY}\"";
  230. echo " base_url : http://${SEARX_ONION_HOSTNAME}/";
  231. echo ' image_proxy : True # Proxying image results through searx';
  232. echo ' http_protocol_version : "1.1" # 1.0 and 1.1 are supported';
  233. echo '';
  234. echo 'ui:';
  235. echo ' static_path : "" # Custom static path - leave it blank if you didnt change';
  236. echo ' templates_path : "" # Custom templates path - leave it blank if you didnt change';
  237. echo ' themes_path : "" # Custom ui themes path';
  238. echo ' default_theme : courgette # ui theme';
  239. echo ' default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the "locales" config section';
  240. echo '';
  241. echo 'outgoing: # communication with search engines';
  242. echo ' request_timeout : 10.0 # seconds';
  243. echo ' useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator';
  244. echo ' pool_connections : 100 # Number of different hosts';
  245. echo ' pool_maxsize : 10 # Number of simultaneous requests by host';
  246. echo ' proxies :';
  247. echo ' http : socks5://127.0.0.1:9050';
  248. echo '';
  249. echo 'engines:';
  250. echo ' - name : arch linux wiki';
  251. echo ' engine : archlinux';
  252. echo ' categories : general';
  253. echo ' shortcut : al';
  254. echo '';
  255. echo ' - name : archive is';
  256. echo ' engine : xpath';
  257. echo ' search_url : https://archive.is/{query}';
  258. echo ' url_xpath : (//div[@class="TEXT-BLOCK"]/a)/@href';
  259. echo ' title_xpath : (//div[@class="TEXT-BLOCK"]/a)';
  260. echo ' content_xpath : //div[@class="TEXT-BLOCK"]/ul/li';
  261. echo ' categories : general';
  262. echo ' timeout : 7.0';
  263. echo ' disabled : True';
  264. echo ' shortcut : ai';
  265. echo '';
  266. echo ' - name : base';
  267. echo ' engine : base';
  268. echo ' shortcut : bs';
  269. echo '';
  270. echo ' - name : wikipedia';
  271. echo ' engine : wikipedia';
  272. echo ' shortcut : wp';
  273. echo ' categories : general';
  274. echo ' base_url : "https://{language}.wikipedia.org/"';
  275. echo '';
  276. echo ' - name : bitbucket';
  277. echo ' engine : xpath';
  278. echo ' paging : True';
  279. echo ' search_url : https://bitbucket.org/repo/all/{pageno}?name={query}';
  280. echo ' url_xpath : //article[@class="repo-summary"]//a[@class="repo-link"]/@href';
  281. echo ' title_xpath : //article[@class="repo-summary"]//a[@class="repo-link"]';
  282. echo ' content_xpath : //article[@class="repo-summary"]/p';
  283. echo ' categories : code';
  284. echo ' timeout : 4.0';
  285. echo ' disabled : True';
  286. echo ' shortcut : bb';
  287. echo '';
  288. echo ' - name : ccc-tv';
  289. echo ' engine : xpath';
  290. echo ' paging : False';
  291. echo ' search_url : https://media.ccc.de/search/?q={query}';
  292. echo ' url_xpath : //div[@class="caption"]/h3/a/@href';
  293. echo ' title_xpath : //div[@class="caption"]/h3/a/text()';
  294. echo ' content_xpath : //div[@class="caption"]/h4/@title';
  295. echo ' categories : videos';
  296. echo ' shortcut : c3tv';
  297. echo '';
  298. echo ' - name : crossref';
  299. echo ' engine : json_engine';
  300. echo ' paging : True';
  301. echo ' search_url : http://search.crossref.org/dois?q={query}&page={pageno}';
  302. echo ' url_query : doi';
  303. echo ' title_query : title';
  304. echo ' content_query : fullCitation';
  305. echo ' categories : science';
  306. echo ' shortcut : cr';
  307. echo '';
  308. echo ' - name : currency';
  309. echo ' engine : currency_convert';
  310. echo ' categories : general';
  311. echo ' shortcut : cc';
  312. echo '';
  313. echo ' - name : deezer';
  314. echo ' engine : deezer';
  315. echo ' shortcut : dz';
  316. echo '';
  317. echo ' - name : deviantart';
  318. echo ' engine : deviantart';
  319. echo ' shortcut : da';
  320. echo ' timeout: 3.0';
  321. echo '';
  322. echo ' - name : ddg definitions';
  323. echo ' engine : duckduckgo_definitions';
  324. echo ' shortcut : ddd';
  325. echo ' weight : 2';
  326. echo ' disabled : True';
  327. echo '';
  328. echo ' - name : digbt';
  329. echo ' engine : digbt';
  330. echo ' shortcut : dbt';
  331. echo ' timeout : 6.0';
  332. echo ' disabled : True';
  333. echo '';
  334. echo ' - name : erowid';
  335. echo ' engine : xpath';
  336. echo ' paging : True';
  337. echo ' first_page_num : 0';
  338. echo ' page_size : 30';
  339. echo ' search_url : https://www.erowid.org/search.php?q={query}&s={pageno}';
  340. echo ' url_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/@href';
  341. echo ' title_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/text()';
  342. echo ' content_xpath : //dl[@class="results-list"]/dd[@class="result-details"]';
  343. echo ' categories : general';
  344. echo ' shortcut : ew';
  345. echo ' disabled : True';
  346. echo '';
  347. echo ' - name : wikidata';
  348. echo ' engine : wikidata';
  349. echo ' shortcut : wd';
  350. echo ' weight : 2';
  351. echo '';
  352. echo ' - name : duckduckgo';
  353. echo ' engine : duckduckgo';
  354. echo ' shortcut : ddg';
  355. echo ' categories : general';
  356. echo '';
  357. echo ' - name : etymonline';
  358. echo ' engine : xpath';
  359. echo ' paging : True';
  360. echo ' search_url : http://etymonline.com/?search={query}&p={pageno}';
  361. echo ' url_xpath : //dt/a[1]/@href';
  362. echo ' title_xpath : //dt';
  363. echo ' content_xpath : //dd';
  364. echo ' suggestion_xpath : //a[@class="crossreference"]';
  365. echo ' first_page_num : 0';
  366. echo ' shortcut : et';
  367. echo ' disabled : True';
  368. echo '';
  369. echo ' - name : 500px';
  370. echo ' engine : www500px';
  371. echo ' shortcut : px';
  372. echo '';
  373. echo ' - name : 1x';
  374. echo ' engine : www1x';
  375. echo ' shortcut : 1x';
  376. echo ' disabled : True';
  377. echo '';
  378. echo ' - name : fdroid';
  379. echo ' engine : fdroid';
  380. echo ' shortcut : fd';
  381. echo ' disabled : True';
  382. echo '';
  383. echo ' - name : flickr';
  384. echo ' categories : images';
  385. echo ' shortcut : fl';
  386. echo '# You can use the engine using the official stable API, but you need an API key';
  387. echo '# See : https://www.flickr.com/services/apps/create/';
  388. echo '# engine : flickr';
  389. echo "# api_key: 'apikey' # required!";
  390. echo '# Or you can use the html non-stable engine, activated by default';
  391. echo ' engine : flickr_noapi';
  392. echo '';
  393. echo ' - name : frinkiac';
  394. echo ' engine : frinkiac';
  395. echo ' shortcut : frk';
  396. echo ' disabled : True';
  397. echo '';
  398. echo ' - name : gigablast';
  399. echo ' engine : gigablast';
  400. echo ' shortcut : gb';
  401. echo ' timeout : 3.0';
  402. echo ' disabled: True';
  403. echo '';
  404. echo ' - name : gitlab';
  405. echo ' engine : json_engine';
  406. echo ' paging : True';
  407. echo ' search_url : https://gitlab.com/api/v4/projects?search={query}&page={pageno}';
  408. echo ' url_query : web_url';
  409. echo ' title_query : name_with_namespace';
  410. echo ' content_query : description';
  411. echo ' page_size : 20';
  412. echo ' categories : code';
  413. echo ' shortcut : gl';
  414. echo ' timeout : 10.0';
  415. echo ' disabled : False';
  416. echo '';
  417. echo ' - name : github';
  418. echo ' engine : github';
  419. echo ' shortcut : gh';
  420. echo ' categories : code';
  421. echo '';
  422. echo ' - name : geektimes';
  423. echo ' engine : xpath';
  424. echo ' paging : True';
  425. echo ' search_url : https://geektimes.ru/search/page{pageno}/?q={query}';
  426. echo ' url_xpath : //div[@class="search_results"]//a[@class="post__title_link"]/@href';
  427. echo ' title_xpath : //div[@class="search_results"]//a[@class="post__title_link"]';
  428. echo ' content_xpath : //div[@class="search_results"]//div[contains(@class, "content")]';
  429. echo ' categories : code';
  430. echo ' timeout : 4.0';
  431. echo ' disabled : True';
  432. echo ' shortcut : gt';
  433. echo '';
  434. echo ' - name : habrahabr';
  435. echo ' engine : xpath';
  436. echo ' paging : True';
  437. echo ' search_url : https://habrahabr.ru/search/page{pageno}/?q={query}';
  438. echo ' url_xpath : //div[@class="search_results"]//a[contains(@class, "post__title_link")]/@href';
  439. echo ' title_xpath : //div[@class="search_results"]//a[contains(@class, "post__title_link")]';
  440. echo ' content_xpath : //div[@class="search_results"]//div[contains(@class, "content")]';
  441. echo ' categories : code';
  442. echo ' timeout : 4.0';
  443. echo ' disabled : True';
  444. echo ' shortcut : habr';
  445. echo '';
  446. echo ' - name : hoogle';
  447. echo ' engine : json_engine';
  448. echo ' paging : True';
  449. echo ' search_url : https://www.haskell.org/hoogle/?mode=json&hoogle={query}&start={pageno}';
  450. echo ' results_query : results';
  451. echo ' url_query : location';
  452. echo ' title_query : self';
  453. echo ' content_query : docs';
  454. echo ' page_size : 20';
  455. echo ' categories : code';
  456. echo ' shortcut : ho';
  457. echo '';
  458. echo ' - name : ina';
  459. echo ' engine : ina';
  460. echo ' shortcut : in';
  461. echo ' timeout : 6.0';
  462. echo ' disabled : True';
  463. echo '';
  464. echo ' - name: kickass';
  465. echo ' engine : kickass';
  466. echo ' shortcut : kc';
  467. echo ' timeout : 4.0';
  468. echo ' disabled : True';
  469. echo '';
  470. echo ' - name : library genesis';
  471. echo ' engine : xpath';
  472. echo ' search_url : http://libgen.io/search.php?req={query}';
  473. echo ' url_xpath : //a[contains(@href,"bookfi.net")]/@href';
  474. echo ' title_xpath : //a[contains(@href,"book/")]/text()[1]';
  475. echo ' content_xpath : //td/a[1][contains(@href,"=author")]/text()';
  476. echo ' categories : general';
  477. echo ' timeout : 7.0';
  478. echo ' disabled : True';
  479. echo ' shortcut : lg';
  480. echo '';
  481. echo ' - name : lobste.rs';
  482. echo ' engine : xpath';
  483. echo ' search_url : https://lobste.rs/search?utf8=%E2%9C%93&q={query}&what=stories&order=relevance';
  484. echo ' results_xpath : //li[contains(@class, "story")]';
  485. echo ' url_xpath : .//span[@class="link"]/a/@href';
  486. echo ' title_xpath : .//span[@class="link"]/a';
  487. echo ' content_xpath : .//a[@class="domain"]';
  488. echo ' categories : code';
  489. echo ' shortcut : lo';
  490. echo '';
  491. echo ' - name : mixcloud';
  492. echo ' engine : mixcloud';
  493. echo ' shortcut : mc';
  494. echo '';
  495. echo ' - name : nyaa';
  496. echo ' engine : nyaa';
  497. echo ' shortcut : nt';
  498. echo ' disabled : True';
  499. echo '';
  500. echo ' - name : openstreetmap';
  501. echo ' engine : openstreetmap';
  502. echo ' shortcut : osm';
  503. echo '';
  504. echo ' - name : openrepos';
  505. echo ' engine : xpath';
  506. echo ' paging : True';
  507. echo ' search_url : https://openrepos.net/search/node/{query}?page={pageno}';
  508. echo ' url_xpath : //li[@class="search-result"]//h3[@class="title"]/a/@href';
  509. echo ' title_xpath : //li[@class="search-result"]//h3[@class="title"]/a';
  510. echo ' content_xpath : //li[@class="search-result"]//div[@class="search-snippet-info"]//p[@class="search-snippet"]';
  511. echo ' categories : files';
  512. echo ' timeout : 4.0';
  513. echo ' disabled : True';
  514. echo ' shortcut : or';
  515. echo '';
  516. echo ' - name : pdbe';
  517. echo ' engine : pdbe';
  518. echo ' shortcut : pdb';
  519. echo '';
  520. echo ' - name : photon';
  521. echo ' engine : photon';
  522. echo ' shortcut : ph';
  523. echo '';
  524. echo ' - name : piratebay';
  525. echo ' engine : piratebay';
  526. echo ' shortcut : tpb';
  527. echo ' url: https://pirateproxy.red/';
  528. echo ' timeout : 3.0';
  529. echo '';
  530. echo ' - name : qwant';
  531. echo ' engine : qwant';
  532. echo ' shortcut : qw';
  533. echo ' categories : general';
  534. echo ' disabled : True';
  535. echo '';
  536. echo ' - name : qwant images';
  537. echo ' engine : qwant';
  538. echo ' shortcut : qwi';
  539. echo ' categories : images';
  540. echo '';
  541. echo ' - name : qwant news';
  542. echo ' engine : qwant';
  543. echo ' shortcut : qwn';
  544. echo ' categories : news';
  545. echo '';
  546. echo ' - name : qwant social';
  547. echo ' engine : qwant';
  548. echo ' shortcut : qws';
  549. echo ' categories : social media';
  550. echo '';
  551. echo ' - name : reddit';
  552. echo ' engine : reddit';
  553. echo ' shortcut : re';
  554. echo ' page_size : 25';
  555. echo ' timeout : 10.0';
  556. echo ' disabled : True';
  557. echo '';
  558. echo ' - name : scanr structures';
  559. echo ' shortcut: scs';
  560. echo ' engine : scanr_structures';
  561. echo ' disabled : True';
  562. echo '';
  563. echo ' - name : soundcloud';
  564. echo ' engine : soundcloud';
  565. echo ' shortcut : sc';
  566. echo '';
  567. echo ' - name : stackoverflow';
  568. echo ' engine : stackoverflow';
  569. echo ' shortcut : st';
  570. echo '';
  571. echo ' - name : searchcode doc';
  572. echo ' engine : searchcode_doc';
  573. echo ' shortcut : scd';
  574. echo '';
  575. echo ' - name : searchcode code';
  576. echo ' engine : searchcode_code';
  577. echo ' shortcut : scc';
  578. echo ' disabled : True';
  579. echo '';
  580. echo ' - name : framalibre';
  581. echo ' engine : framalibre';
  582. echo ' shortcut : frl';
  583. echo ' disabled : True';
  584. echo '';
  585. echo ' - name : semantic scholar';
  586. echo ' engine : xpath';
  587. echo ' paging : True';
  588. echo ' search_url : https://www.semanticscholar.org/search?q={query}&sort=relevance&page={pageno}&ae=false';
  589. echo ' results_xpath : //article';
  590. echo ' url_xpath : .//div[@class="search-result-title"]/a/@href';
  591. echo ' title_xpath : .//div[@class="search-result-title"]/a';
  592. echo ' content_xpath : .//div[@class="search-result-abstract"]';
  593. echo ' shortcut : se';
  594. echo ' categories : science';
  595. echo '';
  596. echo ' - name : spotify';
  597. echo ' engine : spotify';
  598. echo ' shortcut : stf';
  599. echo '';
  600. echo ' - name : subtitleseeker';
  601. echo ' engine : subtitleseeker';
  602. echo ' shortcut : ss';
  603. echo '# The language is an option. You can put any language written in english';
  604. echo '# Examples : English, French, German, Hungarian, Chinese...';
  605. echo '# language : English';
  606. echo '';
  607. echo ' - name : startpage';
  608. echo ' engine : startpage';
  609. echo ' shortcut : sp';
  610. echo ' timeout : 6.0';
  611. echo ' disabled : True';
  612. echo '';
  613. echo ' - name : ixquick';
  614. echo ' engine : startpage';
  615. echo " base_url : 'https://www.ixquick.eu/'";
  616. echo " search_url : 'https://www.ixquick.eu/do/search'";
  617. echo ' shortcut : iq';
  618. echo ' timeout : 6.0';
  619. echo '';
  620. echo ' - name : swisscows';
  621. echo ' engine : swisscows';
  622. echo ' shortcut : sw';
  623. echo ' disabled : True';
  624. echo '';
  625. echo ' - name : tokyotoshokan';
  626. echo ' engine : tokyotoshokan';
  627. echo ' shortcut : tt';
  628. echo ' timeout : 6.0';
  629. echo ' disabled : True';
  630. echo '';
  631. echo ' - name : twitter';
  632. echo ' engine : twitter';
  633. echo ' shortcut : tw';
  634. echo '';
  635. echo ' - name : urbandictionary';
  636. echo ' engine : xpath';
  637. echo ' search_url : http://www.urbandictionary.com/define.php?term={query}';
  638. echo ' url_xpath : //*[@class="word"]/@href';
  639. echo ' title_xpath : //*[@class="def-header"]';
  640. echo ' content_xpath : //*[@class="meaning"]';
  641. echo ' shortcut : ud';
  642. echo '';
  643. echo ' - name : yandex';
  644. echo ' engine : yandex';
  645. echo ' shortcut : yn';
  646. echo ' disabled : True';
  647. echo '';
  648. echo ' - name : youtube';
  649. echo ' shortcut : yt';
  650. echo ' # You can use the engine using the official stable API, but you need an API key';
  651. echo ' # See : https://console.developers.google.com/project';
  652. echo ' # engine : youtube_api';
  653. echo ' # api_key: apikey # required!';
  654. echo ' # Or you can use the html non-stable engine, activated by default';
  655. echo ' engine : youtube_noapi';
  656. echo '';
  657. echo ' - name : dailymotion';
  658. echo ' engine : dailymotion';
  659. echo ' shortcut : dm';
  660. echo '';
  661. echo ' - name : vimeo';
  662. echo ' engine : vimeo';
  663. echo ' shortcut : vm';
  664. echo '';
  665. echo ' - name : wolframalpha';
  666. echo ' shortcut : wa';
  667. echo ' # You can use the engine using the official stable API, but you need an API key';
  668. echo ' # See : http://products.wolframalpha.com/api/';
  669. echo ' # engine : wolframalpha_api';
  670. echo ' # api_key: '' # required!';
  671. echo ' engine : wolframalpha_noapi';
  672. echo ' timeout: 6.0';
  673. echo ' categories : science';
  674. echo '';
  675. echo ' - name : seedpeer';
  676. echo ' engine : seedpeer';
  677. echo ' shortcut: speu'
  678. echo ' categories: files, music, videos'
  679. echo ' disabled: True';
  680. echo '';
  681. echo ' - name : dictzone';
  682. echo ' engine : dictzone';
  683. echo ' shortcut : dc';
  684. echo '';
  685. echo ' - name : mymemory translated';
  686. echo ' engine : translated';
  687. echo ' shortcut : tl';
  688. echo ' timeout : 5.0';
  689. echo ' disabled : True';
  690. echo ' # You can use without an API key, but you are limited to 1000 words/day';
  691. echo ' # See : http://mymemory.translated.net/doc/usagelimits.php';
  692. echo ' # api_key : ""';
  693. echo '';
  694. echo ' - name : voat';
  695. echo ' engine: xpath';
  696. echo ' shortcut: vo';
  697. echo ' categories: social media';
  698. echo ' search_url : https://voat.co/search?q={query}';
  699. echo ' url_xpath : //p[contains(@class, "title")]/a/@href';
  700. echo ' title_xpath : //p[contains(@class, "title")]/a';
  701. echo ' content_xpath : //span[@class="domain"]';
  702. echo ' timeout : 10.0';
  703. echo ' disabled : True';
  704. echo '';
  705. echo ' - name : 1337x';
  706. echo ' engine : 1337x';
  707. echo ' shortcut : 1337x';
  708. echo ' disabled : True';
  709. echo '';
  710. echo 'locales:';
  711. echo ' en : English';
  712. echo ' bg : (Bulgarian)';
  713. echo ' cs : etina (Czech)';
  714. echo ' de : Deutsch (German)';
  715. echo ' de_DE : Deutsch (German_Germany)';
  716. echo ' el_GR : (Greek_Greece)';
  717. echo ' eo : Esperanto (Esperanto)';
  718. echo ' es : Espaol (Spanish)';
  719. echo ' fi : Suomi (Finnish)';
  720. echo ' fr : Franais (French)';
  721. echo ' he : (Hebrew)';
  722. echo ' hu : Magyar (Hungarian)';
  723. echo ' it : Italiano (Italian)';
  724. echo ' ja : (Japanese)';
  725. echo ' nl : Nederlands (Dutch)';
  726. echo ' pt : Portugus (Portuguese)';
  727. echo ' pt_BR : Portugus (Portuguese_Brazil)';
  728. echo ' ro : Romn (Romanian)';
  729. echo ' ru : (Russian)';
  730. echo ' sk : Slovenina (Slovak)';
  731. echo ' sv : Svenska (Swedish)';
  732. echo ' tr : Trke (Turkish)';
  733. echo ' uk : (Ukrainian)';
  734. echo ' zh : (Chinese)';
  735. echo '';
  736. echo 'doi_resolvers :';
  737. echo " oadoi.org : 'https://oadoi.org/'";
  738. echo " doi.org : 'https://doi.org/'";
  739. echo " doai.io : 'http://doai.io/'";
  740. echo '';
  741. echo "default_doi_resolver : 'oadoi.org'"; } > $settings_file
  742. }
  743. function upgrade_searx {
  744. CURR_SEARX_COMMIT=$(get_completion_param "searx commit")
  745. if [[ "$CURR_SEARX_COMMIT" == "$SEARX_COMMIT" ]]; then
  746. return
  747. fi
  748. settings_file=${SEARX_PATH}/searx/searx/settings.yml
  749. background_image=/etc/searx/searx/static/themes/courgette/img/bg-body-index.jpg
  750. # save the background image
  751. if [ -f ${background_image} ]; then
  752. cp ${background_image} ${background_image}.prev
  753. fi
  754. # save the settings
  755. cp ${settings_file} ${settings_file}.prev
  756. # do the upgrade
  757. set_repo_commit $SEARX_PATH/searx "searx commit" "$SEARX_COMMIT" $SEARX_REPO
  758. # restore the background image
  759. if [ -f ${background_image}.prev ]; then
  760. cp ${background_image}.prev ${background_image}
  761. chown -R searx:searx ${SEARX_PATH}/searx
  762. fi
  763. # restore the settings
  764. if [ -f ${settings_file}.prev ]; then
  765. cp ${settings_file}.prev ${settings_file}
  766. chown -R searx:searx ${SEARX_PATH}/searx
  767. fi
  768. # remove the github ribbon icon
  769. if [ -f /etc/searx/searx/static/themes/courgette/img/github_ribbon.png ]; then
  770. mv /etc/searx/searx/static/themes/courgette/img/github_ribbon.png /etc/searx/searx/static/themes/courgette/img/github_ribbon.png.old
  771. fi
  772. }
  773. function backup_local_searx {
  774. echo -n ''
  775. }
  776. function restore_local_searx {
  777. echo -n ''
  778. }
  779. function backup_remote_searx {
  780. echo -n ''
  781. }
  782. function restore_remote_searx {
  783. echo -n ''
  784. }
  785. function remove_searx {
  786. systemctl stop searx
  787. systemctl disable searx
  788. rm /etc/systemd/system/searx.service
  789. systemctl daemon-reload
  790. function_check remove_onion_service
  791. remove_onion_service searx ${SEARX_ONION_PORT}
  792. userdel -r searx
  793. nginx_dissite searx
  794. if [ -f /etc/nginx/sites-available/searx ]; then
  795. rm /etc/nginx/sites-available/searx
  796. fi
  797. if [ -d ${SEARX_PATH}/searx ]; then
  798. rm -rf ${SEARX_PATH}/searx
  799. fi
  800. remove_completion_param install_searx
  801. sed -i '/Search engine /d' "$COMPLETION_FILE"
  802. sed -i '/searx /d' "$COMPLETION_FILE"
  803. }
  804. function install_searx {
  805. # Note: currently socks5 outgoing proxies to other search engines does not work
  806. if [ ! -d /etc/nginx ]; then
  807. echo $'Webserver is not installed'
  808. exit 62429
  809. fi
  810. apt-get -yq install python-pip libyaml-dev python-werkzeug python-babel python-lxml
  811. apt-get -yq install git build-essential libxslt-dev python-dev python-virtualenv zlib1g-dev uwsgi uwsgi-plugin-python imagemagick
  812. apt-get -yq install apache2-utils python-setuptools
  813. apt-get -yq install python-service-identity python-ndg-httpsclient
  814. apt-get -yq remove --purge apache2-bin*
  815. if [ -d /etc/apache2 ]; then
  816. rm -rf /etc/apache2
  817. echo $'Removed Apache installation'
  818. fi
  819. pip install --upgrade pip
  820. if ! pip install certifi; then
  821. echo $'Failed to install certifi'
  822. exit 737692
  823. fi
  824. if ! pip install pyyaml; then
  825. echo $'Failed to install pyyaml'
  826. exit 469242
  827. fi
  828. if ! pip install flask --upgrade; then
  829. echo $'Failed to install flask'
  830. exit 888575
  831. fi
  832. if ! pip install flask_restless --upgrade; then
  833. echo $'Failed to install flask_restless'
  834. exit 54835
  835. fi
  836. if ! pip install flask_babel --upgrade; then
  837. echo $'Failed to install flask_babel'
  838. exit 63738
  839. fi
  840. if ! pip install requests --upgrade; then
  841. echo $'Failed to install requests'
  842. exit 357282
  843. fi
  844. if ! pip install pygments --upgrade; then
  845. echo $'Failed to install pygments'
  846. exit 357282
  847. fi
  848. if [ ! -d $SEARX_PATH ]; then
  849. mkdir -p $SEARX_PATH
  850. fi
  851. # clone the repo
  852. cd $SEARX_PATH || exit 26482468
  853. if [ -d /repos/searx ]; then
  854. mkdir searx
  855. cp -r -p /repos/searx/. searx
  856. cd searx || exit 2468246
  857. git pull
  858. else
  859. function_check git_clone
  860. git_clone $SEARX_REPO searx
  861. fi
  862. git checkout $SEARX_COMMIT -b $SEARX_COMMIT
  863. set_completion_param "searx commit" "$SEARX_COMMIT"
  864. # create an onion service
  865. USE_V2_ONION_ADDRESS=1
  866. SEARX_ONION_HOSTNAME=$(add_onion_service searx 80 ${SEARX_ONION_PORT})
  867. # an unprivileged user to run as
  868. useradd -d ${SEARX_PATH}/searx/ -s /bin/false searx
  869. adduser searx debian-tor
  870. # daemon
  871. { echo '[Unit]';
  872. echo 'Description=Searx (search engine)';
  873. echo 'After=syslog.target';
  874. echo 'After=network.target';
  875. echo '';
  876. echo '[Service]';
  877. echo 'Type=simple';
  878. echo 'User=searx';
  879. echo 'Group=searx';
  880. echo "WorkingDirectory=${SEARX_PATH}/searx";
  881. echo "ExecStart=/usr/bin/python ${SEARX_PATH}/searx/searx/webapp.py";
  882. echo 'Restart=always';
  883. echo 'Environment="USER=searx"';
  884. echo '';
  885. echo '[Install]';
  886. echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/searx.service
  887. # create a webserver file
  888. { echo 'server {';
  889. echo " listen 127.0.0.1:${SEARX_ONION_PORT} default_server;";
  890. echo " root ${SEARX_PATH}/searx;";
  891. echo " server_name ${SEARX_ONION_HOSTNAME};";
  892. echo ' access_log /dev/null;';
  893. echo " error_log /var/log/searx_error.log $WEBSERVER_LOG_LEVEL;";
  894. echo ''; } > /etc/nginx/sites-available/searx
  895. function_check nginx_security_options
  896. nginx_security_options searx
  897. { echo ' add_header Strict-Transport-Security max-age=0;';
  898. echo '';
  899. echo ' location / {'; } >> /etc/nginx/sites-available/searx
  900. function_check nginx_limits
  901. nginx_limits searx '1M'
  902. { echo " proxy_pass http://localhost:${SEARX_PORT};";
  903. echo " #auth_basic \"${SEARX_LOGIN_TEXT}\";";
  904. echo ' #auth_basic_user_file /etc/nginx/.htpasswd;';
  905. echo ' }';
  906. echo '';
  907. echo ' fastcgi_buffers 64 4K;';
  908. echo '';
  909. echo ' error_page 403 /core/templates/403.php;';
  910. echo ' error_page 404 /core/templates/404.php;';
  911. echo '';
  912. echo ' location = /robots.txt {';
  913. echo ' allow all;';
  914. echo ' log_not_found off;';
  915. echo ' access_log /dev/null;';
  916. echo ' }';
  917. echo '}'; } >> /etc/nginx/sites-available/searx
  918. # replace the secret key
  919. if ! grep -q "searx key" "$COMPLETION_FILE"; then
  920. SEARX_SECRET_KEY="$(create_password 30)"
  921. set_completion_param "searx key" "${SEARX_SECRET_KEY}"
  922. fi
  923. create_searx_config
  924. searx_set_default_background
  925. chown -R searx:searx ${SEARX_PATH}/searx
  926. # enable the site
  927. nginx_ensite searx
  928. # restart the web server
  929. systemctl restart php7.0-fpm
  930. systemctl restart nginx
  931. # start the daemon
  932. systemctl enable searx.service
  933. systemctl daemon-reload
  934. systemctl start searx.service
  935. SEARX_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
  936. "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a searx -p "$SEARX_PASSWORD"
  937. if grep -q "$MY_USERNAME:" /etc/nginx/.htpasswd; then
  938. sed -i "/$MY_USERNAME:/d" /etc/nginx/.htpasswd
  939. fi
  940. echo "$SEARX_PASSWORD" | htpasswd -i -s -c /etc/nginx/.htpasswd "$MY_USERNAME"
  941. APP_INSTALLED=1
  942. }
  943. # NOTE: deliberately no exit 0