freedombone-app-searx 35KB

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