Skip to content
Snippets Groups Projects
freedombone-app-postactiv 34.3 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
#
# postactiv application
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2016-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/>.

VARIANTS='full full-vim media'

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
Bob Mottram's avatar
Bob Mottram committed
NOT_ON_ONION=0
Bob Mottram's avatar
Bob Mottram committed

POSTACTIV_DOMAIN_NAME=
POSTACTIV_CODE=
POSTACTIV_ONION_PORT=8100
POSTACTIV_REPO="http://gitea.postactiv.com/postActiv/postActiv.git"
Bob Mottram's avatar
Bob Mottram committed
POSTACTIV_COMMIT='02c981a10b'
Bob Mottram's avatar
Bob Mottram committed
POSTACTIV_ADMIN_PASSWORD=

POSTACTIV_BACKGROUND_IMAGE_URL=
POSTACTIV_TITLE='PostActiv'

# Number of months after which posts expire
POSTACTIV_EXPIRE_MONTHS=3
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
POSTACTIV_SHORT_DESCRIPTION=$'Federated microblogging'
POSTACTIV_DESCRIPTION=$'Federated microblogging'
POSTACTIV_MOBILE_APP_URL='https://f-droid.org/packages/org.mariotaku.twidere/'

postactiv_variables=(ONION_ONLY
Bob Mottram's avatar
Bob Mottram committed
                     POSTACTIV_DOMAIN_NAME
                     POSTACTIV_CODE
                     DDNS_PROVIDER
                     MY_USERNAME
                     POSTACTIV_BACKGROUND_IMAGE_URL
                     POSTACTIV_EXPIRE_MONTHS
                     POSTACTIV_TITLE)
Bob Mottram's avatar
Bob Mottram committed

function logging_on_postactiv {
    echo -n ''
}

function logging_off_postactiv {
    echo -n ''
}

Bob Mottram's avatar
Bob Mottram committed
function postactiv_customise_logo {
    domain_name=$1

Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/${domain_name}/htdocs/static/logo.png" ]; then
Bob Mottram's avatar
Bob Mottram committed
        if [ -f "$HOME/${PROJECT_NAME}/img/postactiv.png" ]; then
            cp "$HOME/${PROJECT_NAME}/img/postactiv.png" "/var/www/${domain_name}/htdocs/static/logo.png"
Bob Mottram's avatar
Bob Mottram committed
        else
Bob Mottram's avatar
Bob Mottram committed
            if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/postactiv.png" ]; then
                cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/postactiv.png" "/var/www/${domain_name}/htdocs/static/logo.png"
Bob Mottram's avatar
Bob Mottram committed
function remove_user_postactiv {
    remove_username="$1"

Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp postactiv
Bob Mottram's avatar
Bob Mottram committed
    function_check get_completion_param
    POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
Bob Mottram's avatar
Bob Mottram committed
    if [ -d "/var/www/$POSTACTIV_DOMAIN_NAME" ]; then
        cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 3658254254
        php scripts/deleteprofile.php -n "$remove_username" -y
Bob Mottram's avatar
Bob Mottram committed
    fi
}

function add_user_postactiv {
    new_username="$1"
    new_user_password="$2"

Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-pass" -u "$new_username" -a postactiv -p "$new_user_password"
Bob Mottram's avatar
Bob Mottram committed
    POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
Bob Mottram's avatar
Bob Mottram committed
    if [ -d "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs" ]; then
        cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 346846834
        php scripts/registeruser.php -n "$new_username" -w "$new_user_password" -e "$new_username@$HOSTNAME"
        "${PROJECT_NAME}-addemail" -u "$new_username" -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
Bob Mottram's avatar
Bob Mottram committed
        echo '0'
    else
        echo '1'
    fi
}

function install_interactive_postactiv {
Bob Mottram's avatar
Bob Mottram committed
    if [ ! "$ONION_ONLY" ]; then
Bob Mottram's avatar
Bob Mottram committed
        ONION_ONLY='no'
    fi

    if [[ $ONION_ONLY != "no" ]]; then
        POSTACTIV_DOMAIN_NAME='postactiv.local'
    else
        POSTACTIV_DETAILS_COMPLETE=
        while [ ! $POSTACTIV_DETAILS_COMPLETE ]
        do
Bob Mottram's avatar
Bob Mottram committed
            data=$(mktemp 2>/dev/null)
            if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
Bob Mottram's avatar
Bob Mottram committed
                dialog --backtitle $"Freedombone Configuration" \
                       --title $"PostActiv Configuration" \
Bob Mottram's avatar
Bob Mottram committed
                       --form $"\\nPlease enter your PostActiv 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 \
Bob Mottram's avatar
Bob Mottram committed
                       $"Domain:" 1 1 "$(grep 'POSTACTIV_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
Bob Mottram's avatar
Bob Mottram committed
                       $"Title:" 2 1 "$(grep "$POSTACTIV_TITLE" temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
                       $"Background image URL:" 3 1 "$(grep "$POSTACTIV_BACKGROUND_IMAGE_URL" temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
                       $"Code:" 4 1 "$(grep 'POSTACTIV_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
Bob Mottram's avatar
Bob Mottram committed
                       2> "$data"
Bob Mottram's avatar
Bob Mottram committed
            else
                dialog --backtitle $"Freedombone Configuration" \
                       --title $"PostActiv Configuration" \
Bob Mottram's avatar
Bob Mottram committed
                       --form $"\\nPlease enter your PostActiv 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 \
Bob Mottram's avatar
Bob Mottram committed
                       $"Domain:" 1 1 "$(grep 'POSTACTIV_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
Bob Mottram's avatar
Bob Mottram committed
                       $"Title:" 2 1 "$(grep "$POSTACTIV_TITLE" temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
                       $"Background image URL:" 3 1 "$(grep "$POSTACTIV_BACKGROUND_IMAGE_URL" temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
                       2> "$data"
Bob Mottram's avatar
Bob Mottram committed
            fi
            sel=$?
            case $sel in
Bob Mottram's avatar
Bob Mottram committed
                1) rm -f "$data"
                   exit 1;;
                255) rm -f "$data"
                     exit 1;;
