freedombone-utils-gnusocialtools 39KB

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