Skip to content
Snippets Groups Projects
freedombone-app-peertube 46 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
#
# PeerTube server
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2017-2019 Bob Mottram <bob@freedombone.net>
Bob Mottram's avatar
Bob Mottram committed
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

VARIANTS="full full-vim media"

Bob Mottram's avatar
Bob Mottram committed
APP_CATEGORY=media

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

PEERTUBE_DOMAIN_NAME=
PEERTUBE_CODE=
Bob Mottram's avatar
Bob Mottram committed
PEERTUBE_VERSION='v1.1.0'
Bob Mottram's avatar
Bob Mottram committed
PEERTUBE_DOWNLOAD_FILENAME="peertube-${PEERTUBE_VERSION}"
Bob Mottram's avatar
Bob Mottram committed
PEERTUBE_DOWNLOAD="https://github.com/Chocobozzz/PeerTube/releases/download/${PEERTUBE_VERSION}/${PEERTUBE_DOWNLOAD_FILENAME}.tar.xz"
Bob Mottram's avatar
Bob Mottram committed
PEERTUBE_ONION_PORT=8136
MESH_PEERTUBE_PORT=8500
Bob Mottram's avatar
Bob Mottram committed
PEERTUBE_DIR=/etc/peertube
PEERTUBE_CONFIG_FILE=$PEERTUBE_DIR/config/production.yaml
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
PEERTUBE_SHORT_DESCRIPTION=$'Video broadcast'
PEERTUBE_DESCRIPTION=$'Video broadcast'
PEERTUBE_MOBILE_APP_URL=

Bob Mottram's avatar
Bob Mottram committed
peertube_variables=(PEERTUBE_DOMAIN_NAME
                    PEERTUBE_CODE
                    PEERTUBE_ADMIN_PASSWORD
                    ONION_ONLY
                    DDNS_PROVIDER
                    MY_USERNAME
Bob Mottram's avatar
Bob Mottram committed
                    ARCHITECTURE
Bob Mottram's avatar
Bob Mottram committed
                    MY_EMAIL_ADDRESS)

Bob Mottram's avatar
Bob Mottram committed
function peertube_tcp_tuning {
    if [ -f "$PEERTUBE_DIR/peertube-latest/support/sysctl.d/30-peertube-tcp.conf" ]; then
        cp "$PEERTUBE_DIR/peertube-latest/support/sysctl.d/30-peertube-tcp.conf" /etc/sysctl.d/
Bob Mottram's avatar
Bob Mottram committed
        sysctl -p /etc/sysctl.d/30-peertube-tcp.conf
    fi
}

Bob Mottram's avatar
Bob Mottram committed
function install_peertube_base {
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d $PEERTUBE_DIR/config ]; then
        mkdir -p $PEERTUBE_DIR/config
    fi
    if [ ! -d $PEERTUBE_DIR/storage ]; then
        mkdir -p $PEERTUBE_DIR/storage
    fi
    if [ ! -d $PEERTUBE_DIR/versions ]; then
        mkdir -p $PEERTUBE_DIR/versions
    fi

    cd ${PEERTUBE_DIR}/versions || exit 35
Bob Mottram's avatar
Bob Mottram committed

    if [ -f "/repos/${PEERTUBE_DOWNLOAD_FILENAME}.tar.xz" ]; then
        cp "/repos/${PEERTUBE_DOWNLOAD_FILENAME}.tar.xz" "${PEERTUBE_DOWNLOAD_FILENAME}.tar.xz"
    else
        wget -q "$PEERTUBE_DOWNLOAD" -O "${PEERTUBE_DOWNLOAD_FILENAME}.tar.xz"
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -f "${PEERTUBE_DOWNLOAD_FILENAME}.tar.xz" ]; then
Bob Mottram's avatar
Bob Mottram committed
    fi
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    unxz "${PEERTUBE_DOWNLOAD_FILENAME}.tar.xz"
    if [ ! -f "${PEERTUBE_DOWNLOAD_FILENAME}.tar" ]; then
        echo $"${PEERTUBE_DOWNLOAD_FILENAME}.tar not found"
Bob Mottram's avatar
Bob Mottram committed
    fi
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    tar -xvf "${PEERTUBE_DOWNLOAD_FILENAME}.tar"
    rm "${PEERTUBE_DOWNLOAD_FILENAME}.tar"

    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    ln -s "versions/${PEERTUBE_DOWNLOAD_FILENAME}" ./peertube-latest
    cd ${PEERTUBE_DIR}/peertube-latest || exit 35
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
    # NOTE: these get installed from the global npm
    npm install npm@6
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    npm install yarn@1.10.1
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -f "${PEERTUBE_DIR}/.bashrc" ]; then
Bob Mottram's avatar
Bob Mottram committed
        echo "PATH=/root/.npm-global/bin:\$PATH" > "${PEERTUBE_DIR}/.bashrc"
Bob Mottram's avatar
Bob Mottram committed
    else
Bob Mottram's avatar
Bob Mottram committed
        if ! grep -q "npm-global" "${PEERTUBE_DIR}/.bashrc"; then
Bob Mottram's avatar
Bob Mottram committed
            echo "PATH=/root/.npm-global/bin:\$PATH" >> "${PEERTUBE_DIR}/.bashrc"
Bob Mottram's avatar
Bob Mottram committed
        fi
    fi
Bob Mottram's avatar
Bob Mottram committed
    chown -R peertube:peertube $PEERTUBE_DIR

    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    # install a second time locally