Bob Mottram's avatar
Bob Mottram committed
            esac
Bob Mottram's avatar
Bob Mottram committed
            POSTACTIV_DOMAIN_NAME=$(sed -n 1p < "$data")
            title=$(sed -n 2p < "$data")
Bob Mottram's avatar
Bob Mottram committed
                POSTACTIV_TITLE=$title
Bob Mottram's avatar
Bob Mottram committed
            img_url=$(sed -n 3p < "$data")
            if [ ${#img_url} -gt 1 ]; then
                POSTACTIV_BACKGROUND_IMAGE_URL=$img_url
            fi
Bob Mottram's avatar
Bob Mottram committed
            if [ "$POSTACTIV_DOMAIN_NAME" ]; then
                if [[ "$POSTACTIV_DOMAIN_NAME" == "$HUBZILLA_DOMAIN_NAME" ]]; then
Bob Mottram's avatar
Bob Mottram committed
                    POSTACTIV_DOMAIN_NAME=""
                fi
                TEST_DOMAIN_NAME=$POSTACTIV_DOMAIN_NAME
                validate_domain_name
Bob Mottram's avatar
Bob Mottram committed
                if [[ "$TEST_DOMAIN_NAME" != "$POSTACTIV_DOMAIN_NAME" ]]; then
Bob Mottram's avatar
Bob Mottram committed
                    POSTACTIV_DOMAIN_NAME=
                    dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
                else
                    if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
Bob Mottram's avatar
Bob Mottram committed
                        POSTACTIV_CODE=$(sed -n 4p < "$data")
Bob Mottram's avatar
Bob Mottram committed
                        validate_freedns_code "$POSTACTIV_CODE"
Bob Mottram's avatar
Bob Mottram committed
                        if [ ! "$VALID_CODE" ]; then
Bob Mottram's avatar
Bob Mottram committed
                            POSTACTIV_DOMAIN_NAME=
                        fi
                    fi
                fi
            fi
            if [ $POSTACTIV_DOMAIN_NAME ]; then
                POSTACTIV_DETAILS_COMPLETE="yes"
            fi
Bob Mottram's avatar
Bob Mottram committed
            rm -f "$data"
Bob Mottram's avatar
Bob Mottram committed
        done

        # remove any invalid characters
        if [ ${#POSTACTIV_TITLE} -gt 0 ]; then
Bob Mottram's avatar
Bob Mottram committed
            new_title=${POSTACTIV_TITLE//\'/}
Bob Mottram's avatar
Bob Mottram committed
        # save the results in the config file
        write_config_param "POSTACTIV_CODE" "$POSTACTIV_CODE"
        write_config_param "POSTACTIV_TITLE" "$POSTACTIV_TITLE"
        write_config_param "POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_BACKGROUND_IMAGE_URL"
Bob Mottram's avatar
Bob Mottram committed
    fi
    write_config_param "POSTACTIV_DOMAIN_NAME" "$POSTACTIV_DOMAIN_NAME"
    APP_INSTALLED=1
}

function change_password_postactiv {
Bob Mottram's avatar
Bob Mottram committed
    curr_username="$1"
    new_user_password="$2"

Bob Mottram's avatar
Bob Mottram committed
    read_config_param 'POSTACTIV_DOMAIN_NAME'
Bob Mottram's avatar
Bob Mottram committed
    cd "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts" || exit 246824682
    php setpassword.php "$curr_username" "$new_user_password"
Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-pass" -u "$curr_username" -a postactiv -p "$new_user_password"
Bob Mottram's avatar
Bob Mottram committed
}

function postactiv_create_database {
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
        POSTACTIV_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
Bob Mottram's avatar
Bob Mottram committed
        if [ ! "$POSTACTIV_ADMIN_PASSWORD" ]; then
            POSTACTIV_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
Bob Mottram's avatar
Bob Mottram committed
        fi
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ ! "$POSTACTIV_ADMIN_PASSWORD" ]; then
Bob Mottram's avatar
Bob Mottram committed
        return
    fi

    function_check create_database
Bob Mottram's avatar
Bob Mottram committed
    create_database postactiv "$POSTACTIV_ADMIN_PASSWORD" "$MY_USERNAME"
Bob Mottram's avatar
Bob Mottram committed
}

function postactiv_running_script {
    gnusocial_hourly_script postactiv $POSTACTIV_DOMAIN_NAME
    # This was a hack to fix a bug in master, but may no longer be needed
Bob Mottram's avatar
Bob Mottram committed
    #echo "if ! grep -q \"//define('POSTACTIV',true);\" scripts/commandline.inc; then" >> /etc/cron.hourly/postactiv-daemons
    #echo "  sed -i \"s|define('POSTACTIV',true);|//define('POSTACTIV',true);|g\" scripts/commandline.inc" >> /etc/cron.hourly/postactiv-daemons
    #echo 'fi' >> /etc/cron.hourly/postactiv-daemons
Bob Mottram's avatar
Bob Mottram committed
}

function reconfigure_postactiv {
    echo -n ''
}

function postactiv_set_background_image {
Bob Mottram's avatar
Bob Mottram committed
    POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")

Bob Mottram's avatar
Bob Mottram committed
    data=$(mktemp 2>/dev/null)
    dialog --title $"PostActiv" \
           --backtitle $"Freedombone Control Panel" \
Bob Mottram's avatar
Bob Mottram committed
           --inputbox $'Set a background image URL' 10 60 2>"$data"
    sel=$?
    case $sel in
        0)
Bob Mottram's avatar
Bob Mottram committed
            temp_background=$(<"$data")
            if [ ${#temp_background} -gt 0 ]; then
                POSTACTIV_BACKGROUND_IMAGE_URL="$temp_background"
                write_config_param "POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_BACKGROUND_IMAGE_URL"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
                if [[ $(pleroma_set_background_image_from_url "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE" | tail -n 1) == "0" ]]; then
Bob Mottram's avatar
Bob Mottram committed
                    dialog --title $"Set PostActiv background" \
                           --msgbox $"The background image has been set" 6 60
                fi
Bob Mottram's avatar
Bob Mottram committed
    rm -f "$data"
}

function postactiv_set_title {
Bob Mottram's avatar
Bob Mottram committed
    data=$(mktemp 2>/dev/null)
    dialog --title $"PostActiv" \
           --backtitle $"Freedombone Control Panel" \
Bob Mottram's avatar
Bob Mottram committed
           --inputbox $'Set a title' 10 60 2>"$data"
    sel=$?
    case $sel in
        0)
Bob Mottram's avatar
Bob Mottram committed
            new_title=$(<"$data")
            if [ ${#new_title} -gt 0 ]; then
                POSTACTIV_TITLE="$new_title"
Bob Mottram's avatar
Bob Mottram committed
                POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
                write_config_param "POSTACTIV_TITLE" "$POSTACTIV_TITLE"
Bob Mottram's avatar
Bob Mottram committed
                cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/static" || exit 782452452
                sed -i "s|\"name\":.*|\"name\": \"${POSTACTIV_TITLE}\",|g" config.json
                dialog --title $"Set PostActiv title" \
                       --msgbox $"The title has been set" 6 60
            fi
           ;;
    esac
Bob Mottram's avatar
Bob Mottram committed
    rm -f "$data"
function postactiv_set_expire_months {
    POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
    read_config_param "POSTACTIV_EXPIRE_MONTHS"

Bob Mottram's avatar
Bob Mottram committed
    data=$(mktemp 2>/dev/null)
    dialog --title $"PostActiv" \
           --backtitle $"Freedombone Control Panel" \
Bob Mottram's avatar
Bob Mottram committed
           --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 "$POSTACTIV_EXPIRE_MONTHS" 2>"$data"
Bob Mottram's avatar
Bob Mottram committed
            new_expiry_months=$(<"$data")
            if [ ${#new_expiry_months} -gt 0 ]; then
                # should contain no spaces
                if [[ "$new_expiry_months" == *" "* ]]; then
                    return
                fi
                # should be a number
                re='^[0-9]+$'
                if ! [[ $new_expiry_months =~ $re ]] ; then
                    return
                fi
                # set the new value
                POSTACTIV_EXPIRE_MONTHS=$new_expiry_months
                write_config_param "POSTACTIV_EXPIRE_MONTHS" "$POSTACTIV_EXPIRE_MONTHS"
                expire_gnusocial_posts "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_EXPIRE_MONTHS"
                dialog --title $"Set PostActiv post expiry period" \
                       --msgbox $"Expiry period set to $POSTACTIV_EXPIRE_MONTHS months" 6 60
            fi
           ;;
    esac
Bob Mottram's avatar
Bob Mottram committed
    rm -f "$data"
function configure_interactive_postactiv {
Bob Mottram's avatar
Bob Mottram committed
    read_config_param "POSTACTIV_EXPIRE_MONTHS"
        W=(1 $"Set a background image"
           2 $"Set the title"
           3 $"Set post expiry period (currently $POSTACTIV_EXPIRE_MONTHS months)"
           4 $"Select Qvitter user interface"
           5 $"Select Pleroma user interface"
           6 $"Select Classic user interface")

        # shellcheck disable=SC2068
        selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"PostActiv" --menu $"Choose an operation, or ESC to exit:" 15 60 6 "${W[@]}" 3>&2 2>&1 1>&3)

        if [ ! "$selection" ]; then
            break
        fi

        case $selection in
            1) postactiv_set_background_image;;
            2) postactiv_set_title;;
            3) postactiv_set_expire_months;;
            4) gnusocial_use_qvitter postactiv;;
            5) gnusocial_use_pleroma postactiv;;
            6) gnusocial_use_classic postactiv;;
Bob Mottram's avatar
Bob Mottram committed
function upgrade_postactiv {
Bob Mottram's avatar
Bob Mottram committed
    CURR_POSTACTIV_COMMIT=$(get_completion_param "postactiv commit")
    if [[ "$CURR_POSTACTIV_COMMIT" == "$POSTACTIV_COMMIT" ]]; then
        return
    fi

Bob Mottram's avatar
Bob Mottram committed
    if grep -q "postactiv domain" "$COMPLETION_FILE"; then
Bob Mottram's avatar
Bob Mottram committed
        POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
    fi

    # update to the next commit
    function_check set_repo_commit
Bob Mottram's avatar
Bob Mottram committed
    set_repo_commit "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" "postactiv commit" "$POSTACTIV_COMMIT" $POSTACTIV_REPO
Bob Mottram's avatar
Bob Mottram committed

    # Ensure that installation script is removed
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php" ]; then
        rm "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php"
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index_qvitter.php" ]; then
        if [ -f "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index.php" ]; then
Bob Mottram's avatar
Bob Mottram committed
            # shellcheck disable=SC2086
            mv /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index.php /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index_qvitter.php
Bob Mottram's avatar
Bob Mottram committed
    function_check postactiv_running_script
    postactiv_running_script
    gnusocial_block_user_script
    gnusocial_block_domain_script postactiv "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    upgrade_pleroma_frontend "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
Bob Mottram's avatar
Bob Mottram committed
    postactiv_customise_logo "$POSTACTIV_DOMAIN_NAME"
    install_gnusocial_default_background "postactiv" "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs"
    systemctl restart mariadb
Bob Mottram's avatar
Bob Mottram committed
}


function backup_local_postactiv {
    POSTACTIV_DOMAIN_NAME='postactiv'
Bob Mottram's avatar
Bob Mottram committed
    if grep -q "postactiv domain" "$COMPLETION_FILE"; then
Bob Mottram's avatar
Bob Mottram committed
        POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
    fi

    # don't backup more data than we need to
    /etc/cron.daily/postactiv-expire
    source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/backup
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "$source_directory" ]; then
        mkdir "$source_directory"
Bob Mottram's avatar
Bob Mottram committed
    cp -p "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/config.php" "$source_directory"
    if [ -d "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static" ]; then
        cp -rp "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static" "$source_directory"
Bob Mottram's avatar
Bob Mottram committed

    function_check suspend_site
Bob Mottram's avatar
Bob Mottram committed
    suspend_site "${POSTACTIV_DOMAIN_NAME}"
Bob Mottram's avatar
Bob Mottram committed

    function_check backup_directory_to_usb
    dest_directory=postactivconfig
Bob Mottram's avatar
Bob Mottram committed
    backup_directory_to_usb "$source_directory" "$dest_directory"
Bob Mottram's avatar
Bob Mottram committed

    source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/file
    dest_directory=postactivfile
Bob Mottram's avatar
Bob Mottram committed
    backup_directory_to_usb "$source_directory" "$dest_directory"

    function_check backup_database_to_usb
    backup_database_to_usb postactiv

    function_check restart_site
    restart_site
Bob Mottram's avatar
Bob Mottram committed
}

function restore_local_postactiv {
Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q "postactiv domain" "$COMPLETION_FILE"; then
Bob Mottram's avatar
Bob Mottram committed
        return
    fi
    POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
Bob Mottram's avatar
Bob Mottram committed
    if [ "$POSTACTIV_DOMAIN_NAME" ]; then
        echo $"Restoring postactiv"
Bob Mottram's avatar
Bob Mottram committed
        temp_restore_dir=/root/temppostactiv
        postactiv_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
        # stop the daemons
Bob Mottram's avatar
Bob Mottram committed
        cd "$postactiv_dir" || exit 468246242
Bob Mottram's avatar
Bob Mottram committed
        scripts/stopdaemons.sh
Bob Mottram's avatar
Bob Mottram committed

        function_check postactiv_create_database
        postactiv_create_database

        restore_database postactiv
        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 postactivconfig
Bob Mottram's avatar
Bob Mottram committed
        if [ -d $temp_restore_dir ]; then
Bob Mottram's avatar
Bob Mottram committed
            if [ -d "$temp_restore_dir$postactiv_dir" ]; then
                cp "$temp_restore_dir$postactiv_dir/backup/config.php" "$postactiv_dir/"
                cp -rp "$temp_restore_dir$postactiv_dir/static" "$postactiv_dir/"
Bob Mottram's avatar
Bob Mottram committed
                cp "$temp_restore_dir/backup/config.php" "$postactiv_dir/"
                if [ ! -d "$postactiv_dir/static" ]; then
                    mkdir "$postactiv_dir/static"
Bob Mottram's avatar
Bob Mottram committed
                cp -rp "$temp_restore_dir/static/"* "$postactiv_dir/static/"
Bob Mottram's avatar
Bob Mottram committed
            chown www-data:www-data "$postactiv_dir/config.php"
            chown -R www-data:www-data "$postactiv_dir/static"
            rm -rf $temp_restore_dir
        fi

        restore_directory_from_usb $temp_restore_dir postactivfile
        if [ -d $temp_restore_dir ]; then
Bob Mottram's avatar
Bob Mottram committed
            if [ -d "$temp_restore_dir$postactiv_dir/file" ]; then
                cp -rp "$temp_restore_dir$postactiv_dir/file" "$postactiv_dir/"
Bob Mottram's avatar
Bob Mottram committed
                if [ ! -d "$postactiv_dir/file" ]; then
                    mkdir "$postactiv_dir/file"
Bob Mottram's avatar
Bob Mottram committed
                cp -rp "$temp_restore_dir/"* "$postactiv_dir/file/"
Bob Mottram's avatar
Bob Mottram committed
            chown -R www-data:www-data "$postactiv_dir/file"
Bob Mottram's avatar
Bob Mottram committed
            rm -rf $temp_restore_dir
        fi

Bob Mottram's avatar
Bob Mottram committed
        gnusocial_update_after_restore postactiv "${POSTACTIV_DOMAIN_NAME}"

        echo $"Restore of postactiv complete"
Bob Mottram's avatar
Bob Mottram committed
    fi
}

function backup_remote_postactiv {
    echo -n ''
Bob Mottram's avatar
Bob Mottram committed
}

function restore_remote_postactiv {
    echo -n ''
Bob Mottram's avatar
Bob Mottram committed
}

function remove_postactiv {
    if [ ${#POSTACTIV_DOMAIN_NAME} -eq 0 ]; then
        return
    fi
    function_check remove_nodejs
    remove_nodejs pleroma-postactiv

Bob Mottram's avatar
Bob Mottram committed
    read_config_param "POSTACTIV_DOMAIN_NAME"
    read_config_param "MY_USERNAME"
    echo "Removing $POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    nginx_dissite "$POSTACTIV_DOMAIN_NAME"
    remove_certs "$POSTACTIV_DOMAIN_NAME"
    if [ -f /etc/cron.hourly/postactiv-daemons ]; then
        rm /etc/cron.hourly/postactiv-daemons
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh" ]; then
        cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 2467245248
Bob Mottram's avatar
Bob Mottram committed
        scripts/stopdaemons.sh
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    kill_pid=$(pgrep "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/queuedaemon.php" | head -n 1)
    kill -9 "$kill_pid"
    pkill "$POSTACTIV_DOMAIN_NAME/htdocs/scripts/queuedaemon.php"
Bob Mottram's avatar
Bob Mottram committed
    if [ -d "/var/www/$POSTACTIV_DOMAIN_NAME" ]; then
        rm -rf "/var/www/$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME" ]; then
        rm "/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    fi
    function_check drop_database
    drop_database postactiv
    function_check remove_onion_service
    remove_onion_service postactiv ${POSTACTIV_ONION_PORT}
    if grep -q "postactiv" /etc/crontab; then
        sed -i "/postactiv/d" /etc/crontab
    fi
    remove_app postactiv
    remove_completion_param install_postactiv
Bob Mottram's avatar
Bob Mottram committed
    sed -i '/postactiv/d' "$COMPLETION_FILE"
    remove_backup_database_local postactiv
    sed -i '/postactiv-firewall/d' /etc/crontab
Bob Mottram's avatar
Bob Mottram committed
    sed -i 's|mysqli.allow_persistent.*|mysqli.allow_persistent = On|g' "/etc/php/${PHP_VERSION}/cli/php.ini"
    sed -i 's|mysqli.reconnect.*|mysqli.reconnect = Off|g' "/etc/php/${PHP_VERSION}/cli/php.ini"
    if [ -f /usr/bin/postactiv-firewall ]; then
        rm /usr/bin/postactiv-firewall
    fi

    if [ -f /etc/cron.daily/postactiv-expire ]; then
        rm /etc/cron.daily/postactiv-expire
    fi
    if [ -f /usr/bin/postactiv-expire-posts ]; then
        rm /usr/bin/postactiv-expire-posts
    fi

    function_check remove_ddns_domain
Bob Mottram's avatar
Bob Mottram committed
    remove_ddns_domain "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
}

function install_postactiv_main {
Bob Mottram's avatar
Bob Mottram committed
    if [ ! "$POSTACTIV_DOMAIN_NAME" ]; then
Bob Mottram's avatar
Bob Mottram committed
        echo $'No domain name was given for postactiv'
        exit 7359
    fi

    if [[ $(app_is_installed postactiv_main) == "1" ]]; then
        return
    fi

Bob Mottram's avatar
Bob Mottram committed
    function_check postactiv_running_script
    postactiv_running_script
Bob Mottram's avatar
Bob Mottram committed

    function_check install_mariadb
    install_mariadb

    function_check get_mariadb_password
    get_mariadb_password

    function_check repair_databases_script
    repair_databases_script

    $INSTALL_PACKAGES php-gettext php-curl php-gd php-mysql git curl
    $INSTALL_PACKAGES memcached php-memcached php-intl exiftool libfcgi0ldbl
    # shellcheck disable=SC2086
    $INSTALL_PACKAGES php${PHP_VERSION}-bcmath php${PHP_VERSION}-curl php${PHP_VERSION}-exif php${PHP_VERSION}-gd
    # shellcheck disable=SC2086
    $INSTALL_PACKAGES php${PHP_VERSION}-intl php${PHP_VERSION}-mbstring php${PHP_VERSION}-mysqlnd
    # shellcheck disable=SC2086
    $INSTALL_PACKAGES php${PHP_VERSION}-opcache php${PHP_VERSION}-readline php${PHP_VERSION}-xmlwriter
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/$POSTACTIV_DOMAIN_NAME" ]; then
        mkdir "/var/www/$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" ]; then

        if [ -d /repos/postactiv ]; then
Bob Mottram's avatar
Bob Mottram committed
            mkdir -p "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
Bob Mottram's avatar
Bob Mottram committed
            cp -r -p /repos/postactiv/. "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
            cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 46824682682
            git pull
        else
Bob Mottram's avatar
Bob Mottram committed
            # This is deliberately non-recursive
            git clone "$POSTACTIV_REPO" "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
Bob Mottram's avatar
Bob Mottram committed
        if [ ! -d "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" ]; then
Bob Mottram's avatar
Bob Mottram committed
            echo $'Unable to clone postactiv repo'
            exit 87525
        fi
    fi

Bob Mottram's avatar
Bob Mottram committed
    cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 46287462828
Bob Mottram's avatar
Bob Mottram committed
    git checkout $POSTACTIV_COMMIT -b $POSTACTIV_COMMIT
    set_completion_param "postactiv commit" "$POSTACTIV_COMMIT"

Bob Mottram's avatar
Bob Mottram committed
    chmod g+w "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
    chmod a+w "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/avatar"
    chmod a+w "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/file"
    chown -R www-data:www-data "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
    chmod +x "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php"
    chmod 755 "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Serializer.php"
    chmod -x "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Serializer.php"
Bob Mottram's avatar
Bob Mottram committed

    function_check postactiv_create_database
    postactiv_create_database

    if [ ! -f "/etc/aliases" ]; then
        touch /etc/aliases
    fi
    if ! grep -q "www-data: root" /etc/aliases; then
        echo 'www-data: root' >> /etc/aliases
    fi
    if ! grep -q "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
        echo "*: /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
    fi

    function_check add_ddns_domain
Bob Mottram's avatar
Bob Mottram committed
    add_ddns_domain "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    POSTACTIV_ONION_HOSTNAME=$(add_onion_service postactiv 80 ${POSTACTIV_ONION_PORT})

Bob Mottram's avatar
Bob Mottram committed
    postactiv_nginx_site=/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME
    if [[ $ONION_ONLY == "no" ]]; then
        function_check nginx_http_redirect
Bob Mottram's avatar
Bob Mottram committed
        nginx_http_redirect "$POSTACTIV_DOMAIN_NAME" "index index.php"
        { echo 'server {';
          echo '  listen 443 ssl;';
          echo '  #listen [::]:443 ssl;';
          echo "  server_name $POSTACTIV_DOMAIN_NAME;";
          echo ''; } >> "$postactiv_nginx_site"
        function_check nginx_compress
Bob Mottram's avatar
Bob Mottram committed
        nginx_compress "$POSTACTIV_DOMAIN_NAME"
        echo '' >> "$postactiv_nginx_site"
        echo '  # Security' >> "$postactiv_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
        function_check nginx_ssl
Bob Mottram's avatar
Bob Mottram committed
        nginx_ssl "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
        function_check nginx_security_options
        nginx_security_options "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

        { echo '  add_header Strict-Transport-Security max-age=15768000;';
          echo '';
          echo '  # Logs';
          echo '  access_log /dev/null;';
          echo '  error_log /dev/null;';
          echo '';
          echo '  # Root';
          echo "  root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;";
          echo '';
          echo '  # Index';
          echo '  index index.php;';
          echo '';
          echo '  # PHP';
          echo '  location ~ \.php {';
          echo '    client_max_body_size 50m;';
          echo '    client_body_buffer_size 50m;';
Bob Mottram's avatar
Bob Mottram committed
          echo '    include snippets/fastcgi-php.conf;';
          echo "    fastcgi_pass unix:/var/run/php/php${PHP_VERSION}-fpm.sock;";
Bob Mottram's avatar
Bob Mottram committed
          echo '    fastcgi_read_timeout 30;';
          echo '  }';
          echo '';
          echo '  # Location';
          echo '  location / {'; } >> "$postactiv_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
        function_check nginx_limits
Bob Mottram's avatar
Bob Mottram committed
        nginx_limits "$POSTACTIV_DOMAIN_NAME" '15m'
        { echo "    try_files \$uri \$uri/ @postactiv;";
          echo '  }';
          echo '';
          echo '  # Fancy URLs';
          echo '  location @postactiv {';
          echo '    client_max_body_size 50m;';
          echo '    client_body_buffer_size 50m;';
Bob Mottram's avatar
Bob Mottram committed
          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
          echo '  }';
          echo '';
          echo '  # Restrict access that is unnecessary anyway';
          echo '  location ~ /\.(ht|git) {';
          echo '    deny all;';
          echo '  }';
          echo '}'; } >> "$postactiv_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
    else
Bob Mottram's avatar
Bob Mottram committed
        echo -n '' > "$postactiv_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    { echo 'server {';
      echo "    listen 127.0.0.1:$POSTACTIV_ONION_PORT default_server;";
      echo '    port_in_redirect off;';
Bob Mottram's avatar
Bob Mottram committed
      echo "    server_name $POSTACTIV_ONION_HOSTNAME;";
      echo ''; } >> "$postactiv_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
    function_check nginx_security_options
    nginx_security_options "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    echo '' >> "$postactiv_nginx_site"
    function_check nginx_compress
Bob Mottram's avatar
Bob Mottram committed
    nginx_compress "$POSTACTIV_DOMAIN_NAME"
    { echo '';
      echo '  # Logs';
      echo '  access_log /dev/null;';
      echo '  error_log /dev/null;';
      echo '';
      echo '  # Root';
      echo "  root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;";
      echo '';
      echo '  # Index';
      echo '  index index.php;';
      echo '';
      echo '  # PHP';
      echo '  location ~ \.php {';
      echo '    client_max_body_size 50m;';
      echo '    client_body_buffer_size 50m;';
Bob Mottram's avatar
Bob Mottram committed
      echo '    include snippets/fastcgi-php.conf;';
      echo "    fastcgi_pass unix:/var/run/php/php${PHP_VERSION}-fpm.sock;";
Bob Mottram's avatar
Bob Mottram committed
      echo '    fastcgi_read_timeout 30;';
      echo '  }';
      echo '';
      echo '  # Location';
      echo '  location / {'; } >> "$postactiv_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
    function_check nginx_limits
Bob Mottram's avatar
Bob Mottram committed
    nginx_limits "$POSTACTIV_DOMAIN_NAME" '15m'
    { echo "    try_files \$uri \$uri/ @postactiv;";
      echo '  }';
      echo '';
      echo '  # Fancy URLs';
      echo '  location @postactiv {';
      echo '    client_max_body_size 50m;';
      echo '    client_body_buffer_size 50m;';
Bob Mottram's avatar
Bob Mottram committed
      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
      echo '  }';
      echo '';
      echo '  # Restrict access that is unnecessary anyway';
      echo '  location ~ /\.(ht|git) {';
      echo '    deny all;';
      echo '  }';
      echo '}'; } >> "$postactiv_nginx_site"
Bob Mottram's avatar
Bob Mottram committed

    function_check gnusocial_set_limits
    gnusocial_set_limits "$postactiv_nginx_site"

Bob Mottram's avatar
Bob Mottram committed
    function_check configure_php
    configure_php

    function_check create_site_certificate
Bob Mottram's avatar
Bob Mottram committed
    create_site_certificate "$POSTACTIV_DOMAIN_NAME" 'yes'
Bob Mottram's avatar
Bob Mottram committed

    # Ensure that the database gets backed up locally, if remote
    # backups are not being used
    function_check backup_databases_script_header
    backup_databases_script_header

    function_check backup_database_local
    backup_database_local postactiv

    function_check nginx_ensite
Bob Mottram's avatar
Bob Mottram committed
    nginx_ensite "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

    # NOTE: For the typical case always enable SSL and only
    # disable it if in onion only mode. This is due to complexities
    # with the way URLs are generated by postactiv
    postactiv_ssl='always'
    if [[ $ONION_ONLY != 'no' ]]; then
        postactiv_ssl='never'
    fi

    POSTACTIV_SERVER=${POSTACTIV_DOMAIN_NAME}
Bob Mottram's avatar
Bob Mottram committed
    if [[ $ONION_ONLY != 'no' ]]; then
        POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME}
    fi
Bob Mottram's avatar
Bob Mottram committed

    # Create the configuration
    postactiv_installer=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts/install_cli.php
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -f "$postactiv_installer" ]; then
        rm -rf "/var/www/$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
        echo $'No postactiv commandline installer found'
        exit 53026
    fi
    ${postactiv_installer} --server "${POSTACTIV_SERVER}" \
                           --host="localhost" --database="postactiv" \
                           --dbtype=mysql --username="root" -v \
                           --password="$MARIADB_PASSWORD" \
                           --sitename=$"postactiv" --fancy='yes' \
                           --admin-nick="$MY_USERNAME" \
                           --admin-pass="$POSTACTIV_ADMIN_PASSWORD" \
                           --site-profile="community" \
                           --ssl=${postactiv_ssl}
    # There can be a lot of warnings here so the return value check is disabled
    #if [ ! "$?" = "0" ]; then
    #    # failed to install
    #    echo $'Could not install postactiv'
    #    exit 72357
    #fi

    # check postactiv has a config file
