Skip to content
Snippets Groups Projects
freedombone-app-pleroma 58.8 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
# =======
#
# Copyright (C) 2017-2018 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

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"
Bob Mottram's avatar
Bob Mottram committed
PLEROMA_COMMIT='945ce9910dc7b29147ec49af0bdb82202008c7c4'
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'

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)

Bob Mottram's avatar
Bob Mottram committed
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
}

Bob Mottram's avatar
Bob Mottram committed
function pleroma_setting_emoji {
    shortcode="$1"
    image_url="$2"
    if [ ! "$shortcode" ]; then
        return
    fi
    if [[ "$shortcode" == *' '* || "$shortcode" == *':'* ]]; then
        return
    fi
    if [ ${#shortcode} -gt 32 ]; then
        return
    fi
    if [[ "$image_url" != 'http'* ]]; then
        return
    fi
    if [ ${#image_url} -gt 256 ]; then
        return
    fi

    image_extension=
    if [[ "$image_url" == *'.jpg' || "$image_url" == *'.jpeg' ]]; then
        image_extension='jpg'
    fi
    if [[ "$image_url" == *'.gif' ]]; then
        image_extension='gif'
    fi
    if [[ "$image_url" == *'.png' ]]; then
        image_extension='png'
    fi
    if [ ! $image_extension ]; then
        echo $'Invalid image type'
Bob Mottram's avatar
Bob Mottram committed
        return
    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}
    if [ -f "$image_filename" ]; then
        mv "$image_filename" "${image_filename}.prev"
    fi
Bob Mottram's avatar
Bob Mottram committed
    wget "$image_url" -O "$image_filename"
    if [ ! -f "$image_filename" ]; then
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "${image_filename}.prev" ]; then
            mv "${image_filename}.prev" "${image_filename}"
        fi
Bob Mottram's avatar
Bob Mottram committed
        return
    fi
    rm "${image_filename}.prev"
Bob Mottram's avatar
Bob Mottram committed

    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
            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
Bob Mottram's avatar
Bob Mottram committed
    cd $PLEROMA_DIR || exit 264862
    pleroma_recompile
Bob Mottram's avatar
Bob Mottram committed
}

function pleroma_setting_registration {
    allow_registration="$1"

Bob Mottram's avatar
Bob Mottram committed
    if [[ "$allow_registration" == '1' ]]; then
Bob Mottram's avatar
Bob Mottram committed
        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
        cd $PLEROMA_DIR || exit 5637568
Bob Mottram's avatar
Bob Mottram committed
        pleroma_recompile
    fi

Bob Mottram's avatar
Bob Mottram committed
    if [[ "$allow_registration" == '0' ]]; then
Bob Mottram's avatar
Bob Mottram committed
        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
        cd $PLEROMA_DIR || exit 4536573
Bob Mottram's avatar
Bob Mottram committed
        pleroma_recompile
    fi
}

function pleroma_enable_chat {
    if [[ "$1" == 't'* || "$1" == 'y'* || "$1" == 'T'* || "$1" == 'Y'* ]]; then
        sed -i 's|"chatDisabled":.*|"chatDisabled": false,|g' $PLEROMA_DIR/priv/static/static/config.json
        sed -i 's|:chat, enabled:.*|:chat, enabled: true|g' $PLEROMA_DIR/config/config.exs
    else
        sed -i 's|"chatDisabled":.*|"chatDisabled": true,|g' $PLEROMA_DIR/priv/static/static/config.json
        sed -i 's|:chat, enabled:.*|:chat, enabled: false|g' $PLEROMA_DIR/config/config.exs
    fi
    pleroma_recompile
}

Bob Mottram's avatar
Bob Mottram committed
function create_pleroma_blocklist {
Bob Mottram's avatar
Bob Mottram committed
    { echo '#!/bin/bash';
      echo '';
      echo 'websub_server_subscriptions_query="DELETE FROM websub_server_subscriptions WHERE"';
      echo 'websub_server_subscriptions_updated='
      echo '';
Bob Mottram's avatar
Bob Mottram committed
      echo "if [ ! -f /root/${PROJECT_NAME}-firewall-domains.cfg ]; then";
      echo '    exit 0';
Loading
Loading full blame...