freedombone-app-postactiv 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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 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:" 16 70 7 \
  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 $"Exit" on 2> $data
  290. sel=$?
  291. case $sel in
  292. 1) return;;
  293. 255) return;;
  294. esac
  295. case $(cat $data) in
  296. 1) postactiv_set_background_image;;
  297. 2) postactiv_set_title;;
  298. 3) postactiv_set_expire_months;;
  299. 4) gnusocial_use_qvitter postactiv;;
  300. 5) gnusocial_use_pleroma postactiv;;
  301. 6) gnusocial_use_classic postactiv;;
  302. 7) break;;
  303. esac
  304. done
  305. }
  306. function upgrade_postactiv {
  307. CURR_POSTACTIV_COMMIT=$(get_completion_param "postactiv commit")
  308. if [[ "$CURR_POSTACTIV_COMMIT" == "$POSTACTIV_COMMIT" ]]; then
  309. return
  310. fi
  311. if grep -q "postactiv domain" $COMPLETION_FILE; then
  312. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  313. fi
  314. # update to the next commit
  315. function_check set_repo_commit
  316. set_repo_commit /var/www/$POSTACTIV_DOMAIN_NAME/htdocs "postactiv commit" "$POSTACTIV_COMMIT" $POSTACTIV_REPO
  317. # Ensure that installation script is removed
  318. if [ -f /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php ]; then
  319. rm /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php
  320. fi
  321. if [ -d $INSTALL_DIR/pleroma ]; then
  322. if [ -f /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index.php ]; then
  323. mv /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index.php /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index_qvitter.php
  324. fi
  325. fi
  326. function_check postactiv_running_script
  327. postactiv_running_script
  328. gnusocial_block_user_script
  329. gnusocial_block_domain_script postactiv "$POSTACTIV_DOMAIN_NAME"
  330. upgrade_pleroma "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
  331. postactiv_customise_logo
  332. install_gnusocial_default_background "postactiv" "$POSTACTIV_DOMAIN_NAME"
  333. chown -R www-data:www-data /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
  334. systemctl restart mariadb
  335. }
  336. function backup_local_postactiv {
  337. POSTACTIV_DOMAIN_NAME='postactiv'
  338. if grep -q "postactiv domain" $COMPLETION_FILE; then
  339. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  340. fi
  341. source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
  342. if [ -d $source_directory ]; then
  343. dest_directory=postactiv
  344. function_check suspend_site
  345. suspend_site ${POSTACTIV_DOMAIN_NAME}
  346. function_check backup_directory_to_usb
  347. backup_directory_to_usb $source_directory $dest_directory
  348. function_check backup_database_to_usb
  349. backup_database_to_usb postactiv
  350. function_check restart_site
  351. restart_site
  352. fi
  353. }
  354. function restore_local_postactiv {
  355. if ! grep -q "postactiv domain" $COMPLETION_FILE; then
  356. return
  357. fi
  358. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  359. if [ $POSTACTIV_DOMAIN_NAME ]; then
  360. temp_restore_dir=/root/temppostactiv
  361. postactiv_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
  362. # stop the daemons
  363. cd $postactiv_dir
  364. scripts/stopdaemons.sh
  365. function_check postactiv_create_database
  366. postactiv_create_database
  367. restore_database postactiv ${POSTACTIV_DOMAIN_NAME}
  368. if [ -d $temp_restore_dir ]; then
  369. rm -rf $temp_restore_dir
  370. fi
  371. gnusocial_update_after_restore postactiv ${POSTACTIV_DOMAIN_NAME}
  372. fi
  373. }
  374. function backup_remote_postactiv {
  375. if grep -q "postactiv domain" $COMPLETION_FILE; then
  376. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  377. temp_backup_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
  378. if [ -d $temp_backup_dir ]; then
  379. function_check suspend_site
  380. suspend_site ${POSTACTIV_DOMAIN_NAME}
  381. function_check backup_database_to_friend
  382. backup_database_to_friend postactiv
  383. function_check backup_directory_to_friend
  384. backup_directory_to_friend $temp_backup_dir postactiv
  385. function_check restart_site
  386. restart_site
  387. else
  388. echo $"postactiv domain specified but not found in ${temp_backup_dir}"
  389. fi
  390. fi
  391. }
  392. function restore_remote_postactiv {
  393. if grep -q "postactiv domain" $COMPLETION_FILE; then
  394. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  395. # stop the daemons
  396. cd /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
  397. scripts/stopdaemons.sh
  398. function_check postactiv_create_database
  399. postactiv_create_database
  400. function_check restore_database_from_friend
  401. restore_database_from_friend postactiv ${POSTACTIV_DOMAIN_NAME}
  402. if [ -d /root/temppostactiv ]; then
  403. rm -rf /root/temppostactiv
  404. fi
  405. gnusocial_update_after_restore postactiv ${POSTACTIV_DOMAIN_NAME}
  406. fi
  407. }
  408. function remove_postactiv {
  409. if [ ${#POSTACTIV_DOMAIN_NAME} -eq 0 ]; then
  410. return
  411. fi
  412. function_check remove_nodejs
  413. remove_nodejs pleroma-postactiv
  414. read_config_param "POSTACTIV_DOMAIN_NAME"
  415. read_config_param "MY_USERNAME"
  416. echo "Removing $POSTACTIV_DOMAIN_NAME"
  417. nginx_dissite $POSTACTIV_DOMAIN_NAME
  418. remove_certs $POSTACTIV_DOMAIN_NAME
  419. if [ -f /etc/cron.hourly/postactiv-daemons ]; then
  420. rm /etc/cron.hourly/postactiv-daemons
  421. fi
  422. if [ -f /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
  423. cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
  424. scripts/stopdaemons.sh
  425. fi
  426. kill_pid=$(ps aux | grep /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/queuedaemon.php | awk -F ' ' '{print $2}' | head -n 1)
  427. kill -9 $kill_pid
  428. if [ -d /var/www/$POSTACTIV_DOMAIN_NAME ]; then
  429. rm -rf /var/www/$POSTACTIV_DOMAIN_NAME
  430. fi
  431. if [ -f /etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME ]; then
  432. rm /etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME
  433. fi
  434. function_check drop_database
  435. drop_database postactiv
  436. function_check remove_onion_service
  437. remove_onion_service postactiv ${POSTACTIV_ONION_PORT}
  438. if grep -q "postactiv" /etc/crontab; then
  439. sed -i "/postactiv/d" /etc/crontab
  440. fi
  441. remove_app postactiv
  442. remove_completion_param install_postactiv
  443. sed -i '/postactiv/d' $COMPLETION_FILE
  444. remove_backup_database_local postactiv
  445. sed -i '/postactiv-firewall/d' /etc/crontab
  446. function_check remove_ddns_domain
  447. remove_ddns_domain $POSTACTIV_DOMAIN_NAME
  448. }
  449. function install_postactiv_main {
  450. if [ ! $POSTACTIV_DOMAIN_NAME ]; then
  451. echo $'No domain name was given for postactiv'
  452. exit 7359
  453. fi
  454. if [[ $(app_is_installed postactiv_main) == "1" ]]; then
  455. return
  456. fi
  457. function_check postactiv_running_script
  458. postactiv_running_script
  459. function_check install_mariadb
  460. install_mariadb
  461. function_check get_mariadb_password
  462. get_mariadb_password
  463. function_check repair_databases_script
  464. repair_databases_script
  465. apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
  466. apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
  467. if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME ]; then
  468. mkdir /var/www/$POSTACTIV_DOMAIN_NAME
  469. fi
  470. if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
  471. if [ -d /repos/postactiv ]; then
  472. mkdir /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
  473. cp -r -p /repos/postactiv/. /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
  474. cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
  475. git pull
  476. else
  477. function_check git_clone
  478. git_clone $POSTACTIV_REPO /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
  479. fi
  480. if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
  481. echo $'Unable to clone postactiv repo'
  482. exit 87525
  483. fi
  484. fi
  485. cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
  486. git checkout $POSTACTIV_COMMIT -b $POSTACTIV_COMMIT
  487. set_completion_param "postactiv commit" "$POSTACTIV_COMMIT"
  488. chmod g+w /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
  489. chmod a+w /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/avatar
  490. chmod a+w /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/file
  491. chown -R www-data:www-data /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
  492. chmod +x /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php
  493. chmod 755 /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Serializer.php
  494. chmod -x /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Serializer.php
  495. function_check postactiv_create_database
  496. postactiv_create_database
  497. if [ ! -f "/etc/aliases" ]; then
  498. touch /etc/aliases
  499. fi
  500. if ! grep -q "www-data: root" /etc/aliases; then
  501. echo 'www-data: root' >> /etc/aliases
  502. fi
  503. if ! grep -q "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
  504. echo "*: /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
  505. fi
  506. function_check add_ddns_domain
  507. add_ddns_domain $POSTACTIV_DOMAIN_NAME
  508. POSTACTIV_ONION_HOSTNAME=$(add_onion_service postactiv 80 ${POSTACTIV_ONION_PORT})
  509. postactiv_nginx_site=/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME
  510. if [[ $ONION_ONLY == "no" ]]; then
  511. function_check nginx_http_redirect
  512. nginx_http_redirect $POSTACTIV_DOMAIN_NAME "index index.php"
  513. echo 'server {' >> $postactiv_nginx_site
  514. echo ' listen 443 ssl;' >> $postactiv_nginx_site
  515. echo ' listen [::]:443 ssl;' >> $postactiv_nginx_site
  516. echo " server_name $POSTACTIV_DOMAIN_NAME;" >> $postactiv_nginx_site
  517. echo '' >> $postactiv_nginx_site
  518. function_check nginx_compress
  519. nginx_compress $POSTACTIV_DOMAIN_NAME
  520. echo '' >> $postactiv_nginx_site
  521. echo ' # Security' >> $postactiv_nginx_site
  522. function_check nginx_ssl
  523. nginx_ssl $POSTACTIV_DOMAIN_NAME
  524. function_check nginx_disable_sniffing
  525. nginx_disable_sniffing $POSTACTIV_DOMAIN_NAME
  526. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $postactiv_nginx_site
  527. echo '' >> $postactiv_nginx_site
  528. echo ' # Logs' >> $postactiv_nginx_site
  529. echo ' access_log /dev/null;' >> $postactiv_nginx_site
  530. echo ' error_log /dev/null;' >> $postactiv_nginx_site
  531. echo '' >> $postactiv_nginx_site
  532. echo ' # Root' >> $postactiv_nginx_site
  533. echo " root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;" >> $postactiv_nginx_site
  534. echo '' >> $postactiv_nginx_site
  535. echo ' # Index' >> $postactiv_nginx_site
  536. echo ' index index.php;' >> $postactiv_nginx_site
  537. echo '' >> $postactiv_nginx_site
  538. echo ' # PHP' >> $postactiv_nginx_site
  539. echo ' location ~ \.php {' >> $postactiv_nginx_site
  540. echo ' include snippets/fastcgi-php.conf;' >> $postactiv_nginx_site
  541. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $postactiv_nginx_site
  542. echo ' }' >> $postactiv_nginx_site
  543. echo '' >> $postactiv_nginx_site
  544. echo ' # Location' >> $postactiv_nginx_site
  545. echo ' location / {' >> $postactiv_nginx_site
  546. function_check nginx_limits
  547. nginx_limits $POSTACTIV_DOMAIN_NAME '15m'
  548. echo ' try_files $uri $uri/ @postactiv;' >> $postactiv_nginx_site
  549. echo ' }' >> $postactiv_nginx_site
  550. echo '' >> $postactiv_nginx_site
  551. echo ' # Fancy URLs' >> $postactiv_nginx_site
  552. echo ' location @postactiv {' >> $postactiv_nginx_site
  553. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $postactiv_nginx_site
  554. echo ' }' >> $postactiv_nginx_site
  555. echo '' >> $postactiv_nginx_site
  556. echo ' # Restrict access that is unnecessary anyway' >> $postactiv_nginx_site
  557. echo ' location ~ /\.(ht|git) {' >> $postactiv_nginx_site
  558. echo ' deny all;' >> $postactiv_nginx_site
  559. echo ' }' >> $postactiv_nginx_site
  560. echo '' >> $postactiv_nginx_site
  561. # DO NOT ENABLE KEYBASE. postactiv really doesn't like having a .well-known directory
  562. echo '}' >> $postactiv_nginx_site
  563. else
  564. echo -n '' > $postactiv_nginx_site
  565. fi
  566. echo 'server {' >> $postactiv_nginx_site
  567. echo " listen 127.0.0.1:$POSTACTIV_ONION_PORT default_server;" >> $postactiv_nginx_site
  568. echo " server_name $POSTACTIV_ONION_HOSTNAME;" >> $postactiv_nginx_site
  569. echo '' >> $postactiv_nginx_site
  570. function_check nginx_disable_sniffing
  571. nginx_disable_sniffing $POSTACTIV_DOMAIN_NAME
  572. echo '' >> $postactiv_nginx_site
  573. function_check nginx_compress
  574. nginx_compress $POSTACTIV_DOMAIN_NAME
  575. echo '' >> $postactiv_nginx_site
  576. echo ' # Logs' >> $postactiv_nginx_site
  577. echo ' access_log /dev/null;' >> $postactiv_nginx_site
  578. echo ' error_log /dev/null;' >> $postactiv_nginx_site
  579. echo '' >> $postactiv_nginx_site
  580. echo ' # Root' >> $postactiv_nginx_site
  581. echo " root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;" >> $postactiv_nginx_site
  582. echo '' >> $postactiv_nginx_site
  583. echo ' # Index' >> $postactiv_nginx_site
  584. echo ' index index.php;' >> $postactiv_nginx_site
  585. echo '' >> $postactiv_nginx_site
  586. echo ' # PHP' >> $postactiv_nginx_site
  587. echo ' location ~ \.php {' >> $postactiv_nginx_site
  588. echo ' include snippets/fastcgi-php.conf;' >> $postactiv_nginx_site
  589. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $postactiv_nginx_site
  590. echo ' }' >> $postactiv_nginx_site
  591. echo '' >> $postactiv_nginx_site
  592. echo ' # Location' >> $postactiv_nginx_site
  593. echo ' location / {' >> $postactiv_nginx_site
  594. function_check nginx_limits
  595. nginx_limits $POSTACTIV_DOMAIN_NAME '15m'
  596. echo ' try_files $uri $uri/ @postactiv;' >> $postactiv_nginx_site
  597. echo ' }' >> $postactiv_nginx_site
  598. echo '' >> $postactiv_nginx_site
  599. echo ' # Fancy URLs' >> $postactiv_nginx_site
  600. echo ' location @postactiv {' >> $postactiv_nginx_site
  601. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $postactiv_nginx_site
  602. echo ' }' >> $postactiv_nginx_site
  603. echo '' >> $postactiv_nginx_site
  604. echo ' # Restrict access that is unnecessary anyway' >> $postactiv_nginx_site
  605. echo ' location ~ /\.(ht|git) {' >> $postactiv_nginx_site
  606. echo ' deny all;' >> $postactiv_nginx_site
  607. echo ' }' >> $postactiv_nginx_site
  608. echo '' >> $postactiv_nginx_site
  609. # DO NOT ENABLE KEYBASE. postactiv really doesn't like having a .well-known directory
  610. echo '}' >> $postactiv_nginx_site
  611. function_check configure_php
  612. configure_php
  613. function_check create_site_certificate
  614. create_site_certificate $POSTACTIV_DOMAIN_NAME 'yes'
  615. # Ensure that the database gets backed up locally, if remote
  616. # backups are not being used
  617. function_check backup_databases_script_header
  618. backup_databases_script_header
  619. function_check backup_database_local
  620. backup_database_local postactiv
  621. function_check nginx_ensite
  622. nginx_ensite $POSTACTIV_DOMAIN_NAME
  623. # NOTE: For the typical case always enable SSL and only
  624. # disable it if in onion only mode. This is due to complexities
  625. # with the way URLs are generated by postactiv
  626. postactiv_ssl='always'
  627. if [[ $ONION_ONLY != 'no' ]]; then
  628. postactiv_ssl='never'
  629. fi
  630. POSTACTIV_SERVER=${POSTACTIV_DOMAIN_NAME}
  631. if [[ $ONION_ONLY != 'no' ]]; then
  632. POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME}
  633. fi
  634. # Create the configuration
  635. postactiv_installer=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts/install_cli.php
  636. if [ ! -f $postactiv_installer ]; then
  637. rm -rf /var/www/$POSTACTIV_DOMAIN_NAME
  638. echo $'No postactiv commandline installer found'
  639. exit 53026
  640. fi
  641. ${postactiv_installer} --server "${POSTACTIV_SERVER}" \
  642. --host="localhost" --database="postactiv" \
  643. --dbtype=mysql --username="root" -v \
  644. --password="$MARIADB_PASSWORD" \
  645. --sitename=$"postactiv" --fancy='yes' \
  646. --admin-nick="$MY_USERNAME" \
  647. --admin-pass="$POSTACTIV_ADMIN_PASSWORD" \
  648. --site-profile="community" \
  649. --ssl=${postactiv_ssl}
  650. # There can be a lot of warnings here so the return value check is disabled
  651. #if [ ! "$?" = "0" ]; then
  652. # # failed to install
  653. # echo $'Could not install postactiv'
  654. # exit 72357
  655. #fi
  656. # check postactiv has a config file
  657. postactiv_config_file=/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/config.php
  658. if [ ! -f $postactiv_config_file ]; then
  659. drop_database postactiv
  660. rm -rf /var/www/$POSTACTIV_DOMAIN_NAME
  661. echo $'Postactiv config.php not found'
  662. exit 87586
  663. fi
  664. # Some useful settings
  665. if ! grep -q "Recommended postactiv settings" $postactiv_config_file; then
  666. echo "" >> $postactiv_config_file
  667. echo "// Recommended postactiv settings" >> $postactiv_config_file
  668. echo "\$config['thumbnail']['maxsize'] = 3000;" >> $postactiv_config_file
  669. echo "\$config['profile']['delete'] = true;" >> $postactiv_config_file
  670. echo "\$config['profile']['changenick'] = true;" >> $postactiv_config_file
  671. echo "\$config['public']['localonly'] = false;" >> $postactiv_config_file
  672. echo "addPlugin('StoreRemoteMedia');" >> $postactiv_config_file
  673. echo "\$config['queue']['enabled'] = true;" >> $postactiv_config_file
  674. echo "\$config['queue']['daemon'] = true;" >> $postactiv_config_file
  675. echo "\$config['ostatus']['hub_retries'] = 3;" >> $postactiv_config_file
  676. fi
  677. echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> $postactiv_config_file
  678. # This improves performance
  679. sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $postactiv_config_file
  680. # remove the install script
  681. if [ -f /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php ]; then
  682. rm /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php
  683. fi
  684. systemctl restart mariadb
  685. systemctl restart php7.0-fpm
  686. systemctl restart nginx
  687. ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
  688. ${PROJECT_NAME}-pass -u $MY_USERNAME -a postactiv -p "$POSTACTIV_ADMIN_PASSWORD"
  689. gnusocial_block_user_script
  690. gnusocial_block_domain_script postactiv "$POSTACTIV_DOMAIN_NAME"
  691. set_completion_param "postactiv domain" "$POSTACTIV_DOMAIN_NAME"
  692. install_completed postactiv_main
  693. }
  694. function install_postactiv {
  695. if [ ! $ONION_ONLY ]; then
  696. ONION_ONLY='no'
  697. fi
  698. install_postactiv_main
  699. install_qvitter "$POSTACTIV_DOMAIN_NAME" "postactiv"
  700. install_gnusocial_markdown "$POSTACTIV_DOMAIN_NAME" "postactiv"
  701. install_gnusocial_plugin_sharings "$POSTACTIV_DOMAIN_NAME" "postactiv"
  702. install_gnusocial_plugin_sharings_theme "$POSTACTIV_DOMAIN_NAME" "postactiv"
  703. # Currently Pleroma won't install on ARM systems
  704. # because it uses node-sass which doesn't support ARM
  705. if [[ "$(arch)" == "arm"* ]]; then
  706. echo -m $'WARNING: Pleroma currently does not support ARM '
  707. echo $'architecture, so it will not be installed'
  708. else
  709. function_check install_nodejs
  710. install_nodejs pleroma-gnusocial
  711. install_pleroma_front_end "postactiv" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
  712. install_gnusocial_default_background "postactiv" "$POSTACTIV_DOMAIN_NAME"
  713. postactiv_customise_logo
  714. sed -i 's|"theme":.*|"theme": "base16-harmonic16-light.css",|g' /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static/config.json
  715. fi
  716. expire_gnusocial_posts "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_EXPIRE_MONTHS"
  717. # unleash the daemons!
  718. /etc/cron.hourly/postactiv-daemons
  719. systemctl restart nginx
  720. # Set qvitter to be the default UI. It's probably the most stable.
  721. # And doesn't forget logins
  722. gnusocial_use_qvitter postactiv
  723. if [ $POSTACTIV_BACKGROUND_IMAGE_URL ]; then
  724. pleroma_set_background_image_from_url "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
  725. fi
  726. APP_INSTALLED=1
  727. }
  728. # NOTE: deliberately there is no "exit 0"