freedombone-app-gnusocial 38KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # gnusocial application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2017 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. VARIANTS='full full-vim media'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. GNUSOCIAL_DOMAIN_NAME=
  34. GNUSOCIAL_CODE=
  35. GNUSOCIAL_ONION_PORT=8087
  36. GNUSOCIAL_REPO="https://git.gnu.io/gnu/gnu-social.git"
  37. GNUSOCIAL_COMMIT='57f78dc61ccaaf4676cb0d6db452c1dadfc4b81e'
  38. GNUSOCIAL_ADMIN_PASSWORD=
  39. GNUSOCIAL_BACKGROUND_IMAGE_URL=
  40. GNUSOCIAL_MARKDOWN_REPO="https://git.gnu.io/chimo/markdown.git"
  41. GNUSOCIAL_MARKDOWN_COMMIT='03c53942f94b3376f0946e6e1fe566cc21ccf232'
  42. # Sharings plugin for gnusocial
  43. SHARINGS_REPO="http://git.lasindias.club/bashrc/Sharings"
  44. SHARINGS_COMMIT='d5c6c7f855d9afff9086c09ea706f38c859bc0d4'
  45. SHARINGS_THEME_REPO="http://git.lasindias.club/manuel/SharingsTheme"
  46. SHARINGS_THEME_COMMIT='7106c7ef03'
  47. # NSFW plugin
  48. GNUSOCIAL_NSFW_REPO="https://gitgud.io/ShitposterClub/SensitiveContent"
  49. GNUSOCIAL_NSFW_COMMIT='a096bbe0cfae9a9b177682920ffb58d32a48e136'
  50. GNUSOCIAL_TITLE='Pleroma FE'
  51. # Number of months after which posts expire
  52. GNUSOCIAL_EXPIRE_MONTHS=3
  53. gnusocial_variables=(ONION_ONLY
  54. GNUSOCIAL_DOMAIN_NAME
  55. GNUSOCIAL_CODE
  56. GNUSOCIAL_WELCOME_MESSAGE
  57. GNUSOCIAL_BACKGROUND_IMAGE_URL
  58. DDNS_PROVIDER
  59. GNUSOCIAL_MARKDOWN_REPO
  60. GNUSOCIAL_MARKDOWN_COMMIT
  61. SHARINGS_REPO
  62. SHARINGS_COMMIT
  63. SHARINGS_THEME_REPO
  64. SHARINGS_THEME_COMMIT
  65. GNUSOCIAL_TITLE
  66. GNUSOCIAL_EXPIRE_MONTHS
  67. MY_USERNAME)
  68. function gnusocial_fix_endless_reloads {
  69. # This fixes a bug introduced with commit 5f7032dfee1fd202c14e76a9f8b37af35d584901
  70. # and which causes OrFox to endlessly reload the page
  71. sed -i 's| && common_local_referer()||g' /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/lib/apiauthaction.php
  72. }
  73. function remove_user_gnusocial {
  74. remove_username="$1"
  75. ${PROJECT_NAME}-pass -u $remove_username --rmapp gnusocial
  76. function_check get_completion_param
  77. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  78. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  79. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  80. php scripts/deleteprofile.php -n $remove_username -y
  81. fi
  82. }
  83. function add_user_gnusocial {
  84. new_username="$1"
  85. new_user_password="$2"
  86. ${PROJECT_NAME}-pass -u $new_username -a gnusocial -p "$new_user_password"
  87. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  88. if [ -d /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs ]; then
  89. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  90. php scripts/registeruser.php -n $new_username -w "$new_user_password" -e "$new_username@$HOSTNAME"
  91. ${PROJECT_NAME}-addemail -u $new_username -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  92. echo '0'
  93. else
  94. echo '1'
  95. fi
  96. }
  97. function install_interactive_gnusocial {
  98. if [ ! $ONION_ONLY ]; then
  99. ONION_ONLY='no'
  100. fi
  101. if [[ $ONION_ONLY != "no" ]]; then
  102. GNUSOCIAL_DOMAIN_NAME='gnusocial.local'
  103. else
  104. GNUSOCIAL_DETAILS_COMPLETE=
  105. while [ ! $GNUSOCIAL_DETAILS_COMPLETE ]
  106. do
  107. data=$(tempfile 2>/dev/null)
  108. trap "rm -f $data" 0 1 2 5 15
  109. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  110. dialog --backtitle $"Freedombone Configuration" \
  111. --title $"GNU Social Configuration" \
  112. --form $"\nPlease enter your GNU Social details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
  113. $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  114. $"Title:" 2 1 "$(grep '$GNUSOCIAL_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  115. $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  116. $"Code:" 4 1 "$(grep 'GNUSOCIAL_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
  117. 2> $data
  118. else
  119. dialog --backtitle $"Freedombone Configuration" \
  120. --title $"GNU Social Configuration" \
  121. --form $"\nPlease enter your GNU Social details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
  122. $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  123. $"Title:" 2 1 "$(grep '$GNUSOCIAL_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  124. $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  125. 2> $data
  126. fi
  127. sel=$?
  128. case $sel in
  129. 1) exit 1;;
  130. 255) exit 1;;
  131. esac
  132. GNUSOCIAL_DOMAIN_NAME=$(cat $data | sed -n 1p)
  133. title=$(cat $data | sed -n 2p)
  134. if [ ${#title} -gt 1 ]; then
  135. GNUSOCIAL_TITLE=$welcome_msg
  136. fi
  137. img_url=$(cat $data | sed -n 3p)
  138. if [ ${#img_url} -gt 1 ]; then
  139. GNUSOCIAL_BACKGROUND_IMAGE_URL=$img_url
  140. fi
  141. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  142. if [[ $GNUSOCIAL_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
  143. GNUSOCIAL_DOMAIN_NAME=""
  144. fi
  145. TEST_DOMAIN_NAME=$GNUSOCIAL_DOMAIN_NAME
  146. validate_domain_name
  147. if [[ $TEST_DOMAIN_NAME != $GNUSOCIAL_DOMAIN_NAME ]]; then
  148. GNUSOCIAL_DOMAIN_NAME=
  149. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  150. else
  151. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  152. GNUSOCIAL_CODE=$(cat $data | sed -n 4p)
  153. validate_freedns_code "$GNUSOCIAL_CODE"
  154. if [ ! $VALID_CODE ]; then
  155. GNUSOCIAL_DOMAIN_NAME=
  156. fi
  157. fi
  158. fi
  159. fi
  160. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  161. GNUSOCIAL_DETAILS_COMPLETE="yes"
  162. fi
  163. done
  164. # remove any invalid characters
  165. if [ ${#GNUSOCIAL_TITLE} -gt 0 ]; then
  166. new_title=$(echo "$GNUSOCIAL_TITLE" | sed "s|'||g")
  167. GNUSOCIAL_TITLE="$new_title"
  168. fi
  169. # save the results in the config file
  170. write_config_param "GNUSOCIAL_CODE" "$GNUSOCIAL_CODE"
  171. write_config_param "GNUSOCIAL_TITLE" "$GNUSOCIAL_TITLE"
  172. write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  173. fi
  174. write_config_param "GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_DOMAIN_NAME"
  175. APP_INSTALLED=1
  176. }
  177. function change_password_gnusocial {
  178. curr_username="$1"
  179. new_user_password="$2"
  180. read_config_param ${GNUSOCIAL_DOMAIN_NAME}
  181. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts
  182. php setpassword.php "$curr_username" "$new_user_password"
  183. ${PROJECT_NAME}-pass -u "$curr_username" -a gnusocial -p "$new_user_password"
  184. }
  185. function gnusocial_create_database {
  186. if [ -f $IMAGE_PASSWORD_FILE ]; then
  187. GNUSOCIAL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  188. else
  189. if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
  190. GNUSOCIAL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  191. fi
  192. fi
  193. if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
  194. return
  195. fi
  196. function_check create_database
  197. create_database gnusocial "$GNUSOCIAL_ADMIN_PASSWORD" $MY_USERNAME
  198. }
  199. function reconfigure_gnusocial {
  200. echo -n ''
  201. }
  202. function gnusocial_set_background_image {
  203. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  204. data=$(tempfile 2>/dev/null)
  205. trap "rm -f $data" 0 1 2 5 15
  206. dialog --title $"GNU Social" \
  207. --backtitle $"Freedombone Control Panel" \
  208. --inputbox $'Set a background image URL' 10 60 2>$data
  209. sel=$?
  210. case $sel in
  211. 0)
  212. temp_background=$(<$data)
  213. if [ ${#temp_background} -gt 0 ]; then
  214. GNUSOCIAL_BACKGROUND_IMAGE_URL="$temp_background"
  215. write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  216. if [[ $(pleroma_set_background_image_from_url "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE" | tail -n 1) == "0" ]]; then
  217. dialog --title $"Set GNU Social login background" \
  218. --msgbox $"The background image has been set" 6 60
  219. fi
  220. fi
  221. ;;
  222. esac
  223. }
  224. function gnusocial_set_title {
  225. data=$(tempfile 2>/dev/null)
  226. trap "rm -f $data" 0 1 2 5 15
  227. dialog --title $"GNU Social" \
  228. --backtitle $"Freedombone Control Panel" \
  229. --inputbox $'Set a title' 10 60 2>$data
  230. sel=$?
  231. case $sel in
  232. 0)
  233. new_title=$(<$data)
  234. if [ ${#new_title} -gt 0 ]; then
  235. GNUSOCIAL_TITLE="$new_title"
  236. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  237. write_config_param "GNUSOCIAL_TITLE" "$GNUSOCIAL_TITLE"
  238. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/static
  239. sed -i "s|\"name\":.*|\"name\": \"${GNUSOCIAL_TITLE}\",|g" config.json
  240. dialog --title $"Set GNU Social title" \
  241. --msgbox $"The title has been set" 6 60
  242. fi
  243. ;;
  244. esac
  245. }
  246. function gnusocial_set_expire_months {
  247. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  248. read_config_param "GNUSOCIAL_EXPIRE_MONTHS"
  249. data=$(tempfile 2>/dev/null)
  250. trap "rm -f $data" 0 1 2 5 15
  251. dialog --title $"GNU Social" \
  252. --backtitle $"Freedombone Control Panel" \
  253. --inputbox $'Set an expiry period for posts in months. Anything older will be deleted. Lower values help to keep the database size small and as fast as possible.' 12 60 "$GNUSOCIAL_EXPIRE_MONTHS" 2>$data
  254. sel=$?
  255. case $sel in
  256. 0)
  257. new_expiry_months=$(<$data)
  258. if [ ${#new_expiry_months} -gt 0 ]; then
  259. # should contain no spaces
  260. if [[ "$new_expiry_months" == *" "* ]]; then
  261. return
  262. fi
  263. # should be a number
  264. re='^[0-9]+$'
  265. if ! [[ $new_expiry_months =~ $re ]] ; then
  266. return
  267. fi
  268. # set the new value
  269. GNUSOCIAL_EXPIRE_MONTHS=$new_expiry_months
  270. write_config_param "GNUSOCIAL_EXPIRE_MONTHS" "$GNUSOCIAL_EXPIRE_MONTHS"
  271. expire_gnusocial_posts "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_EXPIRE_MONTHS"
  272. dialog --title $"Set GNU Social post expiry period" \
  273. --msgbox $"Expiry period set to $GNUSOCIAL_EXPIRE_MONTHS months" 6 60
  274. fi
  275. ;;
  276. esac
  277. }
  278. function configure_interactive_gnusocial {
  279. while true
  280. do
  281. data=$(tempfile 2>/dev/null)
  282. trap "rm -f $data" 0 1 2 5 15
  283. dialog --backtitle $"Freedombone Control Panel" \
  284. --title $"GNU Social" \
  285. --radiolist $"Choose an operation:" 15 70 6 \
  286. 1 $"Set a background image" off \
  287. 2 $"Set the title" off \
  288. 3 $"Set post expiry period (currently $GNUSOCIAL_EXPIRE_MONTHS months)" off \
  289. 4 $"Select Qvitter user interface" off \
  290. 5 $"Select Pleroma user interface" off \
  291. 6 $"Exit" on 2> $data
  292. sel=$?
  293. case $sel in
  294. 1) return;;
  295. 255) return;;
  296. esac
  297. case $(cat $data) in
  298. 1) gnusocial_set_background_image;;
  299. 2) gnusocial_set_title;;
  300. 3) gnusocial_set_expire_months;;
  301. 4) gnusocial_use_qvitter gnusocial;;
  302. 5) gnusocial_use_pleroma gnusocial;;
  303. 6) break;;
  304. esac
  305. done
  306. }
  307. function upgrade_gnusocial {
  308. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  309. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  310. fi
  311. # update to the next commit
  312. function_check set_repo_commit
  313. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs "gnusocial commit" "$GNUSOCIAL_COMMIT" $GNUSOCIAL_REPO
  314. gnusocial_fix_endless_reloads
  315. # Ensure that installation script is removed
  316. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/install.php ]; then
  317. rm /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/install.php
  318. fi
  319. if [ -d $INSTALL_DIR/pleroma ]; then
  320. if [ -f /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index.php ]; then
  321. mv /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index.php /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index_qvitter.php
  322. fi
  323. fi
  324. gnusocial_block_user_script
  325. gnusocial_block_domain_script gnusocial
  326. gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
  327. upgrade_pleroma "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
  328. install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
  329. chown -R www-data:www-data /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  330. }
  331. function backup_local_gnusocial {
  332. GNUSOCIAL_DOMAIN_NAME='gnusocial'
  333. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  334. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  335. fi
  336. source_directory=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  337. if [ -d $source_directory ]; then
  338. dest_directory=gnusocial
  339. function_check suspend_site
  340. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  341. function_check backup_directory_to_usb
  342. backup_directory_to_usb $source_directory $dest_directory
  343. function_check backup_database_to_usb
  344. backup_database_to_usb gnusocial
  345. function_check restart_site
  346. restart_site
  347. fi
  348. }
  349. function restore_local_gnusocial {
  350. if ! grep -q "gnusocial domain" $COMPLETION_FILE; then
  351. return
  352. fi
  353. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  354. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  355. echo $"Restoring gnusocial"
  356. temp_restore_dir=/root/tempgnusocial
  357. gnusocial_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  358. # stop the daemons
  359. cd $gnusocial_dir
  360. scripts/stopdaemons.sh
  361. function_check gnusocial_create_database
  362. gnusocial_create_database
  363. restore_database gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  364. if [ -d $temp_restore_dir ]; then
  365. rm -rf $temp_restore_dir
  366. fi
  367. # start the daemons
  368. cd $gnusocial_dir
  369. scripts/startdaemons.sh
  370. echo $"Restore of gnusocial complete"
  371. fi
  372. }
  373. function backup_remote_gnusocial {
  374. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  375. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  376. temp_backup_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  377. if [ -d $temp_backup_dir ]; then
  378. function_check suspend_site
  379. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  380. function_check backup_database_to_friend
  381. backup_database_to_friend gnusocial
  382. echo $"Backing up GNU social installation"
  383. function_check backup_directory_to_friend
  384. backup_directory_to_friend $temp_backup_dir gnusocial
  385. function_check restart_site
  386. restart_site
  387. else
  388. echo $"gnusocial domain specified but not found in ${temp_backup_dir}"
  389. fi
  390. fi
  391. }
  392. function restore_remote_gnusocial {
  393. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  394. echo $"Restoring gnusocial"
  395. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  396. # stop the daemons
  397. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  398. ./scripts/stopdaemons.sh
  399. function_check gnusocial_create_database
  400. gnusocial_create_database
  401. function_check restore_database_from_friend
  402. restore_database_from_friend gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  403. if [ -d /root/tempgnusocial ]; then
  404. rm -rf /root/tempgnusocial
  405. fi
  406. # start the daemons
  407. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  408. ./scripts/startdaemons.sh
  409. echo $"Restore of gnusocial complete"
  410. fi
  411. }
  412. function remove_gnusocial {
  413. if [ ${#GNUSOCIAL_DOMAIN_NAME} -eq 0 ]; then
  414. return
  415. fi
  416. function_check remove_nodejs
  417. remove_nodejs pleroma-gnusocial
  418. read_config_param "GNUSOCIAL_DOMAIN_NAME"
  419. read_config_param "MY_USERNAME"
  420. echo "Removing $GNUSOCIAL_DOMAIN_NAME"
  421. nginx_dissite $GNUSOCIAL_DOMAIN_NAME
  422. remove_certs $GNUSOCIAL_DOMAIN_NAME
  423. if [ -f /etc/cron.hourly/gnusocial-daemons ]; then
  424. rm /etc/cron.hourly/gnusocial-daemons
  425. fi
  426. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
  427. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts
  428. ./scripts/stopdaemons.sh
  429. fi
  430. kill_pid=$(ps aux | grep /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/queuedaemon.php | awk -F ' ' '{print $2}' | head -n 1)
  431. kill -9 $kill_pid
  432. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  433. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  434. fi
  435. if [ -f /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME ]; then
  436. rm /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  437. fi
  438. function_check drop_database
  439. drop_database gnusocial
  440. function_check remove_onion_service
  441. remove_onion_service gnusocial ${GNUSOCIAL_ONION_PORT}
  442. if grep -q "gnusocial" /etc/crontab; then
  443. sed -i "/gnusocial/d" /etc/crontab
  444. fi
  445. remove_app gnusocial
  446. remove_completion_param install_gnusocial
  447. sed -i '/gnusocial/d' $COMPLETION_FILE
  448. remove_backup_database_local gnusocial
  449. sed -i '/gnusocial-firewall/d' /etc/crontab
  450. function_check remove_ddns_domain
  451. remove_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  452. }
  453. function install_gnusocial_main {
  454. if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
  455. echo $'No domain name was given for gnusocial'
  456. exit 7359
  457. fi
  458. if [[ $(app_is_installed gnusocial_main) == "1" ]]; then
  459. return
  460. fi
  461. gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
  462. function_check install_mariadb
  463. install_mariadb
  464. function_check get_mariadb_password
  465. get_mariadb_password
  466. function_check repair_databases_script
  467. repair_databases_script
  468. apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
  469. apt-get -yq install php5-memcached php5-intl
  470. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  471. mkdir /var/www/$GNUSOCIAL_DOMAIN_NAME
  472. fi
  473. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  474. function_check git_clone
  475. git_clone $GNUSOCIAL_REPO /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  476. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  477. echo $'Unable to clone gnusocial repo'
  478. exit 87525
  479. fi
  480. fi
  481. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  482. git checkout $GNUSOCIAL_COMMIT -b $GNUSOCIAL_COMMIT
  483. set_completion_param "gnusocial commit" "$GNUSOCIAL_COMMIT"
  484. gnusocial_fix_endless_reloads
  485. chmod g+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  486. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/avatar
  487. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/file
  488. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  489. chmod +x /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php
  490. function_check gnusocial_create_database
  491. gnusocial_create_database
  492. if [ ! -f "/etc/aliases" ]; then
  493. touch /etc/aliases
  494. fi
  495. if ! grep -q "www-data: root" /etc/aliases; then
  496. echo 'www-data: root' >> /etc/aliases
  497. fi
  498. if ! grep -q "/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
  499. echo "*: /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
  500. fi
  501. function_check add_ddns_domain
  502. add_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  503. gnusocial_nginx_site=/etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  504. if [[ $ONION_ONLY == "no" ]]; then
  505. function_check nginx_http_redirect
  506. nginx_http_redirect $GNUSOCIAL_DOMAIN_NAME "index index.php"
  507. echo 'server {' >> $gnusocial_nginx_site
  508. echo ' listen 443 ssl;' >> $gnusocial_nginx_site
  509. echo ' listen [::]:443 ssl;' >> $gnusocial_nginx_site
  510. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  511. echo '' >> $gnusocial_nginx_site
  512. echo ' # Security' >> $gnusocial_nginx_site
  513. function_check nginx_ssl
  514. nginx_ssl $GNUSOCIAL_DOMAIN_NAME
  515. function_check nginx_disable_sniffing
  516. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  517. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $gnusocial_nginx_site
  518. echo '' >> $gnusocial_nginx_site
  519. echo ' # Logs' >> $gnusocial_nginx_site
  520. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  521. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  522. echo '' >> $gnusocial_nginx_site
  523. echo ' # Root' >> $gnusocial_nginx_site
  524. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  525. echo '' >> $gnusocial_nginx_site
  526. echo ' # Index' >> $gnusocial_nginx_site
  527. echo ' index index.php;' >> $gnusocial_nginx_site
  528. echo '' >> $gnusocial_nginx_site
  529. echo ' # PHP' >> $gnusocial_nginx_site
  530. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  531. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  532. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $gnusocial_nginx_site
  533. echo ' }' >> $gnusocial_nginx_site
  534. echo '' >> $gnusocial_nginx_site
  535. echo ' # Location' >> $gnusocial_nginx_site
  536. echo ' location / {' >> $gnusocial_nginx_site
  537. function_check nginx_limits
  538. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  539. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  540. echo ' }' >> $gnusocial_nginx_site
  541. echo '' >> $gnusocial_nginx_site
  542. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  543. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  544. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  545. echo ' }' >> $gnusocial_nginx_site
  546. echo '' >> $gnusocial_nginx_site
  547. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  548. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  549. echo ' deny all;' >> $gnusocial_nginx_site
  550. echo ' }' >> $gnusocial_nginx_site
  551. echo '' >> $gnusocial_nginx_site
  552. # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
  553. echo '}' >> $gnusocial_nginx_site
  554. else
  555. echo -n '' > $gnusocial_nginx_site
  556. fi
  557. echo 'server {' >> $gnusocial_nginx_site
  558. echo " listen 127.0.0.1:$GNUSOCIAL_ONION_PORT default_server;" >> $gnusocial_nginx_site
  559. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  560. echo '' >> $gnusocial_nginx_site
  561. function_check nginx_disable_sniffing
  562. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  563. echo '' >> $gnusocial_nginx_site
  564. echo ' # Logs' >> $gnusocial_nginx_site
  565. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  566. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  567. echo '' >> $gnusocial_nginx_site
  568. echo ' # Root' >> $gnusocial_nginx_site
  569. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  570. echo '' >> $gnusocial_nginx_site
  571. echo ' # Index' >> $gnusocial_nginx_site
  572. echo ' index index.php;' >> $gnusocial_nginx_site
  573. echo '' >> $gnusocial_nginx_site
  574. echo ' # PHP' >> $gnusocial_nginx_site
  575. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  576. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  577. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $gnusocial_nginx_site
  578. echo ' }' >> $gnusocial_nginx_site
  579. echo '' >> $gnusocial_nginx_site
  580. echo ' # Location' >> $gnusocial_nginx_site
  581. echo ' location / {' >> $gnusocial_nginx_site
  582. function_check nginx_limits
  583. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  584. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  585. echo ' }' >> $gnusocial_nginx_site
  586. echo '' >> $gnusocial_nginx_site
  587. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  588. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  589. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  590. echo ' }' >> $gnusocial_nginx_site
  591. echo '' >> $gnusocial_nginx_site
  592. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  593. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  594. echo ' deny all;' >> $gnusocial_nginx_site
  595. echo ' }' >> $gnusocial_nginx_site
  596. echo '' >> $gnusocial_nginx_site
  597. # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
  598. echo '}' >> $gnusocial_nginx_site
  599. function_check configure_php
  600. configure_php
  601. function_check create_site_certificate
  602. create_site_certificate $GNUSOCIAL_DOMAIN_NAME 'yes'
  603. # Ensure that the database gets backed up locally, if remote
  604. # backups are not being used
  605. function_check backup_databases_script_header
  606. backup_databases_script_header
  607. function_check backup_database_local
  608. backup_database_local gnusocial
  609. function_check nginx_ensite
  610. nginx_ensite $GNUSOCIAL_DOMAIN_NAME
  611. # NOTE: For the typical case always enable SSL and only
  612. # disable it if in onion only mode. This is due to complexities
  613. # with the way URLs are generated by gnusocial
  614. gnusocial_ssl='always'
  615. if [[ $ONION_ONLY != 'no' ]]; then
  616. gnusocial_ssl='never'
  617. fi
  618. GNUSOCIAL_ONION_HOSTNAME=$(add_onion_service gnusocial 80 ${GNUSOCIAL_ONION_PORT})
  619. GNUSOCIAL_SERVER=${GNUSOCIAL_DOMAIN_NAME}
  620. if [[ $ONION_ONLY != 'no' ]]; then
  621. GNUSOCIAL_SERVER=${GNUSOCIAL_ONION_HOSTNAME}
  622. fi
  623. # Create the configuration
  624. gnusocial_installer=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts/install_cli.php
  625. if [ ! -f $gnusocial_installer ]; then
  626. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  627. echo $'No gnusocial commandline installer found'
  628. exit 53026
  629. fi
  630. ${gnusocial_installer} --server "${GNUSOCIAL_SERVER}" \
  631. --host="localhost" --database="gnusocial" \
  632. --dbtype=mysql --username="root" -v \
  633. --password="$MARIADB_PASSWORD" \
  634. --sitename=$"GNU Social" --fancy='yes' \
  635. --admin-nick="$MY_USERNAME" \
  636. --admin-pass="$GNUSOCIAL_ADMIN_PASSWORD" \
  637. --site-profile="community" \
  638. --ssl=${gnusocial_ssl}
  639. # There can be a lot of warnings here so the return value check is disabled
  640. #if [ ! "$?" = "0" ]; then
  641. # # failed to install
  642. # echo $'Could not install GNU Social'
  643. # exit 72357
  644. #fi
  645. # check gnusocial has a config file
  646. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  647. if [ ! -f $gnusocial_config_file ]; then
  648. drop_database gnusocial
  649. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  650. echo $'Gnusocial config.php not found'
  651. exit 87586
  652. fi
  653. # Some useful settings
  654. if ! grep -q "Recommended GNU social settings" $gnusocial_config_file; then
  655. echo "" >> $gnusocial_config_file
  656. echo "// Recommended GNU social settings" >> $gnusocial_config_file
  657. echo "\$config['thumbnail']['maxsize'] = 3000;" >> $gnusocial_config_file
  658. echo "\$config['profile']['delete'] = true;" >> $gnusocial_config_file
  659. echo "\$config['profile']['changenick'] = true;" >> $gnusocial_config_file
  660. echo "\$config['public']['localonly'] = false;" >> $gnusocial_config_file
  661. echo "addPlugin('StoreRemoteMedia');" >> $gnusocial_config_file
  662. echo "\$config['queue']['enabled'] = true;" >> $gnusocial_config_file
  663. echo "\$config['queue']['daemon'] = true;" >> $gnusocial_config_file
  664. echo "\$config['ostatus']['hub_retries'] = 3;" >> $gnusocial_config_file
  665. fi
  666. # turn off logging
  667. echo "\$config['site']['logfile'] = '/dev/null';" >> $gnusocial_config_file
  668. echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> $gnusocial_config_file
  669. # This improves performance
  670. sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $gnusocial_config_file
  671. systemctl restart php5-fpm
  672. systemctl restart nginx
  673. ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  674. ${PROJECT_NAME}-pass -u $MY_USERNAME -a gnusocial -p "$GNUSOCIAL_ADMIN_PASSWORD"
  675. gnusocial_block_user_script
  676. gnusocial_block_domain_script gnusocial
  677. set_completion_param "gnusocial domain" "$GNUSOCIAL_DOMAIN_NAME"
  678. install_completed gnusocial_main
  679. }
  680. function install_gnusocial_plugin_sharings {
  681. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  682. echo $'No local/plugins directory found for the gnusocial'
  683. exit 72945
  684. fi
  685. apt-get -yq install liblocale-msgfmt-perl gettext
  686. # update to the next commit
  687. function_check set_repo_commit
  688. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial sharings plugin commit" "$SHARINGS_COMMIT" $SHARINGS_REPO
  689. if [[ $(app_is_installed gnusocial_plugin_sharings) == "1" ]]; then
  690. return
  691. fi
  692. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  693. function_check git_clone
  694. git_clone $SHARINGS_REPO Sharings
  695. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings ]; then
  696. echo $'Unable to clone gnusocial sharings plugin'
  697. exit 36738
  698. fi
  699. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings
  700. git stash
  701. git checkout master
  702. git branch -D $SHARINGS_COMMIT
  703. git checkout $SHARINGS_COMMIT -b $SHARINGS_COMMIT
  704. # enable the plugin
  705. if ! grep -q "addPlugin('Sharings');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  706. echo "addPlugin('Sharings');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  707. fi
  708. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  709. php scripts/checkschema.php
  710. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings
  711. php scripts/seedsharings.php
  712. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  713. php scripts/upgrade.php
  714. php scripts/checkschema.php
  715. # Languages
  716. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES
  717. msgfmt -o Sharings.mo Sharings.po
  718. if [ ! -f Sharings.po ]; then
  719. echo $'English translations for gnusocial sharings plugin were not created'
  720. exit 84352
  721. fi
  722. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES
  723. msgfmt -o Sharings.mo Sharings.po
  724. if [ ! -f Sharings.po ]; then
  725. echo $'English (GB) translations for gnusocial sharings plugin were not created'
  726. exit 84352
  727. fi
  728. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES
  729. msgfmt -o Sharings.mo Sharings.po
  730. if [ ! -f Sharings.po ]; then
  731. echo $'English (US) translations for gnusocial sharings plugin were not created'
  732. exit 84352
  733. fi
  734. # Looks like this update function isn't supported by the current php version
  735. sed -i 's|ActivityVerb::UPDATE, ||g' /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/SharingsPlugin.php
  736. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  737. set_completion_param gnusocial "sharings plugin commit" "$SHARINGS_COMMIT"
  738. install_completed gnusocial_plugin_sharings
  739. }
  740. function install_gnusocial_plugin_sharings_theme {
  741. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  742. echo $'No local/plugins directory found for the gnusocial'
  743. exit 74458
  744. fi
  745. # update to the next commit
  746. function_check set_repo_commit
  747. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" $SHARINGS_THEME_REPO
  748. if [[ $(app_is_installed gnusocial_plugin_sharings_theme) == "1" ]]; then
  749. return
  750. fi
  751. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  752. function_check git_clone
  753. git_clone $SHARINGS_THEME_REPO SharingsTheme
  754. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme ]; then
  755. echo $'Unable to clone gnusocial sharings plugin theme'
  756. exit 639253
  757. fi
  758. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme
  759. git stash
  760. git checkout master
  761. git branch -D $SHARINGS_THEME_COMMIT
  762. git checkout $SHARINGS_THEME_COMMIT -b $SHARINGS_THEME_COMMIT
  763. # enable the plugin
  764. if ! grep -q "addPlugin('SharingsTheme');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  765. echo "addPlugin('SharingsTheme');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  766. fi
  767. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  768. php scripts/checkschema.php
  769. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  770. set_completion_param "gnusocial sharings plugin theme commit" "$SHARINGS_THEME_COMMIT"
  771. install_completed gnusocial_plugin_sharings_theme
  772. }
  773. function install_gnusocial_markdown {
  774. GNUSOCIAL_PATH=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  775. # update to the next commit
  776. function_check set_repo_commit
  777. set_repo_commit $GNUSOCIAL_PATH/local/plugins/Markdown "gnusocial Markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT" $GNUSOCIAL_MARKDOWN_REPO
  778. if [[ $(app_is_installed gnusocial_markdown) == "1" ]]; then
  779. return
  780. fi
  781. if [ -d $GNUSOCIAL_PATH/local/plugins/Markdown ]; then
  782. rm -rf $GNUSOCIAL_PATH/local/plugins/Markdown
  783. fi
  784. if [ ! -d $GNUSOCIAL_PATH/local/plugins ]; then
  785. mkdir -p $GNUSOCIAL_PATH/local/plugins
  786. fi
  787. cd $GNUSOCIAL_PATH/local/plugins
  788. function_check git_clone
  789. git_clone $GNUSOCIAL_MARKDOWN_REPO Markdown
  790. cd $GNUSOCIAL_PATH/local/plugins/Markdown
  791. git checkout $GNUSOCIAL_MARKDOWN_COMMIT -b $GNUSOCIAL_MARKDOWN_COMMIT
  792. gnusocial_config_file=$GNUSOCIAL_PATH/config.php
  793. if ! grep -q "addPlugin('Markdown'" $gnusocial_config_file; then
  794. echo "" >> $gnusocial_config_file
  795. echo "// Markdown settings" >> $gnusocial_config_file
  796. echo "addPlugin('Markdown');" >> $gnusocial_config_file
  797. fi
  798. set_completion_param "gnusocial markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT"
  799. chown -R www-data:www-data $GNUSOCIAL_PATH
  800. install_completed gnusocial_markdown
  801. }
  802. function install_gnusocial_plugin_nsfw {
  803. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  804. echo $'No local/plugins directory found for the gnusocial'
  805. exit 37252
  806. fi
  807. # update to the next commit
  808. function_check set_repo_commit
  809. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial NSFW plugin commit" "$GNUSOCIAL_NSFW_COMMIT" $GNUSOCIAL_NSFW_REPO
  810. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  811. return
  812. fi
  813. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  814. function_check git_clone
  815. git_clone $GNUSOCIAL_NSFW_REPO SensitiveContent
  816. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SensitiveContent ]; then
  817. echo $'Unable to clone gnusocial NSFW plugin'
  818. exit 36738
  819. fi
  820. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SensitiveContent
  821. git stash
  822. git checkout master
  823. git branch -D $GNUSOCIAL_NSFW_COMMIT
  824. git checkout $GNUSOCIAL_NSFW_COMMIT -b $GNUSOCIAL_NSFW_COMMIT
  825. # enable the plugin
  826. if ! grep -q "addPlugin('SensitiveContent');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  827. echo "addPlugin('SensitiveContent');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  828. fi
  829. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  830. php scripts/checkschema.php
  831. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  832. set_completion_param "gnusocial NSFW plugin commit" "$GNUSOCIAL_NSFW_COMMIT"
  833. install_completed gnusocial_plugin_nsfw
  834. }
  835. function install_gnusocial {
  836. if [ ! $ONION_ONLY ]; then
  837. ONION_ONLY='no'
  838. fi
  839. install_gnusocial_main
  840. expire_gnusocial_posts "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_EXPIRE_MONTHS"
  841. install_qvitter "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  842. install_gnusocial_markdown
  843. #install_gnusocial_plugin_sharings
  844. #install_gnusocial_plugin_sharings_theme
  845. #install_gnusocial_plugin_nsfw
  846. # Currently Pleroma won't install on ARM systems
  847. # because it uses node-sass which doesn't support ARM
  848. if [[ "$(arch)" == "arm"* ]]; then
  849. echo -m $'WARNING: Pleroma currently does not support ARM '
  850. echo $'architecture, so it will not be installed'
  851. else
  852. function_check install_nodejs
  853. install_nodejs pleroma-gnusocial
  854. install_pleroma_front_end "gnusocial" "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
  855. install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
  856. sed -i 's|"theme":.*|"theme": "base16-apathy.css",|g' /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/static/config.json
  857. fi
  858. # unleash the daemons!
  859. /etc/cron.hourly/gnusocial-daemons
  860. systemctl restart nginx
  861. APP_INSTALLED=1
  862. }
  863. # NOTE: deliberately there is no "exit 0"