Bob Mottram's avatar
Bob Mottram committed
    postactiv_config_file="/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/config.php"
    if [ ! -f "$postactiv_config_file" ]; then
        drop_database postactiv
Bob Mottram's avatar
Bob Mottram committed
        rm -rf "/var/www/$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
        echo $'Postactiv config.php not found'
        exit 87586
    fi

    # Some useful settings
Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q "Recommended postactiv settings" "$postactiv_config_file"; then
        { echo "";
          echo "// Recommended postactiv settings";
          echo "\$config['thumbnail']['maxsize'] = 3000;";
          echo "\$config['profile']['delete'] = true;";
          echo "\$config['profile']['changenick'] = true;";
          echo "\$config['public']['localonly'] = false;";
          echo "addPlugin('StoreRemoteMedia');";
          echo "\$config['queue']['enabled'] = true;";
          echo "\$config['queue']['daemon'] = true;";
          echo "\$config['ostatus']['hub_retries'] = 3;"; } >> "$postactiv_config_file"
Bob Mottram's avatar
Bob Mottram committed
    fi

Bob Mottram's avatar
Bob Mottram committed
    echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> "$postactiv_config_file"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    # This improves performance
Bob Mottram's avatar
Bob Mottram committed
    sed -i "s|//\$config\\['db'\\]\\['schemacheck'\\].*|\$config\\['db'\\]\\['schemacheck'\\] = 'script';|g" "$postactiv_config_file"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    # remove the install script
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php" ]; then
        rm "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php"
    # php configuration
