Add peertube to mesh client
This commit is contained in:
parent
a497c03195
commit
425cfdb5a1
|
@ -39,6 +39,7 @@ PEERTUBE_REPO="https://github.com/Chocobozzz/PeerTube"
|
|||
PEERTUBE_COMMIT='fef2c7164e025b12a64185dbab058ef4129733c6'
|
||||
PEERTUBE_ONION_PORT=8136
|
||||
PEERTUBE_PORT=9004
|
||||
MESH_PEERTUBE_PORT=8500
|
||||
PEERTUBE_DIR=/etc/peertube
|
||||
|
||||
peertube_variables=(PEERTUBE_DOMAIN_NAME
|
||||
|
@ -479,21 +480,83 @@ function peertube_setup_web {
|
|||
nginx_ensite $PEERTUBE_DOMAIN_NAME
|
||||
}
|
||||
|
||||
function mesh_peertube_setup_web {
|
||||
peertube_nginx_file=$rootdir/etc/nginx/sites-available/peertube
|
||||
|
||||
echo 'server {' >> $peertube_nginx_file
|
||||
echo " listen $MESH_PEERTUBE_PORT http2;" >> $peertube_nginx_file
|
||||
echo ' listen [::]:$MESH_PEERTUBE_PORT http2;' >> $peertube_nginx_file
|
||||
echo ' server_name $HOSTNAME;' >> $peertube_nginx_file
|
||||
echo '' >> $peertube_nginx_file
|
||||
echo ' location / {' >> $peertube_nginx_file
|
||||
echo " proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
|
||||
echo ' proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
|
||||
echo ' proxy_set_header Host $host;' >> $peertube_nginx_file
|
||||
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
|
||||
echo '' >> $peertube_nginx_file
|
||||
echo ' # For the video upload' >> $peertube_nginx_file
|
||||
echo ' client_max_body_size 2G;' >> $peertube_nginx_file
|
||||
echo ' }' >> $peertube_nginx_file
|
||||
echo '' >> $peertube_nginx_file
|
||||
echo ' location /static/webseed {' >> $peertube_nginx_file
|
||||
echo " if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
|
||||
echo " add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
|
||||
echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
|
||||
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
|
||||
echo " add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
|
||||
echo " add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
|
||||
echo " add_header 'Content-Length' 0;" >> $peertube_nginx_file
|
||||
echo ' return 204;' >> $peertube_nginx_file
|
||||
echo ' }' >> $peertube_nginx_file
|
||||
echo '' >> $peertube_nginx_file
|
||||
echo " if (\$request_method = 'GET') {" >> $peertube_nginx_file
|
||||
echo " add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
|
||||
echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
|
||||
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
|
||||
echo ' }' >> $peertube_nginx_file
|
||||
echo '' >> $peertube_nginx_file
|
||||
echo " alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
|
||||
echo ' }' >> $peertube_nginx_file
|
||||
echo '' >> $peertube_nginx_file
|
||||
echo ' # Websocket tracker' >> $peertube_nginx_file
|
||||
echo ' location /tracker/socket {' >> $peertube_nginx_file
|
||||
echo ' # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
|
||||
echo ' # Dont close the websocket before this time' >> $peertube_nginx_file
|
||||
echo ' proxy_read_timeout 1200s;' >> $peertube_nginx_file
|
||||
echo ' proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
|
||||
echo ' proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
|
||||
echo ' proxy_http_version 1.1;' >> $peertube_nginx_file
|
||||
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
|
||||
echo ' proxy_set_header Host $host;' >> $peertube_nginx_file
|
||||
echo " proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
|
||||
echo ' }' >> $peertube_nginx_file
|
||||
echo '}' >> $peertube_nginx_file
|
||||
}
|
||||
|
||||
function peertube_create_config {
|
||||
peertube_config_file=$PEERTUBE_DIR/config/production.yaml
|
||||
peertube_prefix=$1
|
||||
|
||||
peertube_config_file=$peertube_prefix$PEERTUBE_DIR/config/production.yaml
|
||||
|
||||
echo 'listen:' > $peertube_config_file
|
||||
echo " port: $PEERTUBE_PORT" >> $peertube_config_file
|
||||
echo '' >> $peertube_config_file
|
||||
echo '# Correspond to your reverse proxy "listen" configuration' >> $peertube_config_file
|
||||
echo 'webserver:' >> $peertube_config_file
|
||||
if [[ $ONION_ONLY == 'no' ]]; then
|
||||
echo ' https: true' >> $peertube_config_file
|
||||
echo " hostname: '$PEERTUBE_DOMAIN_NAME'" >> $peertube_config_file
|
||||
echo ' port: 443' >> $peertube_config_file
|
||||
if [ ! $peertube_prefix ]; then
|
||||
if [[ $ONION_ONLY == 'no' ]]; then
|
||||
echo ' https: true' >> $peertube_config_file
|
||||
echo " hostname: '$PEERTUBE_DOMAIN_NAME'" >> $peertube_config_file
|
||||
echo ' port: 443' >> $peertube_config_file
|
||||
else
|
||||
echo ' https: false' >> $peertube_config_file
|
||||
echo " hostname: '$PEERTUBE_ONION_HOSTNAME'" >> $peertube_config_file
|
||||
echo ' port: 80' >> $peertube_config_file
|
||||
fi
|
||||
else
|
||||
echo ' https: false' >> $peertube_config_file
|
||||
echo " hostname: '$PEERTUBE_ONION_HOSTNAME'" >> $peertube_config_file
|
||||
echo ' port: 80' >> $peertube_config_file
|
||||
echo " hostname: ''" >> $peertube_config_file
|
||||
echo " port: $MESH_PEERTUBE_PORT" >> $peertube_config_file
|
||||
fi
|
||||
echo '' >> $peertube_config_file
|
||||
echo '# Your database name will be "peertube"+database.suffix' >> $peertube_config_file
|
||||
|
@ -502,7 +565,11 @@ function peertube_create_config {
|
|||
echo ' port: 5432' >> $peertube_config_file
|
||||
echo " suffix: ''" >> $peertube_config_file
|
||||
echo " username: 'peertube'" >> $peertube_config_file
|
||||
echo " password: '$PEERTUBE_ADMIN_PASSWORD'" >> $peertube_config_file
|
||||
if [ ! $peertube_prefix ]; then
|
||||
echo " password: '$PEERTUBE_ADMIN_PASSWORD'" >> $peertube_config_file
|
||||
else
|
||||
echo " password: ''" >> $peertube_config_file
|
||||
fi
|
||||
echo '' >> $peertube_config_file
|
||||
echo '# From the project root directory' >> $peertube_config_file
|
||||
echo 'storage:' >> $peertube_config_file
|
||||
|
@ -519,7 +586,7 @@ function peertube_create_config {
|
|||
echo ' size: 10 # Max number of previews you want to cache' >> $peertube_config_file
|
||||
echo '' >> $peertube_config_file
|
||||
echo 'admin:' >> $peertube_config_file
|
||||
echo " email: '$MY_EMAIL_ADDRESS'" >> $peertube_config_file
|
||||
echo " email: 'root@local'" >> $peertube_config_file
|
||||
echo '' >> $peertube_config_file
|
||||
echo 'signup:' >> $peertube_config_file
|
||||
echo ' enabled: true' >> $peertube_config_file
|
||||
|
@ -543,7 +610,93 @@ function peertube_create_config {
|
|||
echo ' 1080p: false' >> $peertube_config_file
|
||||
}
|
||||
|
||||
function mesh_install_peertube {
|
||||
if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
chroot "$rootdir" apt-get -yq install ffmpeg
|
||||
|
||||
function_check install_postgresql
|
||||
install_postgresql
|
||||
|
||||
if [ -d $rootdir$PEERTUBE_DIR ]; then
|
||||
rm -rf $rootdir$PEERTUBE_DIR
|
||||
fi
|
||||
|
||||
chroot "$rootdir" groupadd peertube
|
||||
chroot "$rootdir" useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
|
||||
|
||||
#peertube_create_database
|
||||
|
||||
git clone $PEERTUBE_REPO $rootdir$PEERTUBE_DIR
|
||||
|
||||
cd $rootdir$PEERTUBE_DIR
|
||||
git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
|
||||
|
||||
get_npm_arch
|
||||
|
||||
cat <<EOF > $rootdir/usr/bin/install_peertube
|
||||
#!/bin/bash
|
||||
cd $PEERTUBE_DIR
|
||||
npm install --arch=$NPM_ARCH -g yarn
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo $'PeerTube Failed to install yarn'
|
||||
exit 79353234
|
||||
fi
|
||||
yarn add -D webpack --network-concurrency 1
|
||||
yarn install
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo $'PeerTube Failed to run yarn install'
|
||||
exit 63754235
|
||||
fi
|
||||
npm install --arch=$NPM_ARCH
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo $'PeerTube Failed to install peertube'
|
||||
exit 7835243
|
||||
fi
|
||||
npm run build --arch=$NPM_ARCH
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo $'PeerTube Failed to build peertube'
|
||||
exit 5293593
|
||||
fi
|
||||
EOF
|
||||
chmod +x $rootdir/usr/bin/install_peertube
|
||||
chroot "$rootdir" /usr/bin/install_peertube
|
||||
|
||||
echo '[Unit]' > $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'Description=PeerTube Decentralized video streaming platform' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'After=syslog.target' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'After=network.target' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo '' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo '[Service]' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'User=peertube' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'Group=peertube' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo "WorkingDirectory=$PEERTUBE_DIR" >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo "ExecStart=/usr/local/bin/npm start" >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo "ExecStop=/usr/local/bin/npm stop" >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'StandardOutput=syslog' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'StandardError=syslog' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'SyslogIdentifier=peertube' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'Restart=always' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo "Environment=NODE_ENV=production" >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo '' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo '[Install]' >> $rootdir/etc/systemd/system/peertube.service
|
||||
echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/peertube.service
|
||||
|
||||
peertube_create_config $rootdir
|
||||
|
||||
chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
|
||||
|
||||
mesh_peertube_setup_web
|
||||
}
|
||||
|
||||
function install_peertube {
|
||||
if [[ $VARIANT == "mesh"* ]]; then
|
||||
mesh_install_peertube
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ! $ONION_ONLY ]; then
|
||||
ONION_ONLY='no'
|
||||
fi
|
||||
|
|
|
@ -705,6 +705,7 @@ initialise_mesh() {
|
|||
install_web_server
|
||||
install_pelican
|
||||
mesh_install_cryptpad
|
||||
mesh_install_peertube
|
||||
if [ $ENABLE_ZERONET ]; then
|
||||
install_zeronet
|
||||
fi
|
||||
|
@ -960,6 +961,35 @@ if [ \$no_of_users -gt 0 ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f /home/$MY_USERNAME/.peertube.desktop ]; then
|
||||
if [ ! -f /home/$MY_USERNAME/Desktop/peertube.desktop ]; then
|
||||
echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Name=PeerTube' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment=Upload and view videos on the mesh' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[el]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[ar]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[ca]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[hi]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[fr]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[de]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[es]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[it]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[ru]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Comment[zh]=' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo "Exec=$BROWSER $BROWSER_OPTIONS http://\${HOSTNAME}.local:$MESH_PEERTUBE_PORT" >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo "Icon=/usr/share/$PROJECT_NAME/avatars/icon_peertube.png" >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Terminal=false' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
echo 'Categories=Application;' >> /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
chmod +x /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
else
|
||||
if ! grep -q "\${HOSTNAME}.local" /home/$MY_USERNAME/Desktop/peertube.desktop; then
|
||||
sed -i "s|Exec=.*|Exec=$BROWSER $BROWSER_OPTIONS http://\${HOSTNAME}.local:$MESH_PEERTUBE_PORT|g" /home/$MY_USERNAME/Desktop/peertube.desktop
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f /home/$MY_USERNAME/Desktop/social.desktop ]; then
|
||||
echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/social.desktop
|
||||
echo 'Name=Social' >> /home/$MY_USERNAME/Desktop/social.desktop
|
||||
|
|
|
@ -88,6 +88,59 @@ SCUTTLEBOT_PORT=8010
|
|||
CRYPTPAD_PORT=9003
|
||||
CRYPTPAD_DIR=/etc/cryptpad
|
||||
|
||||
PEERTUBE_DIR=/etc/peertube
|
||||
|
||||
function run_system_query_postgresql {
|
||||
query=$1
|
||||
cd /etc/postgresql
|
||||
sudo -u postgres psql -c "$query"
|
||||
}
|
||||
|
||||
function create_password {
|
||||
openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c ${1} ; echo -n ''
|
||||
}
|
||||
|
||||
function enable_peertube {
|
||||
if [ ! -d $PEERTUBE_DIR ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
PEERTUBE_ADMIN_PASSWORD="$(create_password 10)"
|
||||
|
||||
if [ -d $PEERTUBE_DIR/videos ]; then
|
||||
rm -rf $PEERTUBE_DIR/videos/*
|
||||
fi
|
||||
if [ -d $PEERTUBE_DIR/thumbnails ]; then
|
||||
rm -rf $PEERTUBE_DIR/thumbnails/*
|
||||
fi
|
||||
|
||||
systemctl restart postgresql
|
||||
run_system_query_postgresql "DROP DATABASE peertube;"
|
||||
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;"
|
||||
run_system_query_postgresql "set statement_timeout to 40000;"
|
||||
|
||||
peertube_config_file=$PEERTUBE_DIR/config/production.yaml
|
||||
sed -i "s|hostname:.*|hostname: 'P$PEER_ID.local'|g" $peertube_config_file
|
||||
sed -i "s|password:.*|password: '$PEERTUBE_ADMIN_PASSWORD'|g" $peertube_config_file
|
||||
|
||||
peertube_nginx_file=/etc/nginx/sites-available/peertube
|
||||
sed -i "s|server_name.*|server_name P$PEER_ID.local;|g" $peertube_nginx_file
|
||||
|
||||
chown -R peertube:peertube $PEERTUBE_DIR
|
||||
|
||||
# Set up the web server
|
||||
ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
|
||||
if [ -f /etc/nginx/sites-enabled/default ]; then
|
||||
rm /etc/nginx/sites-enabled/default
|
||||
fi
|
||||
|
||||
systemctl enable peertube
|
||||
systemctl daemon-reload
|
||||
systemctl start peertube
|
||||
}
|
||||
|
||||
function enable_cryptpad {
|
||||
if [ ! -d $CRYPTPAD_DIR ]; then
|
||||
return
|
||||
|
@ -95,7 +148,9 @@ function enable_cryptpad {
|
|||
|
||||
# Set up the web server
|
||||
ln -s /etc/nginx/sites-available/cryptpad /etc/nginx/sites-enabled/cryptpad
|
||||
rm /etc/nginx/sites-enabled/default
|
||||
if [ -f /etc/nginx/sites-enabled/default ]; then
|
||||
rm /etc/nginx/sites-enabled/default
|
||||
fi
|
||||
|
||||
if [ ! -d $CRYPTPAD_DIR/customize/api ]; then
|
||||
mkdir -p $CRYPTPAD_DIR/customize/api
|
||||
|
@ -1042,6 +1097,7 @@ if [ -f $MESH_INSTALL_SETUP ]; then
|
|||
initialise_scuttlebot_pub
|
||||
setup_ipfs
|
||||
enable_cryptpad
|
||||
enable_peertube
|
||||
mesh_amnesic
|
||||
make_root_read_only
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
# Set this when calling backup and restore commands
|
||||
USE_POSTGRESQL=
|
||||
POSTGRESQL_PACKAGES='postgresql-9.6 postgresql-contrib-9.6 postgresql-client'
|
||||
|
||||
function store_original_postgresql_password {
|
||||
if [ ! -f /root/.postgresqloriginal ]; then
|
||||
|
@ -48,7 +49,26 @@ function get_postgresql_password {
|
|||
fi
|
||||
}
|
||||
|
||||
function mesh_install_postgresql {
|
||||
chroot "$rootdir" apt-get -yq install $POSTGRESQL_PACKAGES
|
||||
|
||||
if [ ! -d $rootdir/etc/postgresql ]; then
|
||||
echo $"ERROR: postgresql does not appear to have installed."
|
||||
exit 78352
|
||||
fi
|
||||
|
||||
if [ ! -f $rootdir/usr/bin/psql ]; then
|
||||
echo $"ERROR: psql command does not appear to have installed."
|
||||
exit 835290
|
||||
fi
|
||||
}
|
||||
|
||||
function install_postgresql {
|
||||
if [[ $VARIANT == "mesh"* ]]; then
|
||||
mesh_install_postgresql
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
|
||||
return
|
||||
fi
|
||||
|
@ -64,7 +84,7 @@ function install_postgresql {
|
|||
fi
|
||||
${PROJECT_NAME}-pass -u root -a postgresql -p "$POSTGRESQL_PASSWORD"
|
||||
|
||||
apt-get -yq install postgresql-9.6 postgresql-contrib-9.6 postgresql-client
|
||||
apt-get -yq install $POSTGRESQL_PACKAGES
|
||||
apt-get -yq remove --purge apache2-bin*
|
||||
if [ -d /etc/apache2 ]; then
|
||||
rm -rf /etc/apache2
|
||||
|
@ -72,12 +92,12 @@ function install_postgresql {
|
|||
fi
|
||||
|
||||
if [ ! -d /etc/postgresql ]; then
|
||||
echo $"ERROR: postgresql does not appear to have installed. $CHECK_MESSAGE"
|
||||
echo $"ERROR: postgresql does not appear to have installed."
|
||||
exit 78352
|
||||
fi
|
||||
|
||||
if [ ! -f /usr/bin/psql ]; then
|
||||
echo $"ERROR: psql command does not appear to have installed. $CHECK_MESSAGE"
|
||||
echo $"ERROR: psql command does not appear to have installed."
|
||||
exit 835290
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue