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
        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/priv/static/static/config.json"

    echo "0"
}

function install_qvitter {
Bob Mottram's avatar
Bob Mottram committed
    domain_name="$1"
    app_name="$2"

    # update to the next commit
    function_check set_repo_commit
Bob Mottram's avatar
Bob Mottram committed
    set_repo_commit "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" "${app_name} theme commit" "$QVITTER_THEME_COMMIT" "$QVITTER_THEME_REPO"

    # customise with project logo
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" ]; then
        if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
            cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png"
Bob Mottram's avatar
Bob Mottram committed
            if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
                cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png"
            fi
        fi
    fi

    if [[ $(app_is_installed "${app_name}_theme") == "1" ]]; then
        return
    fi

    $INSTALL_PACKAGES wget
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/${domain_name}/htdocs/local/plugins" ]; then
        mkdir -p "/var/www/${domain_name}/htdocs/local/plugins"
    cd "/var/www/${domain_name}/htdocs/local/plugins" || exit 64

    if [ -d /repos/qvitter ]; then
        mkdir Qvitter
Bob Mottram's avatar
Bob Mottram committed
        cp -r -p /repos/qvitter/. Qvitter
        cd Qvitter || exit 26
        git pull
    else
        function_check git_clone
Bob Mottram's avatar
Bob Mottram committed
        git_clone "$QVITTER_THEME_REPO" Qvitter
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" ]; then
        echo $'Qvitter repo was not installed'
    cd "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" || exit 78
Bob Mottram's avatar
Bob Mottram committed
    git checkout "$QVITTER_THEME_COMMIT" -b "$QVITTER_THEME_COMMIT"
Bob Mottram's avatar
Bob Mottram committed
    config_file="/var/www/${domain_name}/htdocs/config.php"
    if ! grep -q "addPlugin('Qvitter')" "$config_file"; then
        { echo "";
          echo "// Qvitter settings";
          echo "addPlugin('Qvitter');";
          echo "\$config['site']['qvitter']['enabledbydefault'] = true;";
          echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';";
          echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';";
          echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs"; } >> "$config_file"
Bob Mottram's avatar
Bob Mottram committed
        if [[ $ONION_ONLY == 'no' ]]; then
Bob Mottram's avatar
Bob Mottram committed
            echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> "$config_file"
            echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> "$config_file"
Bob Mottram's avatar
Bob Mottram committed
        { echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';";
          echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';";
          echo "\$config['site']['qvitter']['enablewelcometext'] = false;";
          echo "\$config['site']['qvitter']['blocked_ips'] = array();"; } >> "$config_file"
    fi

    # customise with project logo
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" ]; then
        if [ -f "$HOME/${PROJECT_NAME}/img/${app_name}_sprite.png" ]; then
            cp "$HOME/${PROJECT_NAME}/img/${app_name}_sprite.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png"
Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
    cd "/var/www/${domain_name}/htdocs" || exit 37
    php scripts/upgrade.php
    php scripts/checkschema.php
Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
    set_completion_param "${app_name} theme commit" "$QVITTER_THEME_COMMIT"

Bob Mottram's avatar
Bob Mottram committed
    install_completed "${app_name}_theme"
function install_gnusocial_default_background {
Bob Mottram's avatar
Bob Mottram committed
    gnusocial_type="$1"
    domain_name="$2"
Bob Mottram's avatar
Bob Mottram committed
    basedir="/var/www/${domain_name}/htdocs"
    if [[ "$gnusocial_type" == 'pleroma' ]]; then
Bob Mottram's avatar
Bob Mottram committed
        basedir="$PLEROMA_DIR/priv/static"
    # customise the logo
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "$basedir/static/logo.png" ]; then
        if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
            cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo_custom.png"
            sed -i "s|\"logo\":.*|\"logo\": \"/static/logo_custom.png\",|g" "$basedir/static/config.json"
Bob Mottram's avatar
Bob Mottram committed
            if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then
                cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo_custom.png"
                sed -i "s|\"logo\":.*|\"logo\": \"/static/logo_custom.png\",|g" "$basedir/static/config.json"
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -f "$basedir/static/bg.jpg" ]; then
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "$HOME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" ]; then
        cp "$HOME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" "$basedir/static/bg_custom.jpg"
        sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.jpg\",|g" "$basedir/static/config.json"
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" ]; then
            cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" "$basedir/static/bg_custom.jpg"
            sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.jpg\",|g" "$basedir/static/config.json"
Bob Mottram's avatar
Bob Mottram committed

function install_pleroma_front_end {
    app_name="$1"
Bob Mottram's avatar
Bob Mottram committed
    pleroma_domain="$2"
    background_url="$3"
    title="$4"
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "$INSTALL_DIR/pleroma" ]; then
Bob Mottram's avatar
Bob Mottram committed
        if [ -d /repos/pleroma-fe ]; then
Bob Mottram's avatar
Bob Mottram committed
            mkdir -p "$INSTALL_DIR/pleroma"
            cp -r -p /repos/pleroma-fe/. "$INSTALL_DIR/pleroma"
            cd "$INSTALL_DIR/pleroma" || exit 23
            git pull
        else
            function_check git_clone
Bob Mottram's avatar
Bob Mottram committed
            git_clone "$PLEROMA_FRONTEND_REPO" "$INSTALL_DIR/pleroma"
Bob Mottram's avatar
Bob Mottram committed
        if [ ! -d "$INSTALL_DIR/pleroma" ]; then
            echo $'Unable to clone pleroma repo'
    cd "$INSTALL_DIR/pleroma" || exit 25
Bob Mottram's avatar
Bob Mottram committed
    git checkout "$PLEROMA_FRONTEND_COMMIT" -b "$PLEROMA_FRONTEND_COMMIT"
Bob Mottram's avatar
Bob Mottram committed
    set_completion_param "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT"
Bob Mottram's avatar
Bob Mottram committed
    if [ -d "$INSTALL_DIR/pleroma/node_modules" ]; then
        rm -rf "$INSTALL_DIR/pleroma/node_modules"
    npm install -g yarn
Bob Mottram's avatar
Bob Mottram committed
    npm install -g eslint@3.19.0
    npm install -g eslint-plugin-promise@3.5.0
    npm install -g moment@2.18.1
Bob Mottram's avatar
Bob Mottram committed
    npm install -g node-sass@4.5.2
    npm install -g whatwg-fetch@2.0.3
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "$INSTALL_DIR/pleroma/dist/index.html" ]; then
Bob Mottram's avatar
Bob Mottram committed
        rm -rf "$INSTALL_DIR/pleroma/dist/"*
Bob Mottram's avatar
Bob Mottram committed
    fi
    npm run build
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "$INSTALL_DIR/pleroma/dist" ]; then
        echo 'Unable to build pleroma'
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -f "$INSTALL_DIR/pleroma/dist/index.html" ]; then
Bob Mottram's avatar
Bob Mottram committed
        echo $'Unable to build pleroma index.html'
    if [[ "$app_name" != 'pleroma' ]]; then
Bob Mottram's avatar
Bob Mottram committed
        cp -r "$INSTALL_DIR/pleroma/dist/"* "/var/www/${pleroma_domain}/htdocs/"
Bob Mottram's avatar
Bob Mottram committed
        pleroma_set_background_image_from_url "/var/www/${pleroma_domain}/htdocs" "$pleroma_domain" "$background_url" "$title"
Bob Mottram's avatar
Bob Mottram committed
        cp -r "$INSTALL_DIR/pleroma/dist/"* "$PLEROMA_DIR/priv/static"
Bob Mottram's avatar
Bob Mottram committed
        pleroma_set_background_image_from_url "$PLEROMA_DIR/priv/static" "$pleroma_domain" "$background_url" "$title"
Bob Mottram's avatar
Bob Mottram committed
    nginx_site="/etc/nginx/sites-available/${pleroma_domain}"
    sed -i 's|index index.php;|index index.html;|g' "$nginx_site"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/${pleroma_domain}/htdocs/index.php" ]; then
Bob Mottram's avatar
Bob Mottram committed
        # shellcheck disable=SC2086
        mv /var/www/${pleroma_domain}/htdocs/index.php /var/www/${pleroma_domain}/htdocs/index_qvitter.php
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    sed -i 's|index.php|index_qvitter.php|g' "$nginx_site"
Bob Mottram's avatar
Bob Mottram committed

    # remove any cached yarn files
    if [ -d /root/.cache/yarn ]; then
        rm -rf /root/.cache/yarn
    fi

    if [[ "$app_name" != 'pleroma' ]]; then
Bob Mottram's avatar
Bob Mottram committed
        chown -R www-data:www-data "/var/www/${pleroma_domain}/htdocs"
Bob Mottram's avatar
Bob Mottram committed
        chown -R pleroma:pleroma "$PLEROMA_DIR"