Bob Mottram's avatar
Bob Mottram committed
    peertube_local_install="sudo -H -u peertube ${PEERTUBE_DIR}/peertube-latest/node_modules/.bin/npm install"
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    $peertube_local_install npm@6
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    $peertube_local_install yarn@1.10.1
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "${PEERTUBE_DIR}/package-lock.json" ]; then
        rm "${PEERTUBE_DIR}/package-lock.json"
    fi

Bob Mottram's avatar
Bob Mottram committed
    cd ${PEERTUBE_DIR}/peertube-latest || exit 73
    if ! sudo -H -u peertube NPM_CONFIG_PREFIX=${PEERTUBE_DIR}/peertube-latest/node_modules/npm NODE_CONFIG_DIR=${PEERTUBE_DIR}/config ${PEERTUBE_DIR}/peertube-latest/node_modules/.bin/yarn install --production --pure-lockfile; then
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    cd ${PEERTUBE_DIR} || exit 71
Bob Mottram's avatar
Bob Mottram committed
    if [ ! $peertube_upgrading ]; then
        increment_app_install_progress
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d ${PEERTUBE_DIR}/storage/logs ]; then
        sudo -H -u peertube mkdir -p ${PEERTUBE_DIR}/storage/logs
    fi

    #sudo -H -u peertube ${PEERTUBE_DIR}/peertube-latest/node_modules/.bin/npm audit fix
Bob Mottram's avatar
Bob Mottram committed
    peertube_tcp_tuning
}

function peertube_setting_registration {
    allow_registrations="$1"

    if [[ "$allow_registrations" == '1' ]]; then
        sed -i "0,/enabled:.*/s//enabled: false/" ${PEERTUBE_CONFIG_FILE}
        systemctl restart peertube
    fi

    if [[ "$allow_registrations" == '0' ]]; then
        sed -i "0,/enabled:.*/s//enabled: true/" ${PEERTUBE_CONFIG_FILE}
        systemctl restart peertube
    fi
}

function peertube_import_from_syncthing {
Bob Mottram's avatar
Bob Mottram committed
    peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
    nodecmd='node'

    if [[ "$ONION_ONLY" != 'no' ]]; then
        peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
        nodecmd='torsocks node'
    fi

    { echo '#!/bin/bash';
Bob Mottram's avatar
Bob Mottram committed
      echo '';
Bob Mottram's avatar
Bob Mottram committed
      echo 'LOCKFILE=/tmp/.peertube.lock';
Bob Mottram's avatar
Bob Mottram committed
      echo '';
      echo 'if [ -f /root/.peertube.lock ]; then';
Bob Mottram's avatar
Bob Mottram committed
      echo "    lockctr=\$(cat \$LOCKFILE)";
Bob Mottram's avatar
Bob Mottram committed
      echo "    lockctr=\$((lockctr+1))";
Bob Mottram's avatar
Bob Mottram committed
      echo "    echo \"\$lockctr\" > \$LOCKFILE";
Bob Mottram's avatar
Bob Mottram committed
      echo "    if [ \$lockctr -ge 30 ]; then";
Bob Mottram's avatar
Bob Mottram committed
      echo "        rm \$LOCKFILE";
Bob Mottram's avatar
Bob Mottram committed
      echo '    else';
      echo '        exit 0';
      echo '    fi';
      echo 'fi';
      echo '';
      echo "MY_USERNAME=\$(cat /root/${PROJECT_NAME}.cfg | grep MY_USERNAME | awk -F '=' '{print \$2}')";
      echo "if [ ! \"\$MY_USERNAME\" ]; then";
      echo '    exit 0';
      echo 'fi';
      echo '';
      echo "search_dir=/home/\$MY_USERNAME/Sync/peertube_upload";
Bob Mottram's avatar
Bob Mottram committed
      echo "if [ ! -f \$search_dir/login.txt ]; then";
      echo '    exit 0';
      echo 'fi';
      echo "import_script=${PEERTUBE_DIR}/peertube-latest/dist/server/tools/upload.js";
      echo "if [ ! -f \$import_script ]; then";
      echo '    exit 0';
      echo 'fi';
      echo '';
Bob Mottram's avatar
Bob Mottram committed
      echo "peertubedomain=\"$peertubedomain\"";
Bob Mottram's avatar
Bob Mottram committed
      echo "peertubeuser=\$(sed -n 1p < \"\$search_dir/login.txt\")";
      echo "peertubepassword=\$(sed -n 2p < \"\$search_dir/login.txt\")";
      echo 'peertubensfw=';
Bob Mottram's avatar
Bob Mottram committed
      echo "if grep -q 'nsfw' \"\$search_dir/login.txt\"; then";
      echo "    peertubensfw='--nsfw'";
      echo 'fi';
Bob Mottram's avatar
Bob Mottram committed
      echo "if grep -q 'NSFW' \"\$search_dir/login.txt\"; then";
Bob Mottram's avatar
Bob Mottram committed
      echo "    peertubensfw='--nsfw'";
      echo 'fi';
      echo "peertubeprivate='-P 3'";
Bob Mottram's avatar
Bob Mottram committed
      echo "if grep -q 'public' \"\$search_dir/login.txt\"; then";
      echo "    peertubeprivate='-P 1'";
      echo 'fi';
Bob Mottram's avatar
Bob Mottram committed
      echo "if grep -q 'Public' \"\$search_dir/login.txt\"; then";
      echo "    peertubeprivate='-P 1'";
      echo 'fi';
      echo '';
      echo 'failed_uploads=0';
      echo '';
      echo "cd ${PEERTUBE_DIR} || exit 32";
Bob Mottram's avatar
Bob Mottram committed
      echo "echo \"0\" > \$LOCKFILE";
Bob Mottram's avatar
Bob Mottram committed
      echo '';
      echo "for video_file in \$search_dir/*; do";
      echo "    if [[ \"\$video_file\" == *'.ogv' || \"\$video_file\" == *'.webm' ]]; then";
Bob Mottram's avatar
Bob Mottram committed
      echo "        if ! grep -q \"\$video_file\" /root/.peertube_uploaded; then";
Bob Mottram's avatar
Bob Mottram committed
      echo "            peertubetitle=\$(basename \"\$video_file\" | awk -F '.' '{print \$1}' | sed 's|_| |g' | sed 's|-| |g')";
      echo "            if $nodecmd \$import_script -n \"\$peertubetitle\" \$peertubensfw \$peertubeprivate -u \"\$peertubedomain\" -U \"\$peertubeuser\" --password \"\$peertubepassword\" -f \"\$video_file\"; then";
      echo "                echo \"\$video_file\" >> /root/.peertube_uploaded";
Bob Mottram's avatar
Bob Mottram committed
      echo "                rm \$LOCKFILE";
Bob Mottram's avatar
Bob Mottram committed
      echo "                exit 0";
      echo '            else';
      echo "                failed_uploads=\$((failed_uploads+1))";
      echo "                if [ \$failed_uploads -gt 1 ]; then";
Bob Mottram's avatar
Bob Mottram committed
      echo "                    rm \$LOCKFILE";
Bob Mottram's avatar
Bob Mottram committed
      echo '                    exit 0';
      echo '                fi';
      echo '            fi';
      echo '        fi';
      echo '    fi';
Bob Mottram's avatar
Bob Mottram committed
      echo 'done';
Bob Mottram's avatar
Bob Mottram committed
      echo '';
Bob Mottram's avatar
Bob Mottram committed
      echo "rm \$LOCKFILE"; } > /usr/bin/peertubesync

    chmod +x /usr/bin/peertubesync
    cron_add_mins 1 /usr/bin/peertubesync
}

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

    systemctl restart postgresql
