freedombone-app-pleroma 32KB

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