Skip to content
Snippets Groups Projects
freedombone-app-pleroma 78.9 KiB
Newer Older
Bob Mottram's avatar
Bob Mottram committed
#!/bin/bash
Bob Mottram's avatar
Bob Mottram committed
#  _____               _           _
# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
Bob Mottram's avatar
Bob Mottram committed
#
Bob Mottram's avatar
Bob Mottram committed
#                              Freedom in the Cloud
Bob Mottram's avatar
Bob Mottram committed
#
# Pleroma backend application
Bob Mottram's avatar
Bob Mottram committed
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2017-2019 Bob Mottram <bob@freedombone.net>
Bob Mottram's avatar
Bob Mottram committed
#
# 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/>.

Bob Mottram's avatar
Bob Mottram committed
VARIANTS='full full-vim social'
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
APP_CATEGORY=social

Bob Mottram's avatar
Bob Mottram committed
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1
REQUIRES_APP=
Bob Mottram's avatar
Bob Mottram committed

PLEROMA_DOMAIN_NAME=
PLEROMA_CODE=
PLEROMA_PORT=4000
PLEROMA_ONION_PORT=8011
PLEROMA_REPO="https://git.pleroma.social/pleroma/pleroma.git"
Bob Mottram's avatar
Bob Mottram committed
PLEROMA_COMMIT='99fd199bda8bd90cd3e8c69d54087531ddc02eac'
Bob Mottram's avatar
Bob Mottram committed
PLEROMA_ADMIN_PASSWORD=
Bob Mottram's avatar
Bob Mottram committed
PLEROMA_DIR=/etc/pleroma
PLEROMA_SECRET_KEY=""
pleroma_secret=$PLEROMA_DIR/config/dev.secret.exs
Bob Mottram's avatar
Bob Mottram committed

PLEROMA_BACKGROUND_IMAGE_URL=

PLEROMA_TITLE='Pleroma Server'

# Number of months after which posts expire
PLEROMA_EXPIRE_MONTHS=3
Bob Mottram's avatar
Bob Mottram committed
pleroma_expire_posts_script=/usr/bin/pleroma-expire-posts
Bob Mottram's avatar
Bob Mottram committed
blocking_script_file=/usr/bin/pleroma-blocking
Bob Mottram's avatar
Bob Mottram committed

emoji_resolution='128x128'

# limit hellthreads with zillions of mentions
Bob Mottram's avatar
Bob Mottram committed
maximum_tagged_thread_participants=7
Bob Mottram's avatar
Bob Mottram committed
# whether the install function is running
pleroma_installing=

Bob Mottram's avatar
Bob Mottram committed
PLEROMA_SHORT_DESCRIPTION=$'Federated microblogging'
PLEROMA_DESCRIPTION=$'Federated microblogging'
PLEROMA_MOBILE_APP_URL='https://f-droid.org/packages/com.keylesspalace.tusky'

Bob Mottram's avatar
Bob Mottram committed
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 pleroma_remove_setting {
    pleroma_setting="$1"

Bob Mottram's avatar
Bob Mottram committed
    if grep -q " ${pleroma_setting}:" $pleroma_secret; then
        sed -i "/ ${pleroma_setting}:/d" $pleroma_secret
    fi
}

