freedombone-app-postactiv 33KB

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