freedombone-app-postactiv 32KB

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