freedombone-app-pleroma 37KB

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