freedombone-app-gnusocial 39KB

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