freedombone-app-gnusocial 45KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  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-2016 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='c67b89e56bf0f90730a9e22beca7e1bd41fc26c3'
  38. GNUSOCIAL_ADMIN_PASSWORD=
  39. GNUSOCIAL_THEME_REPO="https://git.gnu.io/h2p/Qvitter.git"
  40. GNUSOCIAL_THEME_COMMIT='510b6c5f9ccd89e3693909198aad691492ace081'
  41. GNUSOCIAL_WELCOME_MESSAGE=$'<h1>Welcome to GNU Social – a federated social metwork</h1><p>Another Freedombone site</p>'
  42. GNUSOCIAL_BACKGROUND_IMAGE_URL=
  43. GNUSOCIAL_MARKDOWN_REPO="https://git.gnu.io/chimo/markdown.git"
  44. GNUSOCIAL_MARKDOWN_COMMIT='03c53942f94b3376f0946e6e1fe566cc21ccf232'
  45. # Sharings plugin for gnusocial
  46. SHARINGS_REPO="http://git.lasindias.club/bashrc/Sharings"
  47. SHARINGS_COMMIT='d5c6c7f855d9afff9086c09ea706f38c859bc0d4'
  48. SHARINGS_THEME_REPO="http://git.lasindias.club/manuel/SharingsTheme"
  49. SHARINGS_THEME_COMMIT='7106c7ef03'
  50. # NSFW plugin
  51. GNUSOCIAL_NSFW_REPO="https://gitgud.io/ShitposterClub/SensitiveContent"
  52. GNUSOCIAL_NSFW_COMMIT='a096bbe0cfae9a9b177682920ffb58d32a48e136'
  53. # script which causes old posts to expire
  54. gnusocial_expire_script=/usr/bin/gnusocial-expire
  55. gnusocial_variables=(ONION_ONLY
  56. GNUSOCIAL_DOMAIN_NAME
  57. GNUSOCIAL_CODE
  58. GNUSOCIAL_WELCOME_MESSAGE
  59. GNUSOCIAL_BACKGROUND_IMAGE_URL
  60. DDNS_PROVIDER
  61. GNUSOCIAL_MARKDOWN_REPO
  62. GNUSOCIAL_MARKDOWN_COMMIT
  63. SHARINGS_REPO
  64. SHARINGS_COMMIT
  65. SHARINGS_THEME_REPO
  66. SHARINGS_THEME_COMMIT
  67. MY_USERNAME)
  68. function remove_user_gnusocial {
  69. remove_username="$1"
  70. ${PROJECT_NAME}-pass -u $remove_username --rmapp gnusocial
  71. function_check get_completion_param
  72. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  73. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  74. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  75. php scripts/deleteprofile.php -n $remove_username -y
  76. fi
  77. }
  78. function add_user_gnusocial {
  79. new_username="$1"
  80. new_user_password="$2"
  81. ${PROJECT_NAME}-pass -u $new_username -a gnusocial -p "$new_user_password"
  82. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  83. if [ -d /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs ]; then
  84. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  85. php scripts/registeruser.php -n $new_username -w "$new_user_password" -e "$new_username@$HOSTNAME"
  86. ${PROJECT_NAME}-addemail -u $new_username -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  87. echo '0'
  88. else
  89. echo '1'
  90. fi
  91. }
  92. function install_interactive_gnusocial {
  93. if [ ! $ONION_ONLY ]; then
  94. ONION_ONLY='no'
  95. fi
  96. if [[ $ONION_ONLY != "no" ]]; then
  97. GNUSOCIAL_DOMAIN_NAME='gnusocial.local'
  98. else
  99. GNUSOCIAL_DETAILS_COMPLETE=
  100. while [ ! $GNUSOCIAL_DETAILS_COMPLETE ]
  101. do
  102. data=$(tempfile 2>/dev/null)
  103. trap "rm -f $data" 0 1 2 5 15
  104. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  105. dialog --backtitle $"Freedombone Configuration" \
  106. --title $"GNU Social Configuration" \
  107. --form $"\nPlease enter your GNU Social details. Welcome message and 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 \
  108. $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  109. $"Welcome Message:" 2 1 "$(grep '$GNUSOCIAL_WELCOME_MESSAGE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  110. $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  111. $"Code:" 4 1 "$(grep 'GNUSOCIAL_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
  112. 2> $data
  113. else
  114. dialog --backtitle $"Freedombone Configuration" \
  115. --title $"GNU Social Configuration" \
  116. --form $"\nPlease enter your GNU Social details. Welcome message and 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 \
  117. $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  118. $"Welcome Message:" 2 1 "$(grep '$GNUSOCIAL_WELCOME_MESSAGE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  119. $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  120. 2> $data
  121. fi
  122. sel=$?
  123. case $sel in
  124. 1) exit 1;;
  125. 255) exit 1;;
  126. esac
  127. GNUSOCIAL_DOMAIN_NAME=$(cat $data | sed -n 1p)
  128. welcome_msg=$(cat $data | sed -n 2p)
  129. if [ ${#welcome_msg} -gt 1 ]; then
  130. GNUSOCIAL_WELCOME_MESSAGE=$welcome_msg
  131. fi
  132. img_url=$(cat $data | sed -n 3p)
  133. if [ ${#img_url} -gt 1 ]; then
  134. GNUSOCIAL_BACKGROUND_IMAGE_URL=$img_url
  135. fi
  136. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  137. if [[ $GNUSOCIAL_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
  138. GNUSOCIAL_DOMAIN_NAME=""
  139. fi
  140. TEST_DOMAIN_NAME=$GNUSOCIAL_DOMAIN_NAME
  141. validate_domain_name
  142. if [[ $TEST_DOMAIN_NAME != $GNUSOCIAL_DOMAIN_NAME ]]; then
  143. GNUSOCIAL_DOMAIN_NAME=
  144. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  145. else
  146. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  147. GNUSOCIAL_CODE=$(cat $data | sed -n 4p)
  148. validate_freedns_code "$GNUSOCIAL_CODE"
  149. if [ ! $VALID_CODE ]; then
  150. GNUSOCIAL_DOMAIN_NAME=
  151. fi
  152. fi
  153. fi
  154. fi
  155. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  156. GNUSOCIAL_DETAILS_COMPLETE="yes"
  157. fi
  158. done
  159. # remove any invalid characters
  160. if [ ${#GNUSOCIAL_WELCOME_MESSAGE} -gt 0 ]; then
  161. new_welcome=$(echo "$GNUSOCIAL_WELCOME_MESSAGE" | sed "s|'||g")
  162. GNUSOCIAL_WELCOME_MESSAGE="$new_welcome"
  163. fi
  164. # save the results in the config file
  165. write_config_param "GNUSOCIAL_CODE" "$GNUSOCIAL_CODE"
  166. write_config_param "GNUSOCIAL_WELCOME_MESSAGE" "$GNUSOCIAL_WELCOME_MESSAGE"
  167. write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  168. fi
  169. write_config_param "GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_DOMAIN_NAME"
  170. APP_INSTALLED=1
  171. }
  172. function change_password_gnusocial {
  173. curr_username="$1"
  174. new_user_password="$2"
  175. read_config_param ${GNUSOCIAL_DOMAIN_NAME}
  176. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts
  177. php setpassword.php "$curr_username" "$new_user_password"
  178. ${PROJECT_NAME}-pass -u "$curr_username" -a gnusocial -p "$new_user_password"
  179. }
  180. function gnusocial_create_database {
  181. if [ -f $IMAGE_PASSWORD_FILE ]; then
  182. GNUSOCIAL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  183. else
  184. if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
  185. GNUSOCIAL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  186. fi
  187. fi
  188. if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
  189. return
  190. fi
  191. function_check create_database
  192. create_database gnusocial "$GNUSOCIAL_ADMIN_PASSWORD" $MY_USERNAME
  193. }
  194. function gnusocial_running_script {
  195. # check that the daemon is running
  196. echo '#!/bin/bash' > /etc/cron.hourly/gnusocial-daemons
  197. echo 'daemon_lines=$(ps aux | grep "scripts/queuedaemon.php" | grep "/var/www")' >> /etc/cron.hourly/gnusocial-daemons
  198. echo 'if [[ $daemon_lines != *"/var/www/"* ]]; then' >> /etc/cron.hourly/gnusocial-daemons
  199. echo " ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')" >> /etc/cron.hourly/gnusocial-daemons
  200. echo ' MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME' >> /etc/cron.hourly/gnusocial-daemons
  201. echo ' echo "Restarting GNU Social daemons" | mail -s "GNU Social daemons not found" $MY_EMAIL_ADDRESS' >> /etc/cron.hourly/gnusocial-daemons
  202. echo " cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs" >> /etc/cron.hourly/gnusocial-daemons
  203. echo ' scripts/startdaemons.sh' >> /etc/cron.hourly/gnusocial-daemons
  204. echo 'fi' >> /etc/cron.hourly/gnusocial-daemons
  205. chmod +x /etc/cron.hourly/gnusocial-daemons
  206. }
  207. function reconfigure_gnusocial {
  208. echo -n ''
  209. }
  210. function gnusocial_set_background_image_from_url {
  211. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT=
  212. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
  213. if [[ $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".jpeg" || $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".jpg" ]]; then
  214. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="jpg"
  215. fi
  216. if [[ $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".png" ]]; then
  217. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="png"
  218. fi
  219. if [[ $$GNUSOCIAL_BACKGROUND_IMAGE_URL == *".gif" ]]; then
  220. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="gif"
  221. fi
  222. fi
  223. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT ]; then
  224. read_config_param GNUSOCIAL_DOMAIN_NAME
  225. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  226. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter
  227. wget $GNUSOCIAL_BACKGROUND_IMAGE_URL -O img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}
  228. if [ ! -f img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT} ]; then
  229. echo "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  230. echo $'Custom background image for gnusocial could not be downloaded'
  231. echo "1"
  232. return
  233. fi
  234. if grep -q "'img/custom" $gnusocial_config_file; then
  235. sed -i "s|'img/custom.*|'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';|g" $gnusocial_config_file
  236. fi
  237. fi
  238. echo "0"
  239. }
  240. function gnusocial_set_background_image {
  241. data=$(tempfile 2>/dev/null)
  242. trap "rm -f $data" 0 1 2 5 15
  243. dialog --title $"GNU Social" \
  244. --backtitle $"Freedombone Control Panel" \
  245. --inputbox $'Set a login screen background image URL' 10 60 2>$data
  246. sel=$?
  247. case $sel in
  248. 0)
  249. temp_background=$(<$data)
  250. if [ ${#temp_background} -gt 0 ]; then
  251. GNUSOCIAL_BACKGROUND_IMAGE_URL="$temp_background"
  252. write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  253. if [[ $(gnusocial_set_background_image_from_url) == "0" ]]; then
  254. dialog --title $"Set GNU Social login background" \
  255. --msgbox $"The background image has been set" 6 60
  256. fi
  257. fi
  258. ;;
  259. esac
  260. }
  261. function gnusocial_set_welcome_message {
  262. data=$(tempfile 2>/dev/null)
  263. trap "rm -f $data" 0 1 2 5 15
  264. dialog --title $"GNU Social" \
  265. --backtitle $"Freedombone Control Panel" \
  266. --inputbox $'Set a welcome message, which can include html formatting' 10 60 2>$data
  267. sel=$?
  268. case $sel in
  269. 0)
  270. temp_welcome=$(<$data)
  271. if [ ${#temp_welcome} -gt 0 ]; then
  272. GNUSOCIAL_WELCOME_MESSAGE="$temp_welcome"
  273. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  274. if grep -q "customwelcometext" $gnusocial_config_file; then
  275. write_config_param "GNUSOCIAL_WELCOME_MESSAGE" "$GNUSOCIAL_WELCOME_MESSAGE"
  276. sed -i "s|customwelcometext.*|customwelcometext']['en'] = '${GNUSOCIAL_WELCOME_MESSAGE}';|g" $gnusocial_config_file
  277. dialog --title $"Set GNU Social welcome message" \
  278. --msgbox $"Welcome message has been set" 6 60
  279. fi
  280. fi
  281. ;;
  282. esac
  283. }
  284. function configure_interactive_gnusocial {
  285. while true
  286. do
  287. data=$(tempfile 2>/dev/null)
  288. trap "rm -f $data" 0 1 2 5 15
  289. dialog --backtitle $"Freedombone Control Panel" \
  290. --title $"GNU Social" \
  291. --radiolist $"Choose an operation:" 12 70 3 \
  292. 1 $"Set a login screen background image" off \
  293. 2 $"Set a welcome message" off \
  294. 3 $"Exit" on 2> $data
  295. sel=$?
  296. case $sel in
  297. 1) return;;
  298. 255) return;;
  299. esac
  300. case $(cat $data) in
  301. 1) gnusocial_set_background_image;;
  302. 2) gnusocial_set_welcome_message;;
  303. 3) 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. function_check gnusocial_running_script
  315. gnusocial_running_script
  316. }
  317. function backup_local_gnusocial {
  318. GNUSOCIAL_DOMAIN_NAME='gnusocial'
  319. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  320. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  321. fi
  322. source_directory=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  323. if [ -d $source_directory ]; then
  324. dest_directory=gnusocial
  325. function_check suspend_site
  326. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  327. function_check backup_directory_to_usb
  328. backup_directory_to_usb $source_directory $dest_directory
  329. function_check backup_database_to_usb
  330. backup_database_to_usb gnusocial
  331. function_check restart_site
  332. restart_site
  333. fi
  334. }
  335. function restore_local_gnusocial {
  336. if ! grep -q "gnusocial domain" $COMPLETION_FILE; then
  337. return
  338. fi
  339. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  340. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  341. echo $"Restoring gnusocial"
  342. temp_restore_dir=/root/tempgnusocial
  343. gnusocial_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  344. # stop the daemons
  345. cd $gnusocial_dir
  346. scripts/stopdaemons.sh
  347. function_check gnusocial_create_database
  348. gnusocial_create_database
  349. restore_database gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  350. if [ -d $temp_restore_dir ]; then
  351. rm -rf $temp_restore_dir
  352. fi
  353. # start the daemons
  354. cd $gnusocial_dir
  355. scripts/startdaemons.sh
  356. echo $"Restore of gnusocial complete"
  357. fi
  358. }
  359. function backup_remote_gnusocial {
  360. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  361. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  362. temp_backup_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  363. if [ -d $temp_backup_dir ]; then
  364. function_check suspend_site
  365. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  366. function_check backup_database_to_friend
  367. backup_database_to_friend gnusocial
  368. echo $"Backing up GNU social installation"
  369. function_check backup_directory_to_friend
  370. backup_directory_to_friend $temp_backup_dir gnusocial
  371. function_check restart_site
  372. restart_site
  373. else
  374. echo $"gnusocial domain specified but not found in ${temp_backup_dir}"
  375. fi
  376. fi
  377. }
  378. function restore_remote_gnusocial {
  379. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  380. echo $"Restoring gnusocial"
  381. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  382. # stop the daemons
  383. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  384. ./scripts/stopdaemons.sh
  385. function_check gnusocial_create_database
  386. gnusocial_create_database
  387. function_check restore_database_from_friend
  388. restore_database_from_friend gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  389. if [ -d /root/tempgnusocial ]; then
  390. rm -rf /root/tempgnusocial
  391. fi
  392. # start the daemons
  393. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  394. ./scripts/startdaemons.sh
  395. echo $"Restore of gnusocial complete"
  396. fi
  397. }
  398. function remove_gnusocial {
  399. if [ ${#GNUSOCIAL_DOMAIN_NAME} -eq 0 ]; then
  400. return
  401. fi
  402. read_config_param "GNUSOCIAL_DOMAIN_NAME"
  403. read_config_param "MY_USERNAME"
  404. echo "Removing $GNUSOCIAL_DOMAIN_NAME"
  405. nginx_dissite $GNUSOCIAL_DOMAIN_NAME
  406. remove_certs $GNUSOCIAL_DOMAIN_NAME
  407. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
  408. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts
  409. ./scripts/stopdaemons.sh
  410. fi
  411. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  412. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  413. fi
  414. if [ -f /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME ]; then
  415. rm /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  416. fi
  417. function_check drop_database
  418. drop_database gnusocial
  419. function_check remove_onion_service
  420. remove_onion_service gnusocial ${GNUSOCIAL_ONION_PORT}
  421. if grep -q "gnusocial" /etc/crontab; then
  422. sed -i "/gnusocial/d" /etc/crontab
  423. fi
  424. remove_app gnusocial
  425. remove_completion_param install_gnusocial
  426. sed -i '/gnusocial/d' $COMPLETION_FILE
  427. if [ -f /etc/cron.hourly/gnusocial-daemons ]; then
  428. rm /etc/cron.hourly/gnusocial-daemons
  429. fi
  430. remove_backup_database_local gnusocial
  431. function_check remove_ddns_domain
  432. remove_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  433. }
  434. function install_gnusocial_main {
  435. if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
  436. echo $'No domain name was given for gnusocial'
  437. exit 7359
  438. fi
  439. if [[ $(app_is_installed gnusocial_main) == "1" ]]; then
  440. return
  441. fi
  442. function_check gnusocial_running_script
  443. gnusocial_running_script
  444. function_check install_mariadb
  445. install_mariadb
  446. function_check get_mariadb_password
  447. get_mariadb_password
  448. function_check repair_databases_script
  449. repair_databases_script
  450. apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
  451. apt-get -yq install php5-memcached php5-intl
  452. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  453. mkdir /var/www/$GNUSOCIAL_DOMAIN_NAME
  454. fi
  455. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  456. function_check git_clone
  457. git_clone $GNUSOCIAL_REPO /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  458. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  459. echo $'Unable to clone gnusocial repo'
  460. exit 87525
  461. fi
  462. fi
  463. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  464. git checkout $GNUSOCIAL_COMMIT -b $GNUSOCIAL_COMMIT
  465. set_completion_param "gnusocial commit" "$GNUSOCIAL_COMMIT"
  466. chmod g+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  467. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/avatar
  468. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/file
  469. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  470. chmod +x /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php
  471. function_check gnusocial_create_database
  472. gnusocial_create_database
  473. if [ ! -f "/etc/aliases" ]; then
  474. touch /etc/aliases
  475. fi
  476. if ! grep -q "www-data: root" /etc/aliases; then
  477. echo 'www-data: root' >> /etc/aliases
  478. fi
  479. if ! grep -q "/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
  480. echo "*: /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
  481. fi
  482. function_check add_ddns_domain
  483. add_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  484. gnusocial_nginx_site=/etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  485. if [[ $ONION_ONLY == "no" ]]; then
  486. function_check nginx_http_redirect
  487. nginx_http_redirect $GNUSOCIAL_DOMAIN_NAME
  488. echo 'server {' >> $gnusocial_nginx_site
  489. echo ' listen 443 ssl;' >> $gnusocial_nginx_site
  490. echo ' listen [::]:443 ssl;' >> $gnusocial_nginx_site
  491. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  492. echo '' >> $gnusocial_nginx_site
  493. echo ' # Security' >> $gnusocial_nginx_site
  494. function_check nginx_ssl
  495. nginx_ssl $GNUSOCIAL_DOMAIN_NAME
  496. function_check nginx_disable_sniffing
  497. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  498. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $gnusocial_nginx_site
  499. echo '' >> $gnusocial_nginx_site
  500. echo ' # Logs' >> $gnusocial_nginx_site
  501. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  502. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  503. echo '' >> $gnusocial_nginx_site
  504. echo ' # Root' >> $gnusocial_nginx_site
  505. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  506. echo '' >> $gnusocial_nginx_site
  507. echo ' # Index' >> $gnusocial_nginx_site
  508. echo ' index index.php;' >> $gnusocial_nginx_site
  509. echo '' >> $gnusocial_nginx_site
  510. echo ' # PHP' >> $gnusocial_nginx_site
  511. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  512. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  513. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $gnusocial_nginx_site
  514. echo ' }' >> $gnusocial_nginx_site
  515. echo '' >> $gnusocial_nginx_site
  516. echo ' # Location' >> $gnusocial_nginx_site
  517. echo ' location / {' >> $gnusocial_nginx_site
  518. function_check nginx_limits
  519. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  520. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  521. echo ' }' >> $gnusocial_nginx_site
  522. echo '' >> $gnusocial_nginx_site
  523. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  524. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  525. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  526. echo ' }' >> $gnusocial_nginx_site
  527. echo '' >> $gnusocial_nginx_site
  528. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  529. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  530. echo ' deny all;' >> $gnusocial_nginx_site
  531. echo ' }' >> $gnusocial_nginx_site
  532. echo '' >> $gnusocial_nginx_site
  533. # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
  534. echo '}' >> $gnusocial_nginx_site
  535. else
  536. echo -n '' > $gnusocial_nginx_site
  537. fi
  538. echo 'server {' >> $gnusocial_nginx_site
  539. echo " listen 127.0.0.1:$GNUSOCIAL_ONION_PORT default_server;" >> $gnusocial_nginx_site
  540. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  541. echo '' >> $gnusocial_nginx_site
  542. function_check nginx_disable_sniffing
  543. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  544. echo '' >> $gnusocial_nginx_site
  545. echo ' # Logs' >> $gnusocial_nginx_site
  546. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  547. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  548. echo '' >> $gnusocial_nginx_site
  549. echo ' # Root' >> $gnusocial_nginx_site
  550. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  551. echo '' >> $gnusocial_nginx_site
  552. echo ' # Index' >> $gnusocial_nginx_site
  553. echo ' index index.php;' >> $gnusocial_nginx_site
  554. echo '' >> $gnusocial_nginx_site
  555. echo ' # PHP' >> $gnusocial_nginx_site
  556. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  557. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  558. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $gnusocial_nginx_site
  559. echo ' }' >> $gnusocial_nginx_site
  560. echo '' >> $gnusocial_nginx_site
  561. echo ' # Location' >> $gnusocial_nginx_site
  562. echo ' location / {' >> $gnusocial_nginx_site
  563. function_check nginx_limits
  564. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  565. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  566. echo ' }' >> $gnusocial_nginx_site
  567. echo '' >> $gnusocial_nginx_site
  568. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  569. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  570. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  571. echo ' }' >> $gnusocial_nginx_site
  572. echo '' >> $gnusocial_nginx_site
  573. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  574. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  575. echo ' deny all;' >> $gnusocial_nginx_site
  576. echo ' }' >> $gnusocial_nginx_site
  577. echo '' >> $gnusocial_nginx_site
  578. # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
  579. echo '}' >> $gnusocial_nginx_site
  580. function_check configure_php
  581. configure_php
  582. function_check create_site_certificate
  583. create_site_certificate $GNUSOCIAL_DOMAIN_NAME 'yes'
  584. # Ensure that the database gets backed up locally, if remote
  585. # backups are not being used
  586. function_check backup_databases_script_header
  587. backup_databases_script_header
  588. function_check backup_database_local
  589. backup_database_local gnusocial
  590. function_check nginx_ensite
  591. nginx_ensite $GNUSOCIAL_DOMAIN_NAME
  592. # NOTE: For the typical case always enable SSL and only
  593. # disable it if in onion only mode. This is due to complexities
  594. # with the way URLs are generated by gnusocial
  595. gnusocial_ssl='always'
  596. if [[ $ONION_ONLY != 'no' ]]; then
  597. gnusocial_ssl='never'
  598. fi
  599. GNUSOCIAL_ONION_HOSTNAME=$(add_onion_service gnusocial 80 ${GNUSOCIAL_ONION_PORT})
  600. GNUSOCIAL_SERVER=${GNUSOCIAL_DOMAIN_NAME}
  601. if [[ $ONION_ONLY != 'no' ]]; then
  602. GNUSOCIAL_SERVER=${GNUSOCIAL_ONION_HOSTNAME}
  603. fi
  604. # Create the configuration
  605. gnusocial_installer=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts/install_cli.php
  606. if [ ! -f $gnusocial_installer ]; then
  607. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  608. echo $'No gnusocial commandline installer found'
  609. exit 53026
  610. fi
  611. ${gnusocial_installer} --server "${GNUSOCIAL_SERVER}" \
  612. --host="localhost" --database="gnusocial" \
  613. --dbtype=mysql --username="root" -v \
  614. --password="$MARIADB_PASSWORD" \
  615. --sitename=$"GNU Social" --fancy='yes' \
  616. --admin-nick="$MY_USERNAME" \
  617. --admin-pass="$GNUSOCIAL_ADMIN_PASSWORD" \
  618. --site-profile="community" \
  619. --ssl=${gnusocial_ssl}
  620. # There can be a lot of warnings here so the return value check is disabled
  621. #if [ ! "$?" = "0" ]; then
  622. # # failed to install
  623. # echo $'Could not install GNU Social'
  624. # exit 72357
  625. #fi
  626. # check gnusocial has a config file
  627. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  628. if [ ! -f $gnusocial_config_file ]; then
  629. drop_database gnusocial
  630. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  631. echo $'Gnusocial config.php not found'
  632. exit 87586
  633. fi
  634. # Some useful settings
  635. if ! grep -q "Recommended GNU social settings" $gnusocial_config_file; then
  636. echo "" >> $gnusocial_config_file
  637. echo "// Recommended GNU social settings" >> $gnusocial_config_file
  638. echo "\$config['thumbnail']['maxsize'] = 3000;" >> $gnusocial_config_file
  639. echo "\$config['profile']['delete'] = true;" >> $gnusocial_config_file
  640. echo "\$config['profile']['changenick'] = true;" >> $gnusocial_config_file
  641. echo "\$config['public']['localonly'] = false;" >> $gnusocial_config_file
  642. echo "addPlugin('StoreRemoteMedia');" >> $gnusocial_config_file
  643. echo "\$config['queue']['enabled'] = true;" >> $gnusocial_config_file
  644. echo "\$config['queue']['daemon'] = true;" >> $gnusocial_config_file
  645. echo "\$config['ostatus']['hub_retries'] = 3;" >> $gnusocial_config_file
  646. fi
  647. # turn off logging
  648. echo "\$config['site']['logfile'] = '/dev/null';" >> $gnusocial_config_file
  649. echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> $gnusocial_config_file
  650. # This improves performance
  651. sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $gnusocial_config_file
  652. systemctl restart php5-fpm
  653. systemctl restart nginx
  654. ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  655. ${PROJECT_NAME}-pass -u $MY_USERNAME -a gnusocial -p "$GNUSOCIAL_ADMIN_PASSWORD"
  656. set_completion_param "gnusocial domain" "$GNUSOCIAL_DOMAIN_NAME"
  657. install_completed gnusocial_main
  658. }
  659. function install_gnusocial_plugin_sharings {
  660. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  661. echo $'No local/plugins directory found for the gnusocial'
  662. exit 72945
  663. fi
  664. apt-get -yq install liblocale-msgfmt-perl gettext
  665. # update to the next commit
  666. function_check set_repo_commit
  667. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial sharings plugin commit" "$SHARINGS_COMMIT" $SHARINGS_REPO
  668. if [[ $(app_is_installed gnusocial_plugin_sharings) == "1" ]]; then
  669. return
  670. fi
  671. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  672. function_check git_clone
  673. git_clone $SHARINGS_REPO Sharings
  674. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings ]; then
  675. echo $'Unable to clone gnusocial sharings plugin'
  676. exit 36738
  677. fi
  678. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings
  679. git stash
  680. git checkout master
  681. git branch -D $SHARINGS_COMMIT
  682. git checkout $SHARINGS_COMMIT -b $SHARINGS_COMMIT
  683. # enable the plugin
  684. if ! grep -q "addPlugin('Sharings');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  685. echo "addPlugin('Sharings');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  686. fi
  687. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  688. php scripts/checkschema.php
  689. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings
  690. php scripts/seedsharings.php
  691. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  692. php scripts/checkschema.php
  693. # Languages
  694. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES
  695. msgfmt -o Sharings.mo Sharings.po
  696. if [ ! -f Sharings.po ]; then
  697. echo $'English translations for gnusocial sharings plugin were not created'
  698. exit 84352
  699. fi
  700. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES
  701. msgfmt -o Sharings.mo Sharings.po
  702. if [ ! -f Sharings.po ]; then
  703. echo $'English (GB) translations for gnusocial sharings plugin were not created'
  704. exit 84352
  705. fi
  706. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES
  707. msgfmt -o Sharings.mo Sharings.po
  708. if [ ! -f Sharings.po ]; then
  709. echo $'English (US) translations for gnusocial sharings plugin were not created'
  710. exit 84352
  711. fi
  712. # Looks like this update function isn't supported by the current php version
  713. sed -i 's|ActivityVerb::UPDATE, ||g' /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Sharings/SharingsPlugin.php
  714. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  715. set_completion_param gnusocial "sharings plugin commit" "$SHARINGS_COMMIT"
  716. install_completed gnusocial_plugin_sharings
  717. }
  718. function install_gnusocial_plugin_sharings_theme {
  719. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  720. echo $'No local/plugins directory found for the gnusocial'
  721. exit 74458
  722. fi
  723. # update to the next commit
  724. function_check set_repo_commit
  725. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" $SHARINGS_THEME_REPO
  726. if [[ $(app_is_installed gnusocial_plugin_sharings_theme) == "1" ]]; then
  727. return
  728. fi
  729. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  730. function_check git_clone
  731. git_clone $SHARINGS_THEME_REPO SharingsTheme
  732. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme ]; then
  733. echo $'Unable to clone gnusocial sharings plugin theme'
  734. exit 639253
  735. fi
  736. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme
  737. git stash
  738. git checkout master
  739. git branch -D $SHARINGS_THEME_COMMIT
  740. git checkout $SHARINGS_THEME_COMMIT -b $SHARINGS_THEME_COMMIT
  741. # enable the plugin
  742. if ! grep -q "addPlugin('SharingsTheme');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  743. echo "addPlugin('SharingsTheme');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  744. fi
  745. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  746. php scripts/checkschema.php
  747. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  748. set_completion_param "gnusocial sharings plugin theme commit" "$SHARINGS_THEME_COMMIT"
  749. install_completed gnusocial_plugin_sharings_theme
  750. }
  751. function expire_gnusocial_posts {
  752. # To prevent the database size from growing endlessly this script expires posts
  753. # after a number of months
  754. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  755. return
  756. fi
  757. echo '<?php' > $gnusocial_expire_script
  758. echo '' >> $gnusocial_expire_script
  759. echo '// gnusocial post expiry script, based on StatExpire by Tony Baldwin' >> $gnusocial_expire_script
  760. echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_script
  761. echo '' >> $gnusocial_expire_script
  762. echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $gnusocial_expire_script
  763. echo '$username="root";' >> $gnusocial_expire_script
  764. echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');" >> $gnusocial_expire_script
  765. echo '$database="gnusocial";' >> $gnusocial_expire_script
  766. echo '' >> $gnusocial_expire_script
  767. echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_script
  768. echo ' echo "Could not connect to mariadb";' >> $gnusocial_expire_script
  769. echo ' exit;' >> $gnusocial_expire_script
  770. echo '}' >> $gnusocial_expire_script
  771. echo '' >> $gnusocial_expire_script
  772. echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_script
  773. echo ' echo "Could not select gnusocial database";' >> $gnusocial_expire_script
  774. echo ' exit;' >> $gnusocial_expire_script
  775. echo '}' >> $gnusocial_expire_script
  776. echo '' >> $gnusocial_expire_script
  777. echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
  778. echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_script
  779. echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
  780. echo '' >> $gnusocial_expire_script
  781. echo 'mysql_query($notice_query);' >> $gnusocial_expire_script
  782. echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_script
  783. echo 'mysql_query($conversation_query);' >> $gnusocial_expire_script
  784. echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_script
  785. echo 'mysql_query($reply_query);' >> $gnusocial_expire_script
  786. echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_script
  787. echo 'mysql_close();' >> $gnusocial_expire_script
  788. echo '' >> $gnusocial_expire_script
  789. echo 'echo "Expire gnusocial posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_script
  790. chmod +x $gnusocial_expire_script
  791. # Add a cron job
  792. if ! grep -q "$gnusocial_expire_script" /etc/crontab; then
  793. echo "10 3 5 * * root /usr/bin/timeout 500 /usr/bin/php $gnusocial_expire_script" >> /etc/crontab
  794. fi
  795. # remove old expire script
  796. if [ -f /etc/cron.weekly/clear-gnusocial-database ]; then
  797. rm /etc/cron.weekly/clear-gnusocial-database
  798. fi
  799. }
  800. function install_gnusocial_theme {
  801. # update to the next commit
  802. function_check set_repo_commit
  803. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter "gnusocial theme commit" "$GNUSOCIAL_THEME_COMMIT" $GNUSOCIAL_THEME_REPO
  804. # customise with project logo
  805. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  806. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  807. cp ~/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
  808. else
  809. if [ -f /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png ]; then
  810. cp /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
  811. fi
  812. fi
  813. fi
  814. if [[ $(app_is_installed gnusocial_theme) == "1" ]]; then
  815. return
  816. fi
  817. apt-get -yq install wget
  818. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  819. mkdir -p /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  820. fi
  821. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  822. function_check git_clone
  823. git_clone $GNUSOCIAL_THEME_REPO Qvitter
  824. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter
  825. git checkout $GNUSOCIAL_THEME_COMMIT -b $GNUSOCIAL_THEME_COMMIT
  826. # download a custom background image
  827. if [[ $(gnusocial_set_background_image_from_url) != "0" ]]; then
  828. exit 356723
  829. fi
  830. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
  831. filename=$(basename "$GNUSOCIAL_BACKGROUND_IMAGE_URL")
  832. GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="${filename##*.}"
  833. fi
  834. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  835. if ! grep -q "addPlugin('Qvitter')" $gnusocial_config_file; then
  836. GNUSOCIAL_WELCOME_MESSAGE=$(echo $GNUSOCIAL_WELCOME_MESSAGE | sed "s|\$GNUSOCIAL_DOMAIN_NAME|$GNUSOCIAL_DOMAIN_NAME|g")
  837. echo "" >> $gnusocial_config_file
  838. echo "// Qvitter settings" >> $gnusocial_config_file
  839. echo "addPlugin('Qvitter');" >> $gnusocial_config_file
  840. echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $gnusocial_config_file
  841. echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $gnusocial_config_file
  842. echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $gnusocial_config_file
  843. echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $gnusocial_config_file
  844. if [[ $ONION_ONLY != 'no' ]]; then
  845. echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $gnusocial_config_file
  846. echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $gnusocial_config_file
  847. fi
  848. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
  849. echo "\$config['site']['qvitter']['sitebackground'] = 'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';" >> $gnusocial_config_file
  850. else
  851. echo "\$config['site']['qvitter']['sitebackground'] = 'img/vagnsmossen.jpg';" >> $gnusocial_config_file
  852. fi
  853. echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $gnusocial_config_file
  854. echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $gnusocial_config_file
  855. echo "\$config['site']['qvitter']['enablewelcometext'] = true;" >> $gnusocial_config_file
  856. echo "\$config['site']['qvitter']['customwelcometext']['en'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
  857. echo "\$config['site']['qvitter']['customwelcometext']['de'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
  858. echo "\$config['site']['qvitter']['customwelcometext']['fr'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
  859. echo "\$config['site']['qvitter']['customwelcometext']['es'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
  860. echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $gnusocial_config_file
  861. else
  862. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT ]; then
  863. if [ -f img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT} ]; then
  864. sed -i "s|\$config['site']['qvitter']['sitebackground'].*|\$config['site']['qvitter']['sitebackground'] = 'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';|g" $gnusocial_config_file
  865. fi
  866. fi
  867. fi
  868. # customise with project logo
  869. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
  870. if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
  871. cp ~/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
  872. fi
  873. fi
  874. set_completion_param "gnusocial theme commit" "$GNUSOCIAL_THEME_COMMIT"
  875. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  876. install_completed gnusocial_theme
  877. }
  878. function install_gnusocial_markdown {
  879. GNUSOCIAL_PATH=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  880. # update to the next commit
  881. function_check set_repo_commit
  882. set_repo_commit $GNUSOCIAL_PATH/local/plugins/Markdown "gnusocial Markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT" $GNUSOCIAL_MARKDOWN_REPO
  883. if [[ $(app_is_installed gnusocial_markdown) == "1" ]]; then
  884. return
  885. fi
  886. if [ -d $GNUSOCIAL_PATH/local/plugins/Markdown ]; then
  887. rm -rf $GNUSOCIAL_PATH/local/plugins/Markdown
  888. fi
  889. if [ ! -d $GNUSOCIAL_PATH/local/plugins ]; then
  890. mkdir -p $GNUSOCIAL_PATH/local/plugins
  891. fi
  892. cd $GNUSOCIAL_PATH/local/plugins
  893. function_check git_clone
  894. git_clone $GNUSOCIAL_MARKDOWN_REPO Markdown
  895. cd $GNUSOCIAL_PATH/local/plugins/Markdown
  896. git checkout $GNUSOCIAL_MARKDOWN_COMMIT -b $GNUSOCIAL_MARKDOWN_COMMIT
  897. gnusocial_config_file=$GNUSOCIAL_PATH/config.php
  898. if ! grep -q "addPlugin('Markdown'" $gnusocial_config_file; then
  899. echo "" >> $gnusocial_config_file
  900. echo "// Markdown settings" >> $gnusocial_config_file
  901. echo "addPlugin('Markdown');" >> $gnusocial_config_file
  902. fi
  903. set_completion_param "gnusocial markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT"
  904. chown -R www-data:www-data $GNUSOCIAL_PATH
  905. install_completed gnusocial_markdown
  906. }
  907. function install_gnusocial_plugin_nsfw {
  908. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
  909. echo $'No local/plugins directory found for the gnusocial'
  910. exit 37252
  911. fi
  912. # update to the next commit
  913. function_check set_repo_commit
  914. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins "gnusocial NSFW plugin commit" "$GNUSOCIAL_NSFW_COMMIT" $GNUSOCIAL_NSFW_REPO
  915. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  916. return
  917. fi
  918. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
  919. function_check git_clone
  920. git_clone $GNUSOCIAL_NSFW_REPO SensitiveContent
  921. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SensitiveContent ]; then
  922. echo $'Unable to clone gnusocial NSFW plugin'
  923. exit 36738
  924. fi
  925. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/SensitiveContent
  926. git stash
  927. git checkout master
  928. git branch -D $GNUSOCIAL_NSFW_COMMIT
  929. git checkout $GNUSOCIAL_NSFW_COMMIT -b $GNUSOCIAL_NSFW_COMMIT
  930. # enable the plugin
  931. if ! grep -q "addPlugin('SensitiveContent');" /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php; then
  932. echo "addPlugin('SensitiveContent');" >> /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  933. fi
  934. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  935. php scripts/checkschema.php
  936. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  937. set_completion_param "gnusocial NSFW plugin commit" "$GNUSOCIAL_NSFW_COMMIT"
  938. install_completed gnusocial_plugin_nsfw
  939. }
  940. function install_gnusocial {
  941. if [ ! $ONION_ONLY ]; then
  942. ONION_ONLY='no'
  943. fi
  944. install_gnusocial_main
  945. expire_gnusocial_posts
  946. install_gnusocial_theme
  947. install_gnusocial_markdown
  948. install_gnusocial_plugin_sharings
  949. install_gnusocial_plugin_sharings_theme
  950. install_gnusocial_plugin_nsfw
  951. # unleash the daemons!
  952. /etc/cron.hourly/gnusocial-daemons
  953. APP_INSTALLED=1
  954. }
  955. # NOTE: deliberately there is no "exit 0"