freedombone-app-rss 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # RSS reader application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 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 writer'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. RSS_READER_REPO="https://tt-rss.org/git/tt-rss.git"
  34. RSS_READER_COMMIT='832aa24943f6b65a811dc6c7414dede412ab1ec6'
  35. RSS_READER_ADMIN_PASSWORD=
  36. RSS_READER_ONION_PORT=8092
  37. RSS_MOBILE_READER_ONION_PORT=8095
  38. RSS_READER_DOMAIN_NAME=ttrss
  39. RSS_MOBILE_READER_REPO="https://github.com/mboinet/ttrss-mobile"
  40. RSS_MOBILE_READER_COMMIT='d5242e1c269e9480ab3b66b7a38da3c892dfb326'
  41. RSS_READER_PATH=/etc/share/tt-rss
  42. RSS_READER_GNUSOCIAL_REPO="https://github.com/bashrc/ttrss-gnusocial"
  43. RSS_READER_GNUSOCIAL_COMMIT='20b2535e3f2b0ddc0117b584bdcaa6bf7a2d9fa2'
  44. rss_variables=(RSS_READER_REPO
  45. RSS_MOBILE_READER_REPO
  46. RSS_READER_ADMIN_PASSWORD
  47. RSS_READER_DOMAIN_NAME
  48. USB_MOUNT
  49. MY_USERNAME)
  50. function install_interactive_rss {
  51. echo -n ''
  52. APP_INSTALLED=1
  53. }
  54. function change_password_rss {
  55. curr_username="$1"
  56. new_user_password="$2"
  57. #${PROJECT_NAME}-pass -u "$curr_username" -a rss -p "$new_user_password"
  58. }
  59. function rss_create_database {
  60. if [ -f $IMAGE_PASSWORD_FILE ]; then
  61. RSS_READER_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  62. else
  63. if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
  64. RSS_READER_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  65. fi
  66. fi
  67. if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
  68. return
  69. fi
  70. function_check create_database
  71. create_database ttrss "$RSS_READER_ADMIN_PASSWORD" $MY_USERNAME
  72. }
  73. function reconfigure_rss {
  74. echo -n ''
  75. }
  76. function upgrade_rss {
  77. RSS_MOBILE_READER_PATH=/etc/share/ttrss-mobile
  78. if [[ $(app_is_installed rss) == "1" ]]; then
  79. function_check set_repo_commit
  80. set_repo_commit $RSS_READER_PATH "rss reader commit" "$RSS_READER_COMMIT" $RSS_READER_REPO
  81. if [[ $(commit_has_changed $RSS_READER_PATH "rss reader commit" "$RSS_READER_COMMIT") == "1" ]]; then
  82. function_check rss_modifications
  83. rss_modifications
  84. fi
  85. fi
  86. if [[ $(app_is_installed rss_mobile_reader) == "1" ]]; then
  87. if [ ! $RSS_READER_PATH ]; then
  88. RSS_READER_PATH=/etc/share/tt-rss
  89. fi
  90. if [ ! -d $RSS_READER_PATH ]; then
  91. echo $'tt-rss is not installed, so the mobile version cannot be installed'
  92. exit 63452
  93. fi
  94. # remove any previous install
  95. if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
  96. if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
  97. sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
  98. sed -i '/rss mobile reader commit/d' $COMPLETION_FILE
  99. rm -rf $RSS_READER_PATH/g2ttree-mobile
  100. fi
  101. fi
  102. # update to the next commit
  103. function_check set_repo_commit
  104. set_repo_commit $RSS_MOBILE_READER_PATH "rss mobile reader commit" "$RSS_MOBILE_READER_COMMIT" $RSS_MOBILE_READER_REPO
  105. fi
  106. chown -R www-data:www-data $RSS_MOBILE_READER_PATH
  107. chown -R www-data:www-data $RSS_READER_PATH
  108. chmod a+x $RSS_MOBILE_READER_PATH
  109. }
  110. function backup_local_rss {
  111. if [ -d /etc/share/tt-rss ]; then
  112. RSS_READER_DOMAIN_NAME=$(get_completion_param "rss reader domain")
  113. echo $"Backing up ttrss"
  114. function_check backup_database_to_usb
  115. backup_database_to_usb ttrss
  116. backup_directory_to_usb /etc/share/tt-rss ttrss
  117. echo $"ttrss backup complete"
  118. fi
  119. }
  120. function restore_local_rss {
  121. temp_restore_dir=/root/tempttrss
  122. function_check rss_create_database
  123. rss_create_database
  124. restore_database ttrss ${RSS_READER_DOMAIN_NAME}
  125. if [ -d /etc/share/tt-rss ]; then
  126. if [ -d /root/tempttrss/etc/share/tt-rss ]; then
  127. rm -rf /etc/share/tt-rss
  128. mv /root/tempttrss/etc/share/tt-rss /etc/share/
  129. if [ ! "$?" = "0" ]; then
  130. function_check set_user_permissions
  131. set_user_permissions
  132. function_check backup_unmount_drive
  133. backup_unmount_drive
  134. exit 528823
  135. fi
  136. if [ -d /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME} ]; then
  137. ln -s /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${2}.key
  138. ln -s /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${2}.pem
  139. else
  140. # Ensure that the bundled SSL cert is being used
  141. if [ -f /etc/ssl/certs/${RSS_READER_DOMAIN_NAME}.bundle.crt ]; then
  142. sed -i "s|${RSS_READER_DOMAIN_NAME}.crt|${RSS_READER_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${2}
  143. fi
  144. fi
  145. fi
  146. fi
  147. function_check rss_modifications
  148. rss_modifications
  149. if [ -d $USB_MOUNT/backup/ttrss ]; then
  150. chown -R www-data:www-data /etc/share/tt-rss
  151. if [ -d $temp_restore_dir ]; then
  152. rm -rf $temp_restore_dir
  153. fi
  154. fi
  155. }
  156. function backup_remote_rss {
  157. if [ -d /etc/share/tt-rss ]; then
  158. function_check suspend_site
  159. suspend_site ${RSS_READER_DOMAIN_NAME}
  160. function_check backup_database_to_friend
  161. backup_database_to_friend ttrss
  162. echo $"Backing up RSS reader installation"
  163. function_check backup_directory_to_friend
  164. backup_directory_to_friend /etc/share/tt-rss ttrss
  165. function_check restart_site
  166. restart_site
  167. else
  168. echo $"RSS reader domain specified but not found in /etc/share/ttrss}"
  169. fi
  170. }
  171. function restore_remote_rss {
  172. if grep -q "rss reader domain" $COMPLETION_FILE; then
  173. echo $"Restoring ttrss"
  174. function_check restore_database_from_friend
  175. function_check rss_create_database
  176. rss_create_database
  177. restore_database_from_friend ttrss ${RSS_READER_DOMAIN_NAME}
  178. if [ -d /etc/share/tt-rss ]; then
  179. rm -rf /etc/share/tt-rss
  180. mv /root/tempttrss/etc/share/tt-rss /etc/share/
  181. if [ ! "$?" = "0" ]; then
  182. exit 6391
  183. fi
  184. if [ -d /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME} ]; then
  185. ln -s /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${RSS_READER_DOMAIN_NAME}.key
  186. ln -s /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${RSS_READER_DOMAIN_NAME}.pem
  187. else
  188. # Ensure that the bundled SSL cert is being used
  189. if [ -f /etc/ssl/certs/${RSS_READER_DOMAIN_NAME}.bundle.crt ]; then
  190. sed -i "s|${RSS_READER_DOMAIN_NAME}.crt|${RSS_READER_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${RSS_READER_DOMAIN_NAME}
  191. fi
  192. fi
  193. fi
  194. function_check rss_modifications
  195. rss_modifications
  196. if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then
  197. chown -R www-data:www-data /etc/share/tt-rss
  198. fi
  199. if [ -d /root/tempttrss ]; then
  200. rm -rf /root/tempttrss
  201. fi
  202. echo $"Restore of ttrss complete"
  203. fi
  204. }
  205. function remove_rss {
  206. if [ ${#RSS_READER_DOMAIN_NAME} -eq 0 ]; then
  207. return
  208. fi
  209. nginx_dissite $RSS_READER_DOMAIN_NAME
  210. function_check remove_onion_service
  211. remove_onion_service rss ${RSS_READER_ONION_PORT} ${RSS_MOBILE_READER_ONION_PORT}
  212. if [ -f /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME ]; then
  213. rm /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  214. fi
  215. if [ -d $RSS_READER_PATH ]; then
  216. rm -rf $RSS_READER_PATH
  217. fi
  218. function_check drop_database
  219. drop_database ttrss
  220. remove_completion_param install_rss
  221. sed -i '/RSS /d' $COMPLETION_FILE
  222. sed -i '/rss /d' $COMPLETION_FILE
  223. remove_backup_database_local ttrss
  224. }
  225. function rss_modifications {
  226. # modify the rss reader to use a socks5 proxy rather than a http proxy
  227. if [ ! -d $RSS_READER_PATH ]; then
  228. return
  229. fi
  230. # ensure that socks5 proxy is used
  231. if ! grep -q "CURLOPT_PROXYTYPE" $RSS_READER_PATH/plugins/af_unburn/init.php; then
  232. sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/plugins/af_unburn/init.php
  233. fi
  234. if ! grep -q "CURLOPT_PROXYTYPE" $RSS_READER_PATH/include/functions.php; then
  235. sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/include/functions.php
  236. fi
  237. chown -R www-data:www-data $RSS_READER_PATH
  238. chmod a+x $RSS_READER_PATH
  239. }
  240. function install_rss_main {
  241. function_check remove_onion_service
  242. remove_onion_service rss ${RSS_READER_ONION_PORT} ${RSS_MOBILE_READER_ONION_PORT}
  243. apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git
  244. apt-get -yq install curl php-xml-parser php5-mcrypt
  245. if [ ! -d /etc/share ]; then
  246. mkdir /etc/share
  247. fi
  248. cd /etc/share
  249. function_check git_clone
  250. git_clone $RSS_READER_REPO tt-rss
  251. if [ ! -d $RSS_READER_PATH ]; then
  252. echo $'Could not clone RSS reader repo'
  253. exit 52925
  254. fi
  255. cd $RSS_READER_PATH
  256. git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
  257. set_completion_param "rss reader commit" "$RSS_READER_COMMIT"
  258. function_check install_mariadb
  259. install_mariadb
  260. function_check get_mariadb_password
  261. get_mariadb_password
  262. function_check repair_databases_script
  263. repair_databases_script
  264. rss_create_database
  265. RSS_READER_ONION_HOSTNAME=$(add_onion_service rss 80 ${RSS_READER_ONION_PORT})
  266. RSS_MOBILE_READER_ONION_HOSTNAME=$(add_onion_service rss_mobile 80 ${RSS_MOBILE_READER_ONION_PORT})
  267. echo 'server {' > /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  268. echo " listen 127.0.0.1:$RSS_MOBILE_READER_ONION_PORT;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  269. echo " server_name $RSS_MOBILE_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  270. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  271. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  272. echo ' error_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  273. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  274. echo ' root /etc/share/ttrss-mobile;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  275. echo ' index index.html index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  276. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  277. echo ' location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  278. echo ' include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  279. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  280. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  281. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  282. echo ' location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  283. echo ' try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  284. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  285. echo ' location /tt-rss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  286. echo ' try_files $uri $uri/ @ttrss_base;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  287. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  288. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  289. echo ' location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  290. echo ' rewrite ^(.*)$ /index.html?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  291. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  292. echo ' location @ttrss_base {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  293. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  294. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  295. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  296. echo ' location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  297. echo ' deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  298. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  299. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  300. echo ' add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  301. echo ' add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  302. echo ' client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  303. echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  304. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  305. echo 'server {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  306. echo " listen 127.0.0.1:$RSS_READER_ONION_PORT default_server;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  307. echo " server_name $RSS_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  308. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  309. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  310. echo ' error_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  311. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  312. echo ' root /etc/share/tt-rss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  313. echo ' index index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  314. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  315. echo ' location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  316. echo ' include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  317. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  318. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  319. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  320. echo ' set $mobile_rewrite do_not_perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  321. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  322. echo ' ## chi http_user_agent for mobile / smart phones ##' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  323. echo ' if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  324. echo ' set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  325. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  326. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  327. echo ' if ($http_user_agent ~* "^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-)") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  328. echo ' set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  329. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  330. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  331. echo ' if ($mobile_rewrite = perform) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  332. echo " rewrite ^/(.*) http://$RSS_MOBILE_READER_ONION_HOSTNAME permanent;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  333. echo ' break;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  334. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  335. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  336. echo ' location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  337. echo ' include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  338. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  339. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  340. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  341. echo ' location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  342. echo ' try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  343. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  344. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  345. echo ' location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  346. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  347. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  348. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  349. echo ' location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  350. echo ' deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  351. echo ' }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  352. echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  353. echo ' add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  354. echo ' add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  355. echo ' client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  356. echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
  357. if [ ! -f $RSS_READER_PATH/config.php ]; then
  358. # generate a config file
  359. RSS_FEED_CRYPT_KEY="$(create_password 24)"
  360. echo '<?php' > $RSS_READER_PATH/config.php
  361. echo " define ('_CURL_HTTP_PROXY', '127.0.0.1:9050');" >> $RSS_READER_PATH/config.php
  362. echo " define('DB_TYPE', 'mysql');" >> $RSS_READER_PATH/config.php
  363. echo " define('DB_HOST', 'localhost');" >> $RSS_READER_PATH/config.php
  364. echo " define('DB_USER', 'root');" >> $RSS_READER_PATH/config.php
  365. echo " define('DB_NAME', 'ttrss');" >> $RSS_READER_PATH/config.php
  366. echo " define('DB_PASS', '${MARIADB_PASSWORD}');" >> $RSS_READER_PATH/config.php
  367. echo " define('DB_PORT', '3306');" >> $RSS_READER_PATH/config.php
  368. echo " define('MYSQL_CHARSET', 'UTF8');" >> $RSS_READER_PATH/config.php
  369. echo " define('SELF_URL_PATH', 'http://${RSS_READER_ONION_HOSTNAME}/');" >> $RSS_READER_PATH/config.php
  370. echo " define('FEED_CRYPT_KEY', '${RSS_FEED_CRYPT_KEY}');" >> $RSS_READER_PATH/config.php
  371. echo " define('SINGLE_USER_MODE', false);" >> $RSS_READER_PATH/config.php
  372. echo " define('SIMPLE_UPDATE_MODE', false);" >> $RSS_READER_PATH/config.php
  373. echo " define('PHP_EXECUTABLE', '/usr/bin/php');" >> $RSS_READER_PATH/config.php
  374. echo " define('LOCK_DIRECTORY', 'lock');" >> $RSS_READER_PATH/config.php
  375. echo " define('CACHE_DIR', 'cache');" >> $RSS_READER_PATH/config.php
  376. echo " define('ICONS_DIR', \"feed-icons\");" >> $RSS_READER_PATH/config.php
  377. echo " define('ICONS_URL', \"feed-icons\");" >> $RSS_READER_PATH/config.php
  378. echo " define('AUTH_AUTO_CREATE', true);" >> $RSS_READER_PATH/config.php
  379. echo " define('AUTH_AUTO_LOGIN', true);" >> $RSS_READER_PATH/config.php
  380. echo " define('FORCE_ARTICLE_PURGE', 0);" >> $RSS_READER_PATH/config.php
  381. echo " define('PUBSUBHUBBUB_HUB', '');" >> $RSS_READER_PATH/config.php
  382. echo " define('PUBSUBHUBBUB_ENABLED', false);" >> $RSS_READER_PATH/config.php
  383. echo " define('SPHINX_SERVER', 'localhost:9312');" >> $RSS_READER_PATH/config.php
  384. echo " define('SPHINX_INDEX', 'ttrss, delta');" >> $RSS_READER_PATH/config.php
  385. echo " define('ENABLE_REGISTRATION', false);" >> $RSS_READER_PATH/config.php
  386. echo " define('REG_NOTIFY_ADDRESS', '${MY_EMAIL_ADDRESS}');" >> $RSS_READER_PATH/config.php
  387. echo " define('REG_MAX_USERS', 10);" >> $RSS_READER_PATH/config.php
  388. echo " define('SESSION_COOKIE_LIFETIME', 86400);" >> $RSS_READER_PATH/config.php
  389. echo " define('SMTP_FROM_NAME', 'Tiny Tiny RSS');" >> $RSS_READER_PATH/config.php
  390. echo " define('SMTP_FROM_ADDRESS', 'noreply@${RSS_READER_ONION_HOSTNAME}');" >> $RSS_READER_PATH/config.php
  391. echo " define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');" >> $RSS_READER_PATH/config.php
  392. echo " define('SMTP_SERVER', '');" >> $RSS_READER_PATH/config.php
  393. echo " define('SMTP_LOGIN', '');" >> $RSS_READER_PATH/config.php
  394. echo " define('SMTP_PASSWORD', '');" >> $RSS_READER_PATH/config.php
  395. echo " define('SMTP_SECURE', '');" >> $RSS_READER_PATH/config.php
  396. echo " define('CHECK_FOR_UPDATES', false);" >> $RSS_READER_PATH/config.php
  397. echo " define('ENABLE_GZIP_OUTPUT', false);" >> $RSS_READER_PATH/config.php
  398. echo " define('PLUGINS', 'auth_internal, note, gnusocial');" >> $RSS_READER_PATH/config.php
  399. echo " define('LOG_DESTINATION', 'sql');" >> $RSS_READER_PATH/config.php
  400. echo " define('CONFIG_VERSION', 26);" >> $RSS_READER_PATH/config.php
  401. fi
  402. # initialize the database
  403. if [ ! -f $RSS_READER_PATH/schema/ttrss_schema_mysql.sql ]; then
  404. echo $'No database schema found for rss reader'
  405. exit 52926
  406. fi
  407. initialise_database ttrss $RSS_READER_PATH/schema/ttrss_schema_mysql.sql
  408. # change the password from the default
  409. RSS_READER_ADMIN_PASSWORD_HASH=$(echo -n "${RSS_READER_ADMIN_PASSWORD}" | sha1sum | awk -F ' ' '{print $1}')
  410. function_check run_query
  411. run_query ttrss "update ttrss_users set pwd_hash = 'SHA1:${RSS_READER_ADMIN_PASSWORD_HASH}', salt= '' WHERE login = 'admin';"
  412. function_check rss_modifications
  413. rss_modifications
  414. function_check configure_php
  415. configure_php
  416. nginx_ensite $RSS_READER_DOMAIN_NAME
  417. systemctl restart php5-fpm
  418. systemctl restart nginx
  419. # daemon to update feeds
  420. echo '[Unit]' > /etc/systemd/system/ttrss.service
  421. echo 'Description=ttrss_backend' >> /etc/systemd/system/ttrss.service
  422. echo 'After=network.target mysql.service' >> /etc/systemd/system/ttrss.service
  423. echo 'After=tor.service' >> /etc/systemd/system/ttrss.service
  424. echo '' >> /etc/systemd/system/ttrss.service
  425. echo '[Service]' >> /etc/systemd/system/ttrss.service
  426. echo 'User=www-data' >> /etc/systemd/system/ttrss.service
  427. echo "ExecStart=/usr/bin/php $RSS_READER_PATH/update.php --daemon" >> /etc/systemd/system/ttrss.service
  428. echo '' >> /etc/systemd/system/ttrss.service
  429. echo '[Install]' >> /etc/systemd/system/ttrss.service
  430. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ttrss.service
  431. systemctl enable ttrss
  432. systemctl daemon-reload
  433. systemctl start ttrss
  434. ${PROJECT_NAME}-pass -u $MY_USERNAME -a rss -p "$RSS_READER_ADMIN_PASSWORD"
  435. install_completed rss_main
  436. }
  437. function install_rss_gnusocial {
  438. if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
  439. return
  440. fi
  441. if [ ! $RSS_READER_PATH ]; then
  442. RSS_READER_PATH=/etc/share/tt-rss
  443. fi
  444. RSS_READER_GNUSOCIAL_PATH=${RSS_READER_PATH}/plugins/gnusocial
  445. # update to the next commit
  446. function_check set_repo_commit
  447. set_repo_commit $RSS_READER_GNUSOCIAL_PATH "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT" $RSS_READER_GNUSOCIAL_REPO
  448. chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
  449. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  450. return
  451. fi
  452. if [ ! -d $INSTALL_DIR ]; then
  453. mkdir -p $INSTALL_DIR
  454. fi
  455. cd $INSTALL_DIR
  456. function_check git_clone
  457. git_clone $RSS_READER_GNUSOCIAL_REPO ttrss-gnusocial
  458. if [ ! -d $INSTALL_DIR/ttrss-gnusocial ]; then
  459. echo $'Could not clone repo for RSS reader gnusocial plugin'
  460. exit 52838
  461. fi
  462. cp -r $INSTALL_DIR/ttrss-gnusocial $RSS_READER_GNUSOCIAL_PATH
  463. cd $RSS_READER_GNUSOCIAL_PATH
  464. git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
  465. set_completion_param "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT"
  466. chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
  467. install_completed rss_gnusocial
  468. }
  469. function install_rss_mobile_reader {
  470. if [ ! $RSS_READER_PATH ]; then
  471. RSS_READER_PATH=/etc/share/tt-rss
  472. fi
  473. if [ ! -d $RSS_READER_PATH ]; then
  474. echo $'tt-rss is not installed, so the mobile version cannot be installed'
  475. exit 63452
  476. fi
  477. RSS_MOBILE_READER_PATH=/etc/share/ttrss-mobile
  478. # remove any previous install
  479. if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
  480. if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
  481. sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
  482. sed -i '/rss mobile reader commit/d' $COMPLETION_FILE
  483. rm -rf $RSS_READER_PATH/g2ttree-mobile
  484. fi
  485. fi
  486. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  487. return
  488. fi
  489. cd /etc/share
  490. function_check git_clone
  491. git_clone $RSS_MOBILE_READER_REPO ttrss-mobile
  492. if [ ! -d $RSS_MOBILE_READER_PATH ]; then
  493. echo $'Could not clone RSS mobile reader repo'
  494. exit 24816
  495. fi
  496. cd $RSS_MOBILE_READER_PATH
  497. git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
  498. set_completion_param "rss mobile reader commit" "$RSS_MOBILE_READER_COMMIT"
  499. echo 'define({' > $RSS_MOBILE_READER_PATH/scripts/conf.js
  500. echo ' apiPath: "/tt-rss/"' >> $RSS_MOBILE_READER_PATH/scripts/conf.js
  501. echo '});' >> $RSS_MOBILE_READER_PATH/scripts/conf.js
  502. # link to the main site
  503. ln -s $RSS_READER_PATH $RSS_MOBILE_READER_PATH/tt-rss
  504. chown -R www-data:www-data $RSS_MOBILE_READER_PATH
  505. chown -R www-data:www-data $RSS_READER_PATH
  506. chmod a+x $RSS_MOBILE_READER_PATH
  507. install_completed rss_mobile_reader
  508. }
  509. function install_rss {
  510. install_rss_main
  511. install_rss_gnusocial
  512. install_rss_mobile_reader
  513. APP_INSTALLED=1
  514. }
  515. # NOTE: deliberately no exit 0