|  | @@ -0,0 +1,592 @@
 | 
	
		
			
			|  | 1 | +#!/bin/bash
 | 
	
		
			
			|  | 2 | +#
 | 
	
		
			
			|  | 3 | +# .---.                  .              .
 | 
	
		
			
			|  | 4 | +# |                      |              |
 | 
	
		
			
			|  | 5 | +# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
 | 
	
		
			
			|  | 6 | +# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
 | 
	
		
			
			|  | 7 | +# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
 | 
	
		
			
			|  | 8 | +#
 | 
	
		
			
			|  | 9 | +#                    Freedom in the Cloud
 | 
	
		
			
			|  | 10 | +#
 | 
	
		
			
			|  | 11 | +# PeerTube server
 | 
	
		
			
			|  | 12 | +#
 | 
	
		
			
			|  | 13 | +# License
 | 
	
		
			
			|  | 14 | +# =======
 | 
	
		
			
			|  | 15 | +#
 | 
	
		
			
			|  | 16 | +# Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
 | 
	
		
			
			|  | 17 | +#
 | 
	
		
			
			|  | 18 | +# This program is free software: you can redistribute it and/or modify
 | 
	
		
			
			|  | 19 | +# it under the terms of the GNU Affero General Public License as published by
 | 
	
		
			
			|  | 20 | +# the Free Software Foundation, either version 3 of the License, or
 | 
	
		
			
			|  | 21 | +# (at your option) any later version.
 | 
	
		
			
			|  | 22 | +#
 | 
	
		
			
			|  | 23 | +# This program is distributed in the hope that it will be useful,
 | 
	
		
			
			|  | 24 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
	
		
			
			|  | 25 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
	
		
			
			|  | 26 | +# GNU Affero General Public License for more details.
 | 
	
		
			
			|  | 27 | +#
 | 
	
		
			
			|  | 28 | +# You should have received a copy of the GNU Affero General Public License
 | 
	
		
			
			|  | 29 | +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
	
		
			
			|  | 30 | +
 | 
	
		
			
			|  | 31 | +VARIANTS="full full-vim media"
 | 
	
		
			
			|  | 32 | +
 | 
	
		
			
			|  | 33 | +IN_DEFAULT_INSTALL=0
 | 
	
		
			
			|  | 34 | +SHOW_ON_ABOUT=1
 | 
	
		
			
			|  | 35 | +
 | 
	
		
			
			|  | 36 | +PEERTUBE_DOMAIN_NAME=
 | 
	
		
			
			|  | 37 | +PEERTUBE_CODE=
 | 
	
		
			
			|  | 38 | +PEERTUBE_REPO="https://github.com/Chocobozzz/PeerTube"
 | 
	
		
			
			|  | 39 | +PEERTUBE_COMMIT='62c852b2b40b4f42c32941deb1b1ccd3f17bcd98'
 | 
	
		
			
			|  | 40 | +PEERTUBE_ONION_PORT=8136
 | 
	
		
			
			|  | 41 | +PEERTUBE_PORT=9000
 | 
	
		
			
			|  | 42 | +PEERTUBE_DIR=/etc/peertube
 | 
	
		
			
			|  | 43 | +
 | 
	
		
			
			|  | 44 | +peertube_variables=(PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 45 | +                    PEERTUBE_CODE
 | 
	
		
			
			|  | 46 | +                    PEERTUBE_ADMIN_PASSWORD
 | 
	
		
			
			|  | 47 | +                    ONION_ONLY
 | 
	
		
			
			|  | 48 | +                    DDNS_PROVIDER
 | 
	
		
			
			|  | 49 | +                    MY_USERNAME
 | 
	
		
			
			|  | 50 | +                    MY_EMAIL_ADDRESS)
 | 
	
		
			
			|  | 51 | +
 | 
	
		
			
			|  | 52 | +function peertube_create_database {
 | 
	
		
			
			|  | 53 | +    if [ -f $IMAGE_PASSWORD_FILE ]; then
 | 
	
		
			
			|  | 54 | +        PEERTUBE_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
 | 
	
		
			
			|  | 55 | +    else
 | 
	
		
			
			|  | 56 | +        if [ ! $PEERTUBE_ADMIN_PASSWORD ]; then
 | 
	
		
			
			|  | 57 | +            PEERTUBE_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
 | 
	
		
			
			|  | 58 | +        fi
 | 
	
		
			
			|  | 59 | +    fi
 | 
	
		
			
			|  | 60 | +    if [ ! $PEERTUBE_ADMIN_PASSWORD ]; then
 | 
	
		
			
			|  | 61 | +        return
 | 
	
		
			
			|  | 62 | +    fi
 | 
	
		
			
			|  | 63 | +
 | 
	
		
			
			|  | 64 | +    systemctl restart postgresql
 | 
	
		
			
			|  | 65 | +    add_postgresql_user pleroma "$PEERTUBE_ADMIN_PASSWORD" encrypted
 | 
	
		
			
			|  | 66 | +    run_system_query_postgresql "create database peertube;"
 | 
	
		
			
			|  | 67 | +    # temporarily allow the user to create databases
 | 
	
		
			
			|  | 68 | +    run_system_query_postgresql "ALTER USER peertube CREATEDB;"
 | 
	
		
			
			|  | 69 | +    run_system_query_postgresql "ALTER USER peertube SUPERUSER;"
 | 
	
		
			
			|  | 70 | +    run_system_query_postgresql "GRANT ALL ON ALL tables IN SCHEMA public TO peertube;"
 | 
	
		
			
			|  | 71 | +    run_system_query_postgresql "GRANT ALL ON ALL sequences IN SCHEMA public TO peertube;"
 | 
	
		
			
			|  | 72 | +    run_system_query_postgresql "CREATE EXTENSION citext;"
 | 
	
		
			
			|  | 73 | +    run_system_query_postgresql "set statement_timeout to 40000;"
 | 
	
		
			
			|  | 74 | +}
 | 
	
		
			
			|  | 75 | +
 | 
	
		
			
			|  | 76 | +function logging_on_peertube {
 | 
	
		
			
			|  | 77 | +    echo -n ''
 | 
	
		
			
			|  | 78 | +}
 | 
	
		
			
			|  | 79 | +
 | 
	
		
			
			|  | 80 | +function logging_off_peertube {
 | 
	
		
			
			|  | 81 | +    echo -n ''
 | 
	
		
			
			|  | 82 | +}
 | 
	
		
			
			|  | 83 | +
 | 
	
		
			
			|  | 84 | +function remove_user_peertube {
 | 
	
		
			
			|  | 85 | +    remove_username="$1"
 | 
	
		
			
			|  | 86 | +}
 | 
	
		
			
			|  | 87 | +
 | 
	
		
			
			|  | 88 | +function add_user_peertube {
 | 
	
		
			
			|  | 89 | +    if [[ $(app_is_installed peertube) == "0" ]]; then
 | 
	
		
			
			|  | 90 | +        echo '0'
 | 
	
		
			
			|  | 91 | +        return
 | 
	
		
			
			|  | 92 | +    fi
 | 
	
		
			
			|  | 93 | +
 | 
	
		
			
			|  | 94 | +    new_username="$1"
 | 
	
		
			
			|  | 95 | +    new_user_password="$2"
 | 
	
		
			
			|  | 96 | +
 | 
	
		
			
			|  | 97 | +    echo '0'
 | 
	
		
			
			|  | 98 | +}
 | 
	
		
			
			|  | 99 | +
 | 
	
		
			
			|  | 100 | +function install_interactive_peertube {
 | 
	
		
			
			|  | 101 | +    if [ ! $ONION_ONLY ]; then
 | 
	
		
			
			|  | 102 | +        ONION_ONLY='no'
 | 
	
		
			
			|  | 103 | +    fi
 | 
	
		
			
			|  | 104 | +
 | 
	
		
			
			|  | 105 | +    if [[ $ONION_ONLY != "no" ]]; then
 | 
	
		
			
			|  | 106 | +        PEERTUBE_DOMAIN_NAME='peertube.local'
 | 
	
		
			
			|  | 107 | +        write_config_param "PEERTUBE_DOMAIN_NAME" "$PEERTUBE_DOMAIN_NAME"
 | 
	
		
			
			|  | 108 | +    else
 | 
	
		
			
			|  | 109 | +        function_check interactive_site_details
 | 
	
		
			
			|  | 110 | +        interactive_site_details "peertube" "PEERTUBE_DOMAIN_NAME" "PEERTUBE_CODE"
 | 
	
		
			
			|  | 111 | +    fi
 | 
	
		
			
			|  | 112 | +    APP_INSTALLED=1
 | 
	
		
			
			|  | 113 | +}
 | 
	
		
			
			|  | 114 | +
 | 
	
		
			
			|  | 115 | +function change_password_peertube {
 | 
	
		
			
			|  | 116 | +    PEERTUBE_USERNAME="$1"
 | 
	
		
			
			|  | 117 | +    PEERTUBE_PASSWORD="$2"
 | 
	
		
			
			|  | 118 | +    if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
 | 
	
		
			
			|  | 119 | +        echo $'Peertube password is too short'
 | 
	
		
			
			|  | 120 | +        return
 | 
	
		
			
			|  | 121 | +    fi
 | 
	
		
			
			|  | 122 | +    #${PROJECT_NAME}-pass -u $PEERTUBE_USERNAME -a peertube -p "$PEERTUBE_PASSWORD"
 | 
	
		
			
			|  | 123 | +}
 | 
	
		
			
			|  | 124 | +
 | 
	
		
			
			|  | 125 | +function reconfigure_peertube {
 | 
	
		
			
			|  | 126 | +    echo -n ''
 | 
	
		
			
			|  | 127 | +}
 | 
	
		
			
			|  | 128 | +
 | 
	
		
			
			|  | 129 | +function upgrade_peertube {
 | 
	
		
			
			|  | 130 | +    CURR_PEERTUBE_COMMIT=$(get_completion_param "peertube commit")
 | 
	
		
			
			|  | 131 | +    if [[ "$CURR_PEERTUBE_COMMIT" == "$PEERTUBE_COMMIT" ]]; then
 | 
	
		
			
			|  | 132 | +        return
 | 
	
		
			
			|  | 133 | +    fi
 | 
	
		
			
			|  | 134 | +
 | 
	
		
			
			|  | 135 | +    read_config_param PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 136 | +    systemctl stop peertube
 | 
	
		
			
			|  | 137 | +    cd $PEERTUBE_DIR
 | 
	
		
			
			|  | 138 | +
 | 
	
		
			
			|  | 139 | +    function_check set_repo_commit
 | 
	
		
			
			|  | 140 | +    set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
 | 
	
		
			
			|  | 141 | +
 | 
	
		
			
			|  | 142 | +    npm run upgrade-peertube
 | 
	
		
			
			|  | 143 | +    chown -R peertube:peertube $PEERTUBE_DIR
 | 
	
		
			
			|  | 144 | +    systemctl start peertube
 | 
	
		
			
			|  | 145 | +}
 | 
	
		
			
			|  | 146 | +
 | 
	
		
			
			|  | 147 | +function backup_local_peertube {
 | 
	
		
			
			|  | 148 | +    PEERTUBE_DOMAIN_NAME='peertube.local'
 | 
	
		
			
			|  | 149 | +    if grep -q "peertube domain" $COMPLETION_FILE; then
 | 
	
		
			
			|  | 150 | +        PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
 | 
	
		
			
			|  | 151 | +    fi
 | 
	
		
			
			|  | 152 | +
 | 
	
		
			
			|  | 153 | +    systemctl stop peertube
 | 
	
		
			
			|  | 154 | +    USE_POSTGRESQL=1
 | 
	
		
			
			|  | 155 | +    function_check backup_database_to_usb
 | 
	
		
			
			|  | 156 | +    backup_database_to_usb peertube
 | 
	
		
			
			|  | 157 | +    systemctl start peertube
 | 
	
		
			
			|  | 158 | +
 | 
	
		
			
			|  | 159 | +    peertube_path=$PEERTUBE_DIR/videos
 | 
	
		
			
			|  | 160 | +    if [ -d $peertube_path ]; then
 | 
	
		
			
			|  | 161 | +        suspend_site ${PEERTUBE_DOMAIN_NAME}
 | 
	
		
			
			|  | 162 | +        systemctl stop peertube
 | 
	
		
			
			|  | 163 | +        backup_directory_to_usb $peertube_path peertubevideos
 | 
	
		
			
			|  | 164 | +        systemctl start peertube
 | 
	
		
			
			|  | 165 | +        restart_site
 | 
	
		
			
			|  | 166 | +    fi
 | 
	
		
			
			|  | 167 | +}
 | 
	
		
			
			|  | 168 | +
 | 
	
		
			
			|  | 169 | +function restore_local_peertube {
 | 
	
		
			
			|  | 170 | +    PEERTUBE_DOMAIN_NAME='peertube.local'
 | 
	
		
			
			|  | 171 | +    if grep -q "peertube domain" $COMPLETION_FILE; then
 | 
	
		
			
			|  | 172 | +        PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
 | 
	
		
			
			|  | 173 | +    fi
 | 
	
		
			
			|  | 174 | +    if [ $PEERTUBE_DOMAIN_NAME ]; then
 | 
	
		
			
			|  | 175 | +        suspend_site ${PEERTUBE_DOMAIN_NAME}
 | 
	
		
			
			|  | 176 | +        systemctl stop peertube
 | 
	
		
			
			|  | 177 | +
 | 
	
		
			
			|  | 178 | +        USE_POSTGRESQL=1
 | 
	
		
			
			|  | 179 | +        restore_database peertube
 | 
	
		
			
			|  | 180 | +
 | 
	
		
			
			|  | 181 | +        temp_restore_dir=/root/temppeertubevideos
 | 
	
		
			
			|  | 182 | +        function_check restore_directory_from_usb
 | 
	
		
			
			|  | 183 | +        restore_directory_from_usb $temp_restore_dir peertubevideos
 | 
	
		
			
			|  | 184 | +        if [ -d $temp_restore_dir ]; then
 | 
	
		
			
			|  | 185 | +            if [ -d $temp_restore_dir$PEERTUBE_DIR/videos ]; then
 | 
	
		
			
			|  | 186 | +                cp -r $temp_restore_dir$PEERTUBE_DIR/videos/* $PEERTUBE_DIR/videos/
 | 
	
		
			
			|  | 187 | +            else
 | 
	
		
			
			|  | 188 | +                cp -r $temp_restore_dir/* $PEERTUBE_DIR/videos/
 | 
	
		
			
			|  | 189 | +            fi
 | 
	
		
			
			|  | 190 | +            chown -R peertube:peertube $PEERTUBE_DIR
 | 
	
		
			
			|  | 191 | +            rm -rf $temp_restore_dir
 | 
	
		
			
			|  | 192 | +        fi
 | 
	
		
			
			|  | 193 | +
 | 
	
		
			
			|  | 194 | +        systemctl start peertube
 | 
	
		
			
			|  | 195 | +        restart_site
 | 
	
		
			
			|  | 196 | +    fi
 | 
	
		
			
			|  | 197 | +}
 | 
	
		
			
			|  | 198 | +
 | 
	
		
			
			|  | 199 | +function backup_remote_peertube {
 | 
	
		
			
			|  | 200 | +    PEERTUBE_DOMAIN_NAME='peertube.local'
 | 
	
		
			
			|  | 201 | +    if grep -q "peertube domain" $COMPLETION_FILE; then
 | 
	
		
			
			|  | 202 | +        PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
 | 
	
		
			
			|  | 203 | +    fi
 | 
	
		
			
			|  | 204 | +
 | 
	
		
			
			|  | 205 | +    systemctl stop peertube
 | 
	
		
			
			|  | 206 | +    USE_POSTGRESQL=1
 | 
	
		
			
			|  | 207 | +    function_check backup_database_to_friend
 | 
	
		
			
			|  | 208 | +    backup_database_to_friend peertube
 | 
	
		
			
			|  | 209 | +    systemctl start peertube
 | 
	
		
			
			|  | 210 | +
 | 
	
		
			
			|  | 211 | +    temp_backup_dir=$PEERTUBE_DIR/videos
 | 
	
		
			
			|  | 212 | +    if [ -d $temp_backup_dir ]; then
 | 
	
		
			
			|  | 213 | +        systemctl stop peertube
 | 
	
		
			
			|  | 214 | +        suspend_site ${PEERTUBE_DOMAIN_NAME}
 | 
	
		
			
			|  | 215 | +        backup_directory_to_friend $temp_backup_dir peertubevideos
 | 
	
		
			
			|  | 216 | +        restart_site
 | 
	
		
			
			|  | 217 | +        systemctl start peertube
 | 
	
		
			
			|  | 218 | +    else
 | 
	
		
			
			|  | 219 | +        echo $"Peertube domain specified but not found in $temp_backup_dir"
 | 
	
		
			
			|  | 220 | +        exit 6383523
 | 
	
		
			
			|  | 221 | +    fi
 | 
	
		
			
			|  | 222 | +}
 | 
	
		
			
			|  | 223 | +
 | 
	
		
			
			|  | 224 | +function restore_remote_peertube {
 | 
	
		
			
			|  | 225 | +    PEERTUBE_DOMAIN_NAME='peertube.local'
 | 
	
		
			
			|  | 226 | +    if grep -q "peertube domain" $COMPLETION_FILE; then
 | 
	
		
			
			|  | 227 | +        PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
 | 
	
		
			
			|  | 228 | +    fi
 | 
	
		
			
			|  | 229 | +    suspend_site ${PEERTUBE_DOMAIN_NAME}
 | 
	
		
			
			|  | 230 | +
 | 
	
		
			
			|  | 231 | +    systemctl stop peertube
 | 
	
		
			
			|  | 232 | +
 | 
	
		
			
			|  | 233 | +    USE_POSTGRESQL=1
 | 
	
		
			
			|  | 234 | +    function_check restore_database_from_friend
 | 
	
		
			
			|  | 235 | +    restore_database_from_friend peertube
 | 
	
		
			
			|  | 236 | +
 | 
	
		
			
			|  | 237 | +    temp_restore_dir=/root/temppeertubevideos
 | 
	
		
			
			|  | 238 | +    function_check restore_directory_from_friend
 | 
	
		
			
			|  | 239 | +    restore_directory_from_friend $temp_restore_dir peertubevideos
 | 
	
		
			
			|  | 240 | +    if [ -d $temp_restore_dir ]; then
 | 
	
		
			
			|  | 241 | +        if [ -d $temp_restore_dir$PEERTUBE_DIR/videos ]; then
 | 
	
		
			
			|  | 242 | +            cp -r $temp_restore_dir$PEERTUBE_DIR/videos/* $PEERTUBE_DIR/videos/
 | 
	
		
			
			|  | 243 | +        else
 | 
	
		
			
			|  | 244 | +            cp -r $temp_restore_dir/* $PEERTUBE_DIR/videos/
 | 
	
		
			
			|  | 245 | +        fi
 | 
	
		
			
			|  | 246 | +        chown -R peertube: $PEERTUBE_DIR
 | 
	
		
			
			|  | 247 | +        rm -rf $temp_restore_dir
 | 
	
		
			
			|  | 248 | +    fi
 | 
	
		
			
			|  | 249 | +
 | 
	
		
			
			|  | 250 | +    systemctl start peertube
 | 
	
		
			
			|  | 251 | +    restart_site
 | 
	
		
			
			|  | 252 | +}
 | 
	
		
			
			|  | 253 | +
 | 
	
		
			
			|  | 254 | +function remove_peertube {
 | 
	
		
			
			|  | 255 | +    if [ ${#PEERTUBE_DOMAIN_NAME} -eq 0 ]; then
 | 
	
		
			
			|  | 256 | +        return
 | 
	
		
			
			|  | 257 | +    fi
 | 
	
		
			
			|  | 258 | +
 | 
	
		
			
			|  | 259 | +    systemctl stop peertube
 | 
	
		
			
			|  | 260 | +    systemctl disable peertube
 | 
	
		
			
			|  | 261 | +    rm /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 262 | +    systemctl daemon-reload
 | 
	
		
			
			|  | 263 | +
 | 
	
		
			
			|  | 264 | +    function_check remove_nodejs
 | 
	
		
			
			|  | 265 | +    remove_nodejs peertube
 | 
	
		
			
			|  | 266 | +
 | 
	
		
			
			|  | 267 | +    read_config_param "PEERTUBE_DOMAIN_NAME"
 | 
	
		
			
			|  | 268 | +    nginx_dissite $PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 269 | +    remove_certs ${PEERTUBE_DOMAIN_NAME}
 | 
	
		
			
			|  | 270 | +    if [ -f /etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME ]; then
 | 
	
		
			
			|  | 271 | +        rm -f /etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 272 | +    fi
 | 
	
		
			
			|  | 273 | +    if [ -d /var/www/$PEERTUBE_DOMAIN_NAME ]; then
 | 
	
		
			
			|  | 274 | +        rm -rf /var/www/$PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 275 | +    fi
 | 
	
		
			
			|  | 276 | +    remove_config_param PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 277 | +    remove_config_param PEERTUBE_CODE
 | 
	
		
			
			|  | 278 | +    function_check remove_onion_service
 | 
	
		
			
			|  | 279 | +    remove_onion_service peertube ${PEERTUBE_ONION_PORT}
 | 
	
		
			
			|  | 280 | +    remove_completion_param "install_peertube"
 | 
	
		
			
			|  | 281 | +    sed -i '/peertube/d' $COMPLETION_FILE
 | 
	
		
			
			|  | 282 | +
 | 
	
		
			
			|  | 283 | +    function_check drop_database_postgresql
 | 
	
		
			
			|  | 284 | +    drop_database_postgresql peertube
 | 
	
		
			
			|  | 285 | +
 | 
	
		
			
			|  | 286 | +    groupdel -f peertube
 | 
	
		
			
			|  | 287 | +    userdel -r peertube
 | 
	
		
			
			|  | 288 | +
 | 
	
		
			
			|  | 289 | +    if [ -d $PEERTUBE_DIR ]; then
 | 
	
		
			
			|  | 290 | +        rm -rf $PEERTUBE_DIR
 | 
	
		
			
			|  | 291 | +    fi
 | 
	
		
			
			|  | 292 | +
 | 
	
		
			
			|  | 293 | +    function_check remove_ddns_domain
 | 
	
		
			
			|  | 294 | +    remove_ddns_domain $PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 295 | +}
 | 
	
		
			
			|  | 296 | +
 | 
	
		
			
			|  | 297 | +function peertube_setup_web {
 | 
	
		
			
			|  | 298 | +    peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 299 | +
 | 
	
		
			
			|  | 300 | +    if [[ $ONION_ONLY == "no" ]]; then
 | 
	
		
			
			|  | 301 | +        echo 'server {' > $peertube_nginx_file
 | 
	
		
			
			|  | 302 | +        echo '  listen 80;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 303 | +        echo '  # listen [::]:80;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 304 | +        echo "  server_name $PEERTUBE_DOMAIN_NAME;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 305 | +        echo '  rewrite ^ https://$server_name$request_uri? permanent;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 306 | +        echo '}' >> $peertube_nginx_file
 | 
	
		
			
			|  | 307 | +        echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 308 | +        echo 'server {' >> $peertube_nginx_file
 | 
	
		
			
			|  | 309 | +        echo '  listen 443 ssl; # spdy; # or http2' >> $peertube_nginx_file
 | 
	
		
			
			|  | 310 | +        echo '  # listen [::]:443 ssl spdy;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 311 | +        echo "  server_name $PEERTUBE_DOMAIN_NAME;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 312 | +        echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 313 | +        function_check nginx_ssl
 | 
	
		
			
			|  | 314 | +        nginx_ssl $PEERTUBE_DOMAIN_NAME mobile
 | 
	
		
			
			|  | 315 | +
 | 
	
		
			
			|  | 316 | +        function_check nginx_disable_sniffing
 | 
	
		
			
			|  | 317 | +        nginx_disable_sniffing $PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 318 | +
 | 
	
		
			
			|  | 319 | +        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $peertube_nginx_site
 | 
	
		
			
			|  | 320 | +        echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 321 | +        echo '  location / {' >> $peertube_nginx_file
 | 
	
		
			
			|  | 322 | +        echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
 | 
	
		
			
			|  | 323 | +        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 324 | +        echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 325 | +        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 326 | +        echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 327 | +        echo '    # For the video upload' >> $peertube_nginx_file
 | 
	
		
			
			|  | 328 | +        echo '    client_max_body_size 2G;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 329 | +        echo '  }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 330 | +        echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 331 | +        echo '  location /static/webseed {' >> $peertube_nginx_file
 | 
	
		
			
			|  | 332 | +        echo "    if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
 | 
	
		
			
			|  | 333 | +        echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 334 | +        echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 335 | +        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';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 336 | +        echo "      add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 337 | +        echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 338 | +        echo "      add_header 'Content-Length' 0;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 339 | +        echo '      return 204;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 340 | +        echo '    }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 341 | +        echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 342 | +        echo "    if (\$request_method = 'GET') {" >> $peertube_nginx_file
 | 
	
		
			
			|  | 343 | +        echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 344 | +        echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 345 | +        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';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 346 | +        echo '    }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 347 | +        echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 348 | +        echo "    alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 349 | +        echo '  }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 350 | +        echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 351 | +        echo '  # Websocket tracker' >> $peertube_nginx_file
 | 
	
		
			
			|  | 352 | +        echo '  location /tracker/socket {' >> $peertube_nginx_file
 | 
	
		
			
			|  | 353 | +        echo '    # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
 | 
	
		
			
			|  | 354 | +        echo '    # Dont close the websocket before this time' >> $peertube_nginx_file
 | 
	
		
			
			|  | 355 | +        echo '    proxy_read_timeout 1200s;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 356 | +        echo '    proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 357 | +        echo '    proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
 | 
	
		
			
			|  | 358 | +        echo '    proxy_http_version 1.1;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 359 | +        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 360 | +        echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 361 | +        echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
 | 
	
		
			
			|  | 362 | +        echo '  }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 363 | +        echo '}' >> $peertube_nginx_file
 | 
	
		
			
			|  | 364 | +    else
 | 
	
		
			
			|  | 365 | +        echo -n '' > $peertube_nginx_file
 | 
	
		
			
			|  | 366 | +    fi
 | 
	
		
			
			|  | 367 | +    echo 'server {' >> $peertube_nginx_file
 | 
	
		
			
			|  | 368 | +    echo "  listen 127.0.0.1:$PEERTUBE_ONION_PORT default_server;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 369 | +    echo "  server_name $PEERTUBE_ONION_HOSTNAME;" >> $eertube_nginx_file
 | 
	
		
			
			|  | 370 | +    echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 371 | +    echo '  location / {' >> $peertube_nginx_file
 | 
	
		
			
			|  | 372 | +    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
 | 
	
		
			
			|  | 373 | +    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 374 | +    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 375 | +    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 376 | +    echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 377 | +    echo '    # For the video upload' >> $peertube_nginx_file
 | 
	
		
			
			|  | 378 | +    echo '    client_max_body_size 2G;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 379 | +    echo '  }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 380 | +    echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 381 | +    echo '  location /static/webseed {' >> $peertube_nginx_file
 | 
	
		
			
			|  | 382 | +    echo "    if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
 | 
	
		
			
			|  | 383 | +    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 384 | +    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 385 | +    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';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 386 | +    echo "      add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 387 | +    echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 388 | +    echo "      add_header 'Content-Length' 0;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 389 | +    echo '      return 204;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 390 | +    echo '    }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 391 | +    echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 392 | +    echo "    if (\$request_method = 'GET') {" >> $peertube_nginx_file
 | 
	
		
			
			|  | 393 | +    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 394 | +    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 395 | +    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';" >> $peertube_nginx_file
 | 
	
		
			
			|  | 396 | +    echo '    }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 397 | +    echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 398 | +    echo "    alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
 | 
	
		
			
			|  | 399 | +    echo '  }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 400 | +    echo '' >> $peertube_nginx_file
 | 
	
		
			
			|  | 401 | +    echo '  # Websocket tracker' >> $peertube_nginx_file
 | 
	
		
			
			|  | 402 | +    echo '  location /tracker/socket {' >> $peertube_nginx_file
 | 
	
		
			
			|  | 403 | +    echo '    # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
 | 
	
		
			
			|  | 404 | +    echo '    # Dont close the websocket before this time' >> $peertube_nginx_file
 | 
	
		
			
			|  | 405 | +    echo '    proxy_read_timeout 1200s;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 406 | +    echo '    proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 407 | +    echo '    proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
 | 
	
		
			
			|  | 408 | +    echo '    proxy_http_version 1.1;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 409 | +    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 410 | +    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
 | 
	
		
			
			|  | 411 | +    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
 | 
	
		
			
			|  | 412 | +    echo '  }' >> $peertube_nginx_file
 | 
	
		
			
			|  | 413 | +    echo '}' >> $peertube_nginx_file
 | 
	
		
			
			|  | 414 | +
 | 
	
		
			
			|  | 415 | +    function_check create_site_certificate
 | 
	
		
			
			|  | 416 | +    create_site_certificate $PEERTUBE_DOMAIN_NAME 'yes'
 | 
	
		
			
			|  | 417 | +
 | 
	
		
			
			|  | 418 | +    function_check nginx_ensite
 | 
	
		
			
			|  | 419 | +    nginx_ensite $PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 420 | +}
 | 
	
		
			
			|  | 421 | +
 | 
	
		
			
			|  | 422 | +function peertube_create_config {
 | 
	
		
			
			|  | 423 | +    peertube_config_file=$PEERTUBE_DIR/config/production.yaml
 | 
	
		
			
			|  | 424 | +    echo 'listen:' > $peertube_config_file
 | 
	
		
			
			|  | 425 | +    echo "  port: $PEERTUBE_PORT" >> $peertube_config_file
 | 
	
		
			
			|  | 426 | +    echo '' >> $peertube_config_file
 | 
	
		
			
			|  | 427 | +    echo '# Correspond to your reverse proxy "listen" configuration' >> $peertube_config_file
 | 
	
		
			
			|  | 428 | +    echo 'webserver:' >> $peertube_config_file
 | 
	
		
			
			|  | 429 | +    echo '  https: true' >> $peertube_config_file
 | 
	
		
			
			|  | 430 | +    if [[ $ONION_ONLY == 'no' ]]; then
 | 
	
		
			
			|  | 431 | +        echo "  hostname: '$PEERTUBE_DOMAIN_NAME'" >> $peertube_config_file
 | 
	
		
			
			|  | 432 | +        echo '  port: 443' >> $peertube_config_file
 | 
	
		
			
			|  | 433 | +    else
 | 
	
		
			
			|  | 434 | +        echo "  hostname: '$PEERTUBE_ONION_HOSTNAME'" >> $peertube_config_file
 | 
	
		
			
			|  | 435 | +        echo '  port: 80' >> $peertube_config_file
 | 
	
		
			
			|  | 436 | +    fi
 | 
	
		
			
			|  | 437 | +    echo '' >> $peertube_config_file
 | 
	
		
			
			|  | 438 | +    echo '# Your database name will be "peertube"+database.suffix' >> $peertube_config_file
 | 
	
		
			
			|  | 439 | +    echo 'database:' >> $peertube_config_file
 | 
	
		
			
			|  | 440 | +    echo "  hostname: 'localhost'" >> $peertube_config_file
 | 
	
		
			
			|  | 441 | +    echo '  port: 5432' >> $peertube_config_file
 | 
	
		
			
			|  | 442 | +    echo "  suffix: ''" >> $peertube_config_file
 | 
	
		
			
			|  | 443 | +    echo "  username: 'peertube'" >> $peertube_config_file
 | 
	
		
			
			|  | 444 | +    echo "  password: '$PEERTUBE_ADMIN_PASSWORD'" >> $peertube_config_file
 | 
	
		
			
			|  | 445 | +    echo '' >> $peertube_config_file
 | 
	
		
			
			|  | 446 | +    echo '# From the project root directory' >> $peertube_config_file
 | 
	
		
			
			|  | 447 | +    echo 'storage:' >> $peertube_config_file
 | 
	
		
			
			|  | 448 | +    echo "  certs: 'certs/'" >> $peertube_config_file
 | 
	
		
			
			|  | 449 | +    echo "  videos: 'videos/'" >> $peertube_config_file
 | 
	
		
			
			|  | 450 | +    echo "  logs: 'logs/'" >> $peertube_config_file
 | 
	
		
			
			|  | 451 | +    echo "  previews: 'previews/'" >> $peertube_config_file
 | 
	
		
			
			|  | 452 | +    echo "  thumbnails: 'thumbnails/'" >> $peertube_config_file
 | 
	
		
			
			|  | 453 | +    echo "  torrents: 'torrents/'" >> $peertube_config_file
 | 
	
		
			
			|  | 454 | +    echo "  cache: 'cache/'" >> $peertube_config_file
 | 
	
		
			
			|  | 455 | +    echo '' >> $peertube_config_file
 | 
	
		
			
			|  | 456 | +    echo 'cache:' >> $peertube_config_file
 | 
	
		
			
			|  | 457 | +    echo '  previews:' >> $peertube_config_file
 | 
	
		
			
			|  | 458 | +    echo '    size: 10 # Max number of previews you want to cache' >> $peertube_config_file
 | 
	
		
			
			|  | 459 | +    echo '' >> $peertube_config_file
 | 
	
		
			
			|  | 460 | +    echo 'admin:' >> $peertube_config_file
 | 
	
		
			
			|  | 461 | +    echo "  email: '$MY_EMAIL_ADDRESS'" >> $peertube_config_file
 | 
	
		
			
			|  | 462 | +    echo '' >> $peertube_config_file
 | 
	
		
			
			|  | 463 | +    echo 'signup:' >> $peertube_config_file
 | 
	
		
			
			|  | 464 | +    echo '  enabled: false' >> $peertube_config_file
 | 
	
		
			
			|  | 465 | +    echo ;  limit: 10 # When the limit is reached, registrations are disabled. -1 == unlimited' >> $peertube_config_file
 | 
	
		
			
			|  | 466 | +    echo '' >> $peertube_config_file
 | 
	
		
			
			|  | 467 | +    echo 'user:' >> $peertube_config_file
 | 
	
		
			
			|  | 468 | +    echo '  # Default value of maximum video BYTES the user can upload (does not take into account transcoded files).' >> $peertube_config_file
 | 
	
		
			
			|  | 469 | +    echo '  # -1 == unlimited' >> $peertube_config_file
 | 
	
		
			
			|  | 470 | +    echo '  video_quota: -1' >> $peertube_config_file
 | 
	
		
			
			|  | 471 | +    echo '' >> $peertube_config_file
 | 
	
		
			
			|  | 472 | +    echo '# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag' >> $peertube_config_file
 | 
	
		
			
			|  | 473 | +    echo '# Uses a lot of CPU!' >> $peertube_config_file
 | 
	
		
			
			|  | 474 | +    echo 'transcoding:' >> $peertube_config_file
 | 
	
		
			
			|  | 475 | +    echo '  enabled: false' >> $peertube_config_file
 | 
	
		
			
			|  | 476 | +    echo '  threads: 2' >> $peertube_config_file
 | 
	
		
			
			|  | 477 | +    echo '  resolutions: # Only created if the original video has a higher resolution' >> $peertube_config_file
 | 
	
		
			
			|  | 478 | +    echo '    240p: true' >> $peertube_config_file
 | 
	
		
			
			|  | 479 | +    echo '    360p: true' >> $peertube_config_file
 | 
	
		
			
			|  | 480 | +    echo '    480p: true' >> $peertube_config_file
 | 
	
		
			
			|  | 481 | +    echo '    720p: true' >> $peertube_config_file
 | 
	
		
			
			|  | 482 | +    echo '    1080p: true' >> $peertube_config_file
 | 
	
		
			
			|  | 483 | +}
 | 
	
		
			
			|  | 484 | +
 | 
	
		
			
			|  | 485 | +function install_peertube {
 | 
	
		
			
			|  | 486 | +    if [ ! $ONION_ONLY ]; then
 | 
	
		
			
			|  | 487 | +        ONION_ONLY='no'
 | 
	
		
			
			|  | 488 | +    fi
 | 
	
		
			
			|  | 489 | +
 | 
	
		
			
			|  | 490 | +    if [ ! $PEERTUBE_DOMAIN_NAME ]; then
 | 
	
		
			
			|  | 491 | +        echo $'The peertube domain name was not specified'
 | 
	
		
			
			|  | 492 | +        exit 783523
 | 
	
		
			
			|  | 493 | +    fi
 | 
	
		
			
			|  | 494 | +
 | 
	
		
			
			|  | 495 | +    apt-get -yq install ffmpeg
 | 
	
		
			
			|  | 496 | +
 | 
	
		
			
			|  | 497 | +    function_check install_postgresql
 | 
	
		
			
			|  | 498 | +    install_postgresql
 | 
	
		
			
			|  | 499 | +
 | 
	
		
			
			|  | 500 | +    if [ ! -d /var/www/$PEERTUBE_DOMAIN_NAME/htdocs ]; then
 | 
	
		
			
			|  | 501 | +        mkdir -p /var/www/$PEERTUBE_DOMAIN_NAME/htdocs
 | 
	
		
			
			|  | 502 | +    fi
 | 
	
		
			
			|  | 503 | +
 | 
	
		
			
			|  | 504 | +    if [ -d $PEERTUBE_DIR ]; then
 | 
	
		
			
			|  | 505 | +        rm -rf $PEERTUBE_DIR
 | 
	
		
			
			|  | 506 | +    fi
 | 
	
		
			
			|  | 507 | +
 | 
	
		
			
			|  | 508 | +    groupadd peertube
 | 
	
		
			
			|  | 509 | +    useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
 | 
	
		
			
			|  | 510 | +
 | 
	
		
			
			|  | 511 | +    peertube_create_database
 | 
	
		
			
			|  | 512 | +
 | 
	
		
			
			|  | 513 | +    function_check install_nodejs
 | 
	
		
			
			|  | 514 | +    install_nodejs peertube
 | 
	
		
			
			|  | 515 | +
 | 
	
		
			
			|  | 516 | +    if [ -d /repos/peertube ]; then
 | 
	
		
			
			|  | 517 | +        mkdir -p $PEERTUBE_DIR
 | 
	
		
			
			|  | 518 | +        cp -r -p /repos/peertube/. $PEERTUBE_DIR
 | 
	
		
			
			|  | 519 | +        cd $PEERTUBE_DIR
 | 
	
		
			
			|  | 520 | +        git pull
 | 
	
		
			
			|  | 521 | +    else
 | 
	
		
			
			|  | 522 | +        function_check git_clone
 | 
	
		
			
			|  | 523 | +        git_clone $PEERTUBE_REPO $PEERTUBE_DIR
 | 
	
		
			
			|  | 524 | +    fi
 | 
	
		
			
			|  | 525 | +
 | 
	
		
			
			|  | 526 | +    cd $PEERTUBE_DIR
 | 
	
		
			
			|  | 527 | +    git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
 | 
	
		
			
			|  | 528 | +    set_completion_param "peertube commit" "$PEERTUBE_COMMIT"
 | 
	
		
			
			|  | 529 | +
 | 
	
		
			
			|  | 530 | +    npm install -g yarn
 | 
	
		
			
			|  | 531 | +    if [ ! "$?" = "0" ]; then
 | 
	
		
			
			|  | 532 | +        echo $'Failed to install yarn'
 | 
	
		
			
			|  | 533 | +        exit 79353234
 | 
	
		
			
			|  | 534 | +    fi
 | 
	
		
			
			|  | 535 | +    yarn install
 | 
	
		
			
			|  | 536 | +    if [ ! "$?" = "0" ]; then
 | 
	
		
			
			|  | 537 | +        echo $'Failed to run yarn install'
 | 
	
		
			
			|  | 538 | +        exit 63754235
 | 
	
		
			
			|  | 539 | +    fi
 | 
	
		
			
			|  | 540 | +    npm run build
 | 
	
		
			
			|  | 541 | +    if [ ! "$?" = "0" ]; then
 | 
	
		
			
			|  | 542 | +        echo $'Failed to build peertube'
 | 
	
		
			
			|  | 543 | +        exit 5293593
 | 
	
		
			
			|  | 544 | +    fi
 | 
	
		
			
			|  | 545 | +
 | 
	
		
			
			|  | 546 | +    # revoke the ability to create databases for this user
 | 
	
		
			
			|  | 547 | +    run_system_query_postgresql "ALTER USER peertube NOSUPERUSER;"
 | 
	
		
			
			|  | 548 | +    run_system_query_postgresql "ALTER USER peertube NOCREATEDB;"
 | 
	
		
			
			|  | 549 | +
 | 
	
		
			
			|  | 550 | +    PEERTUBE_ONION_HOSTNAME=$(add_onion_service peertube 80 ${PEERTUBE_ONION_PORT})
 | 
	
		
			
			|  | 551 | +
 | 
	
		
			
			|  | 552 | +    echo '[Unit]' > /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 553 | +    echo 'Description=PeerTube Decentralized video streaming platform' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 554 | +    echo 'After=syslog.target' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 555 | +    echo 'After=network.target' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 556 | +    echo '' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 557 | +    echo '[Service]' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 558 | +    echo 'User=peertube' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 559 | +    echo 'Group=peertube' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 560 | +    echo "WorkingDirectory=$PEERTUBE_DIR" >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 561 | +    echo "ExecStart=/usr/local/bin/npm start" >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 562 | +    echo "ExecStop=/usr/local/bin/npm stop" >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 563 | +    echo 'StandardOutput=syslog' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 564 | +    echo 'StandardError=syslog' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 565 | +    echo 'SyslogIdentifier=peertube' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 566 | +    echo 'Restart=always' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 567 | +    echo "Environment=NODE_ENV=production PORT=${PEERTUBE_PORT}" >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 568 | +    echo '' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 569 | +    echo '[Install]' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 570 | +    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/peertube.service
 | 
	
		
			
			|  | 571 | +
 | 
	
		
			
			|  | 572 | +    peertube_create_config
 | 
	
		
			
			|  | 573 | +
 | 
	
		
			
			|  | 574 | +    chown -R peertube:peertube $PEERTUBE_DIR
 | 
	
		
			
			|  | 575 | +
 | 
	
		
			
			|  | 576 | +    peertube_setup_web
 | 
	
		
			
			|  | 577 | +
 | 
	
		
			
			|  | 578 | +    ${PROJECT_NAME}-pass -u $MY_USERNAME -a peertube -p "$PEERTUBE_ADMIN_PASSWORD"
 | 
	
		
			
			|  | 579 | +
 | 
	
		
			
			|  | 580 | +    function_check add_ddns_domain
 | 
	
		
			
			|  | 581 | +    add_ddns_domain $PEERTUBE_DOMAIN_NAME
 | 
	
		
			
			|  | 582 | +
 | 
	
		
			
			|  | 583 | +    systemctl enable peertube
 | 
	
		
			
			|  | 584 | +    systemctl daemon-reload
 | 
	
		
			
			|  | 585 | +    systemctl start peertube
 | 
	
		
			
			|  | 586 | +    systemctl restart nginx
 | 
	
		
			
			|  | 587 | +
 | 
	
		
			
			|  | 588 | +    set_completion_param "peertube domain" "$PEERTUBE_DOMAIN_NAME"
 | 
	
		
			
			|  | 589 | +    APP_INSTALLED=1
 | 
	
		
			
			|  | 590 | +}
 | 
	
		
			
			|  | 591 | +
 | 
	
		
			
			|  | 592 | +# NOTE: deliberately no exit 0
 |