freedombone-utils-gnusocialtools 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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-2018 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 upstream: https://git.gnu.io/h2p/Qvitter"
  31. QVITTER_THEME_REPO="https://github.com/bashrc/Qvitter"
  32. QVITTER_THEME_COMMIT='c6f09bda4e45be4290cf7409fa5efb4420538032'
  33. PLEROMA_FRONTEND_REPO="https://gitgud.io/lambadalambda/pleroma-fe"
  34. PLEROMA_FRONTEND_COMMIT='3b3bbaab822b553f514a62d20d679acc5ce4414a'
  35. SHARINGS_REPO="http://github.com/bashrc/Sharings"
  36. SHARINGS_COMMIT='0d30fe7d153c7ab44e8459970b8f2b5dec06e43c'
  37. SHARINGS_THEME_REPO="http://github.com/bashrc/SharingsTheme"
  38. SHARINGS_THEME_COMMIT='a46ef375d19e8ef6889653668a7e697b0ba2013c'
  39. GNUSOCIAL_MARKDOWN_REPO="https://git.gnu.io/chimo/markdown.git"
  40. GNUSOCIAL_MARKDOWN_COMMIT='03c53942f94b3376f0946e6e1fe566cc21ccf232'
  41. function gnusocial_set_limits {
  42. filename="$1"
  43. sed -i 's|client_body_buffer_size.*|client_body_buffer_size 5m;|g' "$filename"
  44. sed -i 's|limit_conn conn_limit_per_ip.*|limit_conn conn_limit_per_ip 100;|g' "$filename"
  45. sed -i 's|req_limit_per_ip.*|req_limit_per_ip burst=100 nodelay;|g' "$filename"
  46. }
  47. # Stuff to be done after restoring from backup
  48. function gnusocial_update_after_restore {
  49. gnusocial_variant="$1"
  50. gnusocial_domain="$2"
  51. cd "/var/www/${gnusocial_domain}/htdocs" || exit 36865853
  52. # Ensure that the database password is correct
  53. MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
  54. sed -i "s|\$config['db']['database'].*|\$config['db']['database'] = 'mysqli://root:${MARIADB_PASSWORD}@localhost/${gnusocial_variant}';|g" config.php
  55. MARIADB_PASSWORD=
  56. # Set permissions
  57. chmod g+w "/var/www/$gnusocial_domain/htdocs"
  58. chmod a+w "/var/www/$gnusocial_domain/htdocs/avatar"
  59. chmod a+w "/var/www/$gnusocial_domain/htdocs/file"
  60. chown -R www-data:www-data "/var/www/$gnusocial_domain/htdocs"
  61. chmod +x "/var/www/$gnusocial_domain/htdocs/scripts/maildaemon.php"
  62. # This seems to be necessary to get the UI back
  63. gnusocial_use_classic "$gnusocial_variant"
  64. gnusocial_use_qvitter "$gnusocial_variant"
  65. # start the daemons
  66. su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data
  67. }
  68. function qvitter_update_background {
  69. domain_name="$1"
  70. ext="$2"
  71. if [ -d "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img" ]; then
  72. if [ -f "bg_custom.${ext}" ]; then
  73. cp "bg_custom.${ext}" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img"
  74. if ! grep -q "bg_custom.${ext}" "/var/www/${domain_name}/htdocs/config.php"; then
  75. if grep -q 'sitebackground' "/var/www/${domain_name}/htdocs/config.php"; then
  76. sed -i '/sitebackground/d' "/var/www/${domain_name}/htdocs/config.php"
  77. fi
  78. echo "\$config['site']['qvitter']['sitebackground'] = 'img/bg_custom.${ext}';" >> "/var/www/${domain_name}/htdocs/config.php"
  79. fi
  80. fi
  81. fi
  82. }
  83. function pleroma_custom_logo {
  84. basedir="$1"
  85. if [ "$2" ]; then
  86. if [[ "$2" == *".png" ]]; then
  87. cp "$2" "$basedir/priv/static/static/logo.png"
  88. return
  89. fi
  90. fi
  91. if [ -f "$basedir/priv/static/static/logo.png" ]; then
  92. if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
  93. cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo.png"
  94. cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/priv/static/static/logo.png"
  95. else
  96. if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
  97. cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo.png"
  98. cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/priv/static/static/logo.png"
  99. fi
  100. fi
  101. fi
  102. }
  103. function pleroma_set_background_image_from_url {
  104. basedir="$1"
  105. domain_name="$2"
  106. url="$3"
  107. title="$4"
  108. if [ ${#domain_name} -eq 0 ]; then
  109. echo "1"
  110. return
  111. fi
  112. ext=
  113. if [ ${#url} -gt 0 ]; then
  114. if [[ "$url" == *".jpeg" || "$url" == *".jpg" ]]; then
  115. ext="jpg"
  116. fi
  117. if [[ "$url" == *".png" ]]; then
  118. ext="png"
  119. fi
  120. if [[ "$url" == *".gif" ]]; then
  121. ext="gif"
  122. fi
  123. fi
  124. if [ ${#ext} -gt 0 ]; then
  125. cd "$basedir" || exit 638436783
  126. # remove any existing image
  127. if [ -f "bg_custom.${ext}" ]; then
  128. rm "bg_custom.${ext}"
  129. fi
  130. # get the new image
  131. wget "$url" -O "bg_custom.${ext}"
  132. if [ ! -f "bg_custom.${ext}" ]; then
  133. echo "$url"
  134. echo $'Custom background image for pleroma could not be downloaded'
  135. echo "1"
  136. return
  137. fi
  138. if [ -d "$basedir/static" ]; then
  139. cp "bg_custom.${ext}" "static/bg_custom.${ext}"
  140. chown www-data:www-data "static/bg_custom.${ext}"
  141. sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" static/config.json
  142. fi
  143. if [ -d priv/static/static ]; then
  144. cp "bg_custom.${ext}" "priv/static/static/bg_custom.${ext}"
  145. chown www-data:www-data "priv/static/static/bg_custom.${ext}"
  146. sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" priv/static/static/config.json
  147. fi
  148. if [[ "$basedir" != "$PLEROMA_DIR" ]]; then
  149. qvitter_update_background "${domain_name}" "${ext}"
  150. fi
  151. rm "bg_custom.${ext}"
  152. else
  153. echo "2"
  154. return
  155. fi
  156. pleroma_custom_logo "$basedir"
  157. # customise the title
  158. if [ -f "$basedir/static/config.json" ]; then
  159. sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/static/config.json"
  160. fi
  161. if [ -f "$basedir/priv/static/static/config.json" ]; then
  162. sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/priv/static/static/config.json"
  163. fi
  164. echo "0"
  165. }
  166. function install_qvitter {
  167. domain_name="$1"
  168. app_name="$2"
  169. # update to the next commit
  170. function_check set_repo_commit
  171. set_repo_commit "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" "${app_name} theme commit" "$QVITTER_THEME_COMMIT" "$QVITTER_THEME_REPO"
  172. # customise with project logo
  173. if [ -f "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" ]; then
  174. if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
  175. cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png"
  176. else
  177. if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
  178. cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png"
  179. fi
  180. fi
  181. fi
  182. if [[ $(app_is_installed "${app_name}_theme") == "1" ]]; then
  183. return
  184. fi
  185. apt-get -yq install wget
  186. if [ ! -d "/var/www/${domain_name}/htdocs/local/plugins" ]; then
  187. mkdir -p "/var/www/${domain_name}/htdocs/local/plugins"
  188. fi
  189. cd "/var/www/${domain_name}/htdocs/local/plugins" || exit 64284632
  190. if [ -d /repos/qvitter ]; then
  191. mkdir Qvitter
  192. cp -r -p /repos/qvitter/. Qvitter
  193. cd Qvitter || exit 2648246
  194. git pull
  195. else
  196. function_check git_clone
  197. git_clone "$QVITTER_THEME_REPO" Qvitter
  198. fi
  199. if [ ! -d "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" ]; then
  200. echo $'Qvitter repo was not installed'
  201. exit 835638
  202. fi
  203. cd "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" || exit 7824245
  204. git checkout "$QVITTER_THEME_COMMIT" -b "$QVITTER_THEME_COMMIT"
  205. config_file="/var/www/${domain_name}/htdocs/config.php"
  206. if ! grep -q "addPlugin('Qvitter')" "$config_file"; then
  207. { echo "";
  208. echo "// Qvitter settings";
  209. echo "addPlugin('Qvitter');";
  210. echo "\$config['site']['qvitter']['enabledbydefault'] = true;";
  211. echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';";
  212. echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';";
  213. echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs"; } >> "$config_file"
  214. if [[ $ONION_ONLY == 'no' ]]; then
  215. echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> "$config_file"
  216. echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> "$config_file"
  217. fi
  218. { echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';";
  219. echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';";
  220. echo "\$config['site']['qvitter']['enablewelcometext'] = false;";
  221. echo "\$config['site']['qvitter']['blocked_ips'] = array();"; } >> "$config_file"
  222. fi
  223. # customise with project logo
  224. if [ -f "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" ]; then
  225. if [ -f "$HOME/${PROJECT_NAME}/img/${app_name}_sprite.png" ]; then
  226. cp "$HOME/${PROJECT_NAME}/img/${app_name}_sprite.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png"
  227. fi
  228. fi
  229. chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
  230. cd "/var/www/${domain_name}/htdocs" || exit 37483673
  231. php scripts/upgrade.php
  232. php scripts/checkschema.php
  233. chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
  234. set_completion_param "${app_name} theme commit" "$QVITTER_THEME_COMMIT"
  235. install_completed "${app_name}_theme"
  236. }
  237. function install_gnusocial_default_background {
  238. gnusocial_type="$1"
  239. domain_name="$2"
  240. basedir="/var/www/${domain_name}/htdocs"
  241. if [[ "$gnusocial_type" == 'pleroma' ]]; then
  242. basedir="$PLEROMA_DIR/priv/static"
  243. fi
  244. # customise the logo
  245. if [ -f "$basedir/static/logo.png" ]; then
  246. if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
  247. cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo_custom.png"
  248. sed -i "s|\"logo\":.*|\"logo\": \"/static/logo_custom.png\",|g" "$basedir/static/config.json"
  249. else
  250. if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
  251. cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo_custom.png"
  252. sed -i "s|\"logo\":.*|\"logo\": \"/static/logo_custom.png\",|g" "$basedir/static/config.json"
  253. fi
  254. fi
  255. fi
  256. if [ ! -f "$basedir/static/bg.jpg" ]; then
  257. return
  258. fi
  259. if [ -f "$HOME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" ]; then
  260. cp "$HOME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" "$basedir/static/bg_custom.jpg"
  261. sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.jpg\",|g" "$basedir/static/config.json"
  262. else
  263. if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" ]; then
  264. cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" "$basedir/static/bg_custom.jpg"
  265. sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.jpg\",|g" "$basedir/static/config.json"
  266. fi
  267. fi
  268. }
  269. function install_pleroma_front_end {
  270. app_name="$1"
  271. pleroma_domain="$2"
  272. background_url="$3"
  273. title="$4"
  274. if [ ! -d "$INSTALL_DIR/pleroma" ]; then
  275. if [ -d /repos/pleroma-fe ]; then
  276. mkdir -p "$INSTALL_DIR/pleroma"
  277. cp -r -p /repos/pleroma-fe/. "$INSTALL_DIR/pleroma"
  278. cd "$INSTALL_DIR/pleroma" || exit 23468324
  279. git pull
  280. else
  281. function_check git_clone
  282. git_clone "$PLEROMA_FRONTEND_REPO" "$INSTALL_DIR/pleroma"
  283. fi
  284. if [ ! -d "$INSTALL_DIR/pleroma" ]; then
  285. echo $'Unable to clone pleroma repo'
  286. exit 682252
  287. fi
  288. fi
  289. cd "$INSTALL_DIR/pleroma" || exit 2562844
  290. git checkout "$PLEROMA_FRONTEND_COMMIT" -b "$PLEROMA_FRONTEND_COMMIT"
  291. set_completion_param "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT"
  292. if [ -d "$INSTALL_DIR/pleroma/node_modules" ]; then
  293. rm -rf "$INSTALL_DIR/pleroma/node_modules"
  294. fi
  295. npm install -g yarn
  296. npm install -g eslint@3.19.0
  297. npm install -g eslint-plugin-promise@3.5.0
  298. npm install -g moment@2.18.1
  299. npm install -g node-sass@4.5.2
  300. npm install -g whatwg-fetch@2.0.3
  301. yarn
  302. if [ -f "$INSTALL_DIR/pleroma/dist/index.html" ]; then
  303. rm -rf "$INSTALL_DIR/pleroma/dist/"*
  304. fi
  305. npm run build
  306. if [ ! -d "$INSTALL_DIR/pleroma/dist" ]; then
  307. echo 'Unable to build pleroma'
  308. exit 7629352
  309. fi
  310. if [ ! -f "$INSTALL_DIR/pleroma/dist/index.html" ]; then
  311. echo $'Unable to build pleroma index.html'
  312. exit 5282682
  313. fi
  314. if [[ "$app_name" != 'pleroma' ]]; then
  315. cp -r "$INSTALL_DIR/pleroma/dist/"* "/var/www/${pleroma_domain}/htdocs/"
  316. pleroma_set_background_image_from_url "/var/www/${pleroma_domain}/htdocs" "$pleroma_domain" "$background_url" "$title"
  317. else
  318. cp -r "$INSTALL_DIR/pleroma/dist/"* "$PLEROMA_DIR/priv/static"
  319. pleroma_set_background_image_from_url "$PLEROMA_DIR/priv/static" "$pleroma_domain" "$background_url" "$title"
  320. fi
  321. nginx_site="/etc/nginx/sites-available/${pleroma_domain}"
  322. sed -i 's|index index.php;|index index.html;|g' "$nginx_site"
  323. if [ -f "/var/www/${pleroma_domain}/htdocs/index.php" ]; then
  324. # shellcheck disable=SC2086
  325. mv /var/www/${pleroma_domain}/htdocs/index.php /var/www/${pleroma_domain}/htdocs/index_qvitter.php
  326. fi
  327. sed -i 's|index.php|index_qvitter.php|g' "$nginx_site"
  328. # remove any cached yarn files
  329. if [ -d /root/.cache/yarn ]; then
  330. rm -rf /root/.cache/yarn
  331. fi
  332. if [[ "$app_name" != 'pleroma' ]]; then
  333. chown -R www-data:www-data "/var/www/${pleroma_domain}/htdocs"
  334. else
  335. chown -R pleroma:pleroma "$PLEROMA_DIR"
  336. fi
  337. }
  338. function upgrade_pleroma_frontend {
  339. domain_name="$1"
  340. app_name="$2"
  341. background_url="$3"
  342. title="$4"
  343. if [ -d "$INSTALL_DIR/pleroma" ]; then
  344. set_repo_commit "$INSTALL_DIR/pleroma" "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT" "$PLEROMA_FRONTEND_REPO"
  345. cd "$INSTALL_DIR/pleroma" || exit 3468356385
  346. yarn
  347. npm run build
  348. if [ ! -d "$INSTALL_DIR/pleroma/dist" ]; then
  349. echo 'Unable to build pleroma'
  350. exit 268362
  351. fi
  352. basedir="/var/www/${domain_name}/htdocs"
  353. if [[ "$app_name" == 'pleroma' ]]; then
  354. basedir="$PLEROMA_DIR/priv/static"
  355. fi
  356. if [ -f "$basedir/static/logo.png" ]; then
  357. cp "$basedir/static/logo.png" "$basedir/static/logo.png.old"
  358. fi
  359. if [ -f "$basedir/static/bg.jpg" ]; then
  360. cp "$basedir/static/bg.jpg" "$basedir/static/bg.jpg.old"
  361. fi
  362. if [ -f "$basedir/static/config.json" ]; then
  363. cp "$basedir/static/config.json" "$basedir/static/config.json.old"
  364. fi
  365. cp -r "$INSTALL_DIR/pleroma/dist/"* "$basedir/"
  366. if [ -f "$basedir/static/config.json.old" ]; then
  367. # shellcheck disable=SC2086
  368. mv $basedir/static/config.json.old $basedir/static/config.json
  369. fi
  370. sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/static/config.json"
  371. if [ -f "$basedir/static/logo.png.old" ]; then
  372. cp "$basedir/static/logo.png.old" "$basedir/static/logo.png"
  373. fi
  374. if [ -f "$basedir/static/bg.jpg.old" ]; then
  375. cp "$basedir/static/bg.jpg.old" "$basedir/static/bg.jpg"
  376. fi
  377. if [ -f "$basedir/index.php" ]; then
  378. # shellcheck disable=SC2086
  379. mv $basedir/index.php $basedir/index_qvitter.php
  380. fi
  381. chown -R www-data:www-data "$basedir"
  382. else
  383. install_pleroma_front_end "${app_name}" "${domain_name}" "${background_url}" "${title}"
  384. fi
  385. }
  386. function gnusocial_hourly_script {
  387. gnusocial_type="$1"
  388. domain_name="$2"
  389. # check that the daemon is running
  390. { echo '#!/bin/bash';
  391. echo -n "daemon_lines=\$(ps aux | grep \"";
  392. echo -n "${domain_name}";
  393. echo '/htdocs/scripts/queuedaemon.php" | grep "/var/www")';
  394. echo "cd /var/www/${domain_name}/htdocs";
  395. echo "if [[ \$daemon_lines != *\"/var/www/\"* ]]; then";
  396. echo " ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')";
  397. echo " MY_EMAIL_ADDRESS=\$ADMIN_USER@$HOSTNAME";
  398. echo -n " echo \"Restarting ${gnusocial_type} daemons\" | mail -s \"${gnusocial_type} ";
  399. echo "daemons not found\" \$MY_EMAIL_ADDRESS";
  400. echo ' su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data';
  401. echo 'fi';
  402. echo 'php scripts/delete_orphan_files.php > /dev/null';
  403. echo 'php scripts/clean_thumbnails.php -y > /dev/null';
  404. echo 'php scripts/clean_file_table.php -y > /dev/null';
  405. echo 'php scripts/upgrade.php > /dev/null'; } > "/etc/cron.hourly/${gnusocial_type}-daemons"
  406. chmod +x "/etc/cron.hourly/${gnusocial_type}-daemons"
  407. }
  408. function gnusocial_block_user_script {
  409. { echo '#!/bin/bash';
  410. echo '';
  411. echo "database_name=\$1";
  412. echo "remove_user=\$2";
  413. echo "domain_name=\$3";
  414. echo "MARIADB_PASSWORD=\$(freedombone-pass -u root -a mariadb)";
  415. echo '';
  416. echo "if [ \${#remove_user} -lt 2 ]; then";
  417. echo ' echo $"No user was specified"';
  418. echo ' exit 1';
  419. echo 'fi';
  420. echo '';
  421. echo "if [[ \"\$remove_user\" != *\".\"* || \"\$remove_user\" != *\"@\"* ]]; then";
  422. echo ' echo $"This doesnt look like a user"';
  423. echo ' exit 2';
  424. echo 'fi';
  425. echo '';
  426. echo "if [ \${#database_name} -lt 2 ]; then";
  427. echo ' echo $"No database was specified"';
  428. echo ' exit 3';
  429. echo 'fi';
  430. echo '';
  431. echo "nickname=\$(echo \"\$remove_user\" | awk -F '@' '{print \$1}')";
  432. echo "remove_domain=\$(echo \"\$remove_user\" | awk -F '@' '{print \$2}')";
  433. echo '';
  434. echo "database_query=\"delete from notice where content REGEXP '\\@\${remove_user}';\"";
  435. echo "mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  436. echo '';
  437. echo "database_query=\"select profile.id from profile where nickname = '\${nickname}' and profileurl like '%\${remove_domain}%';\"";
  438. echo "declare -a ids=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF";
  439. echo "use \$database_name;";
  440. echo "\$database_query";
  441. echo 'EOF';
  442. echo ')';
  443. echo '';
  444. echo 'ctr=0';
  445. echo "for id in \$ids";
  446. echo 'do';
  447. echo " if [ \$ctr -gt 0 ]; then";
  448. echo " #echo \"Removing user ID \$id on \$remove_domain\"";
  449. echo '';
  450. echo " database_query=\"delete from reply where profile_id=\${id};\"";
  451. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  452. echo '';
  453. echo " database_query=\"delete from reply where replied_id=\${id};\"";
  454. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  455. echo '';
  456. echo " if [ \$domain_name ]; then";
  457. echo " database_query=\"select rendered from notice where profile_id=\${id} and rendered like '%/file/%';\"";
  458. echo " declare -a stored_files=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF";
  459. echo "use \$database_name;";
  460. echo "\$database_query";
  461. echo 'EOF';
  462. echo ')';
  463. echo -n " files_to_delete=\$(echo \"\$stored_files\" | ";
  464. echo "sed -n 's/.*href=\"\\([^\"]*\\).*/\\1/p' | awk -F 'file/' '{print \$2}')";
  465. echo ' filectr=0';
  466. echo " for f in \$files_to_delete";
  467. echo ' do';
  468. echo " if [ \$filectr -gt 0 ]; then";
  469. echo " if \$(ls /var/www/\${domain_name}/htdocs/file/*\${f}* 1> /dev/null 2>&1); then";
  470. echo " rm /var/www/\${domain_name}/htdocs/file/*\${f}*";
  471. echo ' fi';
  472. echo ' fi';
  473. echo " filectr=\$((filectr + 1))";
  474. echo ' done';
  475. echo ' fi';
  476. echo '';
  477. echo " database_query=\"delete from notice where profile_id=\${id};\"";
  478. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  479. echo '';
  480. echo " database_query=\"delete from profile where id=\${id};\"";
  481. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  482. echo '';
  483. echo " database_query=\"delete from qvitternotification where to_profile_id=\${id} or from_profile_id=\${id};\"";
  484. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  485. echo ' fi';
  486. echo " ctr=\$((ctr + 1))";
  487. echo 'done'; } > /usr/bin/gnusocial-delete-user
  488. chmod +x /usr/bin/gnusocial-delete-user
  489. }
  490. function gnusocial_block_domain_script {
  491. database_name="$1"
  492. gnusoc_domain="$2"
  493. { echo '#!/bin/bash';
  494. echo '';
  495. echo "database_name=\$1";
  496. echo "remove_domain=\$2";
  497. echo "domain_name=\$3";
  498. echo "MARIADB_PASSWORD=\$(${PROJECT_NAME}-pass -u root -a mariadb)";
  499. echo '';
  500. echo "if [ \${#remove_domain} -lt 2 ]; then";
  501. echo ' echo $"No domain was specified"';
  502. echo ' exit 1';
  503. echo 'fi';
  504. echo '';
  505. echo "if [[ \"\$remove_domain\" != *\".\"* ]]; then";
  506. echo ' echo $"This doesnt look like a domain"';
  507. echo ' exit 2';
  508. echo 'fi';
  509. echo '';
  510. echo "if [ \${#database_name} -lt 2 ]; then";
  511. echo ' echo $"No database was specified"';
  512. echo ' exit 3';
  513. echo 'fi';
  514. echo '';
  515. echo "database_query=\"select profile.id from profile where profileurl like '%\${remove_domain}%';\"";
  516. echo "declare -a ids=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF";
  517. echo "use \$database_name;";
  518. echo "\$database_query";
  519. echo 'EOF';
  520. echo ')';
  521. echo '';
  522. echo 'ctr=0';
  523. echo "for id in \$ids";
  524. echo 'do';
  525. echo " if [ \$ctr -gt 0 ]; then";
  526. echo " #echo \"Removing user ID \$id on \$remove_domain\"";
  527. echo '';
  528. echo " database_query=\"delete from conversation where uri like '%\${remove_domain}%';\"";
  529. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  530. echo '';
  531. echo " database_query=\"delete from reply where profile_id=\${id};\"";
  532. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" $database_name";
  533. echo '';
  534. echo " database_query=\"delete from reply where replied_id=\${id};\"";
  535. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  536. echo '';
  537. echo " if [ \$domain_name ]; then";
  538. echo " database_query=\"select rendered from notice where profile_id=\${id} and rendered like '%/file/%';\"";
  539. echo " declare -a stored_files=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF";
  540. echo "use \$database_name;";
  541. echo "\$database_query";
  542. echo 'EOF';
  543. echo ')';
  544. echo -n " files_to_delete=\$(echo \"\$stored_files\" | ";
  545. echo "sed -n 's/.*href=\"\\([^\"]*\\).*/\\1/p' | awk -F 'file/' '{print \$2}')";
  546. echo ' filectr=0';
  547. echo " for f in \$files_to_delete";
  548. echo ' do';
  549. echo " if [ \$filectr -gt 0 ]; then";
  550. echo " if \$(ls /var/www/\${domain_name}/htdocs/file/*\${f}* 1> /dev/null 2>&1); then";
  551. echo " rm /var/www/\${domain_name}/htdocs/file/*\${f}*";
  552. echo ' fi';
  553. echo ' fi';
  554. echo " filectr=\$((filectr + 1))";
  555. echo ' done';
  556. echo ' fi';
  557. echo '';
  558. echo " database_query=\"delete from notice where profile_id=\${id};\"";
  559. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" $database_name";
  560. echo '';
  561. echo " database_query=\"delete from profile where id=\${id};\"";
  562. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  563. echo '';
  564. echo " database_query=\"delete from qvitternotification where to_profile_id=\${id} or from_profile_id=\${id};\"";
  565. echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
  566. echo ' fi';
  567. echo " ctr=\$((ctr + 1))";
  568. echo 'done'; } > /usr/bin/gnusocial-delete-domain
  569. chmod +x /usr/bin/gnusocial-delete-domain
  570. { echo '#!/bin/bash';
  571. echo '';
  572. echo "PROJECT_NAME=$PROJECT_NAME";
  573. echo "GNUSOCIAL_DOMAIN_NAME=$gnusoc_domain";
  574. echo "database_name=$database_name";
  575. echo "FIREWALL_DOMAINS=\$HOME/\${PROJECT_NAME}-firewall-domains.cfg";
  576. echo '';
  577. echo 'while read block; do';
  578. echo " if [[ \"\$block\" != *\"@\"* ]]; then";
  579. echo " /usr/bin/gnusocial-delete-domain \"\$database_name\" \"\$block\" \"\$GNUSOCIAL_DOMAIN_NAME\"";
  580. echo ' else';
  581. echo " /usr/bin/gnusocial-delete-user \"\$database_name\" \"\$block\" \"\$GNUSOCIAL_DOMAIN_NAME\"";
  582. echo ' fi';
  583. echo "done <\$FIREWALL_DOMAINS";
  584. echo '';
  585. echo '# remove any metadata from images uploaded in the last 2 minutes';
  586. echo "if [ -d /var/www/\$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then";
  587. echo " cd /var/www/\$GNUSOCIAL_DOMAIN_NAME/htdocs";
  588. echo " declare -a recent_image=\$(find file ! -name thumb-* -mmin -2 -type f -exec ls -l {} + | awk -F 'file/' '{print \$2}')";
  589. echo " for f in \${recent_image[@]}";
  590. echo ' do';
  591. echo " if [ \${#f} -gt 1 ]; then";
  592. echo " exiftool -q -all= \"file/\${f}\"";
  593. echo ' fi';
  594. echo ' done';
  595. echo 'fi'; } > "/usr/bin/${database_name}-firewall"
  596. chmod +x "/usr/bin/${database_name}-firewall"
  597. if ! grep -q "${database_name}-firewall" /etc/crontab; then
  598. cron_add_mins 1 "/usr/bin/${database_name}-firewall"
  599. fi
  600. }
  601. function expire_gnusocial_posts {
  602. domain_name="$1"
  603. gnusocial_type="$2"
  604. expire_months="$3"
  605. if [ ! "$expire_months" ]; then
  606. expire_months=3
  607. fi
  608. #expire_days=$((expire_months * 30))
  609. # files are what take up most of the backup time, so don't keep them for very long
  610. expire_days_files=7
  611. # To prevent the database size from growing endlessly this script expires posts
  612. # after a number of months
  613. if [ ! -d "/var/www/${domain_name}/htdocs" ]; then
  614. return
  615. fi
  616. gnusocial_expire_posts_script="/usr/bin/${gnusocial_type}-expire-posts"
  617. { echo '<?php';
  618. echo '':
  619. echo "// ${gnusocial_type} post expiry script, based on StatExpire by Tony Baldwin";
  620. echo '// https://github.com/tonybaldwin/statexpire';
  621. echo '';
  622. echo "\$oldate=date((\"Y-m-d\"), strtotime(\"-${expire_months} months\"));";
  623. echo "\$username=\"root\";";
  624. echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');";
  625. echo "\$database=\"${gnusocial_type}\";";
  626. echo '';
  627. echo "if (!\$link = mysqli_connect(\"localhost\", \$username, \$password)) {";
  628. echo ' echo "Could not connect to mariadb";';
  629. echo ' exit;';
  630. echo '}';
  631. echo '';
  632. echo "if (!mysqli_select_db(\$link, \$database)) {";
  633. echo " echo \"Could not select ${gnusocial_type} database\";";
  634. echo ' exit;';
  635. echo '}';
  636. echo '';
  637. echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";";
  638. echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '\$oldate 01:01:01'\";";
  639. echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";";
  640. echo "\$notification_query=\"DELETE FROM qvitternotification WHERE created <= '\$oldate 01:01:01'\";";
  641. echo '';
  642. echo "mysqli_query(\$link, \$notice_query);";
  643. echo "\$rowaff1=mysqli_affected_rows(\$link);";
  644. echo "mysqli_query(\$link, \$conversation_query);";
  645. echo "\$rowaff2=mysqli_affected_rows(\$link);";
  646. echo "mysqli_query(\$link, \$reply_query);";
  647. echo "\$rowaff3=mysqli_affected_rows(\$link);";
  648. echo "mysqli_query(\$link, \$notification_query);";
  649. echo "\$rowaff4=mysqli_affected_rows(\$link);";
  650. echo "mysqli_close(\$link);";
  651. echo '';
  652. echo "echo \"Expire ${gnusocial_type} posts: \$rowaff1 notices, \$rowaff2 conversations, \$rowaff3 replies, and \$rowaff4 qvitter notifications deleted from database.\";"; } > "$gnusocial_expire_posts_script"
  653. chmod +x "$gnusocial_expire_posts_script"
  654. gnusocial_expire_script="/etc/cron.daily/${gnusocial_type}-expire"
  655. { echo '#!/bin/bash';
  656. echo "find /var/www/${domain_name}/htdocs/file/* -mtime +${expire_days_files} -exec rm {} +";
  657. echo "/usr/bin/php $gnusocial_expire_posts_script"; } > "$gnusocial_expire_script"
  658. chmod +x "$gnusocial_expire_script"
  659. # remove any old cron job
  660. if grep -q "${gnusocial_type}-expire" /etc/crontab; then
  661. sed -i "/${gnusocial_type}-expire/d" /etc/crontab
  662. rm "/usr/bin/${gnusocial_type}-expire"
  663. fi
  664. # remove old expire script
  665. if [ -f "/etc/cron.weekly/clear-${gnusocial_type}-database" ]; then
  666. rm "/etc/cron.weekly/clear-${gnusocial_type}-database"
  667. fi
  668. }
  669. function gnusocial_use_classic {
  670. database_name=$1
  671. domain_name=$(get_completion_param "$database_name domain")
  672. if [ -f "/var/www/$domain_name/htdocs/index_qvitter.php" ]; then
  673. # shellcheck disable=SC2086
  674. mv /var/www/$domain_name/htdocs/index_qvitter.php /var/www/$domain_name/htdocs/index.php
  675. fi
  676. if [ -f "/etc/nginx/sites-available/$domain_name" ]; then
  677. sed -i 's|index_qvitter.php|index.php|g' "/etc/nginx/sites-available/$domain_name"
  678. sed -i 's|index.html|index.php|g' "/etc/nginx/sites-available/$domain_name"
  679. sed -i 's|#add_header Content-Security-Policy|add_header Content-Security-Policy|g' "/etc/nginx/sites-available/$domain_name"
  680. fi
  681. if ! grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
  682. sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
  683. sed -i "s|addPlugin('Qvitter')|//addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
  684. fi
  685. chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
  686. systemctl restart nginx
  687. }
  688. function gnusocial_use_qvitter {
  689. database_name=$1
  690. domain_name=$(get_completion_param "$database_name domain")
  691. if [ -f "/var/www/$domain_name/htdocs/index_qvitter.php" ]; then
  692. # shellcheck disable=SC2086
  693. mv /var/www/$domain_name/htdocs/index_qvitter.php /var/www/$domain_name/htdocs/index.php
  694. fi
  695. if [ -f "/etc/nginx/sites-available/$domain_name" ]; then
  696. sed -i 's|index_qvitter.php|index.php|g' "/etc/nginx/sites-available/$domain_name"
  697. sed -i 's|index.html|index.php|g' "/etc/nginx/sites-available/$domain_name"
  698. if ! grep -q "#add_header Content-Security-Policy" "/etc/nginx/sites-available/$domain_name"; then
  699. sed -i 's|add_header Content-Security-Policy|#add_header Content-Security-Policy|g' "/etc/nginx/sites-available/$domain_name"
  700. fi
  701. fi
  702. if grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
  703. sed -i "s|//addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
  704. fi
  705. if grep -q "// addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
  706. sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
  707. fi
  708. chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
  709. systemctl restart nginx
  710. systemctl restart php7.0-fpm
  711. }
  712. function gnusocial_use_pleroma {
  713. database_name="$1"
  714. domain_name=$(get_completion_param "$database_name domain")
  715. if [ ! -d "/var/www/$domain_name/htdocs/static" ]; then
  716. return
  717. fi
  718. if [ -f "/var/www/$domain_name/htdocs/index.php" ]; then
  719. # shellcheck disable=SC2086
  720. mv /var/www/$domain_name/htdocs/index.php /var/www/$domain_name/htdocs/index_qvitter.php
  721. fi
  722. if [ -f "/etc/nginx/sites-available/$domain_name" ]; then
  723. sed -i 's|index.php|index_qvitter.php|g' "/etc/nginx/sites-available/$domain_name"
  724. sed -i 's|index index_qvitter.php|index index.html|g' "/etc/nginx/sites-available/$domain_name"
  725. sed -i 's|#add_header Content-Security-Policy|add_header Content-Security-Policy|g' "/etc/nginx/sites-available/$domain_name"
  726. fi
  727. if grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
  728. sed -i "s|//addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
  729. fi
  730. if grep -q "// addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
  731. sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
  732. fi
  733. cp "$INSTALL_DIR/pleroma/dist/index.html" "/var/www/${domain_name}/htdocs/index.html"
  734. chmod +x static/css
  735. chmod +x static/font
  736. chmod +x static/font/css
  737. chmod +x static/font/font
  738. chmod +x static/js
  739. chmod +x static
  740. chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
  741. systemctl restart nginx
  742. }
  743. function install_gnusocial_plugin_sharings {
  744. domain_name="$1"
  745. social_app_name="$2"
  746. if [ ! -d "/var/www/$domain_name/htdocs/local/plugins" ]; then
  747. mkdir -p "/var/www/$domain_name/htdocs/local/plugins"
  748. fi
  749. apt-get -yq install liblocale-msgfmt-perl gettext
  750. # update to the next commit
  751. function_check set_repo_commit
  752. set_repo_commit "/var/www/$domain_name/htdocs/local/plugins/Sharings" "$social_app_name sharings plugin commit" "$SHARINGS_COMMIT" "$SHARINGS_REPO"
  753. if [[ $(app_is_installed "${social_app_name}_plugin_sharings") == "1" ]]; then
  754. return
  755. fi
  756. cd "/var/www/$domain_name/htdocs/local/plugins" || exit 28746245
  757. if [ -d /repos/sharings ]; then
  758. mkdir Sharings
  759. cp -r -p /repos/sharings/. Sharings
  760. cd Sharings || exit 25762454
  761. git pull
  762. else
  763. function_check git_clone
  764. git_clone "$SHARINGS_REPO" Sharings
  765. fi
  766. if [ ! -d "/var/www/$domain_name/htdocs/local/plugins/Sharings" ]; then
  767. echo $"Unable to clone $social_app_name sharings plugin"
  768. exit 36738
  769. fi
  770. cd "/var/www/$domain_name/htdocs/local/plugins/Sharings" || exit 2846244
  771. git stash
  772. git checkout master
  773. git branch -D "$SHARINGS_COMMIT"
  774. git checkout "$SHARINGS_COMMIT" -b "$SHARINGS_COMMIT"
  775. # enable the plugin
  776. if ! grep -q "addPlugin('Sharings');" "/var/www/$domain_name/htdocs/config.php"; then
  777. echo "addPlugin('Sharings');" >> "/var/www/$domain_name/htdocs/config.php"
  778. fi
  779. cd "/var/www/$domain_name/htdocs" || exit 2684624874
  780. php scripts/checkschema.php
  781. cd "/var/www/$domain_name/htdocs/local/plugins/Sharings" || exit 246824684
  782. php scripts/seedsharings.php
  783. cd "/var/www/$domain_name/htdocs" || exit 23524584
  784. php scripts/upgrade.php
  785. php scripts/checkschema.php
  786. # Languages
  787. cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES" || exit 53825488
  788. msgfmt -o Sharings.mo Sharings.po
  789. if [ ! -f Sharings.po ]; then
  790. echo $"English translations for $social_app_name sharings plugin were not created"
  791. exit 782923
  792. fi
  793. cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES" || exit 268442845
  794. msgfmt -o Sharings.mo Sharings.po
  795. if [ ! -f Sharings.po ]; then
  796. echo $"English (GB) translations for $social_app_name sharings plugin were not created"
  797. exit 23528
  798. fi
  799. cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES" || exit 264824628
  800. msgfmt -o Sharings.mo Sharings.po
  801. if [ ! -f Sharings.po ]; then
  802. echo $"English (US) translations for $social_app_name sharings plugin were not created"
  803. exit 567382
  804. fi
  805. # Looks like this update function isn't supported by the current php version
  806. sed -i 's|ActivityVerb::UPDATE, ||g' "/var/www/$domain_name/htdocs/local/plugins/Sharings/SharingsPlugin.php"
  807. chown -R www-data:www-data "/var/www/$domain_name/htdocs"
  808. set_completion_param gnusocial "$social_app_name sharings plugin commit" "$SHARINGS_COMMIT"
  809. install_completed "${social_app_name}_plugin_sharings"
  810. }
  811. function install_gnusocial_plugin_sharings_theme {
  812. domain_name="$1"
  813. social_app_name="$2"
  814. if [ ! -d "/var/www/$domain_name/htdocs/local/plugins" ]; then
  815. mkdir -p "/var/www/$domain_name/htdocs/local/plugins"
  816. fi
  817. # update to the next commit
  818. function_check set_repo_commit
  819. set_repo_commit "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" "$social_app_name sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" "$SHARINGS_THEME_REPO"
  820. if [[ $(app_is_installed "${social_app_name}_plugin_sharings_theme") == "1" ]]; then
  821. return
  822. fi
  823. cd "/var/www/$domain_name/htdocs/local/plugins" || exit 682425642
  824. function_check git_clone
  825. git_clone "$SHARINGS_THEME_REPO" SharingsTheme
  826. if [ ! -d "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" ]; then
  827. echo $"Unable to clone $social_app_name sharings plugin theme"
  828. exit 639253
  829. fi
  830. cd "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" || exit 2648724684
  831. git stash
  832. git checkout master
  833. git branch -D "$SHARINGS_THEME_COMMIT"
  834. git checkout "$SHARINGS_THEME_COMMIT" -b "$SHARINGS_THEME_COMMIT"
  835. # enable the plugin
  836. if ! grep -q "addPlugin('SharingsTheme');" "/var/www/$domain_name/htdocs/config.php"; then
  837. echo "addPlugin('SharingsTheme');" >> "/var/www/$domain_name/htdocs/config.php"
  838. fi
  839. cd "/var/www/$domain_name/htdocs" || exit 246824624
  840. php scripts/checkschema.php
  841. chown -R www-data:www-data "/var/www/$domain_name/htdocs"
  842. set_completion_param "$social_app_name sharings plugin theme commit" "$SHARINGS_THEME_COMMIT"
  843. install_completed "${social_app_name}_plugin_sharings_theme"
  844. }
  845. function install_gnusocial_markdown {
  846. domain_name="$1"
  847. social_app_name="$2"
  848. GNUSOCIAL_PATH="/var/www/$domain_name/htdocs"
  849. # update to the next commit
  850. function_check set_repo_commit
  851. set_repo_commit "$GNUSOCIAL_PATH/local/plugins/Markdown" "$social_app_name Markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT" "$GNUSOCIAL_MARKDOWN_REPO"
  852. if [[ $(app_is_installed "${social_app_name}_markdown") == "1" ]]; then
  853. return
  854. fi
  855. if [ -d "$GNUSOCIAL_PATH/local/plugins/Markdown" ]; then
  856. rm -rf "$GNUSOCIAL_PATH/local/plugins/Markdown"
  857. fi
  858. if [ ! -d "$GNUSOCIAL_PATH/local/plugins" ]; then
  859. mkdir -p "$GNUSOCIAL_PATH/local/plugins"
  860. fi
  861. cd "$GNUSOCIAL_PATH/local/plugins" || exit 268476248
  862. if [ -d /repos/gnusocial-markdown ]; then
  863. mkdir Markdown
  864. cp -r -p /repos/gnusocial-markdown/. Markdown
  865. cd Markdown || exit 62847524
  866. git pull
  867. else
  868. function_check git_clone
  869. git_clone "$GNUSOCIAL_MARKDOWN_REPO" Markdown
  870. fi
  871. cd "$GNUSOCIAL_PATH/local/plugins/Markdown" || exit 26584526745
  872. git checkout "$GNUSOCIAL_MARKDOWN_COMMIT" -b "$GNUSOCIAL_MARKDOWN_COMMIT"
  873. gnusocial_config_file="$GNUSOCIAL_PATH/config.php"
  874. if ! grep -q "addPlugin('Markdown'" "$gnusocial_config_file"; then
  875. { echo "";
  876. echo "// Markdown settings";
  877. echo "addPlugin('Markdown');"; } >> "$gnusocial_config_file"
  878. fi
  879. set_completion_param "$social_app_name markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT"
  880. chown -R www-data:www-data "$GNUSOCIAL_PATH"
  881. install_completed "${social_app_name}_markdown"
  882. }
  883. # NOTE: deliberately there is no "exit 0"