Bob Mottram's avatar
Bob Mottram committed
    run_system_query_postgresql "CREATE USER peertube WITH PASSWORD '$PEERTUBE_ADMIN_PASSWORD';"
    run_system_query_postgresql "CREATE DATABASE peertube OWNER peertube;"
    run_system_query_postgresql "GRANT ALL PRIVILEGES ON DATABASE peertube to peertube;"
Bob Mottram's avatar
Bob Mottram committed
    run_system_query_postgresql "set statement_timeout to 40000;"
    peertube_database_extensions
Bob Mottram's avatar
Bob Mottram committed
}

function logging_on_peertube {
    if [ ! -d $PEERTUBE_DIR ]; then
        return
    fi

Bob Mottram's avatar
Bob Mottram committed
    sed -i "s|level: '.*|level: 'debug' # debug/info/warning/error|g" "$PEERTUBE_DIR/config/production.yaml"
    systemctl restart peertube
Bob Mottram's avatar
Bob Mottram committed
}

function logging_off_peertube {
    if [ ! -d $PEERTUBE_DIR ]; then
        return
    fi

Bob Mottram's avatar
Bob Mottram committed
    sed -i "s|level: '.*|level: 'error' # debug/info/warning/error|g" "$PEERTUBE_DIR/config/production.yaml"
    systemctl restart peertube
Bob Mottram's avatar
Bob Mottram committed
}

function remove_user_peertube {
Bob Mottram's avatar
Bob Mottram committed
    echo -n ''
    #    remove_username="$1"
    # TODO: remove user
Bob Mottram's avatar
Bob Mottram committed
}

function add_user_peertube {
    if [[ $(app_is_installed peertube) == "0" ]]; then
        echo '0'
        return
    fi

    #    new_username="$1"
    #    new_user_password="$2"
Bob Mottram's avatar
Bob Mottram committed

    echo '0'
}

function install_interactive_peertube {
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
        PEERTUBE_DOMAIN_NAME='peertube.local'
        write_config_param "PEERTUBE_DOMAIN_NAME" "$PEERTUBE_DOMAIN_NAME"
    else
        function_check interactive_site_details
        interactive_site_details "peertube" "PEERTUBE_DOMAIN_NAME" "PEERTUBE_CODE"
    fi
    APP_INSTALLED=1
}

function peertube_set_admin_email {
Bob Mottram's avatar
Bob Mottram committed
    read_config_param "$MY_EMAIL_ADDRESS"
    data=$(mktemp 2>/dev/null)
    dialog --title $"Set PeerTube administrator email address" \
           --backtitle $"Freedombone Control Panel" \
Bob Mottram's avatar
Bob Mottram committed
           --inputbox $"Admin email address" 8 75 "$MY_EMAIL_ADDRESS" 2>"$data"
    sel=$?
    case $sel in
Bob Mottram's avatar
Bob Mottram committed
        0)  peertube_email=$(<"$data")
            if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
                if [ ${#peertube_email} -gt 8 ]; then
                    sed -i "s|email:.*|email: '${peertube_email}'|g" ${PEERTUBE_CONFIG_FILE}
                    systemctl restart peertube
                    dialog --title $"Set PeerTube administrator email address" \
                           --msgbox $"Set to $peertube_email" 6 75
                fi
            fi
            ;;
    esac
Bob Mottram's avatar
Bob Mottram committed
    rm -f "$data"
}

function peertube_disable_signups {
    dialog --title $"Disable PeerTube signups" \
           --backtitle $"Freedombone Control Panel" \
Bob Mottram's avatar
Bob Mottram committed
           --yesno $"\\nDo you wish to disable further PeerTube signups?" 8 75
    sel=$?
    case $sel in
        0) sed -i "0,/enabled:.*/s//enabled: false/" ${PEERTUBE_CONFIG_FILE};;
        1) sed -i "0,/enabled:.*/s//enabled: true/" ${PEERTUBE_CONFIG_FILE};;
        255) return;;
    esac

    systemctl restart peertube
}

