freedombone-app-pleroma 32KB

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