freedombone-app-postactiv 35KB

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