freedombone-utils-gnusocialtools 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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"
  33. PLEROMA_COMMIT='0c7450252a3e42a5fc6488b0def26c5934fb0adb'
  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. # remove any existing image
  54. if [ -f bg_custom.${ext} ]; then
  55. rm bg_custom.${ext}
  56. fi
  57. # get the new image
  58. wget $url -O bg_custom.${ext}
  59. if [ ! -f bg_custom.${ext} ]; then
  60. echo "$url"
  61. echo $'Custom background image for pleroma could not be downloaded'
  62. echo "1"
  63. return
  64. fi
  65. sed -i "s|\"background\":.*|\"background\": \"bg_custom.${ext}\",|g" config.json
  66. fi
  67. else
  68. echo "2"
  69. return
  70. fi
  71. # customise the logo
  72. if [ -f /var/www/${domain_name}/htdocs/static/logo.png ]; then
  73. if [ -f ~/freedombone/img/logo_fbone3.png ]; then
  74. cp ~/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/static/logo.png
  75. else
  76. if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then
  77. cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/static/logo.png
  78. fi
  79. fi
  80. fi
  81. # customise the title
  82. if [ -f /var/www/${domain_name}/htdocs/static/config.json ]; then
  83. sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" /var/www/${domain_name}/htdocs/static/config.json
  84. fi
  85. echo "0"
  86. }
  87. function install_qvitter {
  88. domain_name=$1
  89. app_name=$2
  90. # update to the next commit
  91. function_check set_repo_commit
  92. set_repo_commit /var/www/${domain_name}/htdocs/local/plugins/Qvitter "${app_name} theme commit" "$QVITTER_THEME_COMMIT" $QVITTER_THEME_REPO
  93. # customise with project logo
  94. if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  95. if [ -f ~/freedombone/img/logo_fbone3.png ]; then
  96. cp ~/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  97. else
  98. if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then
  99. cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  100. fi
  101. fi
  102. fi
  103. if [[ $(app_is_installed "${app_name}_theme") == "1" ]]; then
  104. return
  105. fi
  106. apt-get -yq install wget
  107. if [ ! -d /var/www/${domain_name}/htdocs/local/plugins ]; then
  108. mkdir -p /var/www/${domain_name}/htdocs/local/plugins
  109. fi
  110. cd /var/www/${domain_name}/htdocs/local/plugins
  111. function_check git_clone
  112. git_clone $QVITTER_THEME_REPO Qvitter
  113. cd /var/www/${domain_name}/htdocs/local/plugins/Qvitter
  114. git checkout $QVITTER_THEME_COMMIT -b $QVITTER_THEME_COMMIT
  115. config_file=/var/www/${domain_name}/htdocs/config.php
  116. if ! grep -q "addPlugin('Qvitter')" $config_file; then
  117. echo "" >> $config_file
  118. echo "// Qvitter settings" >> $config_file
  119. echo "addPlugin('Qvitter');" >> $config_file
  120. echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $config_file
  121. echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $config_file
  122. echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $config_file
  123. echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $config_file
  124. if [[ $ONION_ONLY != 'no' ]]; then
  125. echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $config_file
  126. echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $config_file
  127. fi
  128. echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $config_file
  129. echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $config_file
  130. echo "\$config['site']['qvitter']['enablewelcometext'] = false;" >> $config_file
  131. echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $config_file
  132. fi
  133. # customise with project logo
  134. if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  135. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  136. cp ~/freedombone/img/gnusocial_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  137. fi
  138. fi
  139. chown -R www-data:www-data /var/www/${domain_name}/htdocs
  140. cd /var/www/${domain_name}/htdocs
  141. php scripts/upgrade.php
  142. php scripts/checkschema.php
  143. chown -R www-data:www-data /var/www/${domain_name}/htdocs
  144. set_completion_param "${app_name} theme commit" "$QVITTER_THEME_COMMIT"
  145. install_completed ${app_name}_theme
  146. }
  147. function install_pleroma {
  148. app_name="$1"
  149. pleroma_domain="$2"
  150. background_url="$3"
  151. title="$4"
  152. if [ ! -d $INSTALL_DIR/pleroma ]; then
  153. function_check git_clone
  154. git_clone $PLEROMA_REPO $INSTALL_DIR/pleroma
  155. if [ ! -d $INSTALL_DIR/pleroma ]; then
  156. echo $'Unable to clone pleroma repo'
  157. exit 682252
  158. fi
  159. fi
  160. cd $INSTALL_DIR/pleroma
  161. git checkout $PLEROMA_COMMIT -b $PLEROMA_COMMIT
  162. set_completion_param "${app_name} pleroma commit" "$PLEROMA_COMMIT"
  163. npm install -g yarn
  164. yarn
  165. npm run build
  166. if [ ! -d $INSTALL_DIR/pleroma/dist ]; then
  167. echo 'Unable to build pleroma'
  168. exit 7629352
  169. fi
  170. if [ ! -f $INSTALL_DIR/pleroma/dist/index.html ]; then
  171. echo $'Unable to build pleroma index.html'
  172. exit 5282682
  173. fi
  174. mv $INSTALL_DIR/pleroma/dist/index.html $INSTALL_DIR/pleroma/dist/pleroma.html
  175. cp -r $INSTALL_DIR/pleroma/dist/* /var/www/${pleroma_domain}/htdocs/
  176. pleroma_set_background_image_from_url "$pleroma_domain" "$background_url" "$title"
  177. nginx_site=/etc/nginx/sites-available/${pleroma_domain}
  178. sed -i 's|index index.php;|index pleroma.html;|g' $nginx_site
  179. }
  180. function upgrade_pleroma {
  181. domain_name="$1"
  182. app_name="$2"
  183. background_url="$3"
  184. title="$4"
  185. if [ -d $INSTALL_DIR/pleroma ]; then
  186. set_repo_commit $INSTALL_DIR/pleroma "${app_name} pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
  187. cd $INSTALL_DIR/pleroma
  188. npm run build
  189. if [ ! -d $INSTALL_DIR/pleroma/dist ]; then
  190. echo 'Unable to build pleroma'
  191. exit 268362
  192. fi
  193. mv $INSTALL_DIR/pleroma/dist/index.html $INSTALL_DIR/pleroma/dist/pleroma.html
  194. cp -r $INSTALL_DIR/pleroma/dist/* /var/www/${domain_name}/htdocs/
  195. pleroma_set_background_image_from_url "$domain_name" "$background_url" "$title"
  196. else
  197. install_pleroma "${app_name}" "${domain_name}" "${background_url}" "${title}"
  198. fi
  199. }
  200. # NOTE: deliberately there is no "exit 0"