Bob Mottram's avatar
Bob Mottram committed
    sed -i 's|mysqli.allow_persistent.*|mysqli.allow_persistent = On|g' "/etc/php/${PHP_VERSION}/cli/php.ini"
    sed -i 's|mysqli.reconnect.*|mysqli.reconnect = On|g' "/etc/php/${PHP_VERSION}/cli/php.ini"
    systemctl restart mariadb
    # shellcheck disable=SC2086
    systemctl restart php${PHP_VERSION}-fpm
Bob Mottram's avatar
Bob Mottram committed
    systemctl restart nginx

Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-addemail" -u "$MY_USERNAME" -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a postactiv -p "$POSTACTIV_ADMIN_PASSWORD"
Bob Mottram's avatar
Bob Mottram committed

    gnusocial_block_user_script
    gnusocial_block_domain_script postactiv "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    set_completion_param "postactiv domain" "$POSTACTIV_DOMAIN_NAME"

    install_completed postactiv_main
}

function install_postactiv {
    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    install_postactiv_main

    increment_app_install_progress

    install_qvitter "$POSTACTIV_DOMAIN_NAME" "postactiv"

    increment_app_install_progress

    install_gnusocial_markdown "$POSTACTIV_DOMAIN_NAME" "postactiv"

    increment_app_install_progress

    install_gnusocial_plugin_sharings "$POSTACTIV_DOMAIN_NAME" "postactiv"

    increment_app_install_progress

    install_gnusocial_plugin_sharings_theme "$POSTACTIV_DOMAIN_NAME" "postactiv"
Bob Mottram's avatar
Bob Mottram committed

    increment_app_install_progress

    # Currently Pleroma won't install on ARM systems
    # because it uses node-sass which doesn't support ARM
    if [[ "$(arch)" == "arm"* || "$(arch)" == "aarch"* ]]; then
        echo -m $'WARNING: Pleroma currently does not support ARM '
        echo $'architecture, so it will not be installed'
    else
        function_check install_nodejs
        install_nodejs pleroma-gnusocial
        install_pleroma_front_end "postactiv" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
        install_gnusocial_default_background "postactiv" "$POSTACTIV_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
        postactiv_customise_logo "$POSTACTIV_DOMAIN_NAME"
        sed -i 's|"theme":.*|"theme": "base16-harmonic16-light.css",|g' "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static/config.json"
    increment_app_install_progress

    expire_gnusocial_posts "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_EXPIRE_MONTHS"
Bob Mottram's avatar
Bob Mottram committed

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    # this has to be run as root initially, otherwise database tables
    # don't get created
    cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 3658254254
    sh scripts/startdaemons.sh
    php scripts/checkschema.php

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    /etc/cron.hourly/postactiv-daemons

    increment_app_install_progress

    systemctl restart nginx

    increment_app_install_progress

    # Set qvitter to be the default UI. It's probably the most stable.
    # And doesn't forget logins
    gnusocial_use_qvitter postactiv

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    if [ "$POSTACTIV_BACKGROUND_IMAGE_URL" ]; then
        pleroma_set_background_image_from_url "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
Bob Mottram's avatar
Bob Mottram committed
    APP_INSTALLED=1
}

# NOTE: deliberately there is no "exit 0"