freedombone-utils-gnusocialtools 40KB

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