freedombone-app-searx 35KB

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