freedombone-app-gnusocial 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # gnusocial application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. VARIANTS='full full-vim media'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. GNUSOCIAL_DOMAIN_NAME=
  34. GNUSOCIAL_CODE=
  35. GNUSOCIAL_ONION_PORT=8087
  36. GNUSOCIAL_REPO="https://git.gnu.io/gnu/gnu-social.git"
  37. GNUSOCIAL_COMMIT='1517deeeb621a0256106d0108855e8827713e2cc'
  38. GNUSOCIAL_ADMIN_PASSWORD=
  39. GNUSOCIAL_BACKGROUND_IMAGE_URL=
  40. GNUSOCIAL_TITLE='Pleroma FE'
  41. # Number of months after which posts expire
  42. GNUSOCIAL_EXPIRE_MONTHS=3
  43. gnusocial_variables=(ONION_ONLY
  44. GNUSOCIAL_DOMAIN_NAME
  45. GNUSOCIAL_CODE
  46. GNUSOCIAL_WELCOME_MESSAGE
  47. GNUSOCIAL_BACKGROUND_IMAGE_URL
  48. DDNS_PROVIDER
  49. GNUSOCIAL_TITLE
  50. GNUSOCIAL_EXPIRE_MONTHS
  51. MY_USERNAME)
  52. function gnusocial_fix_endless_reloads {
  53. # This fixes a bug introduced with commit 5f7032dfee1fd202c14e76a9f8b37af35d584901
  54. # and which causes OrFox to endlessly reload the page
  55. sed -i 's| && common_local_referer()||g' /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/lib/apiauthaction.php
  56. }
  57. function remove_user_gnusocial {
  58. remove_username="$1"
  59. ${PROJECT_NAME}-pass -u $remove_username --rmapp gnusocial
  60. function_check get_completion_param
  61. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  62. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  63. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  64. php scripts/deleteprofile.php -n $remove_username -y
  65. fi
  66. }
  67. function add_user_gnusocial {
  68. new_username="$1"
  69. new_user_password="$2"
  70. ${PROJECT_NAME}-pass -u $new_username -a gnusocial -p "$new_user_password"
  71. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  72. if [ -d /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs ]; then
  73. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  74. php scripts/registeruser.php -n $new_username -w "$new_user_password" -e "$new_username@$HOSTNAME"
  75. ${PROJECT_NAME}-addemail -u $new_username -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  76. echo '0'
  77. else
  78. echo '1'
  79. fi
  80. }
  81. function install_interactive_gnusocial {
  82. if [ ! $ONION_ONLY ]; then
  83. ONION_ONLY='no'
  84. fi
  85. if [[ $ONION_ONLY != "no" ]]; then
  86. GNUSOCIAL_DOMAIN_NAME='gnusocial.local'
  87. else
  88. GNUSOCIAL_DETAILS_COMPLETE=
  89. while [ ! $GNUSOCIAL_DETAILS_COMPLETE ]
  90. do
  91. data=$(tempfile 2>/dev/null)
  92. trap "rm -f $data" 0 1 2 5 15
  93. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  94. dialog --backtitle $"Freedombone Configuration" \
  95. --title $"GNU Social Configuration" \
  96. --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 \
  97. $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  98. $"Title:" 2 1 "$(grep '$GNUSOCIAL_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  99. $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  100. $"Code:" 4 1 "$(grep 'GNUSOCIAL_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
  101. 2> $data
  102. else
  103. dialog --backtitle $"Freedombone Configuration" \
  104. --title $"GNU Social Configuration" \
  105. --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 \
  106. $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  107. $"Title:" 2 1 "$(grep '$GNUSOCIAL_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  108. $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  109. 2> $data
  110. fi
  111. sel=$?
  112. case $sel in
  113. 1) exit 1;;
  114. 255) exit 1;;
  115. esac
  116. GNUSOCIAL_DOMAIN_NAME=$(cat $data | sed -n 1p)
  117. title=$(cat $data | sed -n 2p)
  118. if [ ${#title} -gt 1 ]; then
  119. GNUSOCIAL_TITLE=$welcome_msg
  120. fi
  121. img_url=$(cat $data | sed -n 3p)
  122. if [ ${#img_url} -gt 1 ]; then
  123. GNUSOCIAL_BACKGROUND_IMAGE_URL=$img_url
  124. fi
  125. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  126. if [[ $GNUSOCIAL_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
  127. GNUSOCIAL_DOMAIN_NAME=""
  128. fi
  129. TEST_DOMAIN_NAME=$GNUSOCIAL_DOMAIN_NAME
  130. validate_domain_name
  131. if [[ $TEST_DOMAIN_NAME != $GNUSOCIAL_DOMAIN_NAME ]]; then
  132. GNUSOCIAL_DOMAIN_NAME=
  133. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  134. else
  135. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  136. GNUSOCIAL_CODE=$(cat $data | sed -n 4p)
  137. validate_freedns_code "$GNUSOCIAL_CODE"
  138. if [ ! $VALID_CODE ]; then
  139. GNUSOCIAL_DOMAIN_NAME=
  140. fi
  141. fi
  142. fi
  143. fi
  144. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  145. GNUSOCIAL_DETAILS_COMPLETE="yes"
  146. fi
  147. done
  148. # remove any invalid characters
  149. if [ ${#GNUSOCIAL_TITLE} -gt 0 ]; then
  150. new_title=$(echo "$GNUSOCIAL_TITLE" | sed "s|'||g")
  151. GNUSOCIAL_TITLE="$new_title"
  152. fi
  153. # save the results in the config file
  154. write_config_param "GNUSOCIAL_CODE" "$GNUSOCIAL_CODE"
  155. write_config_param "GNUSOCIAL_TITLE" "$GNUSOCIAL_TITLE"
  156. write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  157. fi
  158. write_config_param "GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_DOMAIN_NAME"
  159. APP_INSTALLED=1
  160. }
  161. function change_password_gnusocial {
  162. curr_username="$1"
  163. new_user_password="$2"
  164. read_config_param 'GNUSOCIAL_DOMAIN_NAME'
  165. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts
  166. php setpassword.php "$curr_username" "$new_user_password"
  167. ${PROJECT_NAME}-pass -u "$curr_username" -a gnusocial -p "$new_user_password"
  168. }
  169. function gnusocial_create_database {
  170. if [ -f $IMAGE_PASSWORD_FILE ]; then
  171. GNUSOCIAL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  172. else
  173. if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
  174. GNUSOCIAL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  175. fi
  176. fi
  177. if [ ! $GNUSOCIAL_ADMIN_PASSWORD ]; then
  178. return
  179. fi
  180. function_check create_database
  181. create_database gnusocial "$GNUSOCIAL_ADMIN_PASSWORD" $MY_USERNAME
  182. }
  183. function reconfigure_gnusocial {
  184. echo -n ''
  185. }
  186. function gnusocial_set_background_image {
  187. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  188. data=$(tempfile 2>/dev/null)
  189. trap "rm -f $data" 0 1 2 5 15
  190. dialog --title $"GNU Social" \
  191. --backtitle $"Freedombone Control Panel" \
  192. --inputbox $'Set a background image URL' 10 60 2>$data
  193. sel=$?
  194. case $sel in
  195. 0)
  196. temp_background=$(<$data)
  197. if [ ${#temp_background} -gt 0 ]; then
  198. GNUSOCIAL_BACKGROUND_IMAGE_URL="$temp_background"
  199. write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
  200. if [[ $(pleroma_set_background_image_from_url "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE" | tail -n 1) == "0" ]]; then
  201. dialog --title $"Set GNU Social login background" \
  202. --msgbox $"The background image has been set" 6 60
  203. fi
  204. fi
  205. ;;
  206. esac
  207. }
  208. function gnusocial_set_title {
  209. data=$(tempfile 2>/dev/null)
  210. trap "rm -f $data" 0 1 2 5 15
  211. dialog --title $"GNU Social" \
  212. --backtitle $"Freedombone Control Panel" \
  213. --inputbox $'Set a title' 10 60 2>$data
  214. sel=$?
  215. case $sel in
  216. 0)
  217. new_title=$(<$data)
  218. if [ ${#new_title} -gt 0 ]; then
  219. GNUSOCIAL_TITLE="$new_title"
  220. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  221. write_config_param "GNUSOCIAL_TITLE" "$GNUSOCIAL_TITLE"
  222. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/static
  223. sed -i "s|\"name\":.*|\"name\": \"${GNUSOCIAL_TITLE}\",|g" config.json
  224. dialog --title $"Set GNU Social title" \
  225. --msgbox $"The title has been set" 6 60
  226. fi
  227. ;;
  228. esac
  229. }
  230. function gnusocial_set_expire_months {
  231. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  232. read_config_param "GNUSOCIAL_EXPIRE_MONTHS"
  233. data=$(tempfile 2>/dev/null)
  234. trap "rm -f $data" 0 1 2 5 15
  235. dialog --title $"GNU Social" \
  236. --backtitle $"Freedombone Control Panel" \
  237. --inputbox $'Set an expiry period for posts in months. Anything older will be deleted. Lower values help to keep the database size small and as fast as possible.' 12 60 "$GNUSOCIAL_EXPIRE_MONTHS" 2>$data
  238. sel=$?
  239. case $sel in
  240. 0)
  241. new_expiry_months=$(<$data)
  242. if [ ${#new_expiry_months} -gt 0 ]; then
  243. # should contain no spaces
  244. if [[ "$new_expiry_months" == *" "* ]]; then
  245. return
  246. fi
  247. # should be a number
  248. re='^[0-9]+$'
  249. if ! [[ $new_expiry_months =~ $re ]] ; then
  250. return
  251. fi
  252. # set the new value
  253. GNUSOCIAL_EXPIRE_MONTHS=$new_expiry_months
  254. write_config_param "GNUSOCIAL_EXPIRE_MONTHS" "$GNUSOCIAL_EXPIRE_MONTHS"
  255. expire_gnusocial_posts "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_EXPIRE_MONTHS"
  256. dialog --title $"Set GNU Social post expiry period" \
  257. --msgbox $"Expiry period set to $GNUSOCIAL_EXPIRE_MONTHS months" 6 60
  258. fi
  259. ;;
  260. esac
  261. }
  262. function configure_interactive_gnusocial {
  263. while true
  264. do
  265. data=$(tempfile 2>/dev/null)
  266. trap "rm -f $data" 0 1 2 5 15
  267. dialog --backtitle $"Freedombone Control Panel" \
  268. --title $"GNU Social" \
  269. --radiolist $"Choose an operation:" 16 70 7 \
  270. 1 $"Set a background image" off \
  271. 2 $"Set the title" off \
  272. 3 $"Set post expiry period (currently $GNUSOCIAL_EXPIRE_MONTHS months)" off \
  273. 4 $"Select Qvitter user interface" off \
  274. 5 $"Select Pleroma user interface" off \
  275. 6 $"Select Classic user interface" off \
  276. 7 $"Exit" on 2> $data
  277. sel=$?
  278. case $sel in
  279. 1) return;;
  280. 255) return;;
  281. esac
  282. case $(cat $data) in
  283. 1) gnusocial_set_background_image;;
  284. 2) gnusocial_set_title;;
  285. 3) gnusocial_set_expire_months;;
  286. 4) gnusocial_use_qvitter gnusocial;;
  287. 5) gnusocial_use_pleroma gnusocial;;
  288. 6) gnusocial_use_classic gnusocial;;
  289. 7) break;;
  290. esac
  291. done
  292. }
  293. function upgrade_gnusocial {
  294. CURR_GNUSOCIAL_COMMIT=$(get_completion_param "gnusocial commit")
  295. if [[ "$CURR_GNUSOCIAL_COMMIT" == "$GNUSOCIAL_COMMIT" ]]; then
  296. return
  297. fi
  298. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  299. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  300. fi
  301. # update to the next commit
  302. function_check set_repo_commit
  303. set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs "gnusocial commit" "$GNUSOCIAL_COMMIT" $GNUSOCIAL_REPO
  304. gnusocial_fix_endless_reloads
  305. # Ensure that installation script is removed
  306. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/install.php ]; then
  307. rm /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/install.php
  308. fi
  309. if [ -d $INSTALL_DIR/pleroma ]; then
  310. if [ -f /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index.php ]; then
  311. mv /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index.php /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/index_qvitter.php
  312. fi
  313. fi
  314. gnusocial_block_user_script
  315. gnusocial_block_domain_script gnusocial $GNUSOCIAL_DOMAIN_NAME
  316. gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
  317. if [ -d $INSTALL_DIR/pleroma ]; then
  318. upgrade_pleroma "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
  319. fi
  320. install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
  321. chown -R www-data:www-data /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  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. function_check suspend_site
  332. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  333. function_check backup_directory_to_usb
  334. backup_directory_to_usb $source_directory $dest_directory
  335. function_check backup_database_to_usb
  336. backup_database_to_usb gnusocial
  337. function_check restart_site
  338. restart_site
  339. fi
  340. }
  341. function restore_local_gnusocial {
  342. if ! grep -q "gnusocial domain" $COMPLETION_FILE; then
  343. return
  344. fi
  345. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  346. if [ $GNUSOCIAL_DOMAIN_NAME ]; then
  347. echo $"Restoring gnusocial"
  348. temp_restore_dir=/root/tempgnusocial
  349. gnusocial_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  350. # stop the daemons
  351. cd $gnusocial_dir
  352. scripts/stopdaemons.sh
  353. function_check gnusocial_create_database
  354. gnusocial_create_database
  355. restore_database gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  356. if [ -d $temp_restore_dir ]; then
  357. rm -rf $temp_restore_dir
  358. fi
  359. gnusocial_update_after_restore gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  360. echo $"Restore of gnusocial complete"
  361. fi
  362. }
  363. function backup_remote_gnusocial {
  364. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  365. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  366. temp_backup_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  367. if [ -d $temp_backup_dir ]; then
  368. function_check suspend_site
  369. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  370. function_check backup_database_to_friend
  371. backup_database_to_friend gnusocial
  372. echo $"Backing up GNU social installation"
  373. function_check backup_directory_to_friend
  374. backup_directory_to_friend $temp_backup_dir gnusocial
  375. function_check restart_site
  376. restart_site
  377. else
  378. echo $"gnusocial domain specified but not found in ${temp_backup_dir}"
  379. fi
  380. fi
  381. }
  382. function restore_remote_gnusocial {
  383. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  384. echo $"Restoring gnusocial"
  385. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  386. # stop the daemons
  387. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  388. scripts/stopdaemons.sh
  389. function_check gnusocial_create_database
  390. gnusocial_create_database
  391. function_check restore_database_from_friend
  392. restore_database_from_friend gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  393. if [ -d /root/tempgnusocial ]; then
  394. rm -rf /root/tempgnusocial
  395. fi
  396. gnusocial_update_after_restore gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  397. echo $"Restore of gnusocial complete"
  398. fi
  399. }
  400. function remove_gnusocial {
  401. if [ ${#GNUSOCIAL_DOMAIN_NAME} -eq 0 ]; then
  402. return
  403. fi
  404. function_check remove_nodejs
  405. remove_nodejs pleroma-gnusocial
  406. read_config_param "GNUSOCIAL_DOMAIN_NAME"
  407. read_config_param "MY_USERNAME"
  408. echo "Removing $GNUSOCIAL_DOMAIN_NAME"
  409. nginx_dissite $GNUSOCIAL_DOMAIN_NAME
  410. remove_certs $GNUSOCIAL_DOMAIN_NAME
  411. if [ -f /etc/cron.hourly/gnusocial-daemons ]; then
  412. rm /etc/cron.hourly/gnusocial-daemons
  413. fi
  414. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
  415. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  416. scripts/stopdaemons.sh
  417. fi
  418. kill_pid=$(ps aux | grep /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/queuedaemon.php | awk -F ' ' '{print $2}' | head -n 1)
  419. kill -9 $kill_pid
  420. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  421. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  422. fi
  423. if [ -f /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME ]; then
  424. rm /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  425. fi
  426. function_check drop_database
  427. drop_database gnusocial
  428. function_check remove_onion_service
  429. remove_onion_service gnusocial ${GNUSOCIAL_ONION_PORT}
  430. if grep -q "gnusocial" /etc/crontab; then
  431. sed -i "/gnusocial/d" /etc/crontab
  432. fi
  433. remove_app gnusocial
  434. remove_completion_param install_gnusocial
  435. sed -i '/gnusocial/d' $COMPLETION_FILE
  436. remove_backup_database_local gnusocial
  437. sed -i '/gnusocial-firewall/d' /etc/crontab
  438. function_check remove_ddns_domain
  439. remove_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  440. }
  441. function install_gnusocial_main {
  442. if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
  443. echo $'No domain name was given for gnusocial'
  444. exit 7359
  445. fi
  446. if [[ $(app_is_installed gnusocial_main) == "1" ]]; then
  447. return
  448. fi
  449. gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
  450. function_check install_mariadb
  451. install_mariadb
  452. function_check get_mariadb_password
  453. get_mariadb_password
  454. function_check repair_databases_script
  455. repair_databases_script
  456. apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
  457. apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
  458. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  459. mkdir /var/www/$GNUSOCIAL_DOMAIN_NAME
  460. fi
  461. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  462. if [ -d /repos/gnusocial ]; then
  463. mkdir /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  464. cp -r -p /repos/gnusocial/. /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  465. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  466. git pull
  467. else
  468. function_check git_clone
  469. git_clone $GNUSOCIAL_REPO /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  470. fi
  471. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  472. echo $'Unable to clone gnusocial repo'
  473. exit 87525
  474. fi
  475. fi
  476. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  477. git checkout $GNUSOCIAL_COMMIT -b $GNUSOCIAL_COMMIT
  478. set_completion_param "gnusocial commit" "$GNUSOCIAL_COMMIT"
  479. gnusocial_fix_endless_reloads
  480. chmod g+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  481. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/avatar
  482. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/file
  483. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  484. chmod +x /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php
  485. function_check gnusocial_create_database
  486. gnusocial_create_database
  487. if [ ! -f "/etc/aliases" ]; then
  488. touch /etc/aliases
  489. fi
  490. if ! grep -q "www-data: root" /etc/aliases; then
  491. echo 'www-data: root' >> /etc/aliases
  492. fi
  493. if ! grep -q "/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
  494. echo "*: /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
  495. fi
  496. function_check add_ddns_domain
  497. add_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  498. GNUSOCIAL_ONION_HOSTNAME=$(add_onion_service gnusocial 80 ${GNUSOCIAL_ONION_PORT})
  499. gnusocial_nginx_site=/etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  500. if [[ $ONION_ONLY == "no" ]]; then
  501. function_check nginx_http_redirect
  502. nginx_http_redirect $GNUSOCIAL_DOMAIN_NAME "index index.php"
  503. echo 'server {' >> $gnusocial_nginx_site
  504. echo ' listen 443 ssl;' >> $gnusocial_nginx_site
  505. echo ' listen [::]:443 ssl;' >> $gnusocial_nginx_site
  506. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  507. echo '' >> $gnusocial_nginx_site
  508. function_check nginx_compress
  509. nginx_compress $GNUSOCIAL_DOMAIN_NAME
  510. echo '' >> $gnusocial_nginx_site
  511. echo ' # Security' >> $gnusocial_nginx_site
  512. function_check nginx_ssl
  513. nginx_ssl $GNUSOCIAL_DOMAIN_NAME
  514. function_check nginx_disable_sniffing
  515. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  516. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $gnusocial_nginx_site
  517. echo '' >> $gnusocial_nginx_site
  518. echo ' # Logs' >> $gnusocial_nginx_site
  519. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  520. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  521. echo '' >> $gnusocial_nginx_site
  522. echo ' # Root' >> $gnusocial_nginx_site
  523. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  524. echo '' >> $gnusocial_nginx_site
  525. echo ' # Index' >> $gnusocial_nginx_site
  526. echo ' index index.php;' >> $gnusocial_nginx_site
  527. echo '' >> $gnusocial_nginx_site
  528. echo ' # PHP' >> $gnusocial_nginx_site
  529. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  530. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  531. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $gnusocial_nginx_site
  532. echo ' }' >> $gnusocial_nginx_site
  533. echo '' >> $gnusocial_nginx_site
  534. echo ' # Location' >> $gnusocial_nginx_site
  535. echo ' location / {' >> $gnusocial_nginx_site
  536. function_check nginx_limits
  537. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  538. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  539. echo ' }' >> $gnusocial_nginx_site
  540. echo '' >> $gnusocial_nginx_site
  541. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  542. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  543. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  544. echo ' }' >> $gnusocial_nginx_site
  545. echo '' >> $gnusocial_nginx_site
  546. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  547. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  548. echo ' deny all;' >> $gnusocial_nginx_site
  549. echo ' }' >> $gnusocial_nginx_site
  550. echo '' >> $gnusocial_nginx_site
  551. # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
  552. echo '}' >> $gnusocial_nginx_site
  553. else
  554. echo -n '' > $gnusocial_nginx_site
  555. fi
  556. echo 'server {' >> $gnusocial_nginx_site
  557. echo " listen 127.0.0.1:$GNUSOCIAL_ONION_PORT default_server;" >> $gnusocial_nginx_site
  558. echo " server_name $GNUSOCIAL_ONION_HOSTNAME;" >> $gnusocial_nginx_site
  559. echo '' >> $gnusocial_nginx_site
  560. function_check nginx_compress
  561. nginx_compress $GNUSOCIAL_DOMAIN_NAME
  562. echo '' >> $gnusocial_nginx_site
  563. function_check nginx_disable_sniffing
  564. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  565. echo '' >> $gnusocial_nginx_site
  566. echo ' # Logs' >> $gnusocial_nginx_site
  567. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  568. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  569. echo '' >> $gnusocial_nginx_site
  570. echo ' # Root' >> $gnusocial_nginx_site
  571. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  572. echo '' >> $gnusocial_nginx_site
  573. echo ' # Index' >> $gnusocial_nginx_site
  574. echo ' index index.php;' >> $gnusocial_nginx_site
  575. echo '' >> $gnusocial_nginx_site
  576. echo ' # PHP' >> $gnusocial_nginx_site
  577. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  578. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  579. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $gnusocial_nginx_site
  580. echo ' }' >> $gnusocial_nginx_site
  581. echo '' >> $gnusocial_nginx_site
  582. echo ' # Location' >> $gnusocial_nginx_site
  583. echo ' location / {' >> $gnusocial_nginx_site
  584. function_check nginx_limits
  585. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  586. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  587. echo ' }' >> $gnusocial_nginx_site
  588. echo '' >> $gnusocial_nginx_site
  589. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  590. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  591. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  592. echo ' }' >> $gnusocial_nginx_site
  593. echo '' >> $gnusocial_nginx_site
  594. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  595. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  596. echo ' deny all;' >> $gnusocial_nginx_site
  597. echo ' }' >> $gnusocial_nginx_site
  598. echo '' >> $gnusocial_nginx_site
  599. # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
  600. echo '}' >> $gnusocial_nginx_site
  601. function_check configure_php
  602. configure_php
  603. function_check create_site_certificate
  604. create_site_certificate $GNUSOCIAL_DOMAIN_NAME 'yes'
  605. # Ensure that the database gets backed up locally, if remote
  606. # backups are not being used
  607. function_check backup_databases_script_header
  608. backup_databases_script_header
  609. function_check backup_database_local
  610. backup_database_local gnusocial
  611. function_check nginx_ensite
  612. nginx_ensite $GNUSOCIAL_DOMAIN_NAME
  613. # NOTE: For the typical case always enable SSL and only
  614. # disable it if in onion only mode. This is due to complexities
  615. # with the way URLs are generated by gnusocial
  616. gnusocial_ssl='always'
  617. if [[ $ONION_ONLY != 'no' ]]; then
  618. gnusocial_ssl='never'
  619. fi
  620. GNUSOCIAL_SERVER=${GNUSOCIAL_DOMAIN_NAME}
  621. if [[ $ONION_ONLY != 'no' ]]; then
  622. GNUSOCIAL_SERVER=${GNUSOCIAL_ONION_HOSTNAME}
  623. fi
  624. # Create the configuration
  625. gnusocial_installer=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts/install_cli.php
  626. if [ ! -f $gnusocial_installer ]; then
  627. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  628. echo $'No gnusocial commandline installer found'
  629. exit 53026
  630. fi
  631. ${gnusocial_installer} --server "${GNUSOCIAL_SERVER}" \
  632. --host="localhost" --database="gnusocial" \
  633. --dbtype=mysql --username="root" -v \
  634. --password="$MARIADB_PASSWORD" \
  635. --sitename=$"GNU Social" --fancy='yes' \
  636. --admin-nick="$MY_USERNAME" \
  637. --admin-pass="$GNUSOCIAL_ADMIN_PASSWORD" \
  638. --site-profile="community" \
  639. --ssl=${gnusocial_ssl}
  640. # There can be a lot of warnings here so the return value check is disabled
  641. #if [ ! "$?" = "0" ]; then
  642. # # failed to install
  643. # echo $'Could not install GNU Social'
  644. # exit 72357
  645. #fi
  646. # check gnusocial has a config file
  647. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  648. if [ ! -f $gnusocial_config_file ]; then
  649. drop_database gnusocial
  650. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  651. echo $'Gnusocial config.php not found'
  652. exit 87586
  653. fi
  654. # Some useful settings
  655. if ! grep -q "Recommended GNU social settings" $gnusocial_config_file; then
  656. echo "" >> $gnusocial_config_file
  657. echo "// Recommended GNU social settings" >> $gnusocial_config_file
  658. echo "\$config['thumbnail']['maxsize'] = 3000;" >> $gnusocial_config_file
  659. echo "\$config['profile']['delete'] = true;" >> $gnusocial_config_file
  660. echo "\$config['profile']['changenick'] = true;" >> $gnusocial_config_file
  661. echo "\$config['public']['localonly'] = false;" >> $gnusocial_config_file
  662. echo "addPlugin('StoreRemoteMedia');" >> $gnusocial_config_file
  663. echo "\$config['queue']['enabled'] = true;" >> $gnusocial_config_file
  664. echo "\$config['queue']['daemon'] = true;" >> $gnusocial_config_file
  665. echo "\$config['ostatus']['hub_retries'] = 3;" >> $gnusocial_config_file
  666. fi
  667. # turn off logging
  668. echo "\$config['site']['logfile'] = '/dev/null';" >> $gnusocial_config_file
  669. echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> $gnusocial_config_file
  670. # This improves performance
  671. sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $gnusocial_config_file
  672. systemctl restart mariadb
  673. systemctl restart php7.0-fpm
  674. systemctl restart nginx
  675. ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  676. ${PROJECT_NAME}-pass -u $MY_USERNAME -a gnusocial -p "$GNUSOCIAL_ADMIN_PASSWORD"
  677. gnusocial_block_user_script
  678. gnusocial_block_domain_script gnusocial "$GNUSOCIAL_DOMAIN_NAME"
  679. set_completion_param "gnusocial domain" "$GNUSOCIAL_DOMAIN_NAME"
  680. install_completed gnusocial_main
  681. }
  682. function install_gnusocial {
  683. if [ ! $ONION_ONLY ]; then
  684. ONION_ONLY='no'
  685. fi
  686. install_gnusocial_main
  687. expire_gnusocial_posts "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_EXPIRE_MONTHS"
  688. install_qvitter "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  689. install_gnusocial_markdown "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  690. install_gnusocial_plugin_sharings "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  691. install_gnusocial_plugin_sharings_theme "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  692. # Currently Pleroma won't install on ARM systems
  693. # because it uses node-sass which doesn't support ARM
  694. if [[ "$(arch)" == "arm"* ]]; then
  695. echo -m $'WARNING: Pleroma currently does not support ARM '
  696. echo $'architecture, so it will not be installed'
  697. else
  698. function_check install_nodejs
  699. install_nodejs pleroma-gnusocial
  700. install_pleroma_front_end "gnusocial" "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
  701. install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
  702. sed -i 's|"theme":.*|"theme": "base16-apathy.css",|g' /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/static/config.json
  703. fi
  704. # unleash the daemons!
  705. /etc/cron.hourly/gnusocial-daemons
  706. systemctl restart nginx
  707. # Set qvitter to be the default UI. It's probably the most stable.
  708. # And doesn't forget logins
  709. gnusocial_use_qvitter gnusocial
  710. if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
  711. pleroma_set_background_image_from_url "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
  712. fi
  713. APP_INSTALLED=1
  714. }
  715. # NOTE: deliberately there is no "exit 0"