| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197 | 
							- #!/bin/bash
 - #
 - # .---.                  .              .
 - # |                      |              |
 - # |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
 - # |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
 - # '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
 - #
 - #                    Freedom in the Cloud
 - #
 - # Pleroma backend application
 - # https://git.pleroma.social/pleroma/pleroma/wikis/Installing-on-Debian-Based-Distributions
 - #
 - # Show stopper: This is dependent on https://placehold.it for avatar images,
 - # so at present it's not usable until a first party placeholder image system
 - # is included.
 - #
 - # There is also a possible issue with the chat system which uses an object called
 - # "Agent" which may not be supported with the version of elixir within the
 - # Debian package. This only applies if you're installing from the latest commit.
 - #
 - # License
 - # =======
 - #
 - # Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
 - #
 - # This program is free software: you can redistribute it and/or modify
 - # it under the terms of the GNU Affero General Public License as published by
 - # the Free Software Foundation, either version 3 of the License, or
 - # (at your option) any later version.
 - #
 - # This program is distributed in the hope that it will be useful,
 - # but WITHOUT ANY WARRANTY; without even the implied warranty of
 - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - # GNU Affero General Public License for more details.
 - #
 - # You should have received a copy of the GNU Affero General Public License
 - # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 - 
 - VARIANTS='full full-vim social'
 - 
 - IN_DEFAULT_INSTALL=0
 - SHOW_ON_ABOUT=1
 - 
 - PLEROMA_DOMAIN_NAME=
 - PLEROMA_CODE=
 - PLEROMA_PORT=4000
 - PLEROMA_ONION_PORT=8011
 - PLEROMA_REPO="https://git.pleroma.social/pleroma/pleroma.git"
 - PLEROMA_COMMIT='000b3f1837d81f46e183f21150972c8c0b0a9115'
 - PLEROMA_ADMIN_PASSWORD=
 - PLEROMA_DIR=/etc/pleroma
 - PLEROMA_SECRET_KEY=""
 - 
 - PLEROMA_BACKGROUND_IMAGE_URL=
 - 
 - PLEROMA_TITLE='Pleroma Server'
 - 
 - # Number of months after which posts expire
 - PLEROMA_EXPIRE_MONTHS=3
 - pleroma_expire_posts_script=/usr/bin/pleroma-expire-posts
 - blocking_script_file=/usr/bin/pleroma-blocking
 - 
 - pleroma_variables=(ONION_ONLY
 -                    PLEROMA_DOMAIN_NAME
 -                    PLEROMA_CODE
 -                    PLEROMA_WELCOME_MESSAGE
 -                    PLEROMA_BACKGROUND_IMAGE_URL
 -                    DDNS_PROVIDER
 -                    PLEROMA_TITLE
 -                    PLEROMA_EXPIRE_MONTHS
 -                    MY_EMAIL_ADDRESS
 -                    MY_USERNAME)
 - 
 - function create_pleroma_blocklist {
 -     { echo '#!/bin/bash';
 -       echo "if [ ! -f /root/${PROJECT_NAME}-firewall-domains.cfg ]; then";
 -       echo '    exit 0';
 -       echo 'fi';
 -       echo 'if [ -f /tmp/pleroma-blocking.lock ]; then';
 -       echo '    cd /tmp';
 -       echo '    find ./pleroma*.lock -type f -mmin +5 -exec rm {} \;';
 -       echo '    if [ -f /tmp/pleroma-blocking.lock ]; then';
 -       echo '        exit 0';
 -       echo '    fi';
 -       echo 'fi';
 -       echo 'touch /tmp/pleroma-blocking.lock';
 -       echo 'objects_query="DELETE FROM objects WHERE"';
 -       echo 'objects_updated=';
 -       echo 'users_query="DELETE FROM users WHERE"';
 -       echo 'websub_server_subscriptions_query="DELETE FROM websub_server_subscriptions WHERE"';
 -       echo 'websub_server_subscriptions_updated=';
 -       echo 'while read blocked; do';
 -       echo "    if [[ \"\$blocked\" == *\".\"* || \"\$blocked\" == *\"@\"* ]]; then";
 -       echo "        if [ \${#blocked} -gt 4 ]; then";
 -       echo "            if [ \$objects_updated ]; then";
 -       echo "                objects_query=\"\${objects_query} or\"";
 -       echo "                users_query=\"\${users_query} or\"";
 -       echo '            fi';
 -       echo "            objects_query=\"\${objects_query} data->>'content' ilike '%\${blocked}%' or data->>'actor' ilike '%\${blocked}%' or data->>'to' ilike '%\${blocked}%' or data->>'id' ilike '%\${blocked}%' or data->>'external_url' ilike '%\${blocked}%'\"";
 -       echo "            users_query=\"\${users_query} nickname ilike '%\${blocked}%'\"";
 -       echo '            objects_updated=1';
 -       echo "            if [[ \"\$blocked\" != *\"@\"* ]]; then";
 -       echo "                if ! grep -q \"127.0.0.1  \$blocked\" /etc/hosts; then";
 -       echo "                    echo \"127.0.0.1  \$blocked\" >> /etc/hosts";
 -       echo '                fi';
 -       echo "                if [ \$websub_server_subscriptions_updated ]; then";
 -       echo "                    websub_server_subscriptions_query=\"\${websub_server_subscriptions_query} or\"";
 -       echo '                fi';
 -       echo "                websub_server_subscriptions_query=\"\${websub_server_subscriptions_query} callback like '%\${blocked}%'\"";
 -       echo '                websub_server_subscriptions_updated=1';
 -       echo '            fi';
 -       echo '        fi';
 -       echo '    fi';
 -       echo 'done </root/freedombone-firewall-domains.cfg';
 -       echo '';
 -       echo 'cd /etc/postgresql';
 -       echo "if [ \$objects_updated ]; then";
 -       echo "    sudo -u postgres psql -d pleroma -c \"\$objects_query\"";
 -       echo "    sudo -u postgres psql -d pleroma -c \"\$users_query\"";
 -       echo 'fi';
 -       echo "if [ \$websub_server_subscriptions_updated ]; then";
 -       echo "    sudo -u postgres psql -d pleroma -c \"\$websub_server_subscriptions_query\"";
 -       echo 'fi';
 -       echo 'rm /tmp/pleroma-blocking.lock'; } > $blocking_script_file
 - 
 -     chmod +x $blocking_script_file
 - 
 -     if ! grep -q "$blocking_script_file" /etc/crontab; then
 -         cron_add_mins 1 "$blocking_script_file 2> /dev/null"
 -     fi
 - }
 - 
 - function expire_pleroma_posts {
 -     domain_name=$1
 -     expire_months=$3
 - 
 -     if [ ! "$expire_months" ]; then
 -         expire_months=3
 -     fi
 - 
 -     #expire_days=$((expire_months * 30))
 - 
 -     # files are what take up most of the backup time, so don't keep them for very long
 -     expire_days_files=7
 - 
 -     # To prevent the database size from growing endlessly this script expires posts
 -     # after a number of months
 -     if [ ! -d /etc/pleroma ]; then
 -         return
 -     fi
 - 
 -     { echo '#!/bin/bash';
 -       echo "plmonths=\"$PLEROMA_EXPIRE_MONTHS\"";
 -       echo "if [ \${#plmonths} -eq 0 ]; then";
 -       echo '    exit 1';
 -       echo 'fi';
 -       echo "if [[ \"\$plmonths\" == \"0\" ]]; then";
 -       echo '    exit 2';
 -       echo 'fi';
 -       echo "oldate=\$(date +%Y-%m-%d --date=\"\$plmonths months ago\")";
 -       echo 'cd /etc/postgresql';
 -       echo "sudo -u postgres psql -d pleroma -c \"DELETE FROM notifications WHERE inserted_at <= '\$oldate 01:01:01'\"";
 -       echo "sudo -u postgres psql -d pleroma -c \"DELETE FROM objects WHERE inserted_at <= '\$oldate 01:01:01'\""; } > $pleroma_expire_posts_script
 -     chmod +x $pleroma_expire_posts_script
 - 
 -     pleroma_expire_script=/etc/cron.daily/pleroma-expire
 -     expire_days_files_threshold=$((expire_days_files - 1))
 -     { echo '#!/bin/bash';
 -       echo 'cd /etc/postgresql';
 -       echo 'if [ -d /etc/pleroma/tempfiles ]; then';
 -       echo '    rm -rf /etc/pleroma/tempfiles';
 -       echo 'fi';
 -       echo '';
 -       echo '# make directory to temporarily store local avatars';
 -       echo 'mkdir /etc/pleroma/tempfiles';
 -       echo '';
 -       echo '# get the local avatar files';
 -       echo "avatars=\$(sudo -u postgres psql -d pleroma -c \"select avatar->>'url' from users where avatar->>'url' like '%${domain_name}%'\")";
 -       echo '';
 -       echo '# copy the avatar files to a temporary directory';
 -       echo "arr=( \$avatars )";
 -       echo "for i in \${arr[@]}; do";
 -       echo "    if [[ \"\$i\" == *'/media/'* ]]; then";
 -       echo "        imagefile=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}');";
 -       echo "        if [ -f \$imagefile ]; then";
 -       echo "            imagedir=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}' | awk -F '/' '{print \$1}')";
 -       echo "            nowdate=\$(date +%s)";
 -       echo "            sinceepoch=\$(date +%s -r \$imagefile)";
 -       echo "            daysold=\$(((\$nowdate - \$sinceepoch) / 86400))";
 -       echo "            if [ \$daysold -ge ${expire_days_files_threshold} ]; then";
 -       echo "                if [ ! -d \$imagedir ]; then";
 -       echo "                    mkdir \$imagedir";
 -       echo '                fi';
 -       echo "                cp -rp \$imagefile \$imagedir";
 -       echo '            fi';
 -       echo '        fi';
 -       echo '    fi';
 -       echo 'done';
 -       echo '';
 -       echo '# get the local banner files';
 -       echo "banners=\$(sudo -u postgres psql -d pleroma -c \"select avatar->>'banner' from users where avatar->>'url' like '%${domain_name}%'\")";
 -       echo '';
 -       echo '# copy the banner files to a temporary directory';
 -       echo "arr=( \$banners )";
 -       echo "for i in \${arr[@]}; do";
 -       echo "    if [[ \"\$i\" == *'/media/'* ]]; then";
 -       echo "        imagefile=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}');";
 -       echo "        if [ -f \$imagefile ]; then";
 -       echo "            imagedir=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}' | awk -F '/' '{print \$1}')";
 -       echo "            nowdate=\$(date +%s)";
 -       echo "            sinceepoch=\$(date +%s -r \$imagefile)";
 -       echo "            daysold=\$(((\$nowdate - \$sinceepoch) / 86400))";
 -       echo "            if [ \$daysold -ge ${expire_days_files_threshold} ]; then";
 -       echo "                if [ ! -d \$imagedir ]; then";
 -       echo "                    mkdir \$imagedir";
 -       echo '                fi';
 -       echo "                cp -rp \$imagefile \$imagedir";
 -       echo '            fi';
 -       echo '        fi';
 -       echo '    fi';
 -       echo 'done';
 -       echo '';
 -       echo '# delete old files';
 -       echo "find /etc/pleroma/uploads/* -mtime +${expire_days_files} -exec rm -rf {} +";
 -       echo '';
 -       echo '# move avatar files back to uploads';
 -       echo 'chown -R pleroma:pleroma /etc/pleroma/tempfiles';
 -       echo 'mv /etc/pleroma/tempfiles/* /etc/pleroma/uploads';
 -       echo 'rm -rf /etc/pleroma/tempfiles';
 -       echo '';
 -       echo '/usr/bin/pleroma-expire-posts 2> /dev/null'; } > $pleroma_expire_script
 -     chmod +x $pleroma_expire_script
 - 
 -     # remove any old cron job
 -     if grep -q "pleroma-expire" /etc/crontab; then
 -         sed -i "/pleroma-expire/d" /etc/crontab
 -         rm /usr/bin/pleroma-expire
 -     fi
 - 
 -     # remove old expire script
 -     if [ -f /etc/cron.weekly/clear-pleroma-database ]; then
 -         rm /etc/cron.weekly/clear-pleroma-database
 -     fi
 - }
 - 
 - function pleroma_recompile {
 -     # necessary after parameter changes
 -     chown -R pleroma:pleroma $PLEROMA_DIR
 -     sudo -u pleroma mix clean
 -     sudo -u pleroma mix deps.compile
 -     sudo -u pleroma mix compile
 - 
 -     if [ -f /etc/systemd/system/pleroma.service ]; then
 -         systemctl restart pleroma
 -     fi
 - 
 - }
 - 
 - function logging_on_pleroma {
 -     echo -n ''
 - }
 - 
 - function logging_off_pleroma {
 -     echo -n ''
 - }
 - 
 - function remove_user_pleroma {
 -     remove_username="$1"
 - 
 -     "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp pleroma
 - }
 - 
 - function add_user_pleroma {
 -     new_username="$1"
 -     new_user_password="$2"
 - 
 -     "${PROJECT_NAME}-pass" -u "$new_username" -a pleroma -p "$new_user_password"
 - 
 -     echo '0'
 - }
 - 
 - function install_interactive_pleroma {
 -     if [ ! "$ONION_ONLY" ]; then
 -         ONION_ONLY='no'
 -     fi
 - 
 -     if [[ $ONION_ONLY != "no" ]]; then
 -         PLEROMA_DOMAIN_NAME='pleroma.local'
 -     else
 -         PLEROMA_DETAILS_COMPLETE=
 -         while [ ! $PLEROMA_DETAILS_COMPLETE ]
 -         do
 -             data=$(mktemp 2>/dev/null)
 -             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
 -                 dialog --backtitle $"Freedombone Configuration" \
 -                        --title $"Pleroma Configuration" \
 -                        --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 \
 -                        $"Domain:" 1 1 "$(grep 'PLEROMA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
 -                        $"Title:" 2 1 "$(grep "$PLEROMA_TITLE" temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
 -                        $"Background image URL:" 3 1 "$(grep "$PLEROMA_BACKGROUND_IMAGE_URL" temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
 -                        $"Code:" 4 1 "$(grep 'PLEROMA_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
 -                        2> "$data"
 -             else
 -                 dialog --backtitle $"Freedombone Configuration" \
 -                        --title $"Pleroma Configuration" \
 -                        --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 \
 -                        $"Domain:" 1 1 "$(grep 'PLEROMA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
 -                        $"Title:" 2 1 "$(grep "$PLEROMA_TITLE" temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
 -                        $"Background image URL:" 3 1 "$(grep "$PLEROMA_BACKGROUND_IMAGE_URL" temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
 -                        2> "$data"
 -             fi
 -             sel=$?
 -             case $sel in
 -                 1) rm -f "$data"
 -                    exit 1;;
 -                 255) rm -f "$data"
 -                      exit 1;;
 -             esac
 -             PLEROMA_DOMAIN_NAME=$(sed -n 1p < "$data")
 -             title=$(sed -n 2p < "$data")
 -             if [ ${#title} -gt 1 ]; then
 -                 PLEROMA_TITLE="$title"
 -             fi
 -             img_url=$(sed -n 3p < "$data")
 -             if [ ${#img_url} -gt 1 ]; then
 -                 PLEROMA_BACKGROUND_IMAGE_URL=$img_url
 -             fi
 -             if [ "$PLEROMA_DOMAIN_NAME" ]; then
 -                 if [[ $PLEROMA_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
 -                     PLEROMA_DOMAIN_NAME=""
 -                 fi
 -                 TEST_DOMAIN_NAME=$PLEROMA_DOMAIN_NAME
 -                 validate_domain_name
 -                 if [[ "$TEST_DOMAIN_NAME" != "$PLEROMA_DOMAIN_NAME" ]]; then
 -                     PLEROMA_DOMAIN_NAME=
 -                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
 -                 else
 -                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
 -                         PLEROMA_CODE=$(sed -n 4p < "$data")
 -                         validate_freedns_code "$PLEROMA_CODE"
 -                         if [ ! "$VALID_CODE" ]; then
 -                             PLEROMA_DOMAIN_NAME=
 -                         fi
 -                     fi
 -                 fi
 -             fi
 -             if [ $PLEROMA_DOMAIN_NAME ]; then
 -                 PLEROMA_DETAILS_COMPLETE="yes"
 -             fi
 -             rm -f "$data"
 -         done
 - 
 -         # remove any invalid characters
 -         if [ ${#PLEROMA_TITLE} -gt 0 ]; then
 -             new_title=${PLEROMA_TITLE//\'/}
 -             PLEROMA_TITLE="$new_title"
 -         fi
 - 
 -         # save the results in the config file
 -         write_config_param "PLEROMA_CODE" "$PLEROMA_CODE"
 -         write_config_param "PLEROMA_TITLE" "$PLEROMA_TITLE"
 -         write_config_param "PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_BACKGROUND_IMAGE_URL"
 -     fi
 -     write_config_param "PLEROMA_DOMAIN_NAME" "$PLEROMA_DOMAIN_NAME"
 -     APP_INSTALLED=1
 - }
 - 
 - function change_password_pleroma {
 - #    curr_username="$1"
 -     new_user_password="$2"
 - 
 -     #${PROJECT_NAME}-pass -u "$curr_username" -a pleroma -p "$new_user_password"
 - }
 - 
 - function pleroma_create_database_failed {
 -     run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
 -     run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
 - }
 - 
 - function pleroma_create_database {
 -     if [ -f "$IMAGE_PASSWORD_FILE" ]; then
 -         PLEROMA_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
 -     else
 -         if [ ! "$PLEROMA_ADMIN_PASSWORD" ]; then
 -             PLEROMA_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
 -         fi
 -     fi
 -     if [ ! "$PLEROMA_ADMIN_PASSWORD" ]; then
 -         return
 -     fi
 - 
 -     systemctl restart postgresql
 -     add_postgresql_user pleroma "$PLEROMA_ADMIN_PASSWORD" encrypted
 -     run_system_query_postgresql "create database pleroma;"
 -     # temporarily allow the user to create databases
 -     run_system_query_postgresql "ALTER USER pleroma CREATEDB;"
 -     run_system_query_postgresql "ALTER USER pleroma SUPERUSER;"
 -     run_system_query_postgresql "GRANT ALL ON ALL tables IN SCHEMA public TO pleroma;"
 -     run_system_query_postgresql "GRANT ALL ON ALL sequences IN SCHEMA public TO pleroma;"
 -     run_system_query_postgresql "CREATE EXTENSION citext;"
 -     run_system_query_postgresql "set statement_timeout to 40000;"
 - 
 -     read_config_param "PLEROMA_SECRET_KEY"
 -     if [ ${#PLEROMA_SECRET_KEY} -lt 64 ]; then
 -         PLEROMA_SECRET_KEY="$(create_password 30)$(create_password 30)$(create_password 30)"
 -         if [ ${#PLEROMA_SECRET_KEY} -lt 64 ]; then
 -             pleroma_create_database_failed
 -             echo $'Pleroma secret key not created'
 -             exit 6782352
 -         fi
 -         write_config_param "PLEROMA_SECRET_KEY" "$PLEROMA_SECRET_KEY"
 -     fi
 - 
 -     if [ ! -d $PLEROMA_DIR/config ]; then
 -         echo $"Missing directory $PLEROMA_DIR/config"
 -         exit 7835393
 -     fi
 -     pleroma_secret=$PLEROMA_DIR/config/dev.secret.exs
 -     if [ ! -f $PLEROMA_DIR/config/dev.exs ]; then
 -         echo $"Did not find $PLEROMA_DIR/config/dev.exs"
 -         exit 78923528
 -     fi
 -     cp $PLEROMA_DIR/config/dev.exs $pleroma_secret
 -     sed -i "s|username:.*|username: \"pleroma\",|g" $pleroma_secret
 -     sed -i "s|password:.*|password: \"$PLEROMA_ADMIN_PASSWORD\",|g" $pleroma_secret
 -     sed -i "s|database:.*|database: \"pleroma\",|g" $pleroma_secret
 -     sed -i "/Pleroma.Web.Endpoint/a secret_key_base: \"$PLEROMA_SECRET_KEY\"," $pleroma_secret
 -     sed -i 's|secret_key_base: |  secret_key_base: |g' $pleroma_secret
 -     sed -i "/Pleroma.Web.Endpoint/a pubsub: [name: Pleroma.Web.PubSub, adapter: Phoenix.PubSub.PG2]," $pleroma_secret
 -     sed -i 's|pubsub: |  pubsub: |g' $pleroma_secret
 -     sed -i 's|watchers: []|watchers: [],|g' $pleroma_secret
 -     if [[ $ONION_ONLY == 'no' ]]; then
 -         sed -i "/watchers: []/a url: [host: \"$PLEROMA_DOMAIN_NAME\", scheme: \"https\", port: 443]" $pleroma_secret
 -     else
 -         sed -i "/watchers: []/a url: [host: \"$PLEROMA_ONION_HOSTNAME\", scheme: \"http\", port: 80]" $pleroma_secret
 -     fi
 -     sed -i 's|url: |  url: |g' $pleroma_secret
 -     if ! grep -q "pbkdf2_rounds" $pleroma_secret; then
 -         sed -i '/config :logger/a config :comeonin, :pbkdf2_rounds, 1' $pleroma_secret
 -     else
 -         sed -i 's|pbkdf2_rounds.*|pbkdf2_rounds, 1|g' $pleroma_secret
 -     fi
 -     sed -i 's|import_config|# import_config|g' $pleroma_secret
 - 
 -     cd "$PLEROMA_DIR" || exit 678245245724
 -     chown -R pleroma:pleroma $PLEROMA_DIR/*
 -     if ! sudo -u pleroma mix local.rebar --force; then
 -         pleroma_create_database_failed
 -         echo $'mix local.rebar failed'
 -         exit 73528562
 -     fi
 -     sudo -u pleroma mix local.hex --force
 -     sudo -u pleroma mix deps.compile mimerl
 -     systemctl restart postgresql
 -     if ! sudo -u pleroma mix ecto.create --force; then
 -         pleroma_create_database_failed
 -         echo $'mix ecto.create failed'
 -         exit 83653582
 -     fi
 -     if ! sudo -u pleroma mix ecto.migrate --force; then
 -         pleroma_create_database_failed
 -         echo $'mix ecto.migrate failed'
 -         exit 73752573
 -     fi
 - 
 -     # revoke the ability to create databases for this user
 -     run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
 -     run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
 - }
 - 
 - function reconfigure_pleroma {
 -     echo -n ''
 - }
 - 
 - function pleroma_set_background_image {
 -     PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
 - 
 -     data=$(mktemp 2>/dev/null)
 -     dialog --title $"Pleroma" \
 -            --backtitle $"Freedombone Control Panel" \
 -            --inputbox $'Set a background image URL' 10 60 2>"$data"
 -     sel=$?
 -     case $sel in
 -         0)
 -             temp_background=$(<"$data")
 -             if [ ${#temp_background} -gt 0 ]; then
 -                 PLEROMA_BACKGROUND_IMAGE_URL="$temp_background"
 -                 write_config_param "PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_BACKGROUND_IMAGE_URL"
 -                 if [[ $(pleroma_set_background_image_from_url $PLEROMA_DIR "$PLEROMA_DOMAIN_NAME" "$PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_TITLE" | tail -n 1) == "0" ]]; then
 -                     pleroma_recompile
 - 
 -                     dialog --title $"Set Pleroma login background" \
 -                            --msgbox $"The background image has been set" 6 60
 -                 fi
 -             fi
 -            ;;
 -     esac
 -     rm -f "$data"
 - }
 - 
 - function pleroma_set_title {
 -     data=$(mktemp 2>/dev/null)
 -     dialog --title $"Pleroma" \
 -            --backtitle $"Freedombone Control Panel" \
 -            --inputbox $'Set a title' 10 60 2>"$data"
 -     sel=$?
 -     case $sel in
 -         0)
 -             new_title=$(<"$data")
 -             if [ ${#new_title} -gt 0 ]; then
 -                 PLEROMA_TITLE="$new_title"
 -                 PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
 -                 write_config_param "PLEROMA_TITLE" "$PLEROMA_TITLE"
 -                 sed -i "s|\"name\":.*|\"name\": \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/static/config.json
 -                 sed -i "s|\"name\":.*|\"name\": \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/priv/static/static/config.json
 -                 sed -i "s|name: .*|name: \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/config/config.exs
 -                 systemctl restart pleroma
 -                 dialog --title $"Set Pleroma title" \
 -                        --msgbox $"The title has been set" 6 60
 -             fi
 -            ;;
 -     esac
 -     rm -f "$data"
 - }
 - 
 - function pleroma_set_expire_months {
 -     PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
 -     read_config_param "PLEROMA_DOMAIN_NAME"
 -     read_config_param "PLEROMA_EXPIRE_MONTHS"
 - 
 -     data=$(mktemp 2>/dev/null)
 -     dialog --title $"Pleroma" \
 -            --backtitle $"Freedombone Control Panel" \
 -            --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"
 -     sel=$?
 -     case $sel in
 -         0)
 -             new_expiry_months=$(<"$data")
 -             if [ ${#new_expiry_months} -gt 0 ]; then
 -                 # should contain no spaces
 -                 if [[ "$new_expiry_months" == *" "* ]]; then
 -                     rm -f "$data"
 -                     return
 -                 fi
 -                 # should be a number
 -                 re='^[0-9]+$'
 -                 if ! [[ $new_expiry_months =~ $re ]] ; then
 -                     rm -f "$data"
 -                     return
 -                 fi
 -                 # set the new value
 -                 PLEROMA_EXPIRE_MONTHS=$new_expiry_months
 -                 write_config_param "PLEROMA_EXPIRE_MONTHS" "$PLEROMA_EXPIRE_MONTHS"
 - 
 -                 expire_pleroma_posts "$PLEROMA_DOMAIN_NAME" "$PLEROMA_EXPIRE_MONTHS"
 -                 create_pleroma_blocklist
 - 
 -                 dialog --title $"Set Pleroma post expiry period" \
 -                        --msgbox $"Expiry period set to $PLEROMA_EXPIRE_MONTHS months" 6 60
 -             fi
 -            ;;
 -     esac
 -     rm -f "$data"
 - }
 - 
 - function pleroma_disable_registrations {
 -     dialog --title $"Disable new Pleroma user registrations" \
 -            --backtitle $"Freedombone Control Panel" \
 -            --yesno $"\\nDo you wish to disable new registrations?" 10 60
 -     sel=$?
 -     case $sel in
 -         0) sed -i 's|registrations_open: true|registrations_open: false|g' $PLEROMA_DIR/config/config.exs
 -            sed -i 's|registrations_open: True|registrations_open: false|g' $PLEROMA_DIR/config/config.exs
 -            sed -i 's|"registrationOpen": true|"registrationOpen": false|g' $PLEROMA_DIR/priv/static/static/config.json
 -            sed -i 's|"registrationOpen": True|"registrationOpen": false|g' $PLEROMA_DIR/priv/static/static/config.json
 -            ;;
 -         1) sed -i 's|registrations_open: false|registrations_open: true|g' $PLEROMA_DIR/config/config.exs
 -            sed -i 's|registrations_open: False|registrations_open: true|g' $PLEROMA_DIR/config/config.exs
 -            sed -i 's|"registrationOpen": false|"registrationOpen": true|g' $PLEROMA_DIR/priv/static/static/config.json
 -            sed -i 's|"registrationOpen": False|"registrationOpen": true|g' $PLEROMA_DIR/priv/static/static/config.json
 -            ;;
 -         255) return;;
 -     esac
 -     pleroma_recompile
 - }
 - 
 - function pleroma_add_emoji {
 -     emoji_resolution='128x128'
 - 
 -     data=$(mktemp 2>/dev/null)
 -     dialog --backtitle $"Freedombone Control Panel" \
 -            --title $"Add Custom Emoji" \
 -            --form "\\n" 8 75 2 \
 -            $"Shortcode:" 1 1 "" 1 18 16 15 \
 -            $"ImageURL:" 2 1 "" 2 18 512 10000 \
 -            2> "$data"
 -     sel=$?
 -     case $sel in
 -         1) rm -f "$data"
 -            return;;
 -         255) rm -f "$data"
 -              return;;
 -     esac
 -     shortcode=$(sed -n 1p < "$data")
 -     image_url=$(sed -n 2p < "$data")
 -     rm -f "$data"
 -     if [ ${#shortcode} -lt 2 ]; then
 -         return
 -     fi
 -     if [ ${#image_url} -lt 2 ]; then
 -         return
 -     fi
 -     if [[ "$image_url" != *'.'* ]]; then
 -         return
 -     fi
 -     if [[ "$image_url" != *'.png' && "$image_url" != *'.jpg' && "$image_url" != *'.jpeg' && "$image_url" != *'.gif' ]]; then
 -         dialog --title $"Add Custom Emoji" \
 -                --msgbox $"The image must be png/jpg/gif format" 6 60
 -         return
 -     fi
 -     if [[ "$shortcode" == *':'* || "$shortcode" == *' '* || "$shortcode" == *'.'* || "$shortcode" == *'!'* ]]; then
 -         dialog --title $"Add Custom Emoji" \
 -                --msgbox $"The shortcode contains invalid characters" 6 60
 -         return
 -     fi
 - 
 -     image_extension='png'
 -     if [[ "$image_url" == *'.jpg' || "$image_url" == *'.jpeg' ]]; then
 -         image_extension='jpg'
 -     fi
 -     if [[ "$image_url" == *'.gif' ]]; then
 -         image_extension='gif'
 -     fi
 - 
 -     if [ ! -d $PLEROMA_DIR/priv/static/emoji ]; then
 -         mkdir -p $PLEROMA_DIR/priv/static/emoji
 -     fi
 - 
 -     image_filename=$PLEROMA_DIR/priv/static/emoji/${shortcode}.${image_extension}
 -     wget "$image_url" -O "$image_filename"
 -     if [ ! -f "$image_filename" ]; then
 -         dialog --title $"Add Custom Emoji" \
 -                --msgbox $"Unable to download the image" 6 60
 -         return
 -     fi
 - 
 -     if [[ "$image_url" == *'.jpg' || "$image_url" == *'.jpeg' || "$image_url" == *'.gif' ]]; then
 -         convert "$image_filename" -resize "$emoji_resolution" "$PLEROMA_DIR/priv/static/emoji/${shortcode}.png"
 -         if [ ! -f "$PLEROMA_DIR/priv/static/emoji/${shortcode}.png" ]; then
 -             dialog --title $"Add Custom Emoji" \
 -                    --msgbox $"Unable to convert empji image to png format" 6 60
 -             return
 -         fi
 - 
 -         # remove the original
 -         rm "$image_filename"
 - 
 -         image_extension='png'
 -         image_filename=$PLEROMA_DIR/priv/static/emoji/${shortcode}.${image_extension}
 -     else
 -         convert "$image_filename" -resize "$emoji_resolution" "$image_filename"
 -     fi
 - 
 -     if ! grep -q "${shortcode}," $PLEROMA_DIR/config/emoji.txt; then
 -         echo "${shortcode}, /emoji/${shortcode}.${image_extension}" >> $PLEROMA_DIR/config/emoji.txt
 -     else
 -         sed -i "s|${shortcode},.*|${shortcode}, /emoji/${shortcode}.${image_extension}|g" $PLEROMA_DIR/config/emoji.txt
 -     fi
 - 
 -     chown -R pleroma:pleroma $PLEROMA_DIR
 -     clear
 -     echo ''
 -     echo $'Recompiling Pleroma with the new emoji'
 -     systemctl stop pleroma
 -     pleroma_recompile
 - 
 -     dialog --title $"Add Custom Emoji" \
 -            --msgbox $"Custom emoji :${shortcode}: has been added" 6 70
 - }
 - 
 - function configure_interactive_pleroma {
 -     read_config_param PLEROMA_DOMAIN_NAME
 -     read_config_param PLEROMA_EXPIRE_MONTHS
 -     while true
 -     do
 -         data=$(mktemp 2>/dev/null)
 -         dialog --backtitle $"Freedombone Control Panel" \
 -                --title $"Pleroma" \
 -                --radiolist $"Choose an operation:" 15 70 6 \
 -                1 $"Set a background image" off \
 -                2 $"Set the title" off \
 -                3 $"Disable new account registrations" off \
 -                4 $"Add a custom emoji" off \
 -                5 $"Set post expiry period (currently $PLEROMA_EXPIRE_MONTHS months)" off \
 -                6 $"Exit" on 2> "$data"
 -         sel=$?
 -         case $sel in
 -             1) rm -f "$data"
 -                return;;
 -             255) rm -f "$data"
 -                  return;;
 -         esac
 -         case $(cat "$data") in
 -             1) pleroma_set_background_image;;
 -             2) pleroma_set_title;;
 -             3) pleroma_disable_registrations;;
 -             4) pleroma_add_emoji;;
 -             5) pleroma_set_expire_months;;
 -             6) rm -f "$data"
 -                break;;
 -         esac
 -         rm -f "$data"
 -     done
 - }
 - 
 - function upgrade_pleroma {
 -     read_config_param PLEROMA_DOMAIN_NAME
 -     read_config_param PLEROMA_EXPIRE_MONTHS
 - 
 -     if ! grep -q "/media/" /etc/cron.daily/pleroma-expire; then
 -         rm $pleroma_expire_posts_script
 -     fi
 -     if [ ! -f $pleroma_expire_posts_script ]; then
 -         expire_pleroma_posts "$PLEROMA_DOMAIN_NAME" "$PLEROMA_EXPIRE_MONTHS"
 -     fi
 -     if [ ! -f $blocking_script_file ]; then
 -         create_pleroma_blocklist
 -     fi
 - 
 -     CURR_PLEROMA_COMMIT=$(get_completion_param "pleroma commit")
 -     if [[ "$CURR_PLEROMA_COMMIT" == "$PLEROMA_COMMIT" ]]; then
 -         return
 -     fi
 - 
 -     # make a copy of the configuration
 -     cp $PLEROMA_DIR/priv/static/static/config.json $PLEROMA_DIR/priv/static/static/config_prev.json
 - 
 -     if [ -f $PLEROMA_DIR/config/emoji.txt ]; then
 -         cp $PLEROMA_DIR/config/emoji.txt $PLEROMA_DIR/config/emoji_prev.txt
 -     fi
 - 
 -     apt-get -yq update
 -     apt-get -yq install --only-upgrade esl-erlang
 -     apt-get -yq install --only-upgrade elixir erlang-xmerl erlang-dev erlang-parsetools
 - 
 -     function_check set_repo_commit
 -     set_repo_commit $PLEROMA_DIR "pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
 -     chown -R pleroma:pleroma $PLEROMA_DIR
 - 
 -     # restore the configuration
 -     cp $PLEROMA_DIR/priv/static/static/config_prev.json $PLEROMA_DIR/priv/static/static/config.json
 -     chown pleroma:pleroma $PLEROMA_DIR/priv/static/static/config.json
 - 
 -     if [ -f $PLEROMA_DIR/config/emoji_prev.txt ]; then
 -         cp $PLEROMA_DIR/config/emoji_prev.txt $PLEROMA_DIR/config/emoji.txt
 -         chown pleroma:pleroma $PLEROMA_DIR/config/emoji.txt
 -         rm cp $PLEROMA_DIR/config/emoji_prev.txt
 -     fi
 - 
 -     sudo -u pleroma mix deps.get
 - 
 -     pleroma_recompile
 - 
 -     # migrate database
 -     sudo -u pleroma mix deps.clean --build mime
 -     sudo -u pleroma mix ecto.migrate
 - 
 -     expire_pleroma_posts "$PLEROMA_DOMAIN_NAME" "$PLEROMA_EXPIRE_MONTHS"
 -     create_pleroma_blocklist
 - 
 -     chown -R pleroma:pleroma $PLEROMA_DIR
 - 
 -     systemctl restart pleroma
 - }
 - 
 - function backup_local_pleroma {
 -     PLEROMA_DOMAIN_NAME='pleroma'
 -     if grep -q "pleroma domain" "$COMPLETION_FILE"; then
 -         PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
 -     fi
 - 
 -     systemctl stop pleroma
 - 
 -     function_check suspend_site
 -     suspend_site "${PLEROMA_DOMAIN_NAME}"
 - 
 -     source_directory=$PLEROMA_DIR
 -     dest_directory=pleroma
 -     backup_directory_to_usb $source_directory $dest_directory
 - 
 -     USE_POSTGRESQL=1
 -     function_check backup_database_to_usb
 -     backup_database_to_usb pleroma
 - 
 -     function_check restart_site
 -     restart_site
 - 
 -     systemctl restart pleroma
 - }
 - 
 - function restore_local_pleroma {
 -     if ! grep -q "pleroma domain" "$COMPLETION_FILE"; then
 -         return
 -     fi
 -     PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
 -     if [ "$PLEROMA_DOMAIN_NAME" ]; then
 -         echo $"Restoring pleroma"
 -         temp_restore_dir=/root/temppleroma
 -         pleroma_dir=$PLEROMA_DIR
 - 
 -         systemctl stop pleroma
 - 
 -         PLEROMA_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_pleroma/hostname)
 -         function_check pleroma_create_database
 -         pleroma_create_database
 - 
 -         USE_POSTGRESQL=1
 -         restore_database pleroma
 -         if [ -d $temp_restore_dir ]; then
 -             rm -rf $temp_restore_dir
 -         fi
 - 
 -         function_check restore_directory_from_usb
 -         restore_directory_from_usb $temp_restore_dir pleroma
 -         if [ -d $temp_restore_dir ]; then
 -             chown -R pleroma:pleroma $pleroma_dir
 -             rm -rf $temp_restore_dir
 -         fi
 -         systemctl restart pleroma
 - 
 -         echo $"Restore of pleroma complete"
 -     fi
 - }
 - 
 - function backup_remote_pleroma {
 -     PLEROMA_DOMAIN_NAME='pleroma'
 -     if grep -q "pleroma domain" "$COMPLETION_FILE"; then
 -         PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
 -     fi
 - 
 -     systemctl stop pleroma
 - 
 -     function_check suspend_site
 -     suspend_site "${PLEROMA_DOMAIN_NAME}"
 - 
 -     source_directory=$PLEROMA_DIR
 -     dest_directory=pleroma
 -     backup_directory_to_friend $source_directory $dest_directory
 - 
 -     USE_POSTGRESQL=1
 -     function_check backup_database_to_friend
 -     backup_database_to_friend pleroma
 - 
 -     function_check restart_site
 -     restart_site
 - 
 -     systemctl restart pleroma
 - }
 - 
 - function restore_remote_pleroma {
 -     if ! grep -q "pleroma domain" "$COMPLETION_FILE"; then
 -         return
 -     fi
 -     PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
 -     if [ "$PLEROMA_DOMAIN_NAME" ]; then
 -         echo $"Restoring pleroma"
 -         temp_restore_dir=/root/temppleroma
 -         pleroma_dir=$PLEROMA_DIR
 - 
 -         systemctl stop pleroma
 - 
 -         PLEROMA_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_pleroma/hostname)
 -         function_check pleroma_create_database
 -         pleroma_create_database
 - 
 -         # shellcheck disable=SC2034
 -         USE_POSTGRESQL=1
 -         function_check restore_database_from_friend
 -         restore_database_from_friend pleroma
 -         if [ -d $temp_restore_dir ]; then
 -             rm -rf $temp_restore_dir
 -         fi
 - 
 -         function_check restore_directory_from_friend
 -         restore_directory_from_friend $temp_restore_dir pleroma
 -         if [ -d $temp_restore_dir ]; then
 -             chown -R pleroma:pleroma $pleroma_dir
 -             rm -rf $temp_restore_dir
 -         fi
 - 
 -         systemctl restart pleroma
 - 
 -         echo $"Restore of pleroma complete"
 -     fi
 - }
 - 
 - function remove_pleroma {
 -     if [ ${#PLEROMA_DOMAIN_NAME} -eq 0 ]; then
 -         return
 -     fi
 -     systemctl stop pleroma
 -     systemctl disable pleroma
 -     rm /etc/systemd/system/pleroma.service
 - 
 -     userdel pleroma
 -     #remove_elixir
 - 
 -     function_check remove_nodejs
 -     remove_nodejs pleroma-backend
 - 
 -     read_config_param "PLEROMA_DOMAIN_NAME"
 -     read_config_param "MY_USERNAME"
 -     echo "Removing $PLEROMA_DOMAIN_NAME"
 -     nginx_dissite "$PLEROMA_DOMAIN_NAME"
 -     remove_certs "$PLEROMA_DOMAIN_NAME"
 - 
 -     if [ -d "/var/www/$PLEROMA_DOMAIN_NAME" ]; then
 -         rm -rf "/var/www/$PLEROMA_DOMAIN_NAME"
 -     fi
 -     if [ -f "/etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME" ]; then
 -         rm "/etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME"
 -     fi
 -     if [ -d $PLEROMA_DIR ]; then
 -         rm -rf $PLEROMA_DIR
 -     fi
 -     function_check drop_database_postgresql
 -     drop_database_postgresql pleroma
 -     function_check remove_onion_service
 -     remove_onion_service pleroma ${PLEROMA_ONION_PORT}
 -     remove_app pleroma
 -     remove_completion_param install_pleroma
 -     sed -i '/pleroma domain/d' "$COMPLETION_FILE"
 -     sed -i '/pleroma commit/d' "$COMPLETION_FILE"
 -     sed -i "/$blocking_script_file/d" /etc/crontab
 - 
 -     if [ -f /usr/bin/pleroma-blocking ]; then
 -         rm /usr/bin/pleroma-blocking
 -     fi
 - 
 -     function_check remove_ddns_domain
 -     remove_ddns_domain "$PLEROMA_DOMAIN_NAME"
 - }
 - 
 - function image_install_pleroma {
 -     if [[ "$SOCIALINSTANCE" != 'pleroma' ]]; then
 -         return
 -     fi
 - 
 -     # shellcheck disable=SC2154
 -     chroot "$rootdir" apt-get -yq install wget imagemagick
 - 
 -     image_install_elixir
 -     image_install_postgresql
 - }
 - 
 - function install_pleroma {
 -     if [ ! $ONION_ONLY ]; then
 -         ONION_ONLY='no'
 -     fi
 - 
 -     apt-get -yq install wget imagemagick
 - 
 -     # We need elixir 1.4+ here, so the debian repo package won't do
 -     install_elixir
 - 
 -     function_check install_nodejs
 -     install_nodejs pleroma-backend
 -     install_postgresql
 - 
 -     if [ ! -d "/var/www/${PLEROMA_DOMAIN_NAME}/htdocs" ]; then
 -         mkdir -p "/var/www/${PLEROMA_DOMAIN_NAME}/htdocs"
 -     fi
 -     if [ -d $PLEROMA_DIR ]; then
 -         rm -rf $PLEROMA_DIR
 -     fi
 - 
 - 
 -     # get the repo
 -     if [ -f /repos/pleroma/index.html ]; then
 -         mv /repos/pleroma /repos/pleroma-fe
 -     fi
 -     if [ -d /repos/pleroma ]; then
 -         mkdir -p $PLEROMA_DIR
 -         cp -r -p /repos/pleroma/. $PLEROMA_DIR
 -         cd "$PLEROMA_DIR" || exit 834537453
 -         git pull
 -     else
 -         function_check git_clone
 -         git_clone $PLEROMA_REPO $PLEROMA_DIR
 -     fi
 - 
 -     if [ ! -d $PLEROMA_DIR ]; then
 -         echo $'Unable to clone pleroma backend repo'
 -         exit 783523
 -     fi
 - 
 - 
 -     # create user
 -     useradd -d $PLEROMA_DIR -s /bin/false pleroma
 - 
 - 
 -     # checkout the commit
 -     cd "$PLEROMA_DIR" || exit 62452428
 -     git checkout $PLEROMA_COMMIT -b $PLEROMA_COMMIT
 -     set_completion_param "pleroma commit" "$PLEROMA_COMMIT"
 -     chown -R pleroma:pleroma $PLEROMA_DIR
 - 
 - 
 -     # web config
 -     function_check add_ddns_domain
 -     add_ddns_domain "$PLEROMA_DOMAIN_NAME"
 - 
 -     PLEROMA_ONION_HOSTNAME=$(add_onion_service pleroma 80 ${PLEROMA_ONION_PORT})
 - 
 -     pleroma_nginx_site=/etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME
 -     if [[ $ONION_ONLY == "no" ]]; then
 -         function_check nginx_http_redirect
 -         nginx_http_redirect "$PLEROMA_DOMAIN_NAME" "index index.html"
 -         { echo '';
 -         echo 'proxy_cache_path /tmp/pleroma-media-cache levels=1:2 keys_zone=pleroma_media_cache:10m max_size=100m inactive=80m use_temp_path=off;';
 -         echo '';
 -         echo 'server {';
 -         echo '  listen 443 ssl;';
 -         echo '  #listen [::]:443 ssl;';
 -         echo "  server_name $PLEROMA_DOMAIN_NAME;";
 -         echo ''; } >> "$pleroma_nginx_site"
 -         function_check nginx_compress
 -         nginx_compress "$PLEROMA_DOMAIN_NAME"
 -         echo '' >> "$pleroma_nginx_site"
 -         echo '  # Security' >> "$pleroma_nginx_site"
 -         function_check nginx_ssl
 -         nginx_ssl "$PLEROMA_DOMAIN_NAME"
 - 
 -         function_check nginx_security_options
 -         nginx_security_options "$PLEROMA_DOMAIN_NAME"
 - 
 -         { echo '  add_header Strict-Transport-Security max-age=0;';
 -           echo '';
 -           echo '  # Logs';
 -           echo '  access_log /dev/null;';
 -           echo '  error_log /dev/null;';
 -           echo '';
 -           echo "  root $PLEROMA_DIR;";
 -           echo '';
 -           echo '  index index.html;';
 -           echo '  location / {'; } >> "$pleroma_nginx_site"
 -         function_check nginx_limits
 -         nginx_limits "$PLEROMA_DOMAIN_NAME" '15m'
 -         { echo "    add_header 'Access-Control-Allow-Origin' '*';";
 -           echo '    proxy_http_version 1.1;';
 -           echo "    proxy_set_header Upgrade \$http_upgrade;";
 -           echo '    proxy_set_header Connection "upgrade";';
 -           echo "    proxy_set_header Host \$http_host;";
 -           echo '';
 -           echo "    proxy_pass http://localhost:$PLEROMA_PORT;";
 -           echo '  }';
 -           echo '';
 -           echo '  location /proxy {'; } >> "$pleroma_nginx_site"
 -         nginx_limits "$PLEROMA_DOMAIN_NAME" '15m'
 -         { echo '    proxy_cache pleroma_media_cache;';
 -           echo '    proxy_cache_lock on;';
 -           echo "    proxy_pass http://localhost:$PLEROMA_PORT;";
 -           echo '  }';
 -           echo '  # include snippets/well-known.conf;';
 -           echo '}'; } >> "$pleroma_nginx_site"
 -     else
 -         echo 'proxy_cache_path /tmp/pleroma-media-cache levels=1:2 keys_zone=pleroma_media_cache:10m max_size=100m inactive=80m use_temp_path=off;' > "$pleroma_nginx_site"
 -         echo '' >> "$pleroma_nginx_site"
 -     fi
 -     { echo 'server {';
 -       echo "    listen 127.0.0.1:$PLEROMA_ONION_PORT default_server;";
 -       echo "    server_name $PLEROMA_ONION_HOSTNAME;";
 -       echo ''; } >> "$pleroma_nginx_site"
 -     function_check nginx_compress
 -     nginx_compress "$PLEROMA_DOMAIN_NAME"
 -     echo '' >> "$pleroma_nginx_site"
 -     function_check nginx_security_options
 -     nginx_security_options "$PLEROMA_DOMAIN_NAME"
 -     { echo '';
 -       echo '  # Logs';
 -       echo '  access_log /dev/null;';
 -       echo '  error_log /dev/null;';
 -       echo '';
 -       echo "  root $PLEROMA_DIR;";
 -       echo '';
 -       echo '  index index.html;';
 -       echo '  location / {'; } >> "$pleroma_nginx_site"
 -     function_check nginx_limits
 -     nginx_limits "$PLEROMA_DOMAIN_NAME" '15m'
 -     { echo "      add_header 'Access-Control-Allow-Origin' '*';";
 -       echo '      proxy_http_version 1.1;';
 -       echo "      proxy_set_header Upgrade \$http_upgrade;";
 -       echo '      proxy_set_header Connection "upgrade";';
 -       echo "      proxy_set_header Host \$http_host;";
 -       echo '';
 -       echo "      proxy_pass http://localhost:$PLEROMA_PORT;";
 -       echo '  }';
 -       echo '';
 -       echo '  location /proxy {'; } >> "$pleroma_nginx_site"
 -     nginx_limits "$PLEROMA_DOMAIN_NAME" '15m'
 -     { echo '    proxy_cache pleroma_media_cache;';
 -       echo '    proxy_cache_lock on;';
 -       echo "    proxy_pass http://localhost:$PLEROMA_PORT;";
 -       echo '  }';
 -       echo '  # include snippets/well-known.conf;';
 -       echo '}'; } >> "$pleroma_nginx_site"
 - 
 -     # back end
 -     cd "$PLEROMA_DIR" || exit 246824684
 -     chown -R pleroma:pleroma "$PLEROMA_DIR/"*
 -     if ! sudo -u pleroma mix local.hex --force; then
 -         echo $'mix local.hex failed'
 -         exit 1745673
 -     fi
 -     if ! sudo -u pleroma mix deps.get --force; then
 -         echo $'mix deps.get failed'
 -         exit 7325733
 -     fi
 - 
 -     function_check pleroma_create_database
 -     pleroma_create_database
 - 
 -     "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a pleroma -p "$PLEROMA_ADMIN_PASSWORD"
 - 
 -     # NOTE: we don't need to install the frontend separately,
 -     # since the backend contains a precompiled version of it
 - 
 -     install_gnusocial_default_background "pleroma" "$PLEROMA_DOMAIN_NAME"
 -     if [ ! -f "$PLEROMA_DIR/priv/static/static/config.json" ]; then
 -         echo $"$PLEROMA_DIR/priv/static/static/config.json file missing"
 -         exit 323689
 -     fi
 -     sed -i 's|"theme":.*|"theme": "base16-summerfruit-dark.css",|g' "$PLEROMA_DIR/priv/static/static/config.json"
 - 
 -     if [ "$PLEROMA_BACKGROUND_IMAGE_URL" ]; then
 -         pleroma_set_background_image_from_url $PLEROMA_DIR/priv/static "$PLEROMA_DOMAIN_NAME" "$PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_TITLE"
 -     fi
 - 
 -     # Get certificate
 -     function_check create_site_certificate
 -     create_site_certificate "$PLEROMA_DOMAIN_NAME" 'yes'
 - 
 -     function_check nginx_ensite
 -     nginx_ensite "$PLEROMA_DOMAIN_NAME"
 - 
 -     systemctl restart postgresql
 -     systemctl restart nginx
 - 
 -     set_completion_param "pleroma domain" "$PLEROMA_DOMAIN_NAME"
 - 
 -     # We need to set up the url option again because it somehow gets
 -     # lost during mix compile
 -     pleroma_secret=$PLEROMA_DIR/config/dev.secret.exs
 -     if ! grep -q 'watchers: [],' $pleroma_secret; then
 -         sed -i 's|watchers: \[\]|watchers: \[\],|g' $pleroma_secret
 -     fi
 -     if ! grep -q 'url:' $pleroma_secret; then
 -         if [[ $ONION_ONLY == 'no' ]]; then
 -             sed -i "/watchers: /a url: [host: \"$PLEROMA_DOMAIN_NAME\", scheme: \"https\", port: 443]" $pleroma_secret
 -         else
 -             sed -i "/watchers: /a url: [host: \"$PLEROMA_ONION_HOSTNAME\", scheme: \"http\", port: 80]" $pleroma_secret
 -         fi
 -     fi
 - 
 -     create_pleroma_blocklist
 - 
 -     # daemon
 -     { echo '[Unit]';
 -       echo 'Description=Pleroma social network';
 -       echo 'After=network.target postgresql.service';
 -       echo '';
 -       echo '[Service]';
 -       echo 'User=pleroma';
 -       echo "WorkingDirectory=$PLEROMA_DIR";
 -       echo "Environment=\"HOME=$PLEROMA_DIR\"";
 -       echo 'ExecStart=/usr/local/bin/mix phx.server';
 -       echo "ExecReload=/bin/kill \$MAINPID";
 -       echo 'KillMode=process';
 -       echo 'Restart=on-failure';
 -       echo '';
 -       echo '[Install]';
 -       echo 'WantedBy=multi-user.target';
 -       echo 'Alias=pleroma.service'; } > /etc/systemd/system/pleroma.service
 - 
 -     # set registrations open initially
 -     sed -i 's|registrations_open:.*|registrations_open: true,|g' $PLEROMA_DIR/config/config.exs
 -     sed -i 's|"registrationOpen":.*|"registrationOpen": true,|g' $PLEROMA_DIR/priv/static/static/config.json
 - 
 -     systemctl daemon-reload
 -     systemctl enable pleroma
 -     systemctl start pleroma
 - 
 -     APP_INSTALLED=1
 - }
 - 
 - # NOTE: deliberately there is no "exit 0"
 
 
  |