freedombone-utils-gnusocialtools 41KB

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