Skip to content
Snippets Groups Projects
freedombone-utils-gnusocialtools 41.2 KiB
Newer Older
#!/bin/bash
Bob Mottram's avatar
Bob Mottram committed
#  _____               _           _
# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
Bob Mottram's avatar
Bob Mottram committed
#                              Freedom in the Cloud
#
# functions common to GNU Social server varieties
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2017-2019 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/>.

# Qvitter upstream: https://git.gnu.io/h2p/Qvitter"
Bob Mottram's avatar
Bob Mottram committed
QVITTER_THEME_REPO="https://code.freedombone.net/bashrc/Qvitter"
QVITTER_THEME_COMMIT='c6f09bda4e45be4290cf7409fa5efb4420538032'
Bob Mottram's avatar
Bob Mottram committed
PLEROMA_FRONTEND_REPO="https://git.pleroma.social/pleroma/pleroma-fe.git"
Bob Mottram's avatar
Bob Mottram committed
PLEROMA_FRONTEND_COMMIT='3b3bbaab822b553f514a62d20d679acc5ce4414a'
Bob Mottram's avatar
Bob Mottram committed
SHARINGS_REPO="http://code.freedombone.net/bashrc/Sharings"
SHARINGS_COMMIT='0d30fe7d153c7ab44e8459970b8f2b5dec06e43c'
Bob Mottram's avatar
Bob Mottram committed
SHARINGS_THEME_REPO="http://code.freedombone.net/bashrc/SharingsTheme"
SHARINGS_THEME_COMMIT='a46ef375d19e8ef6889653668a7e697b0ba2013c'
GNUSOCIAL_MARKDOWN_REPO="https://git.gnu.io/chimo/markdown.git"
GNUSOCIAL_MARKDOWN_COMMIT='03c53942f94b3376f0946e6e1fe566cc21ccf232'

function gnusocial_set_limits {
    filename="$1"

    sed -i 's|client_body_buffer_size.*|client_body_buffer_size 5m;|g' "$filename"
    sed -i 's|limit_conn conn_limit_per_ip.*|limit_conn conn_limit_per_ip 100;|g' "$filename"
    sed -i 's|req_limit_per_ip.*|req_limit_per_ip burst=100 nodelay;|g' "$filename"
}

# Stuff to be done after restoring from backup
function gnusocial_update_after_restore {
Bob Mottram's avatar
Bob Mottram committed
    gnusocial_variant="$1"
    gnusocial_domain="$2"
    cd "/var/www/${gnusocial_domain}/htdocs" || exit 36

    # Ensure that the database password is correct
Bob Mottram's avatar
Bob Mottram committed
    MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
    sed -i "s|\$config['db']['database'].*|\$config['db']['database'] = 'mysqli://root:${MARIADB_PASSWORD}@localhost/${gnusocial_variant}';|g" config.php
Bob Mottram's avatar
Bob Mottram committed
    MARIADB_PASSWORD=

    # Set permissions
Bob Mottram's avatar
Bob Mottram committed
    chmod g+w "/var/www/$gnusocial_domain/htdocs"
    chmod a+w "/var/www/$gnusocial_domain/htdocs/avatar"
    chmod a+w "/var/www/$gnusocial_domain/htdocs/file"
    chown -R www-data:www-data "/var/www/$gnusocial_domain/htdocs"
    chmod +x "/var/www/$gnusocial_domain/htdocs/scripts/maildaemon.php"

    # This seems to be necessary to get the UI back
Bob Mottram's avatar
Bob Mottram committed
    gnusocial_use_classic "$gnusocial_variant"
    gnusocial_use_qvitter "$gnusocial_variant"

    # start the daemons
    su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data
}

