freedombone-utils-gnusocialtools 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # functions common to GNU Social server varieties
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. QVITTER_THEME_REPO="https://git.gnu.io/h2p/Qvitter.git"
  31. QVITTER_THEME_COMMIT='a7f82628402db3a7579bb9b2877da3c5737da77b'
  32. PLEROMA_REPO="https://gitgud.io/lambadalambda/pleroma-fe.git"
  33. PLEROMA_COMMIT='935c0e09'
  34. function pleroma_set_background_image_from_url {
  35. domain_name="$1"
  36. url="$2"
  37. title="$3"
  38. ext=
  39. if [ ${#url} -gt 0 ]; then
  40. if [[ $url == *".jpeg" || $url == *".jpg" ]]; then
  41. ext="jpg"
  42. fi
  43. if [[ $url == *".png" ]]; then
  44. ext="png"
  45. fi
  46. if [[ $url == *".gif" ]]; then
  47. ext="gif"
  48. fi
  49. fi
  50. if [ ${#ext} -gt 0 ]; then
  51. if [ -d /var/www/${domain_name}/htdocs/static ]; then
  52. cd /var/www/${domain_name}/htdocs/static
  53. wget $url -O bg_custom.${ext}
  54. if [ ! -f bg_custom.${ext} ]; then
  55. echo "$url"
  56. echo $'Custom background image for pleroma could not be downloaded'
  57. echo "1"
  58. return
  59. fi
  60. sed -i "s|\"background\":.*|\"background\": \"bg_custom.${ext}\",|g" config.json
  61. fi
  62. fi
  63. # customise the logo
  64. if [ -f /var/www/${domain_name}/htdocs/static/logo.png ]; then
  65. if [ -f ~/freedombone/img/logo_white_small.png ]; then
  66. cp ~/freedombone/img/logo_white_small.png /var/www/${domain_name}/htdocs/static/logo.png
  67. else
  68. if [ -f /home/$MY_USERNAME/freedombone/img/logo_white_small.png ]; then
  69. cp /home/$MY_USERNAME/freedombone/img/logo_white_small.png /var/www/${domain_name}/htdocs/static/logo.png
  70. fi
  71. fi
  72. fi
  73. # customise the title
  74. if [ -f /var/www/${domain_name}/htdocs/static/config.json ]; then
  75. sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" /var/www/${domain_name}/htdocs/static/config.json
  76. fi
  77. echo "0"
  78. }
  79. function install_qvitter {
  80. domain_name=$1
  81. app_name=$2
  82. # update to the next commit
  83. function_check set_repo_commit
  84. set_repo_commit /var/www/${domain_name}/htdocs/local/plugins/Qvitter "${app_name} theme commit" "$QVITTER_THEME_COMMIT" $QVITTER_THEME_REPO
  85. # customise with project logo
  86. if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  87. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  88. cp ~/freedombone/img/gnusocial_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  89. else
  90. if [ -f /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png ]; then
  91. cp /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  92. fi
  93. fi
  94. fi
  95. if [[ $(app_is_installed "${app_name}_theme") == "1" ]]; then
  96. return
  97. fi
  98. apt-get -yq install wget
  99. if [ ! -d /var/www/${domain_name}/htdocs/local/plugins ]; then
  100. mkdir -p /var/www/${domain_name}/htdocs/local/plugins
  101. fi
  102. cd /var/www/${domain_name}/htdocs/local/plugins
  103. function_check git_clone
  104. git_clone $QVITTER_THEME_REPO Qvitter
  105. cd /var/www/${domain_name}/htdocs/local/plugins/Qvitter
  106. git checkout $QVITTER_THEME_COMMIT -b $QVITTER_THEME_COMMIT
  107. config_file=/var/www/${domain_name}/htdocs/config.php
  108. if ! grep -q "addPlugin('Qvitter')" $config_file; then
  109. echo "" >> $config_file
  110. echo "// Qvitter settings" >> $config_file
  111. echo "addPlugin('Qvitter');" >> $config_file
  112. echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $config_file
  113. echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $config_file
  114. echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $config_file
  115. echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $config_file
  116. if [[ $ONION_ONLY != 'no' ]]; then
  117. echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $config_file
  118. echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $config_file
  119. fi
  120. echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $config_file
  121. echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $config_file
  122. echo "\$config['site']['qvitter']['enablewelcometext'] = false;" >> $config_file
  123. echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $config_file
  124. fi
  125. # customise with project logo
  126. if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  127. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  128. cp ~/freedombone/img/gnusocial_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  129. fi
  130. fi
  131. chown -R www-data:www-data /var/www/${domain_name}/htdocs
  132. set_completion_param "${app_name} theme commit" "$QVITTER_THEME_COMMIT"
  133. install_completed ${app_name}_theme
  134. }
  135. function install_pleroma {
  136. app_name="$1"
  137. pleroma_domain="$2"
  138. background_url="$3"
  139. title="$4"
  140. if [ ! -d ~/build/pleroma ]; then
  141. function_check git_clone
  142. git_clone $PLEROMA_REPO ~/build/pleroma
  143. if [ ! -d ~/build/pleroma ]; then
  144. echo $'Unable to clone pleroma repo'
  145. exit 682252
  146. fi
  147. fi
  148. cd ~/build/pleroma
  149. git checkout $PLEROMA_COMMIT -b $PLEROMA_COMMIT
  150. set_completion_param "${app_name} pleroma commit" "$PLEROMA_COMMIT"
  151. npm install -g yarn
  152. yarn
  153. npm run build
  154. if [ ! -d ~/build/pleroma/dist ]; then
  155. echo 'Unable to build pleroma'
  156. exit 7629352
  157. fi
  158. mv ~/build/pleroma/dist/index.html ~/build/pleroma/dist/pleroma.html
  159. cp -r ~/build/pleroma/dist/* /var/www/$pleroma_domain/htdocs/
  160. pleroma_set_background_image_from_url "$pleroma_domain" "$background_url" "$title"
  161. nginx_site=/etc/nginx/sites-available/$pleroma_domain
  162. sed -i 's|index index.php;|index pleroma.html;|g' $nginx_site
  163. }
  164. function upgrade_pleroma {
  165. domain_name="$1"
  166. app_name="$2"
  167. background_url="$3"
  168. title="$4"
  169. if [ -d ~/build/pleroma ]; then
  170. set_repo_commit ~/build/pleroma "${app_name} pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
  171. cd ~/build/pleroma
  172. npm run build
  173. if [ ! -d ~/build/pleroma/dist ]; then
  174. echo 'Unable to build pleroma'
  175. exit 268362
  176. fi
  177. mv ~/build/pleroma/dist/index.html ~/build/pleroma/dist/pleroma.html
  178. cp -r ~/build/pleroma/dist/* /var/www/${domain_name}/htdocs/
  179. pleroma_set_background_image_from_url "$domain_name" "$background_url" "$title"
  180. else
  181. install_pleroma "${app_name}" "${domain_name}" "${background_url}" "${title}"
  182. fi
  183. }
  184. # NOTE: deliberately there is no "exit 0"