function pleroma_deprecate_fe {
    if ! grep -q 'config :pleroma, :fe, false' $pleroma_secret; then
        sed -i 's|config :pleroma, :fe.*|config :pleroma, :fe, false|g' $pleroma_secret
    fi
Bob Mottram's avatar
Bob Mottram committed
    pleroma_remove_setting 'theme'
    pleroma_remove_setting 'logo'
    pleroma_remove_setting 'logo_mask'
    pleroma_remove_setting 'logo_margin'
    pleroma_remove_setting 'background'
    pleroma_remove_setting 'redirect_root_no_login'
    pleroma_remove_setting 'redirect_root_login'
    pleroma_remove_setting 'show_instance_panel'
    pleroma_remove_setting 'collapse_message_with_subject'
    pleroma_remove_setting 'formatting_options_enabled'
    pleroma_remove_setting 'hide_user_stats'
    pleroma_remove_setting 'scope_options_enabled'
Bob Mottram's avatar
Bob Mottram committed
function pleroma_enable_web_push_encryption {
    if grep -q 'web_push_encryption' "$pleroma_secret"; then
        return
    fi

    cd $PLEROMA_DIR || return
    sudo -u pleroma mix web_push.gen.keypair | sudo tee -a "$pleroma_secret"
    sed -i "s|administrator@example.com|$MY_EMAIL_ADDRESS|g" "$pleroma_secret"
    sed -i '/# Put the following/d' "$pleroma_secret"
    if [ $pleroma_installing ]; then
        increment_app_install_progress
    fi
    sudo -u postgres psql pleroma -c "create extension if not exists pg_trgm"
    if [ $pleroma_installing ]; then
        increment_app_install_progress
    fi
    sudo -u postgres psql pleroma -c 'create extension if not exists "uuid-ossp"'
    if [ $pleroma_installing ]; then
        increment_app_install_progress
    fi
    sudo -u pleroma mix ecto.migrate --force
    if [ $pleroma_installing ]; then
        increment_app_install_progress
    fi
    pleroma_recompile
    if [ $pleroma_installing ]; then
        increment_app_install_progress
    fi

    PLEROMA_PUSH_PUBLIC_KEY=$(grep "public_key:" "$pleroma_secret" | head -n 1 | awk -F '"' '{print $2}')
    PLEROMA_PUSH_PRIVATE_KEY=$(grep "private_key:" "$pleroma_secret" | head -n 1 | awk -F '"' '{print $2}')
    if [ "$PLEROMA_PUSH_PUBLIC_KEY" ]; then
        write_config_param PLEROMA_PUSH_PUBLIC_KEY "$PLEROMA_PUSH_PUBLIC_KEY"
    else
        echo $'web_push_encryption failed: no public key'
        return
    fi

    if [ "$PLEROMA_PUSH_PRIVATE_KEY" ]; then
        write_config_param PLEROMA_PUSH_PRIVATE_KEY "$PLEROMA_PUSH_PRIVATE_KEY"
    else
        echo $'web_push_encryption failed: no private key'
        return
    fi
}

function pleroma_set_permissions {
    # set permissions on directories
    if [ -d "$PLEROMA_DIR/config" ]; then
        chmod 644 "$PLEROMA_DIR/config"/*
    fi
    if [ -d "$PLEROMA_DIR/deps" ]; then
        chmod -R 755 "$PLEROMA_DIR/deps"
    fi
}

Bob Mottram's avatar
Bob Mottram committed
function pleroma_create_recompile_command {
    { echo '#!/bin/bash';
      echo "cd $PLEROMA_DIR || exit 1";
      echo "chown -R pleroma:pleroma $PLEROMA_DIR";
      echo 'sudo -u pleroma mix clean';
      echo 'sudo -u pleroma mix deps.compile';
      echo 'sudo -u pleroma mix compile';
      echo "chmod 644 $PLEROMA_DIR/config/*";
      echo "chmod -R 755 $PLEROMA_DIR/deps/*";
Bob Mottram's avatar
Bob Mottram committed
      echo 'systemctl restart pleroma'; } > /usr/bin/pleroma-recompile
    chmod +x /usr/bin/pleroma-recompile
}

Bob Mottram's avatar
Bob Mottram committed
function pleroma_recompile {
    # necessary after parameter changes

Bob Mottram's avatar
Bob Mottram committed
    if [ ! -f /usr/bin/pleroma-recompile ]; then
        pleroma_create_recompile_command
Bob Mottram's avatar
Bob Mottram committed
    fi
    if ! grep -q 'chmod' /usr/bin/pleroma-recompile; then
        pleroma_create_recompile_command
    fi

Bob Mottram's avatar
Bob Mottram committed
    /usr/bin/pleroma-recompile
Bob Mottram's avatar
Bob Mottram committed
}

function pleroma_setting_background {
    pleroma_new_background="$1"

    if [ "$pleroma_new_background" ]; then
        url="$pleroma_new_background"

        ext=
        if [ ${#url} -gt 0 ]; then
            if [[ "$url" == *".jpeg" || "$url" == *".jpg" ]]; then
                ext="jpg"
            fi
            if [[ "$url" == *".png" ]]; then
Loading
Loading full blame...