Bob Mottram's avatar
Bob Mottram committed
function qvitter_update_background {
    domain_name="$1"
Bob Mottram's avatar
Bob Mottram committed
    ext="$2"

    if [ -d "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img" ]; then
        if [ -f "bg_custom.${ext}" ]; then
            cp "bg_custom.${ext}" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img"
            if ! grep -q "bg_custom.${ext}" "/var/www/${domain_name}/htdocs/config.php"; then
                if grep -q 'sitebackground' "/var/www/${domain_name}/htdocs/config.php"; then
                    sed -i '/sitebackground/d' "/var/www/${domain_name}/htdocs/config.php"
Bob Mottram's avatar
Bob Mottram committed
                echo "\$config['site']['qvitter']['sitebackground'] = 'img/bg_custom.${ext}';" >> "/var/www/${domain_name}/htdocs/config.php"
function pleroma_custom_logo {
    basedir="$1"
    if [ "$2" ]; then
        if [[ "$2" == *".png" ]]; then
            cp "$2" "$basedir/priv/static/static/logo.png"
            return
        fi
    fi

Bob Mottram's avatar
Bob Mottram committed
    if [ -f "$basedir/priv/static/static/logo.png" ]; then
        if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
            if [ -d "$basedir/static" ]; then
                cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo.png"
            fi
Bob Mottram's avatar
Bob Mottram committed
            cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/priv/static/static/logo.png"
        else
            if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
                if [ -d "$basedir/static" ]; then
                    cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo.png"
                fi
Bob Mottram's avatar
Bob Mottram committed
                cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/priv/static/static/logo.png"
function pleroma_set_background_image_from_url {
    basedir="$1"
    domain_name="$2"
    url="$3"
    title="$4"
Bob Mottram's avatar
Bob Mottram committed
    if [ ${#domain_name} -eq 0 ]; then
        echo "1"
        return
    fi

    ext=
    if [ ${#url} -gt 0 ]; then
Bob Mottram's avatar
Bob Mottram committed
        if [[ "$url" == *".jpeg" || "$url" == *".jpg" ]]; then
            ext="jpg"
        fi
Bob Mottram's avatar
Bob Mottram committed
        if [[ "$url" == *".png" ]]; then
            ext="png"
        fi
Bob Mottram's avatar
Bob Mottram committed
        if [[ "$url" == *".gif" ]]; then
            ext="gif"
        fi
    fi

    if [ ${#ext} -gt 0 ]; then
        cd "$basedir" || exit 63
Bob Mottram's avatar
Bob Mottram committed
        # remove any existing image
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "bg_custom.${ext}" ]; then
            rm "bg_custom.${ext}"
Bob Mottram's avatar
Bob Mottram committed
        fi
Bob Mottram's avatar
Bob Mottram committed
        # get the new image
Bob Mottram's avatar
Bob Mottram committed
        wget "$url" -O "bg_custom.${ext}"
        if [ ! -f "bg_custom.${ext}" ]; then
Bob Mottram's avatar
Bob Mottram committed
            echo "$url"
            echo $'Custom background image for pleroma could not be downloaded'
            echo "1"
            return
        fi
Bob Mottram's avatar
Bob Mottram committed
        if [ -d "$basedir/static" ]; then
            cp "bg_custom.${ext}" "static/bg_custom.${ext}"
            chown www-data:www-data "static/bg_custom.${ext}"
Bob Mottram's avatar
Bob Mottram committed
            sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" static/config.json
            if [ -f "$pleroma_secret" ]; then
                if grep -q "\"background\":" "$pleroma_secret"; then
                    sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" "$pleroma_secret"
                fi
        if [ -d priv/static/static ]; then
Bob Mottram's avatar
Bob Mottram committed
            cp "bg_custom.${ext}" "priv/static/static/bg_custom.${ext}"
            chown www-data:www-data "priv/static/static/bg_custom.${ext}"
            sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" priv/static/static/config.json
            if [ -f "$pleroma_secret" ]; then
                if grep -q "\"background\":" "$pleroma_secret"; then
                    sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" "$pleroma_secret"
                fi
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
        if [[ "$basedir" != "$PLEROMA_DIR" ]]; then
            qvitter_update_background "${domain_name}" "${ext}"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
        rm "bg_custom.${ext}"
Bob Mottram's avatar
Bob Mottram committed
    else
        echo "2"
        return
    pleroma_custom_logo "$basedir"

    # customise the title
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "$basedir/static/config.json" ]; then
        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/static/config.json"
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "$basedir/priv/static/static/config.json" ]; then
Loading
Loading full blame...