Bob Mottram's avatar
Bob Mottram committed
function upgrade_pleroma_frontend {
    domain_name="$1"
    app_name="$2"
    background_url="$3"
    title="$4"

Bob Mottram's avatar
Bob Mottram committed
    if [ -d "$INSTALL_DIR/pleroma" ]; then
        set_repo_commit "$INSTALL_DIR/pleroma" "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT" "$PLEROMA_FRONTEND_REPO"
        cd "$INSTALL_DIR/pleroma" || exit 34
        npm run build
Bob Mottram's avatar
Bob Mottram committed
        if [ ! -d "$INSTALL_DIR/pleroma/dist" ]; then
            echo 'Unable to build pleroma'
Bob Mottram's avatar
Bob Mottram committed
        basedir="/var/www/${domain_name}/htdocs"
Bob Mottram's avatar
Bob Mottram committed
        if [[ "$app_name" == 'pleroma' ]]; then
Bob Mottram's avatar
Bob Mottram committed
            basedir="$PLEROMA_DIR/priv/static"
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "$basedir/static/logo.png" ]; then
            cp "$basedir/static/logo.png" "$basedir/static/logo.png.old"
Bob Mottram's avatar
Bob Mottram committed
        fi
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "$basedir/static/bg.jpg" ]; then
            cp "$basedir/static/bg.jpg" "$basedir/static/bg.jpg.old"
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "$basedir/static/config.json" ]; then
            cp "$basedir/static/config.json" "$basedir/static/config.json.old"
Bob Mottram's avatar
Bob Mottram committed
        cp -r "$INSTALL_DIR/pleroma/dist/"* "$basedir/"
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "$basedir/static/config.json.old" ]; then
Bob Mottram's avatar
Bob Mottram committed
            # shellcheck disable=SC2086
            mv $basedir/static/config.json.old $basedir/static/config.json
Bob Mottram's avatar
Bob Mottram committed
        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/static/config.json"
        if [ -f "$basedir/static/logo.png.old" ]; then
            cp "$basedir/static/logo.png.old" "$basedir/static/logo.png"
Bob Mottram's avatar
Bob Mottram committed
        fi
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "$basedir/static/bg.jpg.old" ]; then
            cp "$basedir/static/bg.jpg.old" "$basedir/static/bg.jpg"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
        if [ -f "$basedir/index.php" ]; then
Bob Mottram's avatar
Bob Mottram committed
            # shellcheck disable=SC2086
            mv $basedir/index.php $basedir/index_qvitter.php
Bob Mottram's avatar
Bob Mottram committed
        fi
Bob Mottram's avatar
Bob Mottram committed
        chown -R www-data:www-data "$basedir"
        install_pleroma_front_end "${app_name}" "${domain_name}" "${background_url}" "${title}"
