freedombone-app-pleroma 33KB

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