freedombone-app-gnusocial 35KB

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