freedombone-utils-gnusocialtools 41KB

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