freedombone-app-gnusocial 29KB

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