freedombone-utils-gnusocialtools 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. if [ ${#domain_name} -eq 0 ]; then
  39. echo "1"
  40. return
  41. fi
  42. ext=
  43. if [ ${#url} -gt 0 ]; then
  44. if [[ "$url" == *".jpeg" || "$url" == *".jpg" ]]; then
  45. ext="jpg"
  46. fi
  47. if [[ "$url" == *".png" ]]; then
  48. ext="png"
  49. fi
  50. if [[ "$url" == *".gif" ]]; then
  51. ext="gif"
  52. fi
  53. fi
  54. if [ ${#ext} -gt 0 ]; then
  55. if [ -d /var/www/${domain_name}/htdocs/static ]; then
  56. cd /var/www/${domain_name}/htdocs/static
  57. # remove any existing image
  58. if [ -f bg_custom.${ext} ]; then
  59. rm bg_custom.${ext}
  60. fi
  61. # get the new image
  62. wget "$url" -O bg_custom.${ext}
  63. if [ ! -f bg_custom.${ext} ]; then
  64. echo "$url"
  65. echo $'Custom background image for pleroma could not be downloaded'
  66. echo "1"
  67. return
  68. fi
  69. sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" config.json
  70. fi
  71. else
  72. echo "2"
  73. return
  74. fi
  75. # customise the logo
  76. if [ -f /var/www/${domain_name}/htdocs/static/logo.png ]; then
  77. if [ -f ~/freedombone/img/logo_fbone3.png ]; then
  78. cp ~/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/static/logo.png
  79. else
  80. if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then
  81. cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/static/logo.png
  82. fi
  83. fi
  84. fi
  85. # customise the title
  86. if [ -f /var/www/${domain_name}/htdocs/static/config.json ]; then
  87. sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" /var/www/${domain_name}/htdocs/static/config.json
  88. fi
  89. echo "0"
  90. }
  91. function install_qvitter {
  92. domain_name=$1
  93. app_name=$2
  94. # update to the next commit
  95. function_check set_repo_commit
  96. set_repo_commit /var/www/${domain_name}/htdocs/local/plugins/Qvitter "${app_name} theme commit" "$QVITTER_THEME_COMMIT" $QVITTER_THEME_REPO
  97. # customise with project logo
  98. if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  99. if [ -f ~/freedombone/img/logo_fbone3.png ]; then
  100. cp ~/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  101. else
  102. if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then
  103. cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  104. fi
  105. fi
  106. fi
  107. if [[ $(app_is_installed "${app_name}_theme") == "1" ]]; then
  108. return
  109. fi
  110. apt-get -yq install wget
  111. if [ ! -d /var/www/${domain_name}/htdocs/local/plugins ]; then
  112. mkdir -p /var/www/${domain_name}/htdocs/local/plugins
  113. fi
  114. cd /var/www/${domain_name}/htdocs/local/plugins
  115. function_check git_clone
  116. git_clone $QVITTER_THEME_REPO Qvitter
  117. cd /var/www/${domain_name}/htdocs/local/plugins/Qvitter
  118. git checkout $QVITTER_THEME_COMMIT -b $QVITTER_THEME_COMMIT
  119. config_file=/var/www/${domain_name}/htdocs/config.php
  120. if ! grep -q "addPlugin('Qvitter')" $config_file; then
  121. echo "" >> $config_file
  122. echo "// Qvitter settings" >> $config_file
  123. echo "addPlugin('Qvitter');" >> $config_file
  124. echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $config_file
  125. echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $config_file
  126. echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $config_file
  127. echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $config_file
  128. if [[ $ONION_ONLY != 'no' ]]; then
  129. echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $config_file
  130. echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $config_file
  131. fi
  132. echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $config_file
  133. echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $config_file
  134. echo "\$config['site']['qvitter']['enablewelcometext'] = false;" >> $config_file
  135. echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $config_file
  136. fi
  137. # customise with project logo
  138. if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  139. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  140. cp ~/freedombone/img/gnusocial_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
  141. fi
  142. fi
  143. chown -R www-data:www-data /var/www/${domain_name}/htdocs
  144. cd /var/www/${domain_name}/htdocs
  145. php scripts/upgrade.php
  146. php scripts/checkschema.php
  147. chown -R www-data:www-data /var/www/${domain_name}/htdocs
  148. set_completion_param "${app_name} theme commit" "$QVITTER_THEME_COMMIT"
  149. install_completed ${app_name}_theme
  150. }
  151. function install_pleroma {
  152. app_name="$1"
  153. pleroma_domain="$2"
  154. background_url="$3"
  155. title="$4"
  156. if [ ! -d $INSTALL_DIR/pleroma ]; then
  157. function_check git_clone
  158. git_clone $PLEROMA_REPO $INSTALL_DIR/pleroma
  159. if [ ! -d $INSTALL_DIR/pleroma ]; then
  160. echo $'Unable to clone pleroma repo'
  161. exit 682252
  162. fi
  163. fi
  164. cd $INSTALL_DIR/pleroma
  165. git checkout $PLEROMA_COMMIT -b $PLEROMA_COMMIT
  166. set_completion_param "${app_name} pleroma commit" "$PLEROMA_COMMIT"
  167. npm install -g yarn
  168. yarn
  169. npm run build
  170. if [ ! -d $INSTALL_DIR/pleroma/dist ]; then
  171. echo 'Unable to build pleroma'
  172. exit 7629352
  173. fi
  174. if [ ! -f $INSTALL_DIR/pleroma/dist/index.html ]; then
  175. echo $'Unable to build pleroma index.html'
  176. exit 5282682
  177. fi
  178. cp -r $INSTALL_DIR/pleroma/dist/* /var/www/${pleroma_domain}/htdocs/
  179. pleroma_set_background_image_from_url "$pleroma_domain" "$background_url" "$title"
  180. nginx_site=/etc/nginx/sites-available/${pleroma_domain}
  181. sed -i 's|index index.php;|index index.html;|g' $nginx_site
  182. if [ -f /var/www/${pleroma_domain}/htdocs/index.php ]; then
  183. mv /var/www/${pleroma_domain}/htdocs/index.php /var/www/${pleroma_domain}/htdocs/index_qvitter.php
  184. fi
  185. sed -i 's|index.php|index_qvitter.php|g' $nginx_site
  186. chown -R www-data:www-data /var/www/${pleroma_domain}/htdocs
  187. }
  188. function upgrade_pleroma {
  189. domain_name="$1"
  190. app_name="$2"
  191. background_url="$3"
  192. title="$4"
  193. if [ -d $INSTALL_DIR/pleroma ]; then
  194. set_repo_commit $INSTALL_DIR/pleroma "${app_name} pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
  195. cd $INSTALL_DIR/pleroma
  196. npm run build
  197. if [ ! -d $INSTALL_DIR/pleroma/dist ]; then
  198. echo 'Unable to build pleroma'
  199. exit 268362
  200. fi
  201. cp -r $INSTALL_DIR/pleroma/dist/* /var/www/${domain_name}/htdocs/
  202. pleroma_set_background_image_from_url "$domain_name" "$background_url" "$title"
  203. if [ -f /var/www/${domain_name}/htdocs/index.php ]; then
  204. mv /var/www/${domain_name}/htdocs/index.php /var/www/${domain_name}/htdocs/index_qvitter.php
  205. fi
  206. chown -R www-data:www-data /var/www/${domain_name}/htdocs
  207. else
  208. install_pleroma "${app_name}" "${domain_name}" "${background_url}" "${title}"
  209. fi
  210. }
  211. function gnusocial_hourly_script {
  212. gnusocial_type=$1
  213. domain_name=$2
  214. # check that the daemon is running
  215. echo '#!/bin/bash' > /etc/cron.hourly/${gnusocial_type}-daemons
  216. echo -n 'daemon_lines=$(ps aux | grep "' >> /etc/cron.hourly/${gnusocial_type}-daemons
  217. echo -n "${domain_name}" >> /etc/cron.hourly/${gnusocial_type}-daemons
  218. echo '/htdocs/scripts/queuedaemon.php" | grep "/var/www")' >> /etc/cron.hourly/${gnusocial_type}-daemons
  219. echo "cd /var/www/${domain_name}/htdocs" >> /etc/cron.hourly/${gnusocial_type}-daemons
  220. echo 'if [[ $daemon_lines != *"/var/www/"* ]]; then' >> /etc/cron.hourly/${gnusocial_type}-daemons
  221. echo " ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')" >> /etc/cron.hourly/${gnusocial_type}-daemons
  222. echo ' MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME' >> /etc/cron.hourly/${gnusocial_type}-daemons
  223. echo -n " echo \"Restarting ${gnusocial_type} daemons\" | mail -s \"${gnusocial_type} " >> /etc/cron.hourly/${gnusocial_type}-daemons
  224. echo 'daemons not found" $MY_EMAIL_ADDRESS' >> /etc/cron.hourly/${gnusocial_type}-daemons
  225. echo ' scripts/startdaemons.sh' >> /etc/cron.hourly/${gnusocial_type}-daemons
  226. echo 'fi' >> /etc/cron.hourly/${gnusocial_type}-daemons
  227. echo 'php scripts/delete_orphan_files.php > /dev/null' >> /etc/cron.hourly/${gnusocial_type}-daemons
  228. echo 'php scripts/clean_thumbnails.php -y > /dev/null' >> /etc/cron.hourly/${gnusocial_type}-daemons
  229. echo 'php scripts/clean_file_table.php -y > /dev/null' >> /etc/cron.hourly/${gnusocial_type}-daemons
  230. echo 'php scripts/upgrade.php > /dev/null' >> /etc/cron.hourly/${gnusocial_type}-daemons
  231. chmod +x /etc/cron.hourly/${gnusocial_type}-daemons
  232. }
  233. # NOTE: deliberately there is no "exit 0"