freedombone-app-searx 44KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  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-2017 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
  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=$(tempfile 2>/dev/null)
  114. trap "rm -f $data" 0 1 2 5 15
  115. dialog --title $"SearX Metasearch" \
  116. --backtitle $"Freedombone Control Panel" \
  117. --inputbox $'Set a background image URL' 10 60 2>$data
  118. sel=$?
  119. case $sel in
  120. 0)
  121. temp_background=$(<$data)
  122. if [ ${#temp_background} -gt 0 ]; then
  123. SEARX_BACKGROUND_IMAGE_URL="$temp_background"
  124. write_config_param "SEARX_BACKGROUND_IMAGE_URL" "$SEARX_BACKGROUND_IMAGE_URL"
  125. if [[ $(searx_set_background_image_from_url "$SEARX_BACKGROUND_IMAGE_URL" | tail -n 1) == "0" ]]; then
  126. dialog --title $"Set SearX background" \
  127. --msgbox $"The background image has been set" 6 60
  128. fi
  129. fi
  130. ;;
  131. esac
  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=$(tempfile 2>/dev/null)
  163. trap "rm -f $data" 0 1 2 5 15
  164. dialog --backtitle $"Freedombone Control Panel" \
  165. --title $"SearX Metasearch" \
  166. --radiolist $"Choose an operation:" 12 70 3 \
  167. 1 $"Set a background image" off \
  168. 2 $"Enable login" off \
  169. 3 $"Exit" on 2> $data
  170. sel=$?
  171. case $sel in
  172. 1) return;;
  173. 255) return;;
  174. esac
  175. case $(cat $data) in
  176. 1) searx_set_background_image;;
  177. 2) searx_enable_login;;
  178. 3) break;;
  179. esac
  180. done
  181. }
  182. function remove_user_searx {
  183. remove_username="$1"
  184. ${PROJECT_NAME}-pass -u $remove_username --rmapp searx
  185. if grep -q "$remove_username:" /etc/nginx/.htpasswd; then
  186. sed -i "/$remove_username:/d" /etc/nginx/.htpasswd
  187. fi
  188. }
  189. function add_user_searx {
  190. if [[ $(app_is_installed searx) == "0" ]]; then
  191. echo '0'
  192. return
  193. fi
  194. new_username="$1"
  195. new_user_password="$2"
  196. ${PROJECT_NAME}-pass -u $new_username -a searx -p "$new_user_password"
  197. if grep -q "$new_username:" /etc/nginx/.htpasswd; then
  198. sed -i "/$new_username:/d" /etc/nginx/.htpasswd
  199. fi
  200. echo "$new_user_password" | htpasswd -i -s -c /etc/nginx/.htpasswd $new_username
  201. echo '0'
  202. }
  203. function install_interactive_searx {
  204. echo -n ''
  205. APP_INSTALLED=1
  206. }
  207. function change_password_searx {
  208. new_username="$1"
  209. new_user_password="$2"
  210. if grep -q "$new_username:" /etc/nginx/.htpasswd; then
  211. sed -i "/$new_username:/d" /etc/nginx/.htpasswd
  212. echo "$new_user_password" | htpasswd -i -s -c /etc/nginx/.htpasswd $new_username
  213. ${PROJECT_NAME}-pass -u $curr_username -a searx -p "$new_user_password"
  214. echo '0'
  215. fi
  216. echo '1'
  217. }
  218. function reconfigure_searx {
  219. echo -n ''
  220. }
  221. function create_searx_config {
  222. settings_file=${SEARX_PATH}/searx/searx/settings.yml
  223. SEARX_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_searx/hostname)
  224. SEARX_SECRET_KEY=$(get_completion_param "searx key")
  225. echo 'general:' > $settings_file
  226. echo ' debug : False' >> $settings_file
  227. echo ' instance_name : "Freedombone Metasearch"' >> $settings_file
  228. echo '' >> $settings_file
  229. echo 'search:' >> $settings_file
  230. echo ' safe_search : 0 # Filter results. 0: None, 1: Moderate, 2: Strict' >> $settings_file
  231. echo ' autocomplete : "" # Existing autocomplete backends: "dbpedia", "duckduckgo", "startpage", "wikipedia" - leave blank to turn it off by default' >> $settings_file
  232. echo ' language : "all"' >> $settings_file
  233. echo '' >> $settings_file
  234. echo 'server:' >> $settings_file
  235. echo ' port : 8888' >> $settings_file
  236. echo ' bind_address : "127.0.0.1" # address to listen on' >> $settings_file
  237. echo " secret_key : \"${SEARX_SECRET_KEY}\"" >> $settings_file
  238. echo " base_url : http://${SEARX_ONION_HOSTNAME}/" >> $settings_file
  239. echo ' image_proxy : True # Proxying image results through searx' >> $settings_file
  240. echo ' http_protocol_version : "1.1" # 1.0 and 1.1 are supported' >> $settings_file
  241. echo '' >> $settings_file
  242. echo 'ui:' >> $settings_file
  243. echo ' static_path : "" # Custom static path - leave it blank if you didnt change' >> $settings_file
  244. echo ' templates_path : "" # Custom templates path - leave it blank if you didnt change' >> $settings_file
  245. echo ' themes_path : "" # Custom ui themes path' >> $settings_file
  246. echo ' default_theme : courgette # ui theme' >> $settings_file
  247. echo ' default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section' >> $settings_file
  248. echo '' >> $settings_file
  249. echo 'outgoing: # communication with search engines' >> $settings_file
  250. echo ' request_timeout : 10.0 # seconds' >> $settings_file
  251. echo ' useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator' >> $settings_file
  252. echo ' pool_connections : 100 # Number of different hosts' >> $settings_file
  253. echo ' pool_maxsize : 10 # Number of simultaneous requests by host' >> $settings_file
  254. echo ' proxies :' >> $settings_file
  255. echo ' http : socks5://127.0.0.1:9050' >> $settings_file
  256. echo '' >> $settings_file
  257. echo 'engines:' >> $settings_file
  258. echo ' - name : arch linux wiki' >> $settings_file
  259. echo ' engine : archlinux' >> $settings_file
  260. echo ' categories : general' >> $settings_file
  261. echo ' shortcut : al' >> $settings_file
  262. echo '' >> $settings_file
  263. echo ' - name : archive is' >> $settings_file
  264. echo ' engine : xpath' >> $settings_file
  265. echo ' search_url : https://archive.is/{query}' >> $settings_file
  266. echo ' url_xpath : (//div[@class="TEXT-BLOCK"]/a)/@href' >> $settings_file
  267. echo ' title_xpath : (//div[@class="TEXT-BLOCK"]/a)' >> $settings_file
  268. echo ' content_xpath : //div[@class="TEXT-BLOCK"]/ul/li' >> $settings_file
  269. echo ' categories : general' >> $settings_file
  270. echo ' timeout : 7.0' >> $settings_file
  271. echo ' disabled : True' >> $settings_file
  272. echo ' shortcut : ai' >> $settings_file
  273. echo '' >> $settings_file
  274. echo ' - name : base' >> $settings_file
  275. echo ' engine : base' >> $settings_file
  276. echo ' shortcut : bs' >> $settings_file
  277. echo '' >> $settings_file
  278. echo ' - name : wikipedia' >> $settings_file
  279. echo ' engine : wikipedia' >> $settings_file
  280. echo ' shortcut : wp' >> $settings_file
  281. echo ' categories : general' >> $settings_file
  282. echo ' base_url : "https://{language}.wikipedia.org/"' >> $settings_file
  283. echo '' >> $settings_file
  284. echo ' - name : bitbucket' >> $settings_file
  285. echo ' engine : xpath' >> $settings_file
  286. echo ' paging : True' >> $settings_file
  287. echo ' search_url : https://bitbucket.org/repo/all/{pageno}?name={query}' >> $settings_file
  288. echo ' url_xpath : //article[@class="repo-summary"]//a[@class="repo-link"]/@href' >> $settings_file
  289. echo ' title_xpath : //article[@class="repo-summary"]//a[@class="repo-link"]' >> $settings_file
  290. echo ' content_xpath : //article[@class="repo-summary"]/p' >> $settings_file
  291. echo ' categories : code' >> $settings_file
  292. echo ' timeout : 4.0' >> $settings_file
  293. echo ' disabled : True' >> $settings_file
  294. echo ' shortcut : bb' >> $settings_file
  295. echo '' >> $settings_file
  296. echo ' - name : ccc-tv' >> $settings_file
  297. echo ' engine : xpath' >> $settings_file
  298. echo ' paging : False' >> $settings_file
  299. echo ' search_url : https://media.ccc.de/search/?q={query}' >> $settings_file
  300. echo ' url_xpath : //div[@class="caption"]/h3/a/@href' >> $settings_file
  301. echo ' title_xpath : //div[@class="caption"]/h3/a/text()' >> $settings_file
  302. echo ' content_xpath : //div[@class="caption"]/h4/@title' >> $settings_file
  303. echo ' categories : videos' >> $settings_file
  304. echo ' shortcut : c3tv' >> $settings_file
  305. echo '' >> $settings_file
  306. echo ' - name : crossref' >> $settings_file
  307. echo ' engine : json_engine' >> $settings_file
  308. echo ' paging : True' >> $settings_file
  309. echo ' search_url : http://search.crossref.org/dois?q={query}&page={pageno}' >> $settings_file
  310. echo ' url_query : doi' >> $settings_file
  311. echo ' title_query : title' >> $settings_file
  312. echo ' content_query : fullCitation' >> $settings_file
  313. echo ' categories : science' >> $settings_file
  314. echo ' shortcut : cr' >> $settings_file
  315. echo '' >> $settings_file
  316. echo ' - name : currency' >> $settings_file
  317. echo ' engine : currency_convert' >> $settings_file
  318. echo ' categories : general' >> $settings_file
  319. echo ' shortcut : cc' >> $settings_file
  320. echo '' >> $settings_file
  321. echo ' - name : deezer' >> $settings_file
  322. echo ' engine : deezer' >> $settings_file
  323. echo ' shortcut : dz' >> $settings_file
  324. echo '' >> $settings_file
  325. echo ' - name : deviantart' >> $settings_file
  326. echo ' engine : deviantart' >> $settings_file
  327. echo ' shortcut : da' >> $settings_file
  328. echo ' timeout: 3.0' >> $settings_file
  329. echo '' >> $settings_file
  330. echo ' - name : ddg definitions' >> $settings_file
  331. echo ' engine : duckduckgo_definitions' >> $settings_file
  332. echo ' shortcut : ddd' >> $settings_file
  333. echo ' weight : 2' >> $settings_file
  334. echo ' disabled : True' >> $settings_file
  335. echo '' >> $settings_file
  336. echo ' - name : digbt' >> $settings_file
  337. echo ' engine : digbt' >> $settings_file
  338. echo ' shortcut : dbt' >> $settings_file
  339. echo ' timeout : 6.0' >> $settings_file
  340. echo ' disabled : True' >> $settings_file
  341. echo '' >> $settings_file
  342. echo ' - name : erowid' >> $settings_file
  343. echo ' engine : xpath' >> $settings_file
  344. echo ' paging : True' >> $settings_file
  345. echo ' first_page_num : 0' >> $settings_file
  346. echo ' page_size : 30' >> $settings_file
  347. echo ' search_url : https://www.erowid.org/search.php?q={query}&s={pageno}' >> $settings_file
  348. echo ' url_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/@href' >> $settings_file
  349. echo ' title_xpath : //dl[@class="results-list"]/dt[@class="result-title"]/a/text()' >> $settings_file
  350. echo ' content_xpath : //dl[@class="results-list"]/dd[@class="result-details"]' >> $settings_file
  351. echo ' categories : general' >> $settings_file
  352. echo ' shortcut : ew' >> $settings_file
  353. echo ' disabled : True' >> $settings_file
  354. echo '' >> $settings_file
  355. echo ' - name : wikidata' >> $settings_file
  356. echo ' engine : wikidata' >> $settings_file
  357. echo ' shortcut : wd' >> $settings_file
  358. echo ' weight : 2' >> $settings_file
  359. echo '' >> $settings_file
  360. echo ' - name : duckduckgo' >> $settings_file
  361. echo ' engine : duckduckgo' >> $settings_file
  362. echo ' shortcut : ddg' >> $settings_file
  363. echo ' categories : general' >> $settings_file
  364. echo '' >> $settings_file
  365. echo ' - name : etymonline' >> $settings_file
  366. echo ' engine : xpath' >> $settings_file
  367. echo ' paging : True' >> $settings_file
  368. echo ' search_url : http://etymonline.com/?search={query}&p={pageno}' >> $settings_file
  369. echo ' url_xpath : //dt/a[1]/@href' >> $settings_file
  370. echo ' title_xpath : //dt' >> $settings_file
  371. echo ' content_xpath : //dd' >> $settings_file
  372. echo ' suggestion_xpath : //a[@class="crossreference"]' >> $settings_file
  373. echo ' first_page_num : 0' >> $settings_file
  374. echo ' shortcut : et' >> $settings_file
  375. echo ' disabled : True' >> $settings_file
  376. echo '' >> $settings_file
  377. echo ' - name : 500px' >> $settings_file
  378. echo ' engine : www500px' >> $settings_file
  379. echo ' shortcut : px' >> $settings_file
  380. echo '' >> $settings_file
  381. echo ' - name : 1x' >> $settings_file
  382. echo ' engine : www1x' >> $settings_file
  383. echo ' shortcut : 1x' >> $settings_file
  384. echo ' disabled : True' >> $settings_file
  385. echo '' >> $settings_file
  386. echo ' - name : fdroid' >> $settings_file
  387. echo ' engine : fdroid' >> $settings_file
  388. echo ' shortcut : fd' >> $settings_file
  389. echo ' disabled : True' >> $settings_file
  390. echo '' >> $settings_file
  391. echo ' - name : flickr' >> $settings_file
  392. echo ' categories : images' >> $settings_file
  393. echo ' shortcut : fl' >> $settings_file
  394. echo '# You can use the engine using the official stable API, but you need an API key' >> $settings_file
  395. echo '# See : https://www.flickr.com/services/apps/create/' >> $settings_file
  396. echo '# engine : flickr' >> $settings_file
  397. echo '# api_key: 'apikey' # required!' >> $settings_file
  398. echo '# Or you can use the html non-stable engine, activated by default' >> $settings_file
  399. echo ' engine : flickr_noapi' >> $settings_file
  400. echo '' >> $settings_file
  401. echo ' - name : frinkiac' >> $settings_file
  402. echo ' engine : frinkiac' >> $settings_file
  403. echo ' shortcut : frk' >> $settings_file
  404. echo ' disabled : True' >> $settings_file
  405. echo '' >> $settings_file
  406. echo ' - name : gigablast' >> $settings_file
  407. echo ' engine : gigablast' >> $settings_file
  408. echo ' shortcut : gb' >> $settings_file
  409. echo ' timeout : 3.0' >> $settings_file
  410. echo ' disabled: True' >> $settings_file
  411. echo '' >> $settings_file
  412. echo ' - name : gitlab' >> $settings_file
  413. echo ' engine : xpath' >> $settings_file
  414. echo ' paging : True' >> $settings_file
  415. echo ' search_url : https://gitlab.com/search?page={pageno}&search={query}' >> $settings_file
  416. echo ' url_xpath : //li[@class="project-row"]//a[@class="project"]/@href' >> $settings_file
  417. echo ' title_xpath : //li[@class="project-row"]//span[contains(@class, "project-full-name")]' >> $settings_file
  418. echo ' content_xpath : //li[@class="project-row"]//div[@class="description"]/p' >> $settings_file
  419. echo ' categories : code' >> $settings_file
  420. echo ' shortcut : gl' >> $settings_file
  421. echo ' timeout : 5.0' >> $settings_file
  422. echo ' disabled : True' >> $settings_file
  423. echo '' >> $settings_file
  424. echo ' - name : github' >> $settings_file
  425. echo ' engine : github' >> $settings_file
  426. echo ' shortcut : gh' >> $settings_file
  427. echo ' categories : code' >> $settings_file
  428. echo '' >> $settings_file
  429. echo ' - name : geektimes' >> $settings_file
  430. echo ' engine : xpath' >> $settings_file
  431. echo ' paging : True' >> $settings_file
  432. echo ' search_url : https://geektimes.ru/search/page{pageno}/?q={query}' >> $settings_file
  433. echo ' url_xpath : //div[@class="search_results"]//a[@class="post__title_link"]/@href' >> $settings_file
  434. echo ' title_xpath : //div[@class="search_results"]//a[@class="post__title_link"]' >> $settings_file
  435. echo ' content_xpath : //div[@class="search_results"]//div[contains(@class, "content")]' >> $settings_file
  436. echo ' categories : code' >> $settings_file
  437. echo ' timeout : 4.0' >> $settings_file
  438. echo ' disabled : True' >> $settings_file
  439. echo ' shortcut : gt' >> $settings_file
  440. echo '' >> $settings_file
  441. echo ' - name : habrahabr' >> $settings_file
  442. echo ' engine : xpath' >> $settings_file
  443. echo ' paging : True' >> $settings_file
  444. echo ' search_url : https://habrahabr.ru/search/page{pageno}/?q={query}' >> $settings_file
  445. echo ' url_xpath : //div[@class="search_results"]//a[contains(@class, "post__title_link")]/@href' >> $settings_file
  446. echo ' title_xpath : //div[@class="search_results"]//a[contains(@class, "post__title_link")]' >> $settings_file
  447. echo ' content_xpath : //div[@class="search_results"]//div[contains(@class, "content")]' >> $settings_file
  448. echo ' categories : code' >> $settings_file
  449. echo ' timeout : 4.0' >> $settings_file
  450. echo ' disabled : True' >> $settings_file
  451. echo ' shortcut : habr' >> $settings_file
  452. echo '' >> $settings_file
  453. echo ' - name : hoogle' >> $settings_file
  454. echo ' engine : json_engine' >> $settings_file
  455. echo ' paging : True' >> $settings_file
  456. echo ' search_url : https://www.haskell.org/hoogle/?mode=json&hoogle={query}&start={pageno}' >> $settings_file
  457. echo ' results_query : results' >> $settings_file
  458. echo ' url_query : location' >> $settings_file
  459. echo ' title_query : self' >> $settings_file
  460. echo ' content_query : docs' >> $settings_file
  461. echo ' page_size : 20' >> $settings_file
  462. echo ' categories : code' >> $settings_file
  463. echo ' shortcut : ho' >> $settings_file
  464. echo '' >> $settings_file
  465. echo ' - name : ina' >> $settings_file
  466. echo ' engine : ina' >> $settings_file
  467. echo ' shortcut : in' >> $settings_file
  468. echo ' timeout : 6.0' >> $settings_file
  469. echo ' disabled : True' >> $settings_file
  470. echo '' >> $settings_file
  471. echo ' - name: kickass' >> $settings_file
  472. echo ' engine : kickass' >> $settings_file
  473. echo ' shortcut : kc' >> $settings_file
  474. echo ' timeout : 4.0' >> $settings_file
  475. echo ' disabled : True' >> $settings_file
  476. echo '' >> $settings_file
  477. echo ' - name : library genesis' >> $settings_file
  478. echo ' engine : xpath' >> $settings_file
  479. echo ' search_url : http://libgen.io/search.php?req={query}' >> $settings_file
  480. echo ' url_xpath : //a[contains(@href,"bookfi.net")]/@href' >> $settings_file
  481. echo ' title_xpath : //a[contains(@href,"book/")]/text()[1]' >> $settings_file
  482. echo ' content_xpath : //td/a[1][contains(@href,"=author")]/text()' >> $settings_file
  483. echo ' categories : general' >> $settings_file
  484. echo ' timeout : 7.0' >> $settings_file
  485. echo ' disabled : True' >> $settings_file
  486. echo ' shortcut : lg' >> $settings_file
  487. echo '' >> $settings_file
  488. echo ' - name : lobste.rs' >> $settings_file
  489. echo ' engine : xpath' >> $settings_file
  490. echo ' search_url : https://lobste.rs/search?utf8=%E2%9C%93&q={query}&what=stories&order=relevance' >> $settings_file
  491. echo ' results_xpath : //li[contains(@class, "story")]' >> $settings_file
  492. echo ' url_xpath : .//span[@class="link"]/a/@href' >> $settings_file
  493. echo ' title_xpath : .//span[@class="link"]/a' >> $settings_file
  494. echo ' content_xpath : .//a[@class="domain"]' >> $settings_file
  495. echo ' categories : code' >> $settings_file
  496. echo ' shortcut : lo' >> $settings_file
  497. echo '' >> $settings_file
  498. echo ' - name : mixcloud' >> $settings_file
  499. echo ' engine : mixcloud' >> $settings_file
  500. echo ' shortcut : mc' >> $settings_file
  501. echo '' >> $settings_file
  502. echo ' - name : nyaa' >> $settings_file
  503. echo ' engine : nyaa' >> $settings_file
  504. echo ' shortcut : nt' >> $settings_file
  505. echo ' disabled : True' >> $settings_file
  506. echo '' >> $settings_file
  507. echo ' - name : openstreetmap' >> $settings_file
  508. echo ' engine : openstreetmap' >> $settings_file
  509. echo ' shortcut : osm' >> $settings_file
  510. echo '' >> $settings_file
  511. echo ' - name : openrepos' >> $settings_file
  512. echo ' engine : xpath' >> $settings_file
  513. echo ' paging : True' >> $settings_file
  514. echo ' search_url : https://openrepos.net/search/node/{query}?page={pageno}' >> $settings_file
  515. echo ' url_xpath : //li[@class="search-result"]//h3[@class="title"]/a/@href' >> $settings_file
  516. echo ' title_xpath : //li[@class="search-result"]//h3[@class="title"]/a' >> $settings_file
  517. echo ' content_xpath : //li[@class="search-result"]//div[@class="search-snippet-info"]//p[@class="search-snippet"]' >> $settings_file
  518. echo ' categories : files' >> $settings_file
  519. echo ' timeout : 4.0' >> $settings_file
  520. echo ' disabled : True' >> $settings_file
  521. echo ' shortcut : or' >> $settings_file
  522. echo '' >> $settings_file
  523. echo ' - name : pdbe' >> $settings_file
  524. echo ' engine : pdbe' >> $settings_file
  525. echo ' shortcut : pdb' >> $settings_file
  526. echo '' >> $settings_file
  527. echo ' - name : photon' >> $settings_file
  528. echo ' engine : photon' >> $settings_file
  529. echo ' shortcut : ph' >> $settings_file
  530. echo '' >> $settings_file
  531. echo ' - name : piratebay' >> $settings_file
  532. echo ' engine : piratebay' >> $settings_file
  533. echo ' shortcut : tpb' >> $settings_file
  534. echo ' url: https://pirateproxy.red/' >> $settings_file
  535. echo ' timeout : 3.0' >> $settings_file
  536. echo '' >> $settings_file
  537. echo ' - name : qwant' >> $settings_file
  538. echo ' engine : qwant' >> $settings_file
  539. echo ' shortcut : qw' >> $settings_file
  540. echo ' categories : general' >> $settings_file
  541. echo ' disabled : True' >> $settings_file
  542. echo '' >> $settings_file
  543. echo ' - name : qwant images' >> $settings_file
  544. echo ' engine : qwant' >> $settings_file
  545. echo ' shortcut : qwi' >> $settings_file
  546. echo ' categories : images' >> $settings_file
  547. echo '' >> $settings_file
  548. echo ' - name : qwant news' >> $settings_file
  549. echo ' engine : qwant' >> $settings_file
  550. echo ' shortcut : qwn' >> $settings_file
  551. echo ' categories : news' >> $settings_file
  552. echo '' >> $settings_file
  553. echo ' - name : qwant social' >> $settings_file
  554. echo ' engine : qwant' >> $settings_file
  555. echo ' shortcut : qws' >> $settings_file
  556. echo ' categories : social media' >> $settings_file
  557. echo '' >> $settings_file
  558. echo ' - name : reddit' >> $settings_file
  559. echo ' engine : reddit' >> $settings_file
  560. echo ' shortcut : re' >> $settings_file
  561. echo ' page_size : 25' >> $settings_file
  562. echo ' timeout : 10.0' >> $settings_file
  563. echo ' disabled : True' >> $settings_file
  564. echo '' >> $settings_file
  565. echo ' - name : scanr structures' >> $settings_file
  566. echo ' shortcut: scs' >> $settings_file
  567. echo ' engine : scanr_structures' >> $settings_file
  568. echo ' disabled : True' >> $settings_file
  569. echo '' >> $settings_file
  570. echo ' - name : soundcloud' >> $settings_file
  571. echo ' engine : soundcloud' >> $settings_file
  572. echo ' shortcut : sc' >> $settings_file
  573. echo '' >> $settings_file
  574. echo ' - name : stackoverflow' >> $settings_file
  575. echo ' engine : stackoverflow' >> $settings_file
  576. echo ' shortcut : st' >> $settings_file
  577. echo '' >> $settings_file
  578. echo ' - name : searchcode doc' >> $settings_file
  579. echo ' engine : searchcode_doc' >> $settings_file
  580. echo ' shortcut : scd' >> $settings_file
  581. echo '' >> $settings_file
  582. echo ' - name : searchcode code' >> $settings_file
  583. echo ' engine : searchcode_code' >> $settings_file
  584. echo ' shortcut : scc' >> $settings_file
  585. echo ' disabled : True' >> $settings_file
  586. echo '' >> $settings_file
  587. echo ' - name : framalibre' >> $settings_file
  588. echo ' engine : framalibre' >> $settings_file
  589. echo ' shortcut : frl' >> $settings_file
  590. echo ' disabled : True' >> $settings_file
  591. echo '' >> $settings_file
  592. echo ' - name : semantic scholar' >> $settings_file
  593. echo ' engine : xpath' >> $settings_file
  594. echo ' paging : True' >> $settings_file
  595. echo ' search_url : https://www.semanticscholar.org/search?q={query}&sort=relevance&page={pageno}&ae=false' >> $settings_file
  596. echo ' results_xpath : //article' >> $settings_file
  597. echo ' url_xpath : .//div[@class="search-result-title"]/a/@href' >> $settings_file
  598. echo ' title_xpath : .//div[@class="search-result-title"]/a' >> $settings_file
  599. echo ' content_xpath : .//div[@class="search-result-abstract"]' >> $settings_file
  600. echo ' shortcut : se' >> $settings_file
  601. echo ' categories : science' >> $settings_file
  602. echo '' >> $settings_file
  603. echo ' - name : spotify' >> $settings_file
  604. echo ' engine : spotify' >> $settings_file
  605. echo ' shortcut : stf' >> $settings_file
  606. echo '' >> $settings_file
  607. echo ' - name : subtitleseeker' >> $settings_file
  608. echo ' engine : subtitleseeker' >> $settings_file
  609. echo ' shortcut : ss' >> $settings_file
  610. echo '# The language is an option. You can put any language written in english' >> $settings_file
  611. echo '# Examples : English, French, German, Hungarian, Chinese...' >> $settings_file
  612. echo '# language : English' >> $settings_file
  613. echo '' >> $settings_file
  614. echo ' - name : startpage' >> $settings_file
  615. echo ' engine : startpage' >> $settings_file
  616. echo ' shortcut : sp' >> $settings_file
  617. echo ' timeout : 6.0' >> $settings_file
  618. echo ' disabled : True' >> $settings_file
  619. echo '' >> $settings_file
  620. echo ' - name : ixquick' >> $settings_file
  621. echo ' engine : startpage' >> $settings_file
  622. echo " base_url : 'https://www.ixquick.eu/'" >> $settings_file
  623. echo " search_url : 'https://www.ixquick.eu/do/search'" >> $settings_file
  624. echo ' shortcut : iq' >> $settings_file
  625. echo ' timeout : 6.0' >> $settings_file
  626. echo '' >> $settings_file
  627. echo ' - name : swisscows' >> $settings_file
  628. echo ' engine : swisscows' >> $settings_file
  629. echo ' shortcut : sw' >> $settings_file
  630. echo ' disabled : True' >> $settings_file
  631. echo '' >> $settings_file
  632. echo ' - name : tokyotoshokan' >> $settings_file
  633. echo ' engine : tokyotoshokan' >> $settings_file
  634. echo ' shortcut : tt' >> $settings_file
  635. echo ' timeout : 6.0' >> $settings_file
  636. echo ' disabled : True' >> $settings_file
  637. echo '' >> $settings_file
  638. echo ' - name : twitter' >> $settings_file
  639. echo ' engine : twitter' >> $settings_file
  640. echo ' shortcut : tw' >> $settings_file
  641. echo '' >> $settings_file
  642. echo ' - name : urbandictionary' >> $settings_file
  643. echo ' engine : xpath' >> $settings_file
  644. echo ' search_url : http://www.urbandictionary.com/define.php?term={query}' >> $settings_file
  645. echo ' url_xpath : //*[@class="word"]/@href' >> $settings_file
  646. echo ' title_xpath : //*[@class="def-header"]' >> $settings_file
  647. echo ' content_xpath : //*[@class="meaning"]' >> $settings_file
  648. echo ' shortcut : ud' >> $settings_file
  649. echo '' >> $settings_file
  650. echo ' - name : yandex' >> $settings_file
  651. echo ' engine : yandex' >> $settings_file
  652. echo ' shortcut : yn' >> $settings_file
  653. echo ' disabled : True' >> $settings_file
  654. echo '' >> $settings_file
  655. echo ' - name : youtube' >> $settings_file
  656. echo ' shortcut : yt' >> $settings_file
  657. echo ' # You can use the engine using the official stable API, but you need an API key' >> $settings_file
  658. echo ' # See : https://console.developers.google.com/project' >> $settings_file
  659. echo ' # engine : youtube_api' >> $settings_file
  660. echo ' # api_key: apikey # required!' >> $settings_file
  661. echo ' # Or you can use the html non-stable engine, activated by default' >> $settings_file
  662. echo ' engine : youtube_noapi' >> $settings_file
  663. echo '' >> $settings_file
  664. echo ' - name : dailymotion' >> $settings_file
  665. echo ' engine : dailymotion' >> $settings_file
  666. echo ' shortcut : dm' >> $settings_file
  667. echo '' >> $settings_file
  668. echo ' - name : vimeo' >> $settings_file
  669. echo ' engine : vimeo' >> $settings_file
  670. echo ' shortcut : vm' >> $settings_file
  671. echo '' >> $settings_file
  672. echo ' - name : wolframalpha' >> $settings_file
  673. echo ' shortcut : wa' >> $settings_file
  674. echo ' # You can use the engine using the official stable API, but you need an API key' >> $settings_file
  675. echo ' # See : http://products.wolframalpha.com/api/' >> $settings_file
  676. echo ' # engine : wolframalpha_api' >> $settings_file
  677. echo ' # api_key: '' # required!' >> $settings_file
  678. echo ' engine : wolframalpha_noapi' >> $settings_file
  679. echo ' timeout: 6.0' >> $settings_file
  680. echo ' categories : science' >> $settings_file
  681. echo '' >> $settings_file
  682. echo ' - name : seedpeer' >> $settings_file
  683. echo ' engine : seedpeer' >> $settings_file
  684. echo ' shortcut: speu'
  685. echo ' categories: files, music, videos'
  686. echo ' disabled: True' >> $settings_file
  687. echo '' >> $settings_file
  688. echo ' - name : dictzone' >> $settings_file
  689. echo ' engine : dictzone' >> $settings_file
  690. echo ' shortcut : dc' >> $settings_file
  691. echo '' >> $settings_file
  692. echo ' - name : mymemory translated' >> $settings_file
  693. echo ' engine : translated' >> $settings_file
  694. echo ' shortcut : tl' >> $settings_file
  695. echo ' timeout : 5.0' >> $settings_file
  696. echo ' disabled : True' >> $settings_file
  697. echo ' # You can use without an API key, but you are limited to 1000 words/day' >> $settings_file
  698. echo ' # See : http://mymemory.translated.net/doc/usagelimits.php' >> $settings_file
  699. echo ' # api_key : ""' >> $settings_file
  700. echo '' >> $settings_file
  701. echo ' - name : voat' >> $settings_file
  702. echo ' engine: xpath' >> $settings_file
  703. echo ' shortcut: vo' >> $settings_file
  704. echo ' categories: social media' >> $settings_file
  705. echo ' search_url : https://voat.co/search?q={query}' >> $settings_file
  706. echo ' url_xpath : //p[contains(@class, "title")]/a/@href' >> $settings_file
  707. echo ' title_xpath : //p[contains(@class, "title")]/a' >> $settings_file
  708. echo ' content_xpath : //span[@class="domain"]' >> $settings_file
  709. echo ' timeout : 10.0' >> $settings_file
  710. echo ' disabled : True' >> $settings_file
  711. echo '' >> $settings_file
  712. echo ' - name : 1337x' >> $settings_file
  713. echo ' engine : 1337x' >> $settings_file
  714. echo ' shortcut : 1337x' >> $settings_file
  715. echo ' disabled : True' >> $settings_file
  716. echo '' >> $settings_file
  717. echo 'locales:' >> $settings_file
  718. echo ' en : English' >> $settings_file
  719. echo ' bg : Български (Bulgarian)' >> $settings_file
  720. echo ' cs : Čeština (Czech)' >> $settings_file
  721. echo ' de : Deutsch (German)' >> $settings_file
  722. echo ' de_DE : Deutsch (German_Germany)' >> $settings_file
  723. echo ' el_GR : Ελληνικά (Greek_Greece)' >> $settings_file
  724. echo ' eo : Esperanto (Esperanto)' >> $settings_file
  725. echo ' es : Español (Spanish)' >> $settings_file
  726. echo ' fi : Suomi (Finnish)' >> $settings_file
  727. echo ' fr : Français (French)' >> $settings_file
  728. echo ' he : עברית (Hebrew)' >> $settings_file
  729. echo ' hu : Magyar (Hungarian)' >> $settings_file
  730. echo ' it : Italiano (Italian)' >> $settings_file
  731. echo ' ja : 日本語 (Japanese)' >> $settings_file
  732. echo ' nl : Nederlands (Dutch)' >> $settings_file
  733. echo ' pt : Português (Portuguese)' >> $settings_file
  734. echo ' pt_BR : Português (Portuguese_Brazil)' >> $settings_file
  735. echo ' ro : Română (Romanian)' >> $settings_file
  736. echo ' ru : Русский (Russian)' >> $settings_file
  737. echo ' sk : Slovenčina (Slovak)' >> $settings_file
  738. echo ' sv : Svenska (Swedish)' >> $settings_file
  739. echo ' tr : Türkçe (Turkish)' >> $settings_file
  740. echo ' uk : українська мова (Ukrainian)' >> $settings_file
  741. echo ' zh : 中文 (Chinese)' >> $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. pip install certifi
  821. if [ ! "$?" = "0" ]; then
  822. echo $'Failed to install certifi'
  823. exit 737692
  824. fi
  825. pip install pyyaml
  826. if [ ! "$?" = "0" ]; then
  827. echo $'Failed to install pyyaml'
  828. exit 469242
  829. fi
  830. pip install flask --upgrade
  831. if [ ! "$?" = "0" ]; then
  832. echo $'Failed to install flask'
  833. exit 888575
  834. fi
  835. pip install flask_restless --upgrade
  836. if [ ! "$?" = "0" ]; then
  837. echo $'Failed to install flask_restless'
  838. exit 54835
  839. fi
  840. pip install flask_babel --upgrade
  841. if [ ! "$?" = "0" ]; then
  842. echo $'Failed to install flask_babel'
  843. exit 63738
  844. fi
  845. pip install requests --upgrade
  846. if [ ! "$?" = "0" ]; then
  847. echo $'Failed to install requests'
  848. exit 357282
  849. fi
  850. pip install pygments --upgrade
  851. if [ ! "$?" = "0" ]; then
  852. echo $'Failed to install pygments'
  853. exit 357282
  854. fi
  855. if [ ! -d $SEARX_PATH ]; then
  856. mkdir -p $SEARX_PATH
  857. fi
  858. # clone the repo
  859. cd $SEARX_PATH
  860. if [ -d /repos/searx ]; then
  861. mkdir searx
  862. cp -r -p /repos/searx/. searx
  863. cd searx
  864. git pull
  865. else
  866. function_check git_clone
  867. git_clone $SEARX_REPO searx
  868. fi
  869. git checkout $SEARX_COMMIT -b $SEARX_COMMIT
  870. set_completion_param "searx commit" "$SEARX_COMMIT"
  871. # create an onion service
  872. SEARX_ONION_HOSTNAME=$(add_onion_service searx 80 ${SEARX_ONION_PORT})
  873. # an unprivileged user to run as
  874. useradd -d ${SEARX_PATH}/searx/ -s /bin/false searx
  875. adduser searx debian-tor
  876. # daemon
  877. echo '[Unit]' > /etc/systemd/system/searx.service
  878. echo 'Description=Searx (search engine)' >> /etc/systemd/system/searx.service
  879. echo 'After=syslog.target' >> /etc/systemd/system/searx.service
  880. echo 'After=network.target' >> /etc/systemd/system/searx.service
  881. echo '' >> /etc/systemd/system/searx.service
  882. echo '[Service]' >> /etc/systemd/system/searx.service
  883. echo 'Type=simple' >> /etc/systemd/system/searx.service
  884. echo 'User=searx' >> /etc/systemd/system/searx.service
  885. echo 'Group=searx' >> /etc/systemd/system/searx.service
  886. echo "WorkingDirectory=${SEARX_PATH}/searx" >> /etc/systemd/system/searx.service
  887. echo "ExecStart=/usr/bin/python ${SEARX_PATH}/searx/searx/webapp.py" >> /etc/systemd/system/searx.service
  888. echo 'Restart=always' >> /etc/systemd/system/searx.service
  889. echo 'Environment="USER=searx"' >> /etc/systemd/system/searx.service
  890. echo '' >> /etc/systemd/system/searx.service
  891. echo '[Install]' >> /etc/systemd/system/searx.service
  892. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/searx.service
  893. # create a webserver file
  894. echo 'server {' > /etc/nginx/sites-available/searx
  895. echo " listen 127.0.0.1:${SEARX_ONION_PORT} default_server;" >> /etc/nginx/sites-available/searx
  896. echo " root ${SEARX_PATH}/searx;" >> /etc/nginx/sites-available/searx
  897. echo " server_name ${SEARX_ONION_HOSTNAME};" >> /etc/nginx/sites-available/searx
  898. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/searx
  899. echo " error_log /var/log/searx_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/searx
  900. echo '' >> /etc/nginx/sites-available/searx
  901. function_check nginx_disable_sniffing
  902. nginx_disable_sniffing searx
  903. echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/searx
  904. echo '' >> /etc/nginx/sites-available/searx
  905. echo ' location / {' >> /etc/nginx/sites-available/searx
  906. function_check nginx_limits
  907. nginx_limits searx '1M'
  908. echo ' proxy_pass http://localhost:8888;' >> /etc/nginx/sites-available/searx
  909. echo " #auth_basic \"${SEARX_LOGIN_TEXT}\";" >> /etc/nginx/sites-available/searx
  910. echo ' #auth_basic_user_file /etc/nginx/.htpasswd;' >> /etc/nginx/sites-available/searx
  911. echo ' }' >> /etc/nginx/sites-available/searx
  912. echo '' >> /etc/nginx/sites-available/searx
  913. echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/searx
  914. echo '' >> /etc/nginx/sites-available/searx
  915. echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/searx
  916. echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/searx
  917. echo '' >> /etc/nginx/sites-available/searx
  918. echo ' location = /robots.txt {' >> /etc/nginx/sites-available/searx
  919. echo ' allow all;' >> /etc/nginx/sites-available/searx
  920. echo ' log_not_found off;' >> /etc/nginx/sites-available/searx
  921. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/searx
  922. echo ' }' >> /etc/nginx/sites-available/searx
  923. echo '}' >> /etc/nginx/sites-available/searx
  924. # replace the secret key
  925. if ! grep -q "searx key" $COMPLETION_FILE; then
  926. SEARX_SECRET_KEY="$(create_password 30)"
  927. set_completion_param "searx key" "${SEARX_SECRET_KEY}"
  928. fi
  929. create_searx_config
  930. searx_set_default_background
  931. chown -R searx:searx ${SEARX_PATH}/searx
  932. # enable the site
  933. nginx_ensite searx
  934. # restart the web server
  935. systemctl restart php7.0-fpm
  936. systemctl restart nginx
  937. # start the daemon
  938. systemctl enable searx.service
  939. systemctl daemon-reload
  940. systemctl start searx.service
  941. SEARX_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  942. ${PROJECT_NAME}-pass -u $MY_USERNAME -a searx -p "$SEARX_PASSWORD"
  943. if grep -q "$MY_USERNAME:" /etc/nginx/.htpasswd; then
  944. sed -i "/$MY_USERNAME:/d" /etc/nginx/.htpasswd
  945. fi
  946. echo "$SEARX_PASSWORD" | htpasswd -i -s -c /etc/nginx/.htpasswd $MY_USERNAME
  947. APP_INSTALLED=1
  948. }
  949. # NOTE: deliberately no exit 0