freedombone-app-gnusocial 45KB

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