freedombone-utils-gnusocialtools 40KB

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