function peertube_import_from_file {
    read_config_param MY_USERNAME
    read_config_param PEERTUBE_DOMAIN_NAME
    read_config_param ONION_ONLY

    data2=$(mktemp 2>/dev/null)
    dialog --backtitle $"Freedombone Control Panel" \
           --title $"Import Video from file" \
           --form $"Enter your PeerTube login details and video title" 10 65 4 \
           $"Username:" 1 1 "$MY_USERNAME" 1 18 16 15 \
           $"Password:" 2 1 "" 2 18 40 10000 \
           $"Video Title:" 3 1 "" 3 18 40 1000 \
           $"NSFW:" 4 1 $"no" 4 18 4 4 \
           2> "$data2"
    sel=$?
    case $sel in
        1) rm -f "$data2"
           return;;
        255) rm -f "$data2"
             return;;
    esac
    peertubeuser=$(sed -n 1p < "$data2")
    peertubepassword=$(sed -n 2p < "$data2")
    peertubetitle=$(sed -n 3p < "$data2")
    peertubensfw=$(sed -n 4p < "$data2")
    rm -f "$data2"

Bob Mottram's avatar
Bob Mottram committed
    peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
    nodecmd='node'

    if [[ "$ONION_ONLY" != 'no' ]]; then
        peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
        nodecmd='torsocks node'
    fi
Bob Mottram's avatar
Bob Mottram committed
    selected_file=$(dialog --title "Choose the video file (select with spacebar)" --fselect "/home/$MY_USERNAME/" 30 60)
    if [ ! "$selected_file" ]; then
        return
    fi
    if [[ "$selected_file" != *'.ogv' && "$selected_file" != *'.webm' ]]; then
        dialog --title $"Import video from file" \
               --msgbox $"The video should be in ogv or webm format" 6 75
    cd $PEERTUBE_DIR || exit 32
    import_script=$PEERTUBE_DIR/peertube-latest/dist/server/tools/upload.js
    if [ ! -f $import_script ]; then
        dialog --title $"Import videos" \
               --msgbox $"upload script was not found" 6 75
        return
    fi

    nsfwstr=
    if [[ "$peertubensfw" == *'y'* || "$peertubensfw" == *'Y'* ]]; then
        nsfwstr='--nsfw'
    fi

Bob Mottram's avatar
Bob Mottram committed
    titlestr=$(basename "$selected_file" | awk -F '.' '{print $1}' | sed 's|_| |g' | sed 's|-| |g')
    if [ "$peertubetitle" ]; then
        titlestr="-n \"$peertubetitle\""
    fi

    clear
Bob Mottram's avatar
Bob Mottram committed
    $nodecmd $import_script $nsfwstr "$titlestr" -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -f "$selected_file"

    dialog --title $"Import video from file" \
           --msgbox $"Video imported from $selected_file" 6 75
}

function peertube_import_videos {
    read_config_param MY_USERNAME
    read_config_param PEERTUBE_DOMAIN_NAME
    read_config_param ONION_ONLY

    data2=$(mktemp 2>/dev/null)
    dialog --backtitle $"Freedombone Control Panel" \
           --title $"Import Videos from legacy sites" \
           --form $"Enter a channel of video URL for YouTube/Vimeo/Dailymotion" 10 75 4 \
Bob Mottram's avatar
Bob Mottram committed
           $"Username:" 1 1 "$MY_USERNAME" 1 22 16 15 \
           $"Password:" 2 1 "" 2 22 50 10000 \
           $"Video/Channel URL:" 3 1 "" 3 22 50 10000 \
           2> "$data2"
    sel=$?
    case $sel in
        1) rm -f "$data2"
        255) rm -f "$data2"
    peertubeuser=$(sed -n 1p < "$data2")
    peertubepassword=$(sed -n 2p < "$data2")
    video_url=$(sed -n 3p < "$data2")
    rm -f "$data2"
