freedombone-app-gnusocial 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # GNU Social application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  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 media'
  31. MICROBLOG_DOMAIN_NAME=
  32. MICROBLOG_CODE=
  33. MICROBLOG_ONION_PORT=8087
  34. MICROBLOG_REPO="https://git.gnu.io/gnu/gnu-social.git"
  35. MICROBLOG_COMMIT='c67b89e56bf0f90730a9e22beca7e1bd41fc26c3'
  36. MICROBLOG_ADMIN_PASSWORD=
  37. MICROBLOG_THEME_REPO="https://git.gnu.io/h2p/Qvitter.git"
  38. MICROBLOG_THEME_COMMIT='34510bcf37c727f91afad789fb0a531a45171ccf'
  39. MICROBLOG_WELCOME_MESSAGE=$'<h1>Welcome to GNU Social – a federated microblog</h1><p>Another Freedombone site</p>'
  40. MICROBLOG_BACKGROUND_IMAGE_URL=
  41. MICROBLOG_MARKDOWN_REPO="https://git.gnu.io/chimo/markdown.git"
  42. MICROBLOG_MARKDOWN_COMMIT='03c53942f94b3376f0946e6e1fe566cc21ccf232'
  43. # Sharings plugin for the microblog
  44. SHARINGS_REPO="http://git.lasindias.club/bashrc/Sharings"
  45. SHARINGS_COMMIT='d5c6c7f855d9afff9086c09ea706f38c859bc0d4'
  46. SHARINGS_THEME_REPO="http://git.lasindias.club/manuel/SharingsTheme"
  47. SHARINGS_THEME_COMMIT='7106c7ef03'
  48. function gnusocial_running_script {
  49. if ! grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
  50. return
  51. fi
  52. # check that the daemon is running
  53. echo '#!/bin/bash' > /etc/cron.hourly/gnusocial-daemons
  54. echo 'daemon_lines=$(ps aux | grep "scripts/queuedaemon.php" | grep "/var/www")' >> /etc/cron.hourly/gnusocial-daemons
  55. echo 'if [[ $daemon_lines != *"/var/www/"* ]]; then' >> /etc/cron.hourly/gnusocial-daemons
  56. echo " ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')" >> /etc/cron.hourly/gnusocial-daemons
  57. echo ' MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME' >> /etc/cron.hourly/gnusocial-daemons
  58. echo ' echo "Restarting GNU Social daemons" | mail -s "GNU Social daemons not found" $MY_EMAIL_ADDRESS' >> /etc/cron.hourly/gnusocial-daemons
  59. echo " cd /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs" >> /etc/cron.hourly/gnusocial-daemons
  60. echo ' scripts/startdaemons.sh' >> /etc/cron.hourly/gnusocial-daemons
  61. echo 'fi' >> /etc/cron.hourly/gnusocial-daemons
  62. chmod +x /etc/cron.hourly/gnusocial-daemons
  63. }
  64. function reconfigure_gnusocial {
  65. echo -n ''
  66. }
  67. function upgrade_gnusocial {
  68. if ! grep -Fxq "install_gnusocial_main" $COMPLETION_FILE; then
  69. return
  70. fi
  71. # update to the next commit
  72. function_check set_repo_commit
  73. set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs "GNU Social commit" "$MICROBLOG_COMMIT" $MICROBLOG_REPO
  74. function_check gnusocial_running_script
  75. gnusocial_running_script
  76. }
  77. function backup_local_gnusocial {
  78. MICROBLOG_DOMAIN_NAME='microblog'
  79. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  80. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  81. fi
  82. source_directory=/var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
  83. if [ -d $source_directory ]; then
  84. dest_directory=gnusocial
  85. echo $"Backing up $source_directory to $dest_directory"
  86. function_check suspend_site
  87. suspend_site ${MICROBLOG_DOMAIN_NAME}
  88. function_check backup_directory_to_usb
  89. backup_directory_to_usb $source_directory $dest_directory
  90. function_check backup_database_to_usb
  91. backup_database_to_usb gnusocial
  92. function_check restart_site
  93. restart_site
  94. echo $"Backup to $dest_directory complete"
  95. fi
  96. }
  97. function restore_local_gnusocial {
  98. if ! grep -q "GNU Social domain" $COMPLETION_FILE; then
  99. return
  100. fi
  101. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  102. if [ $MICROBLOG_DOMAIN_NAME ]; then
  103. echo $"Restoring GNU Social"
  104. temp_restore_dir=/root/tempgnusocial
  105. gnusocial_dir=/var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
  106. # stop the daemons
  107. cd $gnusocial_dir
  108. scripts/stopdaemons.sh
  109. restore_database gnusocial ${MICROBLOG_DOMAIN_NAME}
  110. if [ -d $temp_restore_dir ]; then
  111. rm -rf $temp_restore_dir
  112. fi
  113. # start the daemons
  114. cd $gnusocial_dir
  115. scripts/startdaemons.sh
  116. echo $"Restore of GNU Social complete"
  117. fi
  118. }
  119. function backup_remote_gnusocial {
  120. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  121. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  122. temp_backup_dir=/var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
  123. if [ -d $temp_backup_dir ]; then
  124. function_check suspend_site
  125. suspend_site ${MICROBLOG_DOMAIN_NAME}
  126. function_check backup_database_to_friend
  127. backup_database_to_friend gnusocial
  128. echo $"Backing up GNU social installation"
  129. function_check backup_directory_to_friend
  130. backup_directory_to_friend $temp_backup_dir gnusocial
  131. function_check restart_site
  132. restart_site
  133. else
  134. echo $"GNU Social domain specified but not found in ${temp_backup_dir}"
  135. fi
  136. fi
  137. }
  138. function restore_remote_gnusocial {
  139. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  140. echo $"Restoring GNU Social"
  141. MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
  142. # stop the daemons
  143. cd /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
  144. scripts/stopdaemons.sh
  145. function_check restore_database_from_friend
  146. restore_database_from_friend gnusocial ${MICROBLOG_DOMAIN_NAME}
  147. if [ -d /root/tempgnusocial ]; then
  148. rm -rf /root/tempgnusocial
  149. fi
  150. # start the daemons
  151. cd /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
  152. scripts/startdaemons.sh
  153. echo $"Restore of GNU Social complete"
  154. fi
  155. }
  156. function remove_gnusocial {
  157. if ! grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
  158. return
  159. fi
  160. nginx_dissite $MICROBLOG_DOMAIN_NAME
  161. if [ -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
  162. rm -rf /var/www/$MICROBLOG_DOMAIN_NAME
  163. fi
  164. if [ -f /etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME ]; then
  165. rm /etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME
  166. fi
  167. function_check drop_database
  168. drop_database gnusocial
  169. function_check remove_onion_service
  170. remove_onion_service microblog ${MICROBLOG_ONION_PORT}
  171. sed -i '/install_gnusocial/d' $COMPLETION_FILE
  172. sed -i '/GNU Social /d' $COMPLETION_FILE
  173. }
  174. function install_gnusocial_main {
  175. if [ ! $MICROBLOG_DOMAIN_NAME ]; then
  176. echo $'No domain name was given for the microblog'
  177. exit 7359
  178. fi
  179. if grep -Fxq "install_gnusocial_main" $COMPLETION_FILE; then
  180. return
  181. fi
  182. function_check gnusocial_running_script
  183. gnusocial_running_script
  184. function_check install_mariadb
  185. install_mariadb
  186. function_check get_mariadb_password
  187. get_mariadb_password
  188. function_check repair_databases_script
  189. repair_databases_script
  190. apt-get -y install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
  191. apt-get -y install php5-memcached
  192. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
  193. mkdir /var/www/$MICROBLOG_DOMAIN_NAME
  194. fi
  195. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
  196. function_check git_clone
  197. git_clone $MICROBLOG_REPO /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  198. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
  199. echo $'Unable to clone gnusocial repo'
  200. exit 87525
  201. fi
  202. fi
  203. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  204. git checkout $MICROBLOG_COMMIT -b $MICROBLOG_COMMIT
  205. if ! grep -q "GNU Social commit" $COMPLETION_FILE; then
  206. echo "GNU Social commit:$MICROBLOG_COMMIT" >> $COMPLETION_FILE
  207. else
  208. sed -i "s/GNU Social commit.*/GNU Social commit:$MICROBLOG_COMMIT/g" $COMPLETION_FILE
  209. fi
  210. chmod a+w /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  211. chown www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  212. chmod +x /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php
  213. function_check get_mariadb_gnusocial_admin_password
  214. get_mariadb_gnusocial_admin_password
  215. if [ ! $MICROBLOG_ADMIN_PASSWORD ]; then
  216. if [ -f $IMAGE_PASSWORD_FILE ]; then
  217. MICROBLOG_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  218. else
  219. MICROBLOG_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  220. fi
  221. fi
  222. function_check create_database
  223. create_database gnusocial "$MICROBLOG_ADMIN_PASSWORD" $MY_USERNAME
  224. if [ ! -f "/etc/aliases" ]; then
  225. touch /etc/aliases
  226. fi
  227. if ! grep -q "www-data: root" /etc/aliases; then
  228. echo 'www-data: root' >> /etc/aliases
  229. fi
  230. if ! grep -q "/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
  231. echo "*: /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
  232. fi
  233. function_check add_ddns_domain
  234. add_ddns_domain $MICROBLOG_DOMAIN_NAME
  235. microblog_nginx_site=/etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME
  236. if [[ $ONION_ONLY == "no" ]]; then
  237. function_check nginx_http_redirect
  238. nginx_http_redirect $MICROBLOG_DOMAIN_NAME
  239. echo 'server {' >> $microblog_nginx_site
  240. echo ' listen 443 ssl;' >> $microblog_nginx_site
  241. echo " server_name $MICROBLOG_DOMAIN_NAME;" >> $microblog_nginx_site
  242. echo '' >> $microblog_nginx_site
  243. echo ' # Security' >> $microblog_nginx_site
  244. function_check nginx_ssl
  245. nginx_ssl $MICROBLOG_DOMAIN_NAME
  246. function_check nginx_disable_sniffing
  247. nginx_disable_sniffing $MICROBLOG_DOMAIN_NAME
  248. function_check nginx_limits
  249. nginx_limits $MICROBLOG_DOMAIN_NAME '15m'
  250. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $microblog_nginx_site
  251. echo '' >> $microblog_nginx_site
  252. echo ' # Logs' >> $microblog_nginx_site
  253. echo ' access_log off;' >> $microblog_nginx_site
  254. echo ' error_log off;' >> $microblog_nginx_site
  255. echo '' >> $microblog_nginx_site
  256. echo ' # Root' >> $microblog_nginx_site
  257. echo " root /var/www/$MICROBLOG_DOMAIN_NAME/htdocs;" >> $microblog_nginx_site
  258. echo '' >> $microblog_nginx_site
  259. echo ' # Index' >> $microblog_nginx_site
  260. echo ' index index.php;' >> $microblog_nginx_site
  261. echo '' >> $microblog_nginx_site
  262. echo ' # PHP' >> $microblog_nginx_site
  263. echo ' location ~ \.php {' >> $microblog_nginx_site
  264. echo ' include snippets/fastcgi-php.conf;' >> $microblog_nginx_site
  265. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $microblog_nginx_site
  266. echo ' }' >> $microblog_nginx_site
  267. echo '' >> $microblog_nginx_site
  268. echo ' # Location' >> $microblog_nginx_site
  269. echo ' location / {' >> $microblog_nginx_site
  270. echo ' try_files $uri $uri/ @gnusocial;' >> $microblog_nginx_site
  271. echo ' }' >> $microblog_nginx_site
  272. echo '' >> $microblog_nginx_site
  273. echo ' # Fancy URLs' >> $microblog_nginx_site
  274. echo ' location @gnusocial {' >> $microblog_nginx_site
  275. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $microblog_nginx_site
  276. echo ' }' >> $microblog_nginx_site
  277. echo '' >> $microblog_nginx_site
  278. echo ' # Restrict access that is unnecessary anyway' >> $microblog_nginx_site
  279. echo ' location ~ /\.(ht|git) {' >> $microblog_nginx_site
  280. echo ' deny all;' >> $microblog_nginx_site
  281. echo ' }' >> $microblog_nginx_site
  282. echo '}' >> $microblog_nginx_site
  283. else
  284. echo -n '' > $microblog_nginx_site
  285. fi
  286. echo 'server {' >> $microblog_nginx_site
  287. echo " listen 127.0.0.1:$MICROBLOG_ONION_PORT default_server;" >> $microblog_nginx_site
  288. echo " server_name $MICROBLOG_DOMAIN_NAME;" >> $microblog_nginx_site
  289. echo '' >> $microblog_nginx_site
  290. function_check nginx_disable_sniffing
  291. nginx_disable_sniffing $MICROBLOG_DOMAIN_NAME
  292. function_check nginx_limits
  293. nginx_limits $MICROBLOG_DOMAIN_NAME '15m'
  294. echo '' >> $microblog_nginx_site
  295. echo ' # Logs' >> $microblog_nginx_site
  296. echo ' access_log off;' >> $microblog_nginx_site
  297. echo ' error_log off;' >> $microblog_nginx_site
  298. echo '' >> $microblog_nginx_site
  299. echo ' # Root' >> $microblog_nginx_site
  300. echo " root /var/www/$MICROBLOG_DOMAIN_NAME/htdocs;" >> $microblog_nginx_site
  301. echo '' >> $microblog_nginx_site
  302. echo ' # Index' >> $microblog_nginx_site
  303. echo ' index index.php;' >> $microblog_nginx_site
  304. echo '' >> $microblog_nginx_site
  305. echo ' # PHP' >> $microblog_nginx_site
  306. echo ' location ~ \.php {' >> $microblog_nginx_site
  307. echo ' include snippets/fastcgi-php.conf;' >> $microblog_nginx_site
  308. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $microblog_nginx_site
  309. echo ' }' >> $microblog_nginx_site
  310. echo '' >> $microblog_nginx_site
  311. echo ' # Location' >> $microblog_nginx_site
  312. echo ' location / {' >> $microblog_nginx_site
  313. echo ' try_files $uri $uri/ @gnusocial;' >> $microblog_nginx_site
  314. echo ' }' >> $microblog_nginx_site
  315. echo '' >> $microblog_nginx_site
  316. echo ' # Fancy URLs' >> $microblog_nginx_site
  317. echo ' location @gnusocial {' >> $microblog_nginx_site
  318. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $microblog_nginx_site
  319. echo ' }' >> $microblog_nginx_site
  320. echo '' >> $microblog_nginx_site
  321. echo ' # Restrict access that is unnecessary anyway' >> $microblog_nginx_site
  322. echo ' location ~ /\.(ht|git) {' >> $microblog_nginx_site
  323. echo ' deny all;' >> $microblog_nginx_site
  324. echo ' }' >> $microblog_nginx_site
  325. echo '}' >> $microblog_nginx_site
  326. function_check configure_php
  327. configure_php
  328. function_check create_site_certificate
  329. create_site_certificate $MICROBLOG_DOMAIN_NAME 'yes'
  330. # Ensure that the database gets backed up locally, if remote
  331. # backups are not being used
  332. function_check backup_databases_script_header
  333. backup_databases_script_header
  334. function_check backup_database_local
  335. backup_database_local gnusocial
  336. function_check nginx_ensite
  337. nginx_ensite $MICROBLOG_DOMAIN_NAME
  338. # NOTE: For the typical case always enable SSL and only
  339. # disable it if in onion only mode. This is due to complexities
  340. # with the way URLs are generated by GNU Social
  341. gnusocial_ssl='always'
  342. if [[ $ONION_ONLY != 'no' ]]; then
  343. gnusocial_ssl='never'
  344. fi
  345. MICROBLOG_ONION_HOSTNAME=$(add_onion_service microblog 80 ${MICROBLOG_ONION_PORT})
  346. MICROBLOG_SERVER=${MICROBLOG_DOMAIN_NAME}
  347. if [[ $ONION_ONLY != 'no' ]]; then
  348. MICROBLOG_SERVER=${MICROBLOG_ONION_HOSTNAME}
  349. fi
  350. # Create the configuration
  351. gnusocial_installer=/var/www/${MICROBLOG_DOMAIN_NAME}/htdocs/scripts/install_cli.php
  352. if [ ! -f $gnusocial_installer ]; then
  353. echo $'No GNU Social commandline installer found'
  354. exit 53026
  355. fi
  356. ${gnusocial_installer} --server "${MICROBLOG_SERVER}" \
  357. --host="localhost" --database="gnusocial" \
  358. --dbtype=mysql --username="root" -v \
  359. --password="$MARIADB_PASSWORD" \
  360. --sitename=$"GNU Social" --fancy='yes' \
  361. --admin-nick="$MY_USERNAME" \
  362. --admin-pass="$MICROBLOG_ADMIN_PASSWORD" \
  363. --site-profile="community" \
  364. --ssl=${gnusocial_ssl}
  365. # There can be a lot of warnings here so the return value check is disabled
  366. #if [ ! "$?" = "0" ]; then
  367. # # failed to install
  368. # echo $'Could not install GNU Social'
  369. # exit 72357
  370. #fi
  371. # check microblog has a config file
  372. microblog_config_file=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
  373. if [ ! -f $microblog_config_file ]; then
  374. echo $'Microblog config.php not found'
  375. exit 87586
  376. fi
  377. # Some useful settings
  378. if ! grep -q "Recommended GNU social settings" $microblog_config_file; then
  379. echo "" >> $microblog_config_file
  380. echo "// Recommended GNU social settings" >> $microblog_config_file
  381. echo "\$config['thumbnail']['maxsize'] = 3000;" >> $microblog_config_file
  382. echo "\$config['profile']['delete'] = true;" >> $microblog_config_file
  383. echo "\$config['profile']['changenick'] = true;" >> $microblog_config_file
  384. echo "\$config['public']['localonly'] = false;" >> $microblog_config_file
  385. echo "addPlugin('StoreRemoteMedia');" >> $microblog_config_file
  386. echo "\$config['queue']['enabled'] = true;" >> $microblog_config_file
  387. echo "\$config['queue']['daemon'] = true;" >> $microblog_config_file
  388. echo "\$config['ostatus']['hub_retries'] = 3;" >> $microblog_config_file
  389. fi
  390. # This improves performance
  391. sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $microblog_config_file
  392. systemctl restart php5-fpm
  393. systemctl restart nginx
  394. ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$MICROBLOG_DOMAIN_NAME" -g gnusocial --public no
  395. # some post-install instructions for the user
  396. if ! grep -q $"Microblog administrator" /home/$MY_USERNAME/README; then
  397. echo '' >> /home/$MY_USERNAME/README
  398. echo '' >> /home/$MY_USERNAME/README
  399. echo $'Microblog' >> /home/$MY_USERNAME/README
  400. echo '=========' >> /home/$MY_USERNAME/README
  401. echo $"Microblog administrator nickname: $MY_USERNAME" >> /home/$MY_USERNAME/README
  402. echo $"Microblog administrator password: $MICROBLOG_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
  403. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  404. chmod 600 /home/$MY_USERNAME/README
  405. fi
  406. if ! grep -q "Microblog onion domain" /home/$MY_USERNAME/README; then
  407. echo $"Microblog onion domain: ${MICROBLOG_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  408. echo '' >> /home/$MY_USERNAME/README
  409. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  410. chmod 600 /home/$MY_USERNAME/README
  411. fi
  412. echo "GNU Social onion domain:${MICROBLOG_ONION_HOSTNAME}" >> $COMPLETION_FILE
  413. echo "GNU Social domain:$MICROBLOG_DOMAIN_NAME" >> $COMPLETION_FILE
  414. echo 'install_gnusocial_main' >> $COMPLETION_FILE
  415. }
  416. function install_gnusocial_plugin_sharings {
  417. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
  418. echo $'No local/plugins directory found for the microblog'
  419. exit 72945
  420. fi
  421. # update to the next commit
  422. function_check set_repo_commit
  423. set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins "GNU Social sharings plugin commit" "$SHARINGS_COMMIT" $SHARINGS_REPO
  424. if grep -Fxq "install_gnusocial_plugin_sharings" $COMPLETION_FILE; then
  425. return
  426. fi
  427. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
  428. function_check git_clone
  429. git_clone $SHARINGS_REPO Sharings
  430. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings ]; then
  431. echo $'Unable to clone microblog sharings plugin'
  432. exit 36738
  433. fi
  434. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings
  435. git stash
  436. git checkout master
  437. git branch -D $SHARINGS_COMMIT
  438. git checkout $SHARINGS_COMMIT -b $SHARINGS_COMMIT
  439. # enable the plugin
  440. if ! grep -q "addPlugin('Sharings');" /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php; then
  441. echo "addPlugin('Sharings');" >> /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
  442. fi
  443. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  444. php scripts/checkschema.php
  445. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings
  446. php scripts/seedsharings.php
  447. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  448. php scripts/checkschema.php
  449. # Languages
  450. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES
  451. msgfmt -o Sharings.mo Sharings.po
  452. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES
  453. msgfmt -o Sharings.mo Sharings.po
  454. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES
  455. msgfmt -o Sharings.mo Sharings.po
  456. chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  457. if ! grep -q "GNU Social sharings plugin commit" $COMPLETION_FILE; then
  458. echo "GNU Social sharings plugin commit:$SHARINGS_COMMIT" >> $COMPLETION_FILE
  459. else
  460. sed -i "s|GNU Social sharings plugin commit.*|GNU Social sharings plugin commit:$SHARINGS_COMMIT|g" $COMPLETION_FILE
  461. fi
  462. echo 'install_gnusocial_plugin_sharings' >> $COMPLETION_FILE
  463. }
  464. function install_gnusocial_plugin_sharings_theme {
  465. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
  466. echo $'No local/plugins directory found for the microblog'
  467. exit 74458
  468. fi
  469. # update to the next commit
  470. function_check set_repo_commit
  471. set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins "GNU Social sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" $SHARINGS_THEME_REPO
  472. if grep -Fxq "install_gnusocial_plugin_sharings_theme" $COMPLETION_FILE; then
  473. return
  474. fi
  475. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
  476. function_check git_clone
  477. git_clone $SHARINGS_THEME_REPO SharingsTheme
  478. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme ]; then
  479. echo $'Unable to clone microblog sharings plugin theme'
  480. exit 639253
  481. fi
  482. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme
  483. git stash
  484. git checkout master
  485. git branch -D $SHARINGS_THEME_COMMIT
  486. git checkout $SHARINGS_THEME_COMMIT -b $SHARINGS_THEME_COMMIT
  487. # enable the plugin
  488. if ! grep -q "addPlugin('SharingsTheme');" /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php; then
  489. echo "addPlugin('SharingsTheme');" >> /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
  490. fi
  491. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  492. php scripts/checkschema.php
  493. chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  494. if ! grep -q "GNU Social sharings plugin theme commit" $COMPLETION_FILE; then
  495. echo "GNU Social sharings plugin theme commit:$SHARINGS_THEME_COMMIT" >> $COMPLETION_FILE
  496. else
  497. sed -i "s|GNU Social sharings plugin theme commit.*|GNU Social sharings plugin theme commit:$SHARINGS_THEME_COMMIT|g" $COMPLETION_FILE
  498. fi
  499. echo 'install_gnusocial_plugin_sharings_theme' >> $COMPLETION_FILE
  500. }
  501. function expire_gnusocial_posts {
  502. # To prevent the database size from growing endlessly this script expires posts
  503. # after a number of months
  504. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
  505. return
  506. fi
  507. gnusocial_expire_script=/usr/bin/gnusocial-expire
  508. echo '<?php' > $gnusocial_expire_script
  509. echo '' >> $gnusocial_expire_script
  510. echo '// GNU Social post expiry script, based on StatExpire by Tony Baldwin' >> $gnusocial_expire_script
  511. echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_script
  512. echo '' >> $gnusocial_expire_script
  513. echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $gnusocial_expire_script
  514. echo '$username="root";' >> $gnusocial_expire_script
  515. echo "\$password=trim(file_get_contents(\"$DATABASE_PASSWORD_FILE\"));" >> $gnusocial_expire_script
  516. echo '$database="gnusocial";' >> $gnusocial_expire_script
  517. echo '' >> $gnusocial_expire_script
  518. echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_script
  519. echo ' echo "Could not connect to mariadb";' >> $gnusocial_expire_script
  520. echo ' exit;' >> $gnusocial_expire_script
  521. echo '}' >> $gnusocial_expire_script
  522. echo '' >> $gnusocial_expire_script
  523. echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_script
  524. echo ' echo "Could not select gnusocial database";' >> $gnusocial_expire_script
  525. echo ' exit;' >> $gnusocial_expire_script
  526. echo '}' >> $gnusocial_expire_script
  527. echo '' >> $gnusocial_expire_script
  528. echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
  529. echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_script
  530. echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
  531. echo '' >> $gnusocial_expire_script
  532. echo 'mysql_query($notice_query);' >> $gnusocial_expire_script
  533. echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_script
  534. echo 'mysql_query($conversation_query);' >> $gnusocial_expire_script
  535. echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_script
  536. echo 'mysql_query($reply_query);' >> $gnusocial_expire_script
  537. echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_script
  538. echo 'mysql_close();' >> $gnusocial_expire_script
  539. echo '' >> $gnusocial_expire_script
  540. echo 'echo "Expire GNU Social posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_script
  541. chmod +x $gnusocial_expire_script
  542. # Add a cron job
  543. if ! grep -q "$gnusocial_expire_script" /etc/crontab; then
  544. echo "10 3 5 * * root /usr/bin/timeout 500 /usr/bin/php $gnusocial_expire_script" >> /etc/crontab
  545. fi
  546. # remove old expire script
  547. if [ -f /etc/cron.weekly/clear-microblog-database ]; then
  548. rm /etc/cron.weekly/clear-microblog-database
  549. fi
  550. }
  551. function install_gnusocial_theme {
  552. # update to the next commit
  553. function_check set_repo_commit
  554. set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter "GNU Social theme commit" "$MICROBLOG_THEME_COMMIT" $MICROBLOG_THEME_REPO
  555. # customise with project logo
  556. if [ -f /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  557. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  558. cp ~/freedombone/img/gnusocial_sprite.png /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
  559. fi
  560. fi
  561. if grep -Fxq "install_gnusocial_theme" $COMPLETION_FILE; then
  562. return
  563. fi
  564. apt-get -y install wget
  565. if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
  566. mkdir -p /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
  567. fi
  568. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
  569. function_check git_clone
  570. git_clone $MICROBLOG_THEME_REPO Qvitter
  571. cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter
  572. git checkout $MICROBLOG_THEME_COMMIT -b $MICROBLOG_THEME_COMMIT
  573. # download a custom background image
  574. MICROBLOG_BACKGROUND_IMAGE_URL_EXT=
  575. if [ $MICROBLOG_BACKGROUND_IMAGE_URL ]; then
  576. if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".jpeg" || $$MICROBLOG_BACKGROUND_IMAGE_URL == *".jpg" ]]; then
  577. MICROBLOG_BACKGROUND_IMAGE_URL_EXT="jpg"
  578. fi
  579. if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".png" ]]; then
  580. MICROBLOG_BACKGROUND_IMAGE_URL_EXT="png"
  581. fi
  582. if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".gif" ]]; then
  583. MICROBLOG_BACKGROUND_IMAGE_URL_EXT="gif"
  584. fi
  585. if [ $MICROBLOG_BACKGROUND_IMAGE_URL_EXT ]; then
  586. wget $MICROBLOG_BACKGROUND_IMAGE_URL -O img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}
  587. if [ ! -f img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT} ]; then
  588. echo "$MICROBLOG_BACKGROUND_IMAGE_URL"
  589. echo $'Custom background image for microblog could not be downloaded'
  590. exit 87524
  591. fi
  592. fi
  593. fi
  594. microblog_config_file=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
  595. if ! grep -q "addPlugin('Qvitter')" $microblog_config_file; then
  596. MICROBLOG_WELCOME_MESSAGE=$(echo $MICROBLOG_WELCOME_MESSAGE | sed "s|\$MICROBLOG_DOMAIN_NAME|$MICROBLOG_DOMAIN_NAME|g")
  597. echo "" >> $microblog_config_file
  598. echo "// Qvitter settings" >> $microblog_config_file
  599. echo "addPlugin('Qvitter');" >> $microblog_config_file
  600. echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $microblog_config_file
  601. echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $microblog_config_file
  602. echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $microblog_config_file
  603. echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $microblog_config_file
  604. echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $microblog_config_file
  605. echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $microblog_config_file
  606. if [ $MICROBLOG_BACKGROUND_IMAGE_URL ]; then
  607. echo "\$config['site']['qvitter']['sitebackground'] = 'img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}';" >> $microblog_config_file
  608. else
  609. echo "\$config['site']['qvitter']['sitebackground'] = 'img/vagnsmossen.jpg';" >> $microblog_config_file
  610. fi
  611. echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $microblog_config_file
  612. echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $microblog_config_file
  613. echo "\$config['site']['qvitter']['enablewelcometext'] = true;" >> $microblog_config_file
  614. echo "\$config['site']['qvitter']['customwelcometext']['en'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
  615. echo "\$config['site']['qvitter']['customwelcometext']['de'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
  616. echo "\$config['site']['qvitter']['customwelcometext']['fr'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
  617. echo "\$config['site']['qvitter']['customwelcometext']['es'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
  618. echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $microblog_config_file
  619. else
  620. if [ $MICROBLOG_BACKGROUND_IMAGE_URL_EXT ]; then
  621. if [ -f img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT} ]; then
  622. sed -i "s|\$config['site']['qvitter']['sitebackground'].*|\$config['site']['qvitter']['sitebackground'] = 'img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}';|g" $microblog_config_file
  623. fi
  624. fi
  625. fi
  626. # customise with project logo
  627. if [ -f /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  628. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  629. cp ~/freedombone/img/gnusocial_sprite.png /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
  630. fi
  631. fi
  632. if ! grep -q "GNU Social theme commit" $COMPLETION_FILE; then
  633. echo "GNU Social theme commit:$MICROBLOG_THEME_COMMIT" >> $COMPLETION_FILE
  634. fi
  635. chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  636. echo 'install_gnusocial_theme' >> $COMPLETION_FILE
  637. }
  638. function install_gnusocial_markdown {
  639. MICROBLOG_PATH=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs
  640. # update to the next commit
  641. function_check set_repo_commit
  642. set_repo_commit $MICROBLOG_PATH/local/plugins/Markdown "GNU Social Markdown commit" "$MICROBLOG_MARKDOWN_COMMIT" $MICROBLOG_MARKDOWN_REPO
  643. if grep -Fxq "install_gnusocial_markdown" $COMPLETION_FILE; then
  644. return
  645. fi
  646. if [ -d $MICROBLOG_PATH/local/plugins/Markdown ]; then
  647. rm -rf $MICROBLOG_PATH/local/plugins/Markdown
  648. fi
  649. if [ ! -d $MICROBLOG_PATH/local/plugins ]; then
  650. mkdir -p $MICROBLOG_PATH/local/plugins
  651. fi
  652. cd $MICROBLOG_PATH/local/plugins
  653. function_check git_clone
  654. git_clone $MICROBLOG_MARKDOWN_REPO Markdown
  655. cd $MICROBLOG_PATH/local/plugins/Markdown
  656. git checkout $MICROBLOG_MARKDOWN_COMMIT -b $MICROBLOG_MARKDOWN_COMMIT
  657. microblog_config_file=$MICROBLOG_PATH/config.php
  658. if ! grep -q "addPlugin('Markdown'" $microblog_config_file; then
  659. echo "" >> $microblog_config_file
  660. echo "// Markdown settings" >> $microblog_config_file
  661. echo "addPlugin('Markdown');" >> $microblog_config_file
  662. fi
  663. if ! grep -q "GNU Social Markdown commit" $COMPLETION_FILE; then
  664. echo "GNU Social Markdown commit:$MICROBLOG_MARKDOWN_COMMIT" >> $COMPLETION_FILE
  665. fi
  666. chown -R www-data:www-data $MICROBLOG_PATH
  667. echo 'install_gnusocial_markdown' >> $COMPLETION_FILE
  668. }
  669. function install_gnusocial {
  670. if grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
  671. return
  672. fi
  673. install_gnusocial_main
  674. expire_gnusocial_posts
  675. install_gnusocial_theme
  676. install_gnusocial_markdown
  677. install_gnusocial_plugin_sharings
  678. install_gnusocial_plugin_sharings_theme
  679. echo 'install_gnusocial' >> $COMPLETION_FILE
  680. }
  681. # NOTE: deliberately there is no "exit 0"