freedombone-app-pleroma 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Pleroma backend application
  12. # https://git.pleroma.social/pleroma/pleroma/wikis/Installing-on-Debian-Based-Distributions
  13. #
  14. # Show stopper: This is dependent on https://placehold.it for avatar images,
  15. # so at present it's not usable until a first party placeholder image system
  16. # is included.
  17. #
  18. # There is also a possible issue with the chat system which uses an object called
  19. # "Agent" which may not be supported with the version of elixir within the
  20. # Debian package. This only applies if you're installing from the latest commit.
  21. #
  22. # License
  23. # =======
  24. #
  25. # Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
  26. #
  27. # This program is free software: you can redistribute it and/or modify
  28. # it under the terms of the GNU Affero General Public License as published by
  29. # the Free Software Foundation, either version 3 of the License, or
  30. # (at your option) any later version.
  31. #
  32. # This program is distributed in the hope that it will be useful,
  33. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. # GNU Affero General Public License for more details.
  36. #
  37. # You should have received a copy of the GNU Affero General Public License
  38. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  39. VARIANTS='full full-vim social'
  40. IN_DEFAULT_INSTALL=0
  41. SHOW_ON_ABOUT=1
  42. PLEROMA_DOMAIN_NAME=
  43. PLEROMA_CODE=
  44. PLEROMA_PORT=4000
  45. PLEROMA_ONION_PORT=8011
  46. PLEROMA_REPO="https://git.pleroma.social/pleroma/pleroma.git"
  47. PLEROMA_COMMIT='80f6ac412a632da090be9f3d86971eac0b95a53d'
  48. PLEROMA_ADMIN_PASSWORD=
  49. PLEROMA_DIR=/etc/pleroma
  50. PLEROMA_SECRET_KEY=""
  51. PLEROMA_BACKGROUND_IMAGE_URL=
  52. PLEROMA_TITLE='Pleroma Server'
  53. # Number of months after which posts expire
  54. PLEROMA_EXPIRE_MONTHS=3
  55. pleroma_expire_posts_script=/usr/bin/pleroma-expire-posts
  56. blocking_script_file=/usr/bin/pleroma-blocking
  57. pleroma_variables=(ONION_ONLY
  58. PLEROMA_DOMAIN_NAME
  59. PLEROMA_CODE
  60. PLEROMA_WELCOME_MESSAGE
  61. PLEROMA_BACKGROUND_IMAGE_URL
  62. DDNS_PROVIDER
  63. PLEROMA_TITLE
  64. PLEROMA_EXPIRE_MONTHS
  65. MY_EMAIL_ADDRESS
  66. MY_USERNAME)
  67. function create_pleroma_blocklist {
  68. echo '#!/bin/bash' > $blocking_script_file
  69. echo "if [ ! -f /root/${PROJECT_NAME}-firewall-domains.cfg ]; then" >> $blocking_script_file
  70. echo ' exit 0' >> $blocking_script_file
  71. echo 'fi' >> $blocking_script_file
  72. echo 'cd /etc/postgresql' >> $blocking_script_file
  73. echo 'while read blocked; do' >> $blocking_script_file
  74. echo ' if [[ "$blocked" == *"."* || "$blocked" == *"@"* ]]; then' >> $blocking_script_file
  75. echo ' if [ ${#blocked} -gt 4 ]; then' >> $blocking_script_file
  76. echo " sudo -u postgres psql -d pleroma -c \"DELETE FROM objects WHERE data->>'content' ilike '%\${blocked}%' or data->>'actor' ilike '%\${blocked}%' or data->>'to' ilike '%\${blocked}%' or data->>'id' ilike '%\${blocked}%' or data->>'external_url' ilike '%\${blocked}%'\"" >> $blocking_script_file
  77. echo " sudo -u postgres psql -d pleroma -c \"DELETE FROM users WHERE nickname ilike '%\${blocked}%'\"" >> $blocking_script_file
  78. echo ' if [[ "$blocked" != *"@"* ]]; then' >> $blocking_script_file
  79. echo " sudo -u postgres psql -d pleroma -c \"DELETE FROM websub_server_subscriptions WHERE callback like '%\${blocked}%'\"" >> $blocking_script_file
  80. echo ' fi' >> $blocking_script_file
  81. echo ' fi' >> $blocking_script_file
  82. echo ' fi' >> $blocking_script_file
  83. echo "done </root/${PROJECT_NAME}-firewall-domains.cfg" >> $blocking_script_file
  84. chmod +x $blocking_script_file
  85. if ! grep -q "$blocking_script_file" /etc/crontab; then
  86. echo "*/2 * * * * root $blocking_script_file > /dev/null" >> /etc/crontab
  87. fi
  88. }
  89. function expire_pleroma_posts {
  90. domain_name=$1
  91. expire_months=$3
  92. if [ ! $expire_months ]; then
  93. expire_months=3
  94. fi
  95. expire_days=$((expire_months * 30))
  96. # files are what take up most of the backup time, so don't keep them for very long
  97. expire_days_files=7
  98. # To prevent the database size from growing endlessly this script expires posts
  99. # after a number of months
  100. if [ ! -d /etc/pleroma ]; then
  101. return
  102. fi
  103. echo '#!/bin/bash' > $pleroma_expire_posts_script
  104. echo "plmonths=\"$PLEROMA_EXPIRE_MONTHS\"" >> $pleroma_expire_posts_script
  105. echo 'if [ ${#plmonths} -eq 0 ]; then' >> $pleroma_expire_posts_script
  106. echo ' exit 1' >> $pleroma_expire_posts_script
  107. echo 'fi' >> $pleroma_expire_posts_script
  108. echo 'if [[ "$plmonths" == "0" ]]; then' >> $pleroma_expire_posts_script
  109. echo ' exit 2' >> $pleroma_expire_posts_script
  110. echo 'fi' >> $pleroma_expire_posts_script
  111. echo 'oldate=$(date +%Y-%m-%d --date="$plmonths months ago")' >> $pleroma_expire_posts_script
  112. echo 'cd /etc/postgresql' >> $pleroma_expire_posts_script
  113. echo "sudo -u postgres psql -d pleroma -c \"DELETE FROM notifications WHERE inserted_at <= '\$oldate 01:01:01'\"" >> $pleroma_expire_posts_script
  114. echo "sudo -u postgres psql -d pleroma -c \"DELETE FROM objects WHERE inserted_at <= '\$oldate 01:01:01'\"" >> $pleroma_expire_posts_script
  115. chmod +x $pleroma_expire_posts_script
  116. pleroma_expire_script=/etc/cron.daily/pleroma-expire
  117. echo '#!/bin/bash' > $pleroma_expire_script
  118. echo "find /etc/pleroma/uploads/* -mtime +${expire_days_files} -exec rm -rf {} +" >> $pleroma_expire_script
  119. echo "$pleroma_expire_posts_script 2> /dev/null" >> $pleroma_expire_script
  120. chmod +x $pleroma_expire_script
  121. # remove any old cron job
  122. if grep -q "pleroma-expire" /etc/crontab; then
  123. sed -i "/pleroma-expire/d" /etc/crontab
  124. rm /usr/bin/pleroma-expire
  125. fi
  126. # remove old expire script
  127. if [ -f /etc/cron.weekly/clear-pleroma-database ]; then
  128. rm /etc/cron.weekly/clear-pleroma-database
  129. fi
  130. }
  131. function pleroma_recompile {
  132. # necessary after parameter changes
  133. chown -R pleroma:pleroma $PLEROMA_DIR
  134. sudo -u pleroma mix clean
  135. sudo -u pleroma mix deps.compile
  136. sudo -u pleroma mix compile
  137. if [ -f /etc/systemd/system/pleroma.service ]; then
  138. systemctl restart pleroma
  139. fi
  140. }
  141. function logging_on_pleroma {
  142. echo -n ''
  143. }
  144. function logging_off_pleroma {
  145. echo -n ''
  146. }
  147. function remove_user_pleroma {
  148. remove_username="$1"
  149. ${PROJECT_NAME}-pass -u $remove_username --rmapp pleroma
  150. }
  151. function add_user_pleroma {
  152. new_username="$1"
  153. new_user_password="$2"
  154. ${PROJECT_NAME}-pass -u $new_username -a pleroma -p "$new_user_password"
  155. echo '0'
  156. }
  157. function install_interactive_pleroma {
  158. if [ ! $ONION_ONLY ]; then
  159. ONION_ONLY='no'
  160. fi
  161. if [[ $ONION_ONLY != "no" ]]; then
  162. PLEROMA_DOMAIN_NAME='pleroma.local'
  163. else
  164. PLEROMA_DETAILS_COMPLETE=
  165. while [ ! $PLEROMA_DETAILS_COMPLETE ]
  166. do
  167. data=$(tempfile 2>/dev/null)
  168. trap "rm -f $data" 0 1 2 5 15
  169. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  170. dialog --backtitle $"Freedombone Configuration" \
  171. --title $"Pleroma Configuration" \
  172. --form $"\nPlease enter your Pleroma 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 \
  173. $"Domain:" 1 1 "$(grep 'PLEROMA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  174. $"Title:" 2 1 "$(grep '$PLEROMA_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  175. $"Background image URL:" 3 1 "$(grep '$PLEROMA_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  176. $"Code:" 4 1 "$(grep 'PLEROMA_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
  177. 2> $data
  178. else
  179. dialog --backtitle $"Freedombone Configuration" \
  180. --title $"Pleroma Configuration" \
  181. --form $"\nPlease enter your Pleroma 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 \
  182. $"Domain:" 1 1 "$(grep 'PLEROMA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  183. $"Title:" 2 1 "$(grep '$PLEROMA_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  184. $"Background image URL:" 3 1 "$(grep '$PLEROMA_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  185. 2> $data
  186. fi
  187. sel=$?
  188. case $sel in
  189. 1) exit 1;;
  190. 255) exit 1;;
  191. esac
  192. PLEROMA_DOMAIN_NAME=$(cat $data | sed -n 1p)
  193. title=$(cat $data | sed -n 2p)
  194. if [ ${#title} -gt 1 ]; then
  195. PLEROMA_TITLE=$welcome_msg
  196. fi
  197. img_url=$(cat $data | sed -n 3p)
  198. if [ ${#img_url} -gt 1 ]; then
  199. PLEROMA_BACKGROUND_IMAGE_URL=$img_url
  200. fi
  201. if [ $PLEROMA_DOMAIN_NAME ]; then
  202. if [[ $PLEROMA_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
  203. PLEROMA_DOMAIN_NAME=""
  204. fi
  205. TEST_DOMAIN_NAME=$PLEROMA_DOMAIN_NAME
  206. validate_domain_name
  207. if [[ $TEST_DOMAIN_NAME != $PLEROMA_DOMAIN_NAME ]]; then
  208. PLEROMA_DOMAIN_NAME=
  209. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  210. else
  211. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  212. PLEROMA_CODE=$(cat $data | sed -n 4p)
  213. validate_freedns_code "$PLEROMA_CODE"
  214. if [ ! $VALID_CODE ]; then
  215. PLEROMA_DOMAIN_NAME=
  216. fi
  217. fi
  218. fi
  219. fi
  220. if [ $PLEROMA_DOMAIN_NAME ]; then
  221. PLEROMA_DETAILS_COMPLETE="yes"
  222. fi
  223. done
  224. # remove any invalid characters
  225. if [ ${#PLEROMA_TITLE} -gt 0 ]; then
  226. new_title=$(echo "$PLEROMA_TITLE" | sed "s|'||g")
  227. PLEROMA_TITLE="$new_title"
  228. fi
  229. # save the results in the config file
  230. write_config_param "PLEROMA_CODE" "$PLEROMA_CODE"
  231. write_config_param "PLEROMA_TITLE" "$PLEROMA_TITLE"
  232. write_config_param "PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_BACKGROUND_IMAGE_URL"
  233. fi
  234. write_config_param "PLEROMA_DOMAIN_NAME" "$PLEROMA_DOMAIN_NAME"
  235. APP_INSTALLED=1
  236. }
  237. function change_password_pleroma {
  238. curr_username="$1"
  239. new_user_password="$2"
  240. #${PROJECT_NAME}-pass -u "$curr_username" -a pleroma -p "$new_user_password"
  241. }
  242. function pleroma_create_database_failed {
  243. run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
  244. run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
  245. }
  246. function pleroma_create_database {
  247. if [ -f $IMAGE_PASSWORD_FILE ]; then
  248. PLEROMA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  249. else
  250. if [ ! $PLEROMA_ADMIN_PASSWORD ]; then
  251. PLEROMA_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  252. fi
  253. fi
  254. if [ ! $PLEROMA_ADMIN_PASSWORD ]; then
  255. return
  256. fi
  257. systemctl restart postgresql
  258. add_postgresql_user pleroma "$PLEROMA_ADMIN_PASSWORD" encrypted
  259. run_system_query_postgresql "create database pleroma;"
  260. # temporarily allow the user to create databases
  261. run_system_query_postgresql "ALTER USER pleroma CREATEDB;"
  262. run_system_query_postgresql "ALTER USER pleroma SUPERUSER;"
  263. run_system_query_postgresql "GRANT ALL ON ALL tables IN SCHEMA public TO pleroma;"
  264. run_system_query_postgresql "GRANT ALL ON ALL sequences IN SCHEMA public TO pleroma;"
  265. run_system_query_postgresql "CREATE EXTENSION citext;"
  266. run_system_query_postgresql "set statement_timeout to 40000;"
  267. read_config_param "PLEROMA_SECRET_KEY"
  268. if [ ${#PLEROMA_SECRET_KEY} -lt 64 ]; then
  269. PLEROMA_SECRET_KEY="$(create_password 30)$(create_password 30)$(create_password 30)"
  270. if [ ${#PLEROMA_SECRET_KEY} -lt 64 ]; then
  271. pleroma_create_database_failed
  272. echo $'Pleroma secret key not created'
  273. exit 6782352
  274. fi
  275. write_config_param "PLEROMA_SECRET_KEY" "$PLEROMA_SECRET_KEY"
  276. fi
  277. if [ ! -d $PLEROMA_DIR/config ]; then
  278. echo $"Missing directory $PLEROMA_DIR/config"
  279. exit 7835393
  280. fi
  281. pleroma_secret=$PLEROMA_DIR/config/dev.secret.exs
  282. if [ ! -f $PLEROMA_DIR/config/dev.exs ]; then
  283. echo $"Did not find $PLEROMA_DIR/config/dev.exs"
  284. exit 78923528
  285. fi
  286. cp $PLEROMA_DIR/config/dev.exs $pleroma_secret
  287. sed -i "s|username:.*|username: \"pleroma\",|g" $pleroma_secret
  288. sed -i "s|password:.*|password: \"$PLEROMA_ADMIN_PASSWORD\",|g" $pleroma_secret
  289. sed -i "s|database:.*|database: \"pleroma\",|g" $pleroma_secret
  290. sed -i "/Pleroma.Web.Endpoint/a secret_key_base: \"$PLEROMA_SECRET_KEY\"," $pleroma_secret
  291. sed -i 's|secret_key_base: | secret_key_base: |g' $pleroma_secret
  292. sed -i "/Pleroma.Web.Endpoint/a pubsub: [name: Pleroma.Web.PubSub, adapter: Phoenix.PubSub.PG2]," $pleroma_secret
  293. sed -i 's|pubsub: | pubsub: |g' $pleroma_secret
  294. sed -i 's|watchers: []|watchers: [],|g' $pleroma_secret
  295. if [[ $ONION_ONLY == 'no' ]]; then
  296. sed -i "/watchers: []/a url: [host: \"$PLEROMA_DOMAIN_NAME\", scheme: \"https\", port: 443]" $pleroma_secret
  297. else
  298. sed -i "/watchers: []/a url: [host: \"$PLEROMA_ONION_HOSTNAME\", scheme: \"http\", port: 80]" $pleroma_secret
  299. fi
  300. sed -i 's|url: | url: |g' $pleroma_secret
  301. if ! grep -q "pbkdf2_rounds" $pleroma_secret; then
  302. sed -i '/config :logger/a config :comeonin, :pbkdf2_rounds, 1' $pleroma_secret
  303. else
  304. sed -i 's|pbkdf2_rounds.*|pbkdf2_rounds, 1|g' $pleroma_secret
  305. fi
  306. sed -i 's|import_config|# import_config|g' $pleroma_secret
  307. cd $PLEROMA_DIR
  308. chown -R pleroma:pleroma $PLEROMA_DIR/*
  309. sudo -u pleroma mix local.rebar --force
  310. if [ ! "$?" = "0" ]; then
  311. pleroma_create_database_failed
  312. echo $'mix local.rebar failed'
  313. exit 73528562
  314. fi
  315. sudo -u pleroma mix local.hex --force
  316. sudo -u pleroma mix deps.compile mimerl
  317. systemctl restart postgresql
  318. sudo -u pleroma mix ecto.create --force
  319. if [ ! "$?" = "0" ]; then
  320. pleroma_create_database_failed
  321. echo $'mix ecto.create failed'
  322. exit 83653582
  323. fi
  324. sudo -u pleroma mix ecto.migrate --force
  325. if [ ! "$?" = "0" ]; then
  326. pleroma_create_database_failed
  327. echo $'mix ecto.migrate failed'
  328. exit 73752573
  329. fi
  330. # revoke the ability to create databases for this user
  331. run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
  332. run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
  333. }
  334. function reconfigure_pleroma {
  335. echo -n ''
  336. }
  337. function pleroma_set_background_image {
  338. PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
  339. data=$(tempfile 2>/dev/null)
  340. trap "rm -f $data" 0 1 2 5 15
  341. dialog --title $"Pleroma" \
  342. --backtitle $"Freedombone Control Panel" \
  343. --inputbox $'Set a background image URL' 10 60 2>$data
  344. sel=$?
  345. case $sel in
  346. 0)
  347. temp_background=$(<$data)
  348. if [ ${#temp_background} -gt 0 ]; then
  349. PLEROMA_BACKGROUND_IMAGE_URL="$temp_background"
  350. write_config_param "PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_BACKGROUND_IMAGE_URL"
  351. if [[ $(pleroma_set_background_image_from_url $PLEROMA_DIR "$PLEROMA_DOMAIN_NAME" "$PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_TITLE" | tail -n 1) == "0" ]]; then
  352. pleroma_recompile
  353. dialog --title $"Set Pleroma login background" \
  354. --msgbox $"The background image has been set" 6 60
  355. fi
  356. fi
  357. ;;
  358. esac
  359. rm $data
  360. }
  361. function pleroma_set_title {
  362. data=$(tempfile 2>/dev/null)
  363. trap "rm -f $data" 0 1 2 5 15
  364. dialog --title $"Pleroma" \
  365. --backtitle $"Freedombone Control Panel" \
  366. --inputbox $'Set a title' 10 60 2>$data
  367. sel=$?
  368. case $sel in
  369. 0)
  370. new_title=$(<$data)
  371. if [ ${#new_title} -gt 0 ]; then
  372. PLEROMA_TITLE="$new_title"
  373. PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
  374. write_config_param "PLEROMA_TITLE" "$PLEROMA_TITLE"
  375. sed -i "s|\"name\":.*|\"name\": \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/static/config.json
  376. sed -i "s|\"name\":.*|\"name\": \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/priv/static/static/config.json
  377. sed -i "s|name: .*|name: \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/config/config.exs
  378. systemctl restart pleroma
  379. dialog --title $"Set Pleroma title" \
  380. --msgbox $"The title has been set" 6 60
  381. fi
  382. ;;
  383. esac
  384. rm $data
  385. }
  386. function pleroma_set_expire_months {
  387. PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
  388. read_config_param "PLEROMA_DOMAIN_NAME"
  389. read_config_param "PLEROMA_EXPIRE_MONTHS"
  390. data=$(tempfile 2>/dev/null)
  391. trap "rm -f $data" 0 1 2 5 15
  392. dialog --title $"Pleroma" \
  393. --backtitle $"Freedombone Control Panel" \
  394. --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 "$PLEROMA_EXPIRE_MONTHS" 2>$data
  395. sel=$?
  396. case $sel in
  397. 0)
  398. new_expiry_months=$(<$data)
  399. if [ ${#new_expiry_months} -gt 0 ]; then
  400. # should contain no spaces
  401. if [[ "$new_expiry_months" == *" "* ]]; then
  402. return
  403. fi
  404. # should be a number
  405. re='^[0-9]+$'
  406. if ! [[ $new_expiry_months =~ $re ]] ; then
  407. return
  408. fi
  409. # set the new value
  410. PLEROMA_EXPIRE_MONTHS=$new_expiry_months
  411. write_config_param "PLEROMA_EXPIRE_MONTHS" "$PLEROMA_EXPIRE_MONTHS"
  412. expire_pleroma_posts $PLEROMA_DOMAIN_NAME $PLEROMA_EXPIRE_MONTHS
  413. create_pleroma_blocklist
  414. dialog --title $"Set Pleroma post expiry period" \
  415. --msgbox $"Expiry period set to $PLEROMA_EXPIRE_MONTHS months" 6 60
  416. fi
  417. ;;
  418. esac
  419. rm $data
  420. }
  421. function pleroma_disable_registrations {
  422. dialog --title $"Disable new Pleroma user registrations" \
  423. --backtitle $"Freedombone Control Panel" \
  424. --yesno $"\nDo you wish to disable new registrations?" 10 60
  425. sel=$?
  426. case $sel in
  427. 0) sed -i 's|registrations_open:.*|registrations_open: false|g' $PLEROMA_DIR/config/config.exs
  428. sed -i 's|"registrationOpen":.*|"registrationOpen": false|g' $PLEROMA_DIR/priv/static/static/config.json
  429. ;;
  430. 1) sed -i 's|registrations_open:.*|registrations_open: true|g' $PLEROMA_DIR/config/config.exs
  431. sed -i 's|"registrationOpen":.*|"registrationOpen": true|g' $PLEROMA_DIR/priv/static/static/config.json
  432. ;;
  433. 255) return;;
  434. esac
  435. pleroma_recompile
  436. }
  437. function pleroma_add_emoji {
  438. emoji_resolution='128x128'
  439. data=$(tempfile 2>/dev/null)
  440. trap "rm -f $data" 0 1 2 5 15
  441. dialog --backtitle $"Freedombone Control Panel" \
  442. --title $"Add Custom Emoji" \
  443. --form "\n" 8 75 2 \
  444. $"Shortcode:" 1 1 "" 1 18 16 15 \
  445. $"ImageURL:" 2 1 "" 2 18 512 10000 \
  446. 2> $data
  447. sel=$?
  448. case $sel in
  449. 1) return;;
  450. 255) return;;
  451. esac
  452. shortcode=$(cat $data | sed -n 1p)
  453. image_url=$(cat $data | sed -n 2p)
  454. rm $data
  455. if [ ${#shortcode} -lt 2 ]; then
  456. return
  457. fi
  458. if [ ${#image_url} -lt 2 ]; then
  459. return
  460. fi
  461. if [[ "$image_url" != *'.'* ]]; then
  462. return
  463. fi
  464. if [[ "$image_url" != *'.png' && "$image_url" != *'.jpg' && "$image_url" != *'.jpeg' && "$image_url" != *'.gif' ]]; then
  465. dialog --title $"Add Custom Emoji" \
  466. --msgbox $"The image must be png/jpg/gif format" 6 60
  467. return
  468. fi
  469. if [[ "$shortcode" == *':'* || "$shortcode" == *' '* || "$shortcode" == *'.'* || "$shortcode" == *'!'* ]]; then
  470. dialog --title $"Add Custom Emoji" \
  471. --msgbox $"The shortcode contains invalid characters" 6 60
  472. return
  473. fi
  474. image_extension='png'
  475. if [[ "$image_url" == *'.jpg' || "$image_url" == *'.jpeg' ]]; then
  476. image_extension='jpg'
  477. fi
  478. if [[ "$image_url" == *'.gif' ]]; then
  479. image_extension='gif'
  480. fi
  481. if [ ! -d $PLEROMA_DIR/priv/static/emoji ]; then
  482. mkdir -p $PLEROMA_DIR/priv/static/emoji
  483. fi
  484. image_filename=$PLEROMA_DIR/priv/static/emoji/${shortcode}.${image_extension}
  485. wget "$image_url" -O $image_filename
  486. if [ ! -f $image_filename ]; then
  487. dialog --title $"Add Custom Emoji" \
  488. --msgbox $"Unable to download the image" 6 60
  489. return
  490. fi
  491. if [[ "$image_url" == *'.jpg' || "$image_url" == *'.jpeg' || "$image_url" == *'.gif' ]]; then
  492. convert $image_filename -resize $emoji_resolution $PLEROMA_DIR/priv/static/emoji/${shortcode}.png
  493. if [ ! -f $PLEROMA_DIR/priv/static/emoji/${shortcode}.png ]; then
  494. dialog --title $"Add Custom Emoji" \
  495. --msgbox $"Unable to convert empji image to png format" 6 60
  496. return
  497. fi
  498. # remove the original
  499. rm $image_filename
  500. image_extension='png'
  501. image_filename=$PLEROMA_DIR/priv/static/emoji/${shortcode}.${image_extension}
  502. else
  503. convert $image_filename -resize $emoji_resolution $image_filename
  504. fi
  505. if ! grep -q "${shortcode}," $PLEROMA_DIR/config/emoji.txt; then
  506. echo "${shortcode}, /emoji/${shortcode}.${image_extension}" >> $PLEROMA_DIR/config/emoji.txt
  507. else
  508. sed -i "s|${shortcode},.*|${shortcode}, /emoji/${shortcode}.${image_extension}|g" $PLEROMA_DIR/config/emoji.txt
  509. fi
  510. chown -R pleroma:pleroma $PLEROMA_DIR
  511. clear
  512. echo ''
  513. echo $'Recompiling Pleroma with the new emoji'
  514. systemctl stop pleroma
  515. pleroma_recompile
  516. dialog --title $"Add Custom Emoji" \
  517. --msgbox $"Custom emoji :${shortcode}: has been added" 6 70
  518. }
  519. function configure_interactive_pleroma {
  520. read_config_param PLEROMA_DOMAIN_NAME
  521. read_config_param PLEROMA_EXPIRE_MONTHS
  522. while true
  523. do
  524. data=$(tempfile 2>/dev/null)
  525. trap "rm -f $data" 0 1 2 5 15
  526. dialog --backtitle $"Freedombone Control Panel" \
  527. --title $"Pleroma" \
  528. --radiolist $"Choose an operation:" 15 70 6 \
  529. 1 $"Set a background image" off \
  530. 2 $"Set the title" off \
  531. 3 $"Disable new account registrations" off \
  532. 4 $"Add a custom emoji" off \
  533. 5 $"Set post expiry period (currently $PLEROMA_EXPIRE_MONTHS months)" off \
  534. 6 $"Exit" on 2> $data
  535. sel=$?
  536. case $sel in
  537. 1) return;;
  538. 255) return;;
  539. esac
  540. case $(cat $data) in
  541. 1) pleroma_set_background_image;;
  542. 2) pleroma_set_title;;
  543. 3) pleroma_disable_registrations;;
  544. 4) pleroma_add_emoji;;
  545. 5) pleroma_set_expire_months;;
  546. 6) break;;
  547. esac
  548. rm $data
  549. done
  550. }
  551. function upgrade_pleroma {
  552. read_config_param PLEROMA_DOMAIN_NAME
  553. read_config_param PLEROMA_EXPIRE_MONTHS
  554. if [ ! -f $pleroma_expire_posts_script ]; then
  555. expire_pleroma_posts $PLEROMA_DOMAIN_NAME $PLEROMA_EXPIRE_MONTHS
  556. fi
  557. if [ ! -f $blocking_script_file ]; then
  558. create_pleroma_blocklist
  559. fi
  560. CURR_PLEROMA_COMMIT=$(get_completion_param "pleroma commit")
  561. if [[ "$CURR_PLEROMA_COMMIT" == "$PLEROMA_COMMIT" ]]; then
  562. return
  563. fi
  564. function_check set_repo_commit
  565. set_repo_commit $PLEROMA_DIR "pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
  566. chown -R pleroma:pleroma $PLEROMA_DIR
  567. sudo -u pleroma mix deps.get
  568. pleroma_recompile
  569. expire_pleroma_posts $PLEROMA_DOMAIN_NAME $PLEROMA_EXPIRE_MONTHS
  570. create_pleroma_blocklist
  571. }
  572. function backup_local_pleroma {
  573. PLEROMA_DOMAIN_NAME='pleroma'
  574. if grep -q "pleroma domain" $COMPLETION_FILE; then
  575. PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
  576. fi
  577. function_check suspend_site
  578. suspend_site ${PLEROMA_DOMAIN_NAME}
  579. source_directory=$PLEROMA_DIR
  580. dest_directory=pleroma
  581. backup_directory_to_usb $source_directory $dest_directory
  582. USE_POSTGRESQL=1
  583. function_check backup_database_to_usb
  584. backup_database_to_usb pleroma
  585. function_check restart_site
  586. restart_site
  587. }
  588. function restore_local_pleroma {
  589. if ! grep -q "pleroma domain" $COMPLETION_FILE; then
  590. return
  591. fi
  592. PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
  593. if [ $PLEROMA_DOMAIN_NAME ]; then
  594. echo $"Restoring pleroma"
  595. temp_restore_dir=/root/temppleroma
  596. pleroma_dir=$PLEROMA_DIR
  597. PLEROMA_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_pleroma/hostname)
  598. function_check pleroma_create_database
  599. pleroma_create_database
  600. USE_POSTGRESQL=1
  601. restore_database pleroma
  602. if [ -d $temp_restore_dir ]; then
  603. rm -rf $temp_restore_dir
  604. fi
  605. function_check restore_directory_from_usb
  606. restore_directory_from_usb $temp_restore_dir pleroma
  607. if [ -d $temp_restore_dir ]; then
  608. chown -R pleroma:pleroma $pleroma_dir
  609. rm -rf $temp_restore_dir
  610. fi
  611. echo $"Restore of pleroma complete"
  612. fi
  613. }
  614. function backup_remote_pleroma {
  615. PLEROMA_DOMAIN_NAME='pleroma'
  616. if grep -q "pleroma domain" $COMPLETION_FILE; then
  617. PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
  618. fi
  619. function_check suspend_site
  620. suspend_site ${PLEROMA_DOMAIN_NAME}
  621. source_directory=$PLEROMA_DIR
  622. dest_directory=pleroma
  623. backup_directory_to_friend $source_directory $dest_directory
  624. USE_POSTGRESQL=1
  625. function_check backup_database_to_friend
  626. backup_database_to_friend pleroma
  627. function_check restart_site
  628. restart_site
  629. }
  630. function restore_remote_pleroma {
  631. if ! grep -q "pleroma domain" $COMPLETION_FILE; then
  632. return
  633. fi
  634. PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
  635. if [ $PLEROMA_DOMAIN_NAME ]; then
  636. echo $"Restoring pleroma"
  637. temp_restore_dir=/root/temppleroma
  638. pleroma_dir=$PLEROMA_DIR
  639. PLEROMA_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_pleroma/hostname)
  640. function_check pleroma_create_database
  641. pleroma_create_database
  642. USE_POSTGRESQL=1
  643. function_check restore_database_from_friend
  644. restore_database_from_friend pleroma
  645. if [ -d $temp_restore_dir ]; then
  646. rm -rf $temp_restore_dir
  647. fi
  648. function_check restore_directory_from_friend
  649. restore_directory_from_friend $temp_restore_dir pleroma
  650. if [ -d $temp_restore_dir ]; then
  651. chown -R pleroma:pleroma $pleroma_dir
  652. rm -rf $temp_restore_dir
  653. fi
  654. pleroma_update_after_restore pleroma ${PLEROMA_DOMAIN_NAME}
  655. echo $"Restore of pleroma complete"
  656. fi
  657. }
  658. function remove_pleroma {
  659. if [ ${#PLEROMA_DOMAIN_NAME} -eq 0 ]; then
  660. return
  661. fi
  662. systemctl stop pleroma
  663. systemctl disable pleroma
  664. rm /etc/systemd/system/pleroma.service
  665. userdel pleroma
  666. #apt-get -yq remove esl-erlang elixir erlang-xmerl erlang-dev erlang-parsetools
  667. function_check remove_nodejs
  668. remove_nodejs pleroma-backend
  669. read_config_param "PLEROMA_DOMAIN_NAME"
  670. read_config_param "MY_USERNAME"
  671. echo "Removing $PLEROMA_DOMAIN_NAME"
  672. nginx_dissite $PLEROMA_DOMAIN_NAME
  673. remove_certs $PLEROMA_DOMAIN_NAME
  674. if [ -d /var/www/$PLEROMA_DOMAIN_NAME ]; then
  675. rm -rf /var/www/$PLEROMA_DOMAIN_NAME
  676. fi
  677. if [ -f /etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME ]; then
  678. rm /etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME
  679. fi
  680. if [ -d $PLEROMA_DIR ]; then
  681. rm -rf $PLEROMA_DIR
  682. fi
  683. function_check drop_database_postgresql
  684. drop_database_postgresql pleroma
  685. function_check remove_onion_service
  686. remove_onion_service pleroma ${PLEROMA_ONION_PORT}
  687. remove_app pleroma
  688. remove_completion_param install_pleroma
  689. sed -i '/pleroma domain/d' $COMPLETION_FILE
  690. sed -i '/pleroma commit/d' $COMPLETION_FILE
  691. sed -i "/$blocking_script_file/d" /etc/crontab
  692. function_check remove_ddns_domain
  693. remove_ddns_domain $PLEROMA_DOMAIN_NAME
  694. }
  695. function install_elixir {
  696. apt-get -yq install wget build-essential
  697. if [ ! -d $INSTALL_DIR ]; then
  698. mkdir -p $INSTALL_DIR
  699. fi
  700. cd $INSTALL_DIR
  701. erlang_package=erlang-solutions_1.0_all.deb
  702. wget https://packages.erlang-solutions.com/$erlang_package
  703. if [ ! -f $INSTALL_DIR/$erlang_package ]; then
  704. exit 72853
  705. fi
  706. dpkg -i $erlang_package
  707. apt-get -yq update
  708. apt-get -yq install esl-erlang
  709. apt-get -yq install elixir erlang-xmerl erlang-dev erlang-parsetools
  710. if [ ! -f /usr/local/bin/mix ]; then
  711. echo $'/usr/local/bin/mix not found after elixir installation'
  712. exit 629352
  713. fi
  714. }
  715. function install_pleroma {
  716. if [ ! $ONION_ONLY ]; then
  717. ONION_ONLY='no'
  718. fi
  719. apt-get -yq install wget imagemagick
  720. # We need elixir 1.4+ here, so the debian repo package won't do
  721. install_elixir
  722. function_check install_nodejs
  723. install_nodejs pleroma-backend
  724. install_postgresql
  725. if [ ! -d /var/www/${PLEROMA_DOMAIN_NAME}/htdocs ]; then
  726. mkdir -p /var/www/${PLEROMA_DOMAIN_NAME}/htdocs
  727. fi
  728. if [ -d $PLEROMA_DIR ]; then
  729. rm -rf $PLEROMA_DIR
  730. fi
  731. # get the repo
  732. if [ -f /repos/pleroma/index.html ]; then
  733. mv /repos/pleroma /repos/pleroma-fe
  734. fi
  735. if [ -d /repos/pleroma ]; then
  736. mkdir -p $PLEROMA_DIR
  737. cp -r -p /repos/pleroma/. $PLEROMA_DIR
  738. cd $PLEROMA_DIR
  739. git pull
  740. else
  741. function_check git_clone
  742. git_clone $PLEROMA_REPO $PLEROMA_DIR
  743. fi
  744. if [ ! -d $PLEROMA_DIR ]; then
  745. echo $'Unable to clone pleroma backend repo'
  746. exit 783523
  747. fi
  748. # create user
  749. useradd -d $PLEROMA_DIR -s /bin/false pleroma
  750. # checkout the commit
  751. cd $PLEROMA_DIR
  752. git checkout $PLEROMA_COMMIT -b $PLEROMA_COMMIT
  753. set_completion_param "pleroma commit" "$PLEROMA_COMMIT"
  754. chown -R pleroma:pleroma $PLEROMA_DIR
  755. # web config
  756. function_check add_ddns_domain
  757. add_ddns_domain $PLEROMA_DOMAIN_NAME
  758. PLEROMA_ONION_HOSTNAME=$(add_onion_service pleroma 80 ${PLEROMA_ONION_PORT})
  759. pleroma_nginx_site=/etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME
  760. if [[ $ONION_ONLY == "no" ]]; then
  761. function_check nginx_http_redirect
  762. nginx_http_redirect $PLEROMA_DOMAIN_NAME "index index.html"
  763. echo 'server {' >> $pleroma_nginx_site
  764. echo ' listen 443 ssl;' >> $pleroma_nginx_site
  765. echo ' listen [::]:443 ssl;' >> $pleroma_nginx_site
  766. echo " server_name $PLEROMA_DOMAIN_NAME;" >> $pleroma_nginx_site
  767. echo '' >> $pleroma_nginx_site
  768. function_check nginx_compress
  769. nginx_compress $PLEROMA_DOMAIN_NAME
  770. echo '' >> $pleroma_nginx_site
  771. echo ' # Security' >> $pleroma_nginx_site
  772. function_check nginx_ssl
  773. nginx_ssl $PLEROMA_DOMAIN_NAME
  774. function_check nginx_disable_sniffing
  775. nginx_disable_sniffing $PLEROMA_DOMAIN_NAME
  776. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $pleroma_nginx_site
  777. echo '' >> $pleroma_nginx_site
  778. echo ' # Logs' >> $pleroma_nginx_site
  779. echo ' access_log /dev/null;' >> $pleroma_nginx_site
  780. echo ' error_log /dev/null;' >> $pleroma_nginx_site
  781. echo '' >> $pleroma_nginx_site
  782. echo " root $PLEROMA_DIR;" >> $pleroma_nginx_site
  783. echo '' >> $pleroma_nginx_site
  784. echo ' index index.html;' >> $pleroma_nginx_site
  785. echo ' location / {' >> $pleroma_nginx_site
  786. function_check nginx_limits
  787. nginx_limits $PLEROMA_DOMAIN_NAME '15m'
  788. echo " proxy_pass http://localhost:$PLEROMA_PORT;" >> $pleroma_nginx_site
  789. echo ' }' >> $pleroma_nginx_site
  790. echo ' # include snippets/well-known.conf;' >> $pleroma_nginx_site
  791. echo '}' >> $pleroma_nginx_site
  792. else
  793. echo -n '' > $pleroma_nginx_site
  794. fi
  795. echo 'server {' >> $pleroma_nginx_site
  796. echo " listen 127.0.0.1:$PLEROMA_ONION_PORT default_server;" >> $pleroma_nginx_site
  797. echo " server_name $PLEROMA_ONION_HOSTNAME;" >> $pleroma_nginx_site
  798. echo '' >> $pleroma_nginx_site
  799. function_check nginx_compress
  800. nginx_compress $PLEROMA_DOMAIN_NAME
  801. echo '' >> $pleroma_nginx_site
  802. function_check nginx_disable_sniffing
  803. nginx_disable_sniffing $PLEROMA_DOMAIN_NAME
  804. echo '' >> $pleroma_nginx_site
  805. echo ' # Logs' >> $pleroma_nginx_site
  806. echo ' access_log /dev/null;' >> $pleroma_nginx_site
  807. echo ' error_log /dev/null;' >> $pleroma_nginx_site
  808. echo '' >> $pleroma_nginx_site
  809. echo " root $PLEROMA_DIR;" >> $pleroma_nginx_site
  810. echo '' >> $pleroma_nginx_site
  811. echo ' index index.html;' >> $pleroma_nginx_site
  812. echo ' location / {' >> $pleroma_nginx_site
  813. function_check nginx_limits
  814. nginx_limits $PLEROMA_DOMAIN_NAME '15m'
  815. echo " proxy_pass http://localhost:$PLEROMA_PORT;" >> $pleroma_nginx_site
  816. echo ' }' >> $pleroma_nginx_site
  817. echo ' # include snippets/well-known.conf;' >> $pleroma_nginx_site
  818. echo '}' >> $pleroma_nginx_site
  819. # back end
  820. cd $PLEROMA_DIR
  821. chown -R pleroma:pleroma *
  822. sudo -u pleroma mix local.hex --force
  823. if [ ! "$?" = "0" ]; then
  824. echo $'mix local.hex failed'
  825. exit 1745673
  826. fi
  827. sudo -u pleroma mix deps.get --force
  828. if [ ! "$?" = "0" ]; then
  829. echo $'mix deps.get failed'
  830. exit 7325733
  831. fi
  832. function_check pleroma_create_database
  833. pleroma_create_database
  834. ${PROJECT_NAME}-pass -u $MY_USERNAME -a pleroma -p "$PLEROMA_ADMIN_PASSWORD"
  835. # NOTE: we don't need to install the frontend separately,
  836. # since the backend contains a precompiled version of it
  837. install_gnusocial_default_background "pleroma" "$PLEROMA_DOMAIN_NAME"
  838. if [ ! -f $PLEROMA_DIR/priv/static/static/config.json ]; then
  839. echo $"$PLEROMA_DIR/priv/static/static/config.json file missing"
  840. exit 323689
  841. fi
  842. sed -i 's|"theme":.*|"theme": "base16-summerfruit-dark.css",|g' $PLEROMA_DIR/priv/static/static/config.json
  843. if [ $PLEROMA_BACKGROUND_IMAGE_URL ]; then
  844. pleroma_set_background_image_from_url $PLEROMA_DIR/priv/static "$PLEROMA_DOMAIN_NAME" "$PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_TITLE"
  845. fi
  846. # Get certificate
  847. function_check create_site_certificate
  848. create_site_certificate $PLEROMA_DOMAIN_NAME 'yes'
  849. function_check nginx_ensite
  850. nginx_ensite $PLEROMA_DOMAIN_NAME
  851. systemctl restart postgresql
  852. systemctl restart nginx
  853. set_completion_param "pleroma domain" "$PLEROMA_DOMAIN_NAME"
  854. # We need to set up the url option again because it somehow gets
  855. # lost during mix compile
  856. pleroma_secret=$PLEROMA_DIR/config/dev.secret.exs
  857. if ! grep -q 'watchers: [],' $pleroma_secret; then
  858. sed -i 's|watchers: \[\]|watchers: \[\],|g' $pleroma_secret
  859. fi
  860. if ! grep -q 'url:' $pleroma_secret; then
  861. if [[ $ONION_ONLY == 'no' ]]; then
  862. sed -i "/watchers: /a url: [host: \"$PLEROMA_DOMAIN_NAME\", scheme: \"https\", port: 443]" $pleroma_secret
  863. else
  864. sed -i "/watchers: /a url: [host: \"$PLEROMA_ONION_HOSTNAME\", scheme: \"http\", port: 80]" $pleroma_secret
  865. fi
  866. fi
  867. create_pleroma_blocklist
  868. # daemon
  869. echo '[Unit]' > /etc/systemd/system/pleroma.service
  870. echo 'Description=Pleroma social network' >> /etc/systemd/system/pleroma.service
  871. echo 'After=network.target postgresql.service' >> /etc/systemd/system/pleroma.service
  872. echo '' >> /etc/systemd/system/pleroma.service
  873. echo '[Service]' >> /etc/systemd/system/pleroma.service
  874. echo 'User=pleroma' >> /etc/systemd/system/pleroma.service
  875. echo "WorkingDirectory=$PLEROMA_DIR" >> /etc/systemd/system/pleroma.service
  876. echo "Environment=\"HOME=$PLEROMA_DIR\"" >> /etc/systemd/system/pleroma.service
  877. echo 'ExecStart=/usr/local/bin/mix phx.server' >> /etc/systemd/system/pleroma.service
  878. echo 'ExecReload=/bin/kill $MAINPID' >> /etc/systemd/system/pleroma.service
  879. echo 'KillMode=process' >> /etc/systemd/system/pleroma.service
  880. echo 'Restart=on-failure' >> /etc/systemd/system/pleroma.service
  881. echo '' >> /etc/systemd/system/pleroma.service
  882. echo '[Install]' >> /etc/systemd/system/pleroma.service
  883. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/pleroma.service
  884. echo 'Alias=pleroma.service' >> /etc/systemd/system/pleroma.service
  885. systemctl daemon-reload
  886. systemctl enable pleroma
  887. systemctl start pleroma
  888. APP_INSTALLED=1
  889. }
  890. # NOTE: deliberately there is no "exit 0"