Bob Mottram's avatar
Bob Mottram committed
    peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
    nodecmd='node'

    if [[ "$ONION_ONLY" != 'no' ]]; then
        peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
        nodecmd='torsocks node'
    fi

    if [ ${#peertubeuser} -lt 3 ]; then
        dialog --title $"Import videos from legacy sites" \
               --msgbox $"Username was not valid" 6 75
        return
    fi

    if [ ${#peertubepassword} -lt 3 ]; then
        dialog --title $"Import videos from legacy sites" \
               --msgbox $"Password was not valid" 6 75
        return
    fi

    if [[ "$video_url" == *' '* || "$video_url" == *','* || "$video_url" == *'@'* ]]; then
        dialog --title $"Import videos from legacy sites" \
               --msgbox $"Video/channel URL was not valid" 6 75
        return
    fi

    if [ ${#video_url} -lt 8 ]; then
        dialog --title $"Import videos from legacy sites" \
               --msgbox $"Video/channel URL was not valid" 6 75
        return
    fi

    cd $PEERTUBE_DIR || exit 32
    import_script=$PEERTUBE_DIR/peertube-latest/dist/server/tools/import-videos.js

    # default to downloading as webm
    sed -i "s|'.mp4'|'.webm'|g" $import_script
Bob Mottram's avatar
Bob Mottram committed
    sed -i "s|const options = \\['-f'.*|const options = ['-f', '43', '-o', path];|g" $import_script
    if [ ! -f $import_script ]; then
        dialog --title $"Import videos from legacy sites" \
               --msgbox $"import-videos script was not found" 6 75
        return
    fi

    clear
Bob Mottram's avatar
Bob Mottram committed
    $nodecmd $import_script -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -t "$video_url"
    dialog --title $"Import videos from legacy sites" \
           --msgbox $"Video/s imported from $video_url" 6 75
}

function configure_interactive_peertube {
    W=(1 $"Set administrator email address"
       2 $"Disable or enable signups"
       3 $"Import video from file")
        # shellcheck disable=SC2068
Bob Mottram's avatar
Bob Mottram committed
        selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"PeerTube" --menu $"Choose an operation, or ESC to exit:" 12 60 4 "${W[@]}" 3>&2 2>&1 1>&3)

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

        case $selection in
            1) peertube_set_admin_email;;
            2) peertube_disable_signups;;
            3) peertube_import_from_file;;
Bob Mottram's avatar
Bob Mottram committed
function change_password_peertube {
    peertube_user="$1"
    new_peertube_password="$2"
    if [ ${#new_peertube_password} -lt 8 ]; then
Bob Mottram's avatar
Bob Mottram committed
        echo $'Peertube password is too short'
        return
    fi
    cd $PEERTUBE_DIR/peertube-latest || exit 53
    echo -n "$new_peertube_password" | sudo -H -u peertube NODE_CONFIG_DIR=$PEERTUBE_DIR/config NODE_ENV=production npm run reset-password -- -u "$peertube_user"
    "${PROJECT_NAME}-pass" -u "$peertube_user" -a peertube -p "$new_peertube_password"

    # also change the root password if this is the admin user
    read_config_param MY_USERNAME
    if [[ "$peertube_user" == "$MY_USERNAME" ]]; then
        peertube_user=root
        echo -n "$new_peertube_password" | sudo -H -u peertube NODE_CONFIG_DIR=$PEERTUBE_DIR/config NODE_ENV=production npm run reset-password -- -u "$peertube_user"
        "${PROJECT_NAME}-pass" -u "$peertube_user" -a peertube -p "$new_peertube_password"
    fi
Bob Mottram's avatar
Bob Mottram committed
}

function reconfigure_peertube {
    echo -n ''
}

function peertube_database_extensions {
    cd /etc/postgresql || exit 34
    sudo -u postgres psql peertube -c 'CREATE EXTENSION IF NOT EXISTS unaccent;'
    sudo -u postgres psql peertube -c 'CREATE EXTENSION IF NOT EXISTS pg_trgm;'
}

Bob Mottram's avatar
Bob Mottram committed
function upgrade_peertube {
    peertube_import_from_syncthing

Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "$PEERTUBE_DIR/peertube-latest" ]; then
Bob Mottram's avatar
Bob Mottram committed
        return
    fi

    CURR_PEERTUBE_VERSION=$(get_completion_param "peertube version")
    if [[ "$CURR_PEERTUBE_VERSION" == "$PEERTUBE_VERSION" ]]; then
Bob Mottram's avatar
Bob Mottram committed
        return
    fi

    read_config_param PEERTUBE_DOMAIN_NAME
    systemctl stop peertube
Bob Mottram's avatar
Bob Mottram committed
    install_peertube_base
Bob Mottram's avatar
Bob Mottram committed
    chown -R peertube:peertube $PEERTUBE_DIR
Bob Mottram's avatar
Bob Mottram committed
    if [ -d $PEERTUBE_DIR/.cache ]; then
        chmod -R 700 $PEERTUBE_DIR/.cache
    fi

    peertube_database_extensions
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q 'tmp: ' "${PEERTUBE_CONFIG_FILE}"; then
        sed -i "/storage:/a tmp: '$PEERTUBE_DIR/storage/tmp/'" "${PEERTUBE_CONFIG_FILE}"
        sed -i 's|tmp:|  tmp:|g' "${PEERTUBE_CONFIG_FILE}"
    fi
Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q 'redundancy: ' "${PEERTUBE_CONFIG_FILE}"; then
        sed -i "/storage:/a redundancy: '$PEERTUBE_DIR/storage/videos/'" "${PEERTUBE_CONFIG_FILE}"
        sed -i 's|redundancy:|  redundancy:|g' "${PEERTUBE_CONFIG_FILE}"
    fi

    if ! grep -q 'csp-logger:' "${PEERTUBE_CONFIG_FILE}"; then
        sed -i "/services:/a csp-logger:" "${PEERTUBE_CONFIG_FILE}"
        sed -i 's|csp-logger:|  csp-logger:|g' "${PEERTUBE_CONFIG_FILE}"
    fi

Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q 'allow_additional_extensions:' "${PEERTUBE_CONFIG_FILE}"; then
        sed -i "/transcoding:/a allow_additional_extensions:" "${PEERTUBE_CONFIG_FILE}"
        sed -i 's|allow_additional_extensions:|  allow_additional_extensions:|g' "${PEERTUBE_CONFIG_FILE}"
    fi

    if ! grep -q 'contact_form:' "${PEERTUBE_CONFIG_FILE}"; then
        sed -i "/email:/a contact_form:" "${PEERTUBE_CONFIG_FILE}"
        sed -i "/contact_form:/a enabled: true 82284" "${PEERTUBE_CONFIG_FILE}"
        sed -i 's|enabled: true 82284|  enabled: true|g' "${PEERTUBE_CONFIG_FILE}"
    fi

Bob Mottram's avatar
Bob Mottram committed
    systemctl start peertube

    set_completion_param "peertube version" "$PEERTUBE_VERSION"
Bob Mottram's avatar
Bob Mottram committed
}

function backup_local_peertube {
    PEERTUBE_DOMAIN_NAME='peertube.local'
Bob Mottram's avatar
Bob Mottram committed
    if grep -q "peertube domain" "$COMPLETION_FILE"; then
Bob Mottram's avatar
Bob Mottram committed
        PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
    fi

    systemctl stop peertube
    USE_POSTGRESQL=1
    function_check backup_database_to_usb
    backup_database_to_usb peertube
    systemctl start peertube

    peertube_path=$PEERTUBE_DIR/storage/videos
Bob Mottram's avatar
Bob Mottram committed
    if [ -d $peertube_path ]; then
Bob Mottram's avatar
Bob Mottram committed
        suspend_site "${PEERTUBE_DOMAIN_NAME}"
Bob Mottram's avatar
Bob Mottram committed
        systemctl stop peertube
        backup_directory_to_usb $peertube_path peertubevideos
        systemctl start peertube
        restart_site
    fi
}

function restore_local_peertube {
    PEERTUBE_DOMAIN_NAME='peertube.local'
Bob Mottram's avatar
Bob Mottram committed
    if grep -q "peertube domain" "$COMPLETION_FILE"; then
Bob Mottram's avatar
Bob Mottram committed
        PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ "$PEERTUBE_DOMAIN_NAME" ]; then
        suspend_site "${PEERTUBE_DOMAIN_NAME}"
Bob Mottram's avatar
Bob Mottram committed
        systemctl stop peertube

        USE_POSTGRESQL=1
        restore_database peertube

        temp_restore_dir=/root/temppeertubevideos
        function_check restore_directory_from_usb
        restore_directory_from_usb $temp_restore_dir peertubevideos
        if [ -d $temp_restore_dir ]; then
            if [ -d $temp_restore_dir$PEERTUBE_DIR/storage/videos ]; then
                cp -r $temp_restore_dir$PEERTUBE_DIR/storage/videos/* $PEERTUBE_DIR/storage/videos/
Bob Mottram's avatar
Bob Mottram committed
            else
                cp -r $temp_restore_dir/* $PEERTUBE_DIR/storage/videos/
Bob Mottram's avatar
Bob Mottram committed
            fi
            chown -R peertube:peertube $PEERTUBE_DIR
            rm -rf $temp_restore_dir
        fi

        systemctl start peertube
        restart_site
    fi
}

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

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

function remove_peertube {
    if [ ${#PEERTUBE_DOMAIN_NAME} -eq 0 ]; then
        return
    fi

    systemctl stop peertube
    systemctl disable peertube
    rm /etc/systemd/system/peertube.service
    systemctl daemon-reload

    function_check remove_nodejs
    remove_nodejs peertube

    rm /etc/sysctl.d/30-peertube-tcp.conf
    sysctl -p -q

Bob Mottram's avatar
Bob Mottram committed
    read_config_param "PEERTUBE_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    nginx_dissite "$PEERTUBE_DOMAIN_NAME"
    remove_certs "${PEERTUBE_DOMAIN_NAME}"
    if [ -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME" ]; then
        rm -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ -d "/var/www/$PEERTUBE_DOMAIN_NAME" ]; then
        rm -rf "/var/www/$PEERTUBE_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    fi
    remove_config_param PEERTUBE_DOMAIN_NAME
    remove_config_param PEERTUBE_CODE
    function_check remove_onion_service
    remove_onion_service peertube ${PEERTUBE_ONION_PORT}
    remove_completion_param "install_peertube"
Bob Mottram's avatar
Bob Mottram committed
    sed -i '/peertube/d' "$COMPLETION_FILE"
    sed -i '/peertubesync/d' /etc/crontab

    if [ -f /usr/bin/peertubesync ]; then
        rm /usr/bin/peertubesync
    fi
    if [ -f /root/peertube_uploaded ]; then
        rm /root/peertube_uploaded
    fi
Bob Mottram's avatar
Bob Mottram committed

    function_check drop_database_postgresql
    drop_database_postgresql peertube peertube
Bob Mottram's avatar
Bob Mottram committed

    groupdel -f peertube
    userdel -r peertube

    if [ -d $PEERTUBE_DIR ]; then
        rm -rf $PEERTUBE_DIR
    fi

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

function peertube_setup_web {
    peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME

    if [[ $ONION_ONLY == "no" ]]; then
Bob Mottram's avatar
Bob Mottram committed
        { echo 'server {';
          echo '  listen 80;';
          echo '  listen [::]:80;';
          echo "  server_name ${PEERTUBE_DOMAIN_NAME};";
          echo '';
Bob Mottram's avatar
Bob Mottram committed
          echo "  access_log /dev/null;";
          echo "  error_log /dev/null;";
          echo '';
          echo "  location / { return 301 https://\$host\$request_uri; }";
Bob Mottram's avatar
Bob Mottram committed
          echo '}';
          echo '';
          echo 'server {';
          echo '  listen 443 ssl http2;';
          echo '  listen [::]:443 ssl http2;';
          echo "  server_name ${PEERTUBE_DOMAIN_NAME};";
Bob Mottram's avatar
Bob Mottram committed
          echo ''; } > "$peertube_nginx_file"

        function_check nginx_ssl
        nginx_ssl "$PEERTUBE_DOMAIN_NAME" mobile

        function_check nginx_security_options
        nginx_security_options "$PEERTUBE_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
        nginx_robots "$PEERTUBE_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

        { echo '  ssl_ecdh_curve secp384r1;';
          echo '  ssl_session_cache shared:SSL:10m;';
          echo '  ssl_session_tickets off;';
          echo '';
          echo '  # Enable compression for JS/CSS/HTML bundle, for improved client load times.';
          echo '  # It might be nice to compress JSON, but leaving that out to protect against potential';
          echo '  # compression+encryption information leak attacks like BREACH.';
          echo '  gzip on;';
Bob Mottram's avatar
Bob Mottram committed
          echo '  gzip_types text/css application/javascript;';
          echo '  gzip_vary on;';
          echo '';
          echo '  # Enable HSTS'
          echo '  # Tells browsers to stick with HTTPS and never visit the insecure HTTP';
          echo '  # version. Once a browser sees this header, it will only visit the site over';
          echo '  # HTTPS for the next 2 years: (read more on hstspreload.org)';
Bob Mottram's avatar
Bob Mottram committed
          echo '  add_header Strict-Transport-Security "max-age=63072000;";';
          echo '';
          echo '  access_log /dev/null;';
          echo '  error_log /dev/null;';
          echo '';
Bob Mottram's avatar
Bob Mottram committed
          echo '  location / {';
          echo "    proxy_pass http://localhost:$PEERTUBE_PORT;";
Bob Mottram's avatar
Bob Mottram committed
          echo "    proxy_set_header X-Real-IP \$remote_addr;";
          echo "    proxy_set_header Host \$host;";
          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
          echo '';
          echo '    # Hard limit, PeerTube does not support videos > 8GB';
          echo '    client_max_body_size 8G;';
          echo '    proxy_connect_timeout       600;';
          echo '    proxy_send_timeout          600;';
          echo '    proxy_read_timeout          600;';
          echo '    send_timeout                600;';
Bob Mottram's avatar
Bob Mottram committed
          echo '  }';
          echo '';
          echo '  # Bypass PeerTube for performance reasons. Could be removed';
Bob Mottram's avatar
Bob Mottram committed
          echo '  location ~ ^/static/(webseed|redundancy)/ {';
          echo '    # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client';
          echo '    limit_rate 800k;';
          echo '';
Bob Mottram's avatar
Bob Mottram committed
          echo "    if (\$request_method = 'OPTIONS') {";
          echo "      add_header 'Access-Control-Allow-Origin' '*';";
          echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
          echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
          echo "      add_header 'Access-Control-Max-Age' 1728000;";
          echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';";
          echo "      add_header 'Content-Length' 0;";
          echo '      return 204;';
          echo '    }';
          echo '';
          echo "    if (\$request_method = 'GET') {";
          echo "      add_header 'Access-Control-Allow-Origin' '*';";
          echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
          echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
          echo '';
          echo '      # Dont spam access log file with byte range requests';
          echo '      access_log off;';
Bob Mottram's avatar
Bob Mottram committed
          echo '    }';
          echo '';
          echo "    alias $PEERTUBE_DIR/storage/videos;";
Bob Mottram's avatar
Bob Mottram committed
          echo '  }';
          echo '';
          echo '  # Websocket tracker';
          echo '  location /tracker/socket {';
          echo '    # Peers send a message to the tracker every 15 minutes';
          echo '    # Dont close the websocket before this time';
          echo '    proxy_read_timeout 1200s;';
          echo "    proxy_set_header Upgrade \$http_upgrade;";
          echo "    proxy_set_header Connection \"upgrade\";";
Bob Mottram's avatar
Bob Mottram committed
          echo '    proxy_http_version 1.1;';
          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
          echo "    proxy_set_header Host \$host;";
          echo "    proxy_pass http://localhost:$PEERTUBE_PORT;";
Bob Mottram's avatar
Bob Mottram committed
          echo '  }';
Bob Mottram's avatar
Bob Mottram committed
          echo '}';
          echo ''; } >> "$peertube_nginx_file"
Bob Mottram's avatar
Bob Mottram committed
    else
Bob Mottram's avatar
Bob Mottram committed
        echo -n '' > "$peertube_nginx_file"
    fi
    { echo 'server {';
      echo "  listen 127.0.0.1:$PEERTUBE_ONION_PORT default_server;";
      echo '  port_in_redirect off;';
Bob Mottram's avatar
Bob Mottram committed
      echo "  server_name $PEERTUBE_ONION_HOSTNAME;";
      echo '';
      echo '  # Enable compression for JS/CSS/HTML bundle, for improved client load times.';
      echo '  # It might be nice to compress JSON, but leaving that out to protect against potential';
      echo '  # compression+encryption information leak attacks like BREACH.';
      echo '  gzip on;';
Bob Mottram's avatar
Bob Mottram committed
      echo '  gzip_types text/css application/javascript;';
      echo '  gzip_vary on;';
Bob Mottram's avatar
Bob Mottram committed
      echo '';
      echo '  access_log /dev/null;';
      echo '  error_log /dev/null;';
      echo '';
Bob Mottram's avatar
Bob Mottram committed
      echo '  location / {';
      echo "    proxy_pass http://localhost:$PEERTUBE_PORT;";
Bob Mottram's avatar
Bob Mottram committed
      echo "    proxy_set_header X-Real-IP \$remote_addr;";
      echo "    proxy_set_header Host \$host;";
      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
      echo '';
      echo '    # Hard limit, PeerTube does not support videos > 8GB';
      echo '    client_max_body_size 8G;';
      echo '    proxy_connect_timeout       600;';
      echo '    proxy_send_timeout          600;';
      echo '    proxy_read_timeout          600;';
      echo '    send_timeout                600;';
Bob Mottram's avatar
Bob Mottram committed
      echo '  }';
      echo '';
      echo '  # Bypass PeerTube for performance reasons. Could be removed';
Bob Mottram's avatar
Bob Mottram committed
      echo '  location ~ ^/static/(webseed|redundancy)/ {';
      echo '    # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client';
      echo '    limit_rate 800k;';
      echo '';
Bob Mottram's avatar
Bob Mottram committed
      echo "    if (\$request_method = 'OPTIONS') {";
      echo "      add_header 'Access-Control-Allow-Origin' '*';";
      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
      echo "      add_header 'Access-Control-Max-Age' 1728000;";
      echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';";
      echo "      add_header 'Content-Length' 0;";
      echo '      return 204;';
      echo '    }';
      echo '';
      echo "    if (\$request_method = 'GET') {";
      echo "      add_header 'Access-Control-Allow-Origin' '*';";
      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
      echo '';
      echo '      # Dont spam access log file with byte range requests';
      echo '      access_log off;';
Bob Mottram's avatar
Bob Mottram committed
      echo '    }';
      echo '';
      echo "    alias $PEERTUBE_DIR/storage/videos;";
Bob Mottram's avatar
Bob Mottram committed
      echo '  }';
      echo '';
      echo '  # Websocket tracker';
      echo '  location /tracker/socket {';
      echo '    # Peers send a message to the tracker every 15 minutes';
      echo '    # Dont close the websocket before this time';
      echo '    proxy_read_timeout 1200s;';
      echo "    proxy_set_header Upgrade \$http_upgrade;";
      echo "    proxy_set_header Connection \"upgrade\";";
      echo '    proxy_http_version 1.1;';
      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
      echo "    proxy_set_header Host \$host;";
      echo "    proxy_pass http://localhost:$PEERTUBE_PORT;";
Bob Mottram's avatar
Bob Mottram committed
      echo '  }';
      echo '}'; } >> "$peertube_nginx_file"

Bob Mottram's avatar
Bob Mottram committed
    # CSP currently causes an error
    sed -i '/Content-Security-Policy/d' "$peertube_nginx_file"

    function_check create_site_certificate
    create_site_certificate "$PEERTUBE_DOMAIN_NAME" 'yes'

    function_check nginx_ensite
    nginx_ensite "$PEERTUBE_DOMAIN_NAME"
}

function mesh_peertube_setup_web {
    # TODO
    echo -n ''
Bob Mottram's avatar
Bob Mottram committed
function peertube_create_config {
    peertube_prefix=
    new_peertube_config_file=$peertube_prefix${PEERTUBE_CONFIG_FILE}
Bob Mottram's avatar
Bob Mottram committed
    { echo 'listen:';
Bob Mottram's avatar
Bob Mottram committed
      echo "  hostname: 'localhost'";
Bob Mottram's avatar
Bob Mottram committed
      echo "  port: $PEERTUBE_PORT";
      echo '';
      echo '# Correspond to your reverse proxy "listen" configuration';
      echo 'webserver:'; } > "$new_peertube_config_file"
Bob Mottram's avatar
Bob Mottram committed
    if [ ! "$peertube_prefix" ]; then
        if [[ "$ONION_ONLY" == 'no' ]]; then
            { echo '  https: true';
              echo "  hostname: '$PEERTUBE_DOMAIN_NAME'";
              echo '  port: 443'; } >> "$new_peertube_config_file"
        else
Bob Mottram's avatar
Bob Mottram committed
            { echo '  https: false';
              echo "  hostname: '$PEERTUBE_ONION_HOSTNAME'";
              echo '  port: 80'; } >> "$new_peertube_config_file"
Bob Mottram's avatar
Bob Mottram committed
    else
Bob Mottram's avatar
Bob Mottram committed
        { echo '  https: false';
          echo "  hostname: ''";
          echo "  port: $MESH_PEERTUBE_PORT"; } >> "$new_peertube_config_file"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    { echo '# Proxies to trust to get real client IP';
      echo "# If you run PeerTube just behind a local proxy (nginx), keep 'loopback'";
      echo '# If you run PeerTube behind a remote proxy, add the proxy IP address (or subnet)';
      echo 'trust_proxy:';
      echo "  - 'loopback'";
      echo '';
Bob Mottram's avatar
Bob Mottram committed
      echo '# Your database name will be "peertube"+database.suffix';