function gnusocial_hourly_script {
Bob Mottram's avatar
Bob Mottram committed
    gnusocial_type="$1"
    domain_name="$2"

    # check that the daemon is running
Bob Mottram's avatar
Bob Mottram committed
    { echo '#!/bin/bash';
      echo -n "daemon_lines=\$(ps aux | grep \"";
      echo -n "${domain_name}";
      echo '/htdocs/scripts/queuedaemon.php" | grep "/var/www")';
      echo "cd /var/www/${domain_name}/htdocs";
      echo "if [[ \$daemon_lines != *\"/var/www/\"* ]]; then";
      echo "    UPTIME=\$(awk -F '.' '{print \$1}' < \"/proc/uptime\")";
      echo "    if [ \"\$UPTIME\" -gt 500 ]; then";
      echo "        ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')";
      echo "        MY_EMAIL_ADDRESS=\$ADMIN_USER@$HOSTNAME";
Bob Mottram's avatar
Bob Mottram committed
      echo -n "        /bin/bash /usr/local/bin/${PROJECT_NAME}-notification -m \"Restarting ${gnusocial_type} daemons\" -s \"${gnusocial_type} ";
      echo "daemons not found\"";
Bob Mottram's avatar
Bob Mottram committed
      echo '    su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data';
      echo 'fi';
      echo 'php scripts/delete_orphan_files.php > /dev/null';
      echo 'php scripts/clean_thumbnails.php -y > /dev/null';
      echo 'php scripts/clean_file_table.php -y > /dev/null';
      echo 'php scripts/upgrade.php > /dev/null'; } > "/etc/cron.hourly/${gnusocial_type}-daemons"

    chmod +x "/etc/cron.hourly/${gnusocial_type}-daemons"
function gnusocial_block_user_script {
Bob Mottram's avatar
Bob Mottram committed
    { echo '#!/bin/bash';
      echo '';
      echo "database_name=\$1";
      echo "remove_user=\$2";
      echo "domain_name=\$3";
Bob Mottram's avatar
Bob Mottram committed
      echo "MARIADB_PASSWORD=\$(${PROJECT_NAME}-pass -u root -a mariadb)";
Bob Mottram's avatar
Bob Mottram committed
      echo '';
      echo "if [ \${#remove_user} -lt 2 ]; then";
      echo '  echo $"No user was specified"';
      echo '  exit 1';
      echo 'fi';
      echo '';
      echo "if [[ \"\$remove_user\" != *\".\"* || \"\$remove_user\" != *\"@\"* ]]; then";
      echo '  echo $"This doesnt look like a user"';
      echo '  exit 2';
      echo 'fi';
      echo '';
      echo "if [ \${#database_name} -lt 2 ]; then";
      echo '  echo $"No database was specified"';
      echo '  exit 3';
      echo 'fi';
      echo '';
      echo "nickname=\$(echo \"\$remove_user\" | awk -F '@' '{print \$1}')";
      echo "remove_domain=\$(echo \"\$remove_user\" | awk -F '@' '{print \$2}')";
      echo '';
      echo "database_query=\"delete from notice where content REGEXP '\\@\${remove_user}';\"";
      echo "mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '';
      echo "database_query=\"select profile.id from profile where nickname = '\${nickname}' and profileurl like '%\${remove_domain}%';\"";
      echo "declare -a ids=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF";
      echo "use \$database_name;";
      echo "\$database_query";
      echo 'EOF';
      echo ')';
      echo '';
      echo 'ctr=0';
      echo "for id in \$ids";
      echo 'do';
      echo "  if [ \$ctr -gt 0 ]; then";
      echo "      #echo \"Removing user ID \$id on \$remove_domain\"";
      echo '';
      echo "      database_query=\"delete from reply where profile_id=\${id};\"";
      echo "      mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '';
      echo "      database_query=\"delete from reply where replied_id=\${id};\"";
      echo "      mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '';
      echo "      if [ \$domain_name ]; then";
      echo "          database_query=\"select rendered from notice where profile_id=\${id} and rendered like '%/file/%';\"";
      echo "          declare -a stored_files=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF";
      echo "use \$database_name;";
      echo "\$database_query";
      echo 'EOF';
      echo ')';
      echo -n "          files_to_delete=\$(echo \"\$stored_files\" | ";
      echo "sed -n 's/.*href=\"\\([^\"]*\\).*/\\1/p' | awk -F 'file/' '{print \$2}')";
      echo '          filectr=0';
      echo "          for f in \$files_to_delete";
      echo '          do';
      echo "              if [ \$filectr -gt 0 ]; then";
      echo "                  if \$(ls /var/www/\${domain_name}/htdocs/file/*\${f}* 1> /dev/null 2>&1); then";
      echo "                      rm /var/www/\${domain_name}/htdocs/file/*\${f}*";
      echo '                  fi';
      echo '              fi';
      echo "              filectr=\$((filectr + 1))";
      echo '          done';
      echo '      fi';
      echo '';
      echo "      database_query=\"delete from notice where profile_id=\${id};\"";
      echo "      mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '';
      echo "      database_query=\"delete from profile where id=\${id};\"";
      echo "      mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '';
      echo "      database_query=\"delete from qvitternotification where to_profile_id=\${id} or from_profile_id=\${id};\"";
      echo "      mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '  fi';
      echo "  ctr=\$((ctr + 1))";
      echo 'done'; } > /usr/bin/gnusocial-delete-user
    chmod +x /usr/bin/gnusocial-delete-user
}

function gnusocial_block_domain_script {
Bob Mottram's avatar
Bob Mottram committed
    database_name="$1"
    gnusoc_domain="$2"

    { echo '#!/bin/bash';
      echo '';
      echo "database_name=\$1";
      echo "remove_domain=\$2";
      echo "domain_name=\$3";
      echo "MARIADB_PASSWORD=\$(${PROJECT_NAME}-pass -u root -a mariadb)";
      echo '';
      echo "if [ \${#remove_domain} -lt 2 ]; then";
      echo '    echo $"No domain was specified"';
      echo '    exit 1';
      echo 'fi';
      echo '';
      echo "if [[ \"\$remove_domain\" != *\".\"* ]]; then";
      echo '    echo $"This doesnt look like a domain"';
      echo '    exit 2';
      echo 'fi';
      echo '';
      echo "if [ \${#database_name} -lt 2 ]; then";
      echo '    echo $"No database was specified"';
      echo '    exit 3';
      echo 'fi';
      echo '';
      echo "database_query=\"select profile.id from profile where profileurl like '%\${remove_domain}%';\"";
      echo "declare -a ids=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF";
      echo "use \$database_name;";
      echo "\$database_query";
      echo 'EOF';
      echo ')';
      echo '';
      echo 'ctr=0';
      echo "for id in \$ids";
      echo 'do';
      echo "    if [ \$ctr -gt 0 ]; then";
      echo "        #echo \"Removing user ID \$id on \$remove_domain\"";
      echo '';
      echo "        database_query=\"delete from conversation where uri like '%\${remove_domain}%';\"";
      echo "        mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '';
      echo "        database_query=\"delete from reply where profile_id=\${id};\"";
      echo "        mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" $database_name";
      echo '';
      echo "        database_query=\"delete from reply where replied_id=\${id};\"";
      echo "        mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '';
      echo "        if [ \$domain_name ]; then";
      echo "          database_query=\"select rendered from notice where profile_id=\${id} and rendered like '%/file/%';\"";
      echo "          declare -a stored_files=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF";
      echo "use \$database_name;";
      echo "\$database_query";
      echo 'EOF';
      echo ')';
      echo -n "           files_to_delete=\$(echo \"\$stored_files\" | ";
      echo "sed -n 's/.*href=\"\\([^\"]*\\).*/\\1/p' | awk -F 'file/' '{print \$2}')";
      echo '            filectr=0';
      echo "            for f in \$files_to_delete";
      echo '            do';
      echo "                if [ \$filectr -gt 0 ]; then";
      echo "                    if \$(ls /var/www/\${domain_name}/htdocs/file/*\${f}* 1> /dev/null 2>&1); then";
      echo "                        rm /var/www/\${domain_name}/htdocs/file/*\${f}*";
      echo '                    fi';
      echo '                fi';
      echo "                filectr=\$((filectr + 1))";
      echo '            done';
      echo '        fi';
      echo '';
      echo "        database_query=\"delete from notice where profile_id=\${id};\"";
      echo "        mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" $database_name";
      echo '';
      echo "        database_query=\"delete from profile where id=\${id};\"";
      echo "        mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '';
      echo "        database_query=\"delete from qvitternotification where to_profile_id=\${id} or from_profile_id=\${id};\"";
      echo "        mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name";
      echo '    fi';
      echo "    ctr=\$((ctr + 1))";
      echo 'done'; } > /usr/bin/gnusocial-delete-domain
    chmod +x /usr/bin/gnusocial-delete-domain

Bob Mottram's avatar
Bob Mottram committed
    { echo '#!/bin/bash';
      echo '';
      echo "PROJECT_NAME=$PROJECT_NAME";
      echo "GNUSOCIAL_DOMAIN_NAME=$gnusoc_domain";
      echo "database_name=$database_name";
      echo "FIREWALL_DOMAINS=\$HOME/\${PROJECT_NAME}-firewall-domains.cfg";
      echo '';
      echo 'while read block; do';
      echo "    if [[ \"\$block\" != *\"@\"* ]]; then";
      echo "        /usr/bin/gnusocial-delete-domain \"\$database_name\" \"\$block\" \"\$GNUSOCIAL_DOMAIN_NAME\"";
      echo '    else';
      echo "        /usr/bin/gnusocial-delete-user \"\$database_name\" \"\$block\" \"\$GNUSOCIAL_DOMAIN_NAME\"";
      echo '    fi';
      echo "done <\$FIREWALL_DOMAINS";
      echo '';
      echo '# remove any metadata from images uploaded in the last 2 minutes';
      echo "if [ -d /var/www/\$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then";
      echo "    cd /var/www/\$GNUSOCIAL_DOMAIN_NAME/htdocs";
      echo "    declare -a recent_image=\$(find file ! -name thumb-* -mmin -2 -type f -exec ls -l {} + | awk -F 'file/' '{print \$2}')";
      echo "    for f in \${recent_image[@]}";
      echo '    do';
      echo "        if [ \${#f} -gt 1 ]; then";
      echo "            exiftool -q -all= \"file/\${f}\"";
      echo '        fi';
      echo '    done';
      echo 'fi'; } > "/usr/bin/${database_name}-firewall"
    chmod +x "/usr/bin/${database_name}-firewall"

    if ! grep -q "${database_name}-firewall" /etc/crontab; then
Bob Mottram's avatar
Bob Mottram committed
        cron_add_mins 1 "/usr/bin/${database_name}-firewall"
function expire_gnusocial_posts {
Bob Mottram's avatar
Bob Mottram committed
    domain_name="$1"
    gnusocial_type="$2"
    expire_months="$3"
Bob Mottram's avatar
Bob Mottram committed
    if [ ! "$expire_months" ]; then
Bob Mottram's avatar
Bob Mottram committed
    #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
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/${domain_name}/htdocs" ]; then
Bob Mottram's avatar
Bob Mottram committed
    gnusocial_expire_posts_script="/usr/bin/${gnusocial_type}-expire-posts"

    { echo '<?php';
      echo '':
      echo "// ${gnusocial_type} post expiry script, based on StatExpire by Tony Baldwin";
      echo '// https://github.com/tonybaldwin/statexpire';
      echo '';
      echo "\$oldate=date((\"Y-m-d\"), strtotime(\"-${expire_months} months\"));";
      echo "\$username=\"root\";";
      echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');";
      echo "\$database=\"${gnusocial_type}\";";
      echo '';
      echo "if (!\$link = mysqli_connect(\"localhost\", \$username, \$password)) {";
      echo '    echo "Could not connect to mariadb";';
      echo '    exit;';
      echo '}';
      echo '';
      echo "if (!mysqli_select_db(\$link, \$database)) {";
      echo "    echo \"Could not select ${gnusocial_type} database\";";
      echo '    exit;';
      echo '}';
      echo '';
      echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";";
      echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '\$oldate 01:01:01'\";";
      echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";";
      echo "\$notification_query=\"DELETE FROM qvitternotification WHERE created <= '\$oldate 01:01:01'\";";
      echo '';
      echo "mysqli_query(\$link, \$notice_query);";
      echo "\$rowaff1=mysqli_affected_rows(\$link);";
      echo "mysqli_query(\$link, \$conversation_query);";
      echo "\$rowaff2=mysqli_affected_rows(\$link);";
      echo "mysqli_query(\$link, \$reply_query);";
      echo "\$rowaff3=mysqli_affected_rows(\$link);";
      echo "mysqli_query(\$link, \$notification_query);";
      echo "\$rowaff4=mysqli_affected_rows(\$link);";
      echo "mysqli_close(\$link);";
      echo '';
      echo "echo \"Expire ${gnusocial_type} posts: \$rowaff1 notices, \$rowaff2 conversations, \$rowaff3 replies, and \$rowaff4 qvitter notifications deleted from database.\";"; } > "$gnusocial_expire_posts_script"
    chmod +x "$gnusocial_expire_posts_script"

    gnusocial_expire_script="/etc/cron.daily/${gnusocial_type}-expire"
    { echo '#!/bin/bash';
      echo "find /var/www/${domain_name}/htdocs/file/* -mtime +${expire_days_files} -exec rm {} +";
      echo "/usr/bin/php $gnusocial_expire_posts_script"; } > "$gnusocial_expire_script"
    chmod +x "$gnusocial_expire_script"
    # remove any old cron job
    if grep -q "${gnusocial_type}-expire" /etc/crontab; then
        sed -i "/${gnusocial_type}-expire/d" /etc/crontab
Bob Mottram's avatar
Bob Mottram committed
        rm "/usr/bin/${gnusocial_type}-expire"
    fi

    # remove old expire script
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/etc/cron.weekly/clear-${gnusocial_type}-database" ]; then
        rm "/etc/cron.weekly/clear-${gnusocial_type}-database"
function gnusocial_use_classic {
    database_name=$1

    domain_name=$(get_completion_param "$database_name domain")

Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/$domain_name/htdocs/index_qvitter.php" ]; then
Bob Mottram's avatar
Bob Mottram committed
        # shellcheck disable=SC2086
        mv /var/www/$domain_name/htdocs/index_qvitter.php /var/www/$domain_name/htdocs/index.php
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/etc/nginx/sites-available/$domain_name" ]; then
        sed -i 's|index_qvitter.php|index.php|g' "/etc/nginx/sites-available/$domain_name"
        sed -i 's|index.html|index.php|g' "/etc/nginx/sites-available/$domain_name"
        sed -i 's|#add_header Content-Security-Policy|add_header Content-Security-Policy|g' "/etc/nginx/sites-available/$domain_name"
Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
        sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
        sed -i "s|addPlugin('Qvitter')|//addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
    fuser -k 80/tcp
    fuser -k 443/tcp
function gnusocial_use_qvitter {
    database_name=$1

    domain_name=$(get_completion_param "$database_name domain")

Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/$domain_name/htdocs/index_qvitter.php" ]; then
Bob Mottram's avatar
Bob Mottram committed
        # shellcheck disable=SC2086
        mv /var/www/$domain_name/htdocs/index_qvitter.php /var/www/$domain_name/htdocs/index.php
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/etc/nginx/sites-available/$domain_name" ]; then
        sed -i 's|index_qvitter.php|index.php|g' "/etc/nginx/sites-available/$domain_name"
        sed -i 's|index.html|index.php|g' "/etc/nginx/sites-available/$domain_name"
        if ! grep -q "#add_header Content-Security-Policy" "/etc/nginx/sites-available/$domain_name"; then
            sed -i 's|add_header Content-Security-Policy|#add_header Content-Security-Policy|g' "/etc/nginx/sites-available/$domain_name"
        fi
Bob Mottram's avatar
Bob Mottram committed
    if grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
        sed -i "s|//addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
Bob Mottram's avatar
Bob Mottram committed
    if grep -q "// addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
        sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
    fuser -k 80/tcp
    fuser -k 443/tcp
    systemctl restart nginx
    # shellcheck disable=SC2086
    systemctl restart php${PHP_VERSION}-fpm
}

function gnusocial_use_pleroma {
Bob Mottram's avatar
Bob Mottram committed
    database_name="$1"

    domain_name=$(get_completion_param "$database_name domain")

Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/$domain_name/htdocs/static" ]; then
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/$domain_name/htdocs/index.php" ]; then
Bob Mottram's avatar
Bob Mottram committed
        # shellcheck disable=SC2086
        mv /var/www/$domain_name/htdocs/index.php /var/www/$domain_name/htdocs/index_qvitter.php
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/etc/nginx/sites-available/$domain_name" ]; then
        sed -i 's|index.php|index_qvitter.php|g' "/etc/nginx/sites-available/$domain_name"
        sed -i 's|index index_qvitter.php|index index.html|g' "/etc/nginx/sites-available/$domain_name"
        sed -i 's|#add_header Content-Security-Policy|add_header Content-Security-Policy|g' "/etc/nginx/sites-available/$domain_name"
Bob Mottram's avatar
Bob Mottram committed
    if grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
        sed -i "s|//addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
Bob Mottram's avatar
Bob Mottram committed
    if grep -q "// addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then
        sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php"
Bob Mottram's avatar
Bob Mottram committed
    cp "$INSTALL_DIR/pleroma/dist/index.html" "/var/www/${domain_name}/htdocs/index.html"
Bob Mottram's avatar
Bob Mottram committed
    chmod +x static/css
    chmod +x static/font
    chmod +x static/font/css
    chmod +x static/font/font
    chmod +x static/js
    chmod +x static
Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/${domain_name}/htdocs"
Bob Mottram's avatar
Bob Mottram committed

    fuser -k 80/tcp
    fuser -k 443/tcp
Bob Mottram's avatar
Bob Mottram committed
    systemctl restart nginx
}

function install_gnusocial_plugin_sharings {
Bob Mottram's avatar
Bob Mottram committed
    domain_name="$1"
    social_app_name="$2"
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/$domain_name/htdocs/local/plugins" ]; then
        mkdir -p "/var/www/$domain_name/htdocs/local/plugins"
    $INSTALL_PACKAGES liblocale-msgfmt-perl gettext

    # update to the next commit
    function_check set_repo_commit
Bob Mottram's avatar
Bob Mottram committed
    set_repo_commit "/var/www/$domain_name/htdocs/local/plugins/Sharings" "$social_app_name sharings plugin commit" "$SHARINGS_COMMIT" "$SHARINGS_REPO"
Bob Mottram's avatar
Bob Mottram committed
    if [[ $(app_is_installed "${social_app_name}_plugin_sharings") == "1" ]]; then
    cd "/var/www/$domain_name/htdocs/local/plugins" || exit 28

    if [ -d /repos/sharings ]; then
        mkdir Sharings
        cp -r -p /repos/sharings/. Sharings
        cd Sharings || exit 25
        git pull
    else
        function_check git_clone
Bob Mottram's avatar
Bob Mottram committed
        git_clone "$SHARINGS_REPO" Sharings
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/$domain_name/htdocs/local/plugins/Sharings" ]; then
        echo $"Unable to clone $social_app_name sharings plugin"
    cd "/var/www/$domain_name/htdocs/local/plugins/Sharings" || exit 28
    git stash
    git checkout master
Bob Mottram's avatar
Bob Mottram committed
    git branch -D "$SHARINGS_COMMIT"
    git checkout "$SHARINGS_COMMIT" -b "$SHARINGS_COMMIT"

    # enable the plugin
Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q "addPlugin('Sharings');" "/var/www/$domain_name/htdocs/config.php"; then
        echo "addPlugin('Sharings');" >> "/var/www/$domain_name/htdocs/config.php"
    cd "/var/www/$domain_name/htdocs" || exit 26
    php scripts/checkschema.php
    cd "/var/www/$domain_name/htdocs/local/plugins/Sharings" || exit 24
    php scripts/seedsharings.php
    cd "/var/www/$domain_name/htdocs" || exit 23
    php scripts/upgrade.php
    php scripts/checkschema.php

    # Languages
    cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES" || exit 53
    msgfmt -o Sharings.mo Sharings.po
    if [ ! -f Sharings.po ]; then
        echo $"English translations for $social_app_name sharings plugin were not created"
    cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES" || exit 26
    msgfmt -o Sharings.mo Sharings.po
    if [ ! -f Sharings.po ]; then
        echo $"English (GB) translations for $social_app_name sharings plugin were not created"
    cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES" || exit 29
    msgfmt -o Sharings.mo Sharings.po
    if [ ! -f Sharings.po ]; then
        echo $"English (US) translations for $social_app_name sharings plugin were not created"
    fi

    # Looks like this update function isn't supported by the current php version
Bob Mottram's avatar
Bob Mottram committed
    sed -i 's|ActivityVerb::UPDATE, ||g' "/var/www/$domain_name/htdocs/local/plugins/Sharings/SharingsPlugin.php"
Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/$domain_name/htdocs"

    set_completion_param gnusocial "$social_app_name sharings plugin commit" "$SHARINGS_COMMIT"
Bob Mottram's avatar
Bob Mottram committed
    install_completed "${social_app_name}_plugin_sharings"
}

function install_gnusocial_plugin_sharings_theme {
Bob Mottram's avatar
Bob Mottram committed
    domain_name="$1"
    social_app_name="$2"
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/$domain_name/htdocs/local/plugins" ]; then
        mkdir -p "/var/www/$domain_name/htdocs/local/plugins"
    fi

    # update to the next commit
    function_check set_repo_commit
Bob Mottram's avatar
Bob Mottram committed
    set_repo_commit "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" "$social_app_name sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" "$SHARINGS_THEME_REPO"
Bob Mottram's avatar
Bob Mottram committed
    if [[ $(app_is_installed "${social_app_name}_plugin_sharings_theme") == "1" ]]; then
    cd "/var/www/$domain_name/htdocs/local/plugins" || exit 68
    function_check git_clone
Bob Mottram's avatar
Bob Mottram committed
    git_clone "$SHARINGS_THEME_REPO" SharingsTheme
    if [ ! -d "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" ]; then
        echo $"Unable to clone $social_app_name sharings plugin theme"
    cd "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" || exit 26
    git stash
    git checkout master
Bob Mottram's avatar
Bob Mottram committed
    git branch -D "$SHARINGS_THEME_COMMIT"
    git checkout "$SHARINGS_THEME_COMMIT" -b "$SHARINGS_THEME_COMMIT"

    # enable the plugin
Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q "addPlugin('SharingsTheme');" "/var/www/$domain_name/htdocs/config.php"; then
        echo "addPlugin('SharingsTheme');" >> "/var/www/$domain_name/htdocs/config.php"
    cd "/var/www/$domain_name/htdocs" || exit 24
    php scripts/checkschema.php

Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/$domain_name/htdocs"

    set_completion_param "$social_app_name sharings plugin theme commit" "$SHARINGS_THEME_COMMIT"
Bob Mottram's avatar
Bob Mottram committed
    install_completed "${social_app_name}_plugin_sharings_theme"
function install_gnusocial_markdown {
Bob Mottram's avatar
Bob Mottram committed
    domain_name="$1"
    social_app_name="$2"