freedombone-app-gnusocial 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. # start the daemons
  360. cd $gnusocial_dir
  361. su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data
  362. echo $"Restore of gnusocial complete"
  363. fi
  364. }
  365. function backup_remote_gnusocial {
  366. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  367. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  368. temp_backup_dir=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  369. if [ -d $temp_backup_dir ]; then
  370. function_check suspend_site
  371. suspend_site ${GNUSOCIAL_DOMAIN_NAME}
  372. function_check backup_database_to_friend
  373. backup_database_to_friend gnusocial
  374. echo $"Backing up GNU social installation"
  375. function_check backup_directory_to_friend
  376. backup_directory_to_friend $temp_backup_dir gnusocial
  377. function_check restart_site
  378. restart_site
  379. else
  380. echo $"gnusocial domain specified but not found in ${temp_backup_dir}"
  381. fi
  382. fi
  383. }
  384. function restore_remote_gnusocial {
  385. if grep -q "gnusocial domain" $COMPLETION_FILE; then
  386. echo $"Restoring gnusocial"
  387. GNUSOCIAL_DOMAIN_NAME=$(get_completion_param "gnusocial domain")
  388. # stop the daemons
  389. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  390. scripts/stopdaemons.sh
  391. function_check gnusocial_create_database
  392. gnusocial_create_database
  393. function_check restore_database_from_friend
  394. restore_database_from_friend gnusocial ${GNUSOCIAL_DOMAIN_NAME}
  395. if [ -d /root/tempgnusocial ]; then
  396. rm -rf /root/tempgnusocial
  397. fi
  398. # start the daemons
  399. cd /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
  400. su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data
  401. echo $"Restore of gnusocial complete"
  402. fi
  403. }
  404. function remove_gnusocial {
  405. if [ ${#GNUSOCIAL_DOMAIN_NAME} -eq 0 ]; then
  406. return
  407. fi
  408. function_check remove_nodejs
  409. remove_nodejs pleroma-gnusocial
  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 [ -f /etc/cron.hourly/gnusocial-daemons ]; then
  416. rm /etc/cron.hourly/gnusocial-daemons
  417. fi
  418. if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
  419. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  420. scripts/stopdaemons.sh
  421. fi
  422. kill_pid=$(ps aux | grep /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/queuedaemon.php | awk -F ' ' '{print $2}' | head -n 1)
  423. kill -9 $kill_pid
  424. if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  425. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  426. fi
  427. if [ -f /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME ]; then
  428. rm /etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  429. fi
  430. function_check drop_database
  431. drop_database gnusocial
  432. function_check remove_onion_service
  433. remove_onion_service gnusocial ${GNUSOCIAL_ONION_PORT}
  434. if grep -q "gnusocial" /etc/crontab; then
  435. sed -i "/gnusocial/d" /etc/crontab
  436. fi
  437. remove_app gnusocial
  438. remove_completion_param install_gnusocial
  439. sed -i '/gnusocial/d' $COMPLETION_FILE
  440. remove_backup_database_local gnusocial
  441. sed -i '/gnusocial-firewall/d' /etc/crontab
  442. function_check remove_ddns_domain
  443. remove_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  444. }
  445. function install_gnusocial_main {
  446. if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
  447. echo $'No domain name was given for gnusocial'
  448. exit 7359
  449. fi
  450. if [[ $(app_is_installed gnusocial_main) == "1" ]]; then
  451. return
  452. fi
  453. gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
  454. function_check install_mariadb
  455. install_mariadb
  456. function_check get_mariadb_password
  457. get_mariadb_password
  458. function_check repair_databases_script
  459. repair_databases_script
  460. apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
  461. apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
  462. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME ]; then
  463. mkdir /var/www/$GNUSOCIAL_DOMAIN_NAME
  464. fi
  465. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  466. if [ -d /repos/gnusocial ]; then
  467. mkdir /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  468. cp -r -p /repos/gnusocial/. /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  469. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  470. git pull
  471. else
  472. function_check git_clone
  473. git_clone $GNUSOCIAL_REPO /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  474. fi
  475. if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
  476. echo $'Unable to clone gnusocial repo'
  477. exit 87525
  478. fi
  479. fi
  480. cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  481. git checkout $GNUSOCIAL_COMMIT -b $GNUSOCIAL_COMMIT
  482. set_completion_param "gnusocial commit" "$GNUSOCIAL_COMMIT"
  483. gnusocial_fix_endless_reloads
  484. chmod g+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  485. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/avatar
  486. chmod a+w /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/file
  487. chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
  488. chmod +x /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php
  489. function_check gnusocial_create_database
  490. gnusocial_create_database
  491. if [ ! -f "/etc/aliases" ]; then
  492. touch /etc/aliases
  493. fi
  494. if ! grep -q "www-data: root" /etc/aliases; then
  495. echo 'www-data: root' >> /etc/aliases
  496. fi
  497. if ! grep -q "/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
  498. echo "*: /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
  499. fi
  500. function_check add_ddns_domain
  501. add_ddns_domain $GNUSOCIAL_DOMAIN_NAME
  502. gnusocial_nginx_site=/etc/nginx/sites-available/$GNUSOCIAL_DOMAIN_NAME
  503. if [[ $ONION_ONLY == "no" ]]; then
  504. function_check nginx_http_redirect
  505. nginx_http_redirect $GNUSOCIAL_DOMAIN_NAME "index index.php"
  506. echo 'server {' >> $gnusocial_nginx_site
  507. echo ' listen 443 ssl;' >> $gnusocial_nginx_site
  508. echo ' listen [::]:443 ssl;' >> $gnusocial_nginx_site
  509. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  510. echo '' >> $gnusocial_nginx_site
  511. function_check nginx_compress
  512. nginx_compress $GNUSOCIAL_DOMAIN_NAME
  513. echo '' >> $gnusocial_nginx_site
  514. echo ' # Security' >> $gnusocial_nginx_site
  515. function_check nginx_ssl
  516. nginx_ssl $GNUSOCIAL_DOMAIN_NAME
  517. function_check nginx_disable_sniffing
  518. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  519. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $gnusocial_nginx_site
  520. echo '' >> $gnusocial_nginx_site
  521. echo ' # Logs' >> $gnusocial_nginx_site
  522. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  523. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  524. echo '' >> $gnusocial_nginx_site
  525. echo ' # Root' >> $gnusocial_nginx_site
  526. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  527. echo '' >> $gnusocial_nginx_site
  528. echo ' # Index' >> $gnusocial_nginx_site
  529. echo ' index index.php;' >> $gnusocial_nginx_site
  530. echo '' >> $gnusocial_nginx_site
  531. echo ' # PHP' >> $gnusocial_nginx_site
  532. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  533. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  534. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $gnusocial_nginx_site
  535. echo ' }' >> $gnusocial_nginx_site
  536. echo '' >> $gnusocial_nginx_site
  537. echo ' # Location' >> $gnusocial_nginx_site
  538. echo ' location / {' >> $gnusocial_nginx_site
  539. function_check nginx_limits
  540. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  541. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  542. echo ' }' >> $gnusocial_nginx_site
  543. echo '' >> $gnusocial_nginx_site
  544. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  545. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  546. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  547. echo ' }' >> $gnusocial_nginx_site
  548. echo '' >> $gnusocial_nginx_site
  549. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  550. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  551. echo ' deny all;' >> $gnusocial_nginx_site
  552. echo ' }' >> $gnusocial_nginx_site
  553. echo '' >> $gnusocial_nginx_site
  554. # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
  555. echo '}' >> $gnusocial_nginx_site
  556. else
  557. echo -n '' > $gnusocial_nginx_site
  558. fi
  559. echo 'server {' >> $gnusocial_nginx_site
  560. echo " listen 127.0.0.1:$GNUSOCIAL_ONION_PORT default_server;" >> $gnusocial_nginx_site
  561. echo " server_name $GNUSOCIAL_DOMAIN_NAME;" >> $gnusocial_nginx_site
  562. echo '' >> $gnusocial_nginx_site
  563. function_check nginx_compress
  564. nginx_compress $GNUSOCIAL_DOMAIN_NAME
  565. echo '' >> $gnusocial_nginx_site
  566. function_check nginx_disable_sniffing
  567. nginx_disable_sniffing $GNUSOCIAL_DOMAIN_NAME
  568. echo '' >> $gnusocial_nginx_site
  569. echo ' # Logs' >> $gnusocial_nginx_site
  570. echo ' access_log /dev/null;' >> $gnusocial_nginx_site
  571. echo ' error_log /dev/null;' >> $gnusocial_nginx_site
  572. echo '' >> $gnusocial_nginx_site
  573. echo ' # Root' >> $gnusocial_nginx_site
  574. echo " root /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs;" >> $gnusocial_nginx_site
  575. echo '' >> $gnusocial_nginx_site
  576. echo ' # Index' >> $gnusocial_nginx_site
  577. echo ' index index.php;' >> $gnusocial_nginx_site
  578. echo '' >> $gnusocial_nginx_site
  579. echo ' # PHP' >> $gnusocial_nginx_site
  580. echo ' location ~ \.php {' >> $gnusocial_nginx_site
  581. echo ' include snippets/fastcgi-php.conf;' >> $gnusocial_nginx_site
  582. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $gnusocial_nginx_site
  583. echo ' }' >> $gnusocial_nginx_site
  584. echo '' >> $gnusocial_nginx_site
  585. echo ' # Location' >> $gnusocial_nginx_site
  586. echo ' location / {' >> $gnusocial_nginx_site
  587. function_check nginx_limits
  588. nginx_limits $GNUSOCIAL_DOMAIN_NAME '15m'
  589. echo ' try_files $uri $uri/ @gnusocial;' >> $gnusocial_nginx_site
  590. echo ' }' >> $gnusocial_nginx_site
  591. echo '' >> $gnusocial_nginx_site
  592. echo ' # Fancy URLs' >> $gnusocial_nginx_site
  593. echo ' location @gnusocial {' >> $gnusocial_nginx_site
  594. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $gnusocial_nginx_site
  595. echo ' }' >> $gnusocial_nginx_site
  596. echo '' >> $gnusocial_nginx_site
  597. echo ' # Restrict access that is unnecessary anyway' >> $gnusocial_nginx_site
  598. echo ' location ~ /\.(ht|git) {' >> $gnusocial_nginx_site
  599. echo ' deny all;' >> $gnusocial_nginx_site
  600. echo ' }' >> $gnusocial_nginx_site
  601. echo '' >> $gnusocial_nginx_site
  602. # DO NOT ENABLE KEYBASE. gnusocial really doesn't like having a .well-known directory
  603. echo '}' >> $gnusocial_nginx_site
  604. function_check configure_php
  605. configure_php
  606. function_check create_site_certificate
  607. create_site_certificate $GNUSOCIAL_DOMAIN_NAME 'yes'
  608. # Ensure that the database gets backed up locally, if remote
  609. # backups are not being used
  610. function_check backup_databases_script_header
  611. backup_databases_script_header
  612. function_check backup_database_local
  613. backup_database_local gnusocial
  614. function_check nginx_ensite
  615. nginx_ensite $GNUSOCIAL_DOMAIN_NAME
  616. # NOTE: For the typical case always enable SSL and only
  617. # disable it if in onion only mode. This is due to complexities
  618. # with the way URLs are generated by gnusocial
  619. gnusocial_ssl='always'
  620. if [[ $ONION_ONLY != 'no' ]]; then
  621. gnusocial_ssl='never'
  622. fi
  623. GNUSOCIAL_ONION_HOSTNAME=$(add_onion_service gnusocial 80 ${GNUSOCIAL_ONION_PORT})
  624. GNUSOCIAL_SERVER=${GNUSOCIAL_DOMAIN_NAME}
  625. if [[ $ONION_ONLY != 'no' ]]; then
  626. GNUSOCIAL_SERVER=${GNUSOCIAL_ONION_HOSTNAME}
  627. fi
  628. # Create the configuration
  629. gnusocial_installer=/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/scripts/install_cli.php
  630. if [ ! -f $gnusocial_installer ]; then
  631. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  632. echo $'No gnusocial commandline installer found'
  633. exit 53026
  634. fi
  635. ${gnusocial_installer} --server "${GNUSOCIAL_SERVER}" \
  636. --host="localhost" --database="gnusocial" \
  637. --dbtype=mysql --username="root" -v \
  638. --password="$MARIADB_PASSWORD" \
  639. --sitename=$"GNU Social" --fancy='yes' \
  640. --admin-nick="$MY_USERNAME" \
  641. --admin-pass="$GNUSOCIAL_ADMIN_PASSWORD" \
  642. --site-profile="community" \
  643. --ssl=${gnusocial_ssl}
  644. # There can be a lot of warnings here so the return value check is disabled
  645. #if [ ! "$?" = "0" ]; then
  646. # # failed to install
  647. # echo $'Could not install GNU Social'
  648. # exit 72357
  649. #fi
  650. # check gnusocial has a config file
  651. gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
  652. if [ ! -f $gnusocial_config_file ]; then
  653. drop_database gnusocial
  654. rm -rf /var/www/$GNUSOCIAL_DOMAIN_NAME
  655. echo $'Gnusocial config.php not found'
  656. exit 87586
  657. fi
  658. # Some useful settings
  659. if ! grep -q "Recommended GNU social settings" $gnusocial_config_file; then
  660. echo "" >> $gnusocial_config_file
  661. echo "// Recommended GNU social settings" >> $gnusocial_config_file
  662. echo "\$config['thumbnail']['maxsize'] = 3000;" >> $gnusocial_config_file
  663. echo "\$config['profile']['delete'] = true;" >> $gnusocial_config_file
  664. echo "\$config['profile']['changenick'] = true;" >> $gnusocial_config_file
  665. echo "\$config['public']['localonly'] = false;" >> $gnusocial_config_file
  666. echo "addPlugin('StoreRemoteMedia');" >> $gnusocial_config_file
  667. echo "\$config['queue']['enabled'] = true;" >> $gnusocial_config_file
  668. echo "\$config['queue']['daemon'] = true;" >> $gnusocial_config_file
  669. echo "\$config['ostatus']['hub_retries'] = 3;" >> $gnusocial_config_file
  670. fi
  671. # turn off logging
  672. echo "\$config['site']['logfile'] = '/dev/null';" >> $gnusocial_config_file
  673. echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> $gnusocial_config_file
  674. # This improves performance
  675. sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $gnusocial_config_file
  676. systemctl restart mariadb
  677. systemctl restart php7.0-fpm
  678. systemctl restart nginx
  679. ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
  680. ${PROJECT_NAME}-pass -u $MY_USERNAME -a gnusocial -p "$GNUSOCIAL_ADMIN_PASSWORD"
  681. gnusocial_block_user_script
  682. gnusocial_block_domain_script gnusocial "$GNUSOCIAL_DOMAIN_NAME"
  683. set_completion_param "gnusocial domain" "$GNUSOCIAL_DOMAIN_NAME"
  684. install_completed gnusocial_main
  685. }
  686. function install_gnusocial {
  687. if [ ! $ONION_ONLY ]; then
  688. ONION_ONLY='no'
  689. fi
  690. install_gnusocial_main
  691. expire_gnusocial_posts "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_EXPIRE_MONTHS"
  692. install_qvitter "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  693. install_gnusocial_markdown "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  694. install_gnusocial_plugin_sharings "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  695. install_gnusocial_plugin_sharings_theme "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
  696. # Currently Pleroma won't install on ARM systems
  697. # because it uses node-sass which doesn't support ARM
  698. if [[ "$(arch)" == "arm"* ]]; then
  699. echo -m $'WARNING: Pleroma currently does not support ARM '
  700. echo $'architecture, so it will not be installed'
  701. else
  702. function_check install_nodejs
  703. install_nodejs pleroma-gnusocial
  704. install_pleroma_front_end "gnusocial" "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
  705. install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
  706. sed -i 's|"theme":.*|"theme": "base16-apathy.css",|g' /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/static/config.json
  707. fi
  708. # unleash the daemons!
  709. /etc/cron.hourly/gnusocial-daemons
  710. systemctl restart nginx
  711. # Set qvitter to be the default UI. It's probably the most stable.
  712. # And doesn't forget logins
  713. gnusocial_use_qvitter gnusocial
  714. APP_INSTALLED=1
  715. }
  716. # NOTE: deliberately there is no "exit 0"