Skip to content

Instantly share code, notes, and snippets.

@EWouters
Created March 9, 2017 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EWouters/f56114030e16a1e64eeee7c67696d2f6 to your computer and use it in GitHub Desktop.
Save EWouters/f56114030e16a1e64eeee7c67696d2f6 to your computer and use it in GitHub Desktop.
Script to install Spreed WebRTC. Will not work by itself.
#!/bin/bash
# The repo for Spreed WebRTC will not work, therefore:
ASK_INSTALL_SPREED=2
CPUS=$(grep ^processor /proc/cpuinfo | wc -l)
do_install_spreed_webrtc() {
if [ -f $LOCK_DIR/spreed_webrtc-installed.lock ]; then
echo && echo "Spreed WebRTC is already installed and configured. Continuing..." && echo && sleep 1
else
# https://help.nextcloud.com/t/install-collabora-and-spreed-me/9532/6
# https://www.c-rieger.de/enable-spreed-me-in-nextcloud/
do_ask_install_go
do_ask_install_nodejs
do_ask_install_spreed
# First we gonna make go available on our system.
if [[ $ASK_INSTALL_GO -eq 0 ]]; then
apt-get$QUIET_APT install -y golang-go
else
VERSION_GO=go1.8.linux-armv6l
SOURCE_GO=https://storage.googleapis.com/golang/
GPATH=/usr/local/src
do_install_go_source
fi
go version
# Node.js
if [[ $ASK_INSTALL_NODE -eq 2 ]]; then
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
fi
apt-get$QUIET_APT install -y git nodejs make automake
# Install Spreed WebRTC
if [[ $ASK_INSTALL_SPREED -eq 0 ]]; then
apt-get$QUIET_APT install -y software-properties-common
apt-add-repository ppa:strukturag/spreed-webrtc
apt-get$QUIET_APT update
apt-get install spreed-webrtc
else
VERSION_SPREED=master
SOURCE_SPREED=https://github.com/strukturag/spreed-webrtc/archive/
BPATH=/opt
do_install_spreed_webrtc_source
SPREED_ROOT=/opt/spreed-webrtc-$VERSION_SPREED
fi
# Download the Spreed.ME app, unzip the package, rename it to spreedme and remove the master.zip
# Name of latest version of the package
VERSION_SPREED_APP=master
# URL to the source directory
SOURCE_SPREED_APP=https://github.com/strukturag/nextcloud-spreedme/archive/
cd /var/www/nextcloud/apps
wget -P /var/www/nextcloud/apps $SOURCE_SPREED_APP$VERSION_SPREED_APP.tar.gz
tar -xzf $VERSION_SPREED_APP.tar.gz
rm $VERSION_SPREED_APP.tar.gz
mv nextcloud-spreedme-$VERSION_SPREED spreedme
do_load_php_conf
OCC="sudo -u www-data $PHP_BIN /var/www/nextcloud/occ"
$OCC app:enable spreedme
# Configure
cp $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf.in $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
SHARED_SECRET=$($OCC config:app:get spreedme SPREED_WEBRTC_SHAREDSECRET)
#nano $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
if [[ $ASK_INSTALL_SPREED -eq 2 ]]; then
sed -i "s~;root = /usr/share/spreed-webrtc-server/www~root = /opt/spreed-webrtc-$VERSION_SPREED~" $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
fi
sed -i 's~;basePath = /some/sub/path/~basePath = /webrtc/~' $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i "s/sessionSecret = the-default-secret-do-not-keep-me/sessionSecret = $(openssl rand -hex 32)/" $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i "s/encryptionSecret = tne-default-encryption-block-key/encryptionSecret = $(openssl rand -hex 32)/" $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i "s/;authorizeRoomJoin = false/authorizeRoomJoin = true/" $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i 's~;extra = /usr/share/spreed-webrtc-server/extra~extra = /var/www/nextcloud/apps/spreedme/extra~' $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i 's~;plugin = extra/static/myplugin.js~plugin = extra/static/owncloud.js~' $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i 's/;stunURIs = stun:stun.spreed.me:443/stunURIs = stun:stun.spreed.me:443/' $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i 's/enabled = false/enabled = true/' $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i 's/;mode = sharedsecret/mode = sharedsecret/' $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
sed -i "s/;sharedsecret_secret = some-secret-do-not-keep/sharedsecret_secret = $SHARED_SECRET/" $BPATH/spreed-webrtc-$VERSION_SPREED/server.conf
do_configure_spreed_webrtc_gateway
sleep 1
#touch $LOCK_DIR/spreed_webrtc-installed.lock
fi
}
do_install_spreed_webrtc_source() {
# Compile Spreed WebRTC
cd $BPATH
wget -P $BPATH $SOURCE_SPREED$VERSION_SPREED.tar.gz
tar -xzf $VERSION_SPREED.tar.gz
rm $VERSION_SPREED.tar.gz
cd $BPATH/spreed-webrtc-$VERSION_SPREED
./autogen.sh
./configure
make -j $CPUS
# https://help.nextcloud.com/t/spreed-me-howto-autorun-spreed-webrtc-server-step-by-step/7721
# Create a system user spreed:www-data, that will be used to start the spreed server later by the systemd unit
adduser --quiet --system --ingroup "www-data" --home "/opt/spreed-webrtc-$VERSION_SPREED" --no-create-home --disabled-login "spreed" 2>/dev/null || true
# Create a log file and chown it to our new user to be able to write it
touch /var/log/spreed.log
chown spreed:www-data /var/log/spreed.log
#We will now make the whole spreed server directory executable to the user.
#It might be possible to just make a few files executable, but at least the two binaries in server root and /bin, as well as the folders itself are not enough.
chmod -R 755 /opt/spreed-webrtc-$VERSION_SPREED
# Now we will create the environment file for the systemd script, adding the information about the user, files and folders we just created:
#nano /etc/default/spreed
cat > /etc/default/spreed << EOF
# Defaults for spreed-webrtc initscripts
WEBRTC_USER='spreed'
WEBRTC_GROUP='www-data'
WEBRTC_CONF='/opt/spreed-webrtc-$VERSION_SPREED/server.conf'
WEBRTC_LOG='/var/log/spreed.log'
WEBRTC_GOMAXPROCS=1
WEBRTC_NOFILE=1024
EOF
# Create the systemd unit itself and enable it to establish the service
#nano /etc/systemd/system/spreed.service
cat > /etc/systemd/system/spreed.service << EOF
[Unit]
Description=Spreed WebRTC server
After=network.target
[Service]
Type=simple
EnvironmentFile=/etc/default/spreed
# TODO: These values should come from the EnvironmentFile.
Environment=GOMAXPROCS=1
LimitNOFILE=1024
User=spreed
Group=www-data
PermissionsStartOnly=true
ExecStart=/opt/spreed-webrtc-$VERSION_SPREED/bin/spreed-webrtc-server -c ${WEBRTC_CONF} -l ${WEBRTC_LOG}
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl enable spreed.service
## Add the init script
#wget -O /etc/init.d/spreed-webrtc https://github.com/spreedbox-packaging/spreed-webrtc-debian/raw/5837478fd33089bc7cc8a4323ed736a669b60b7a/debian/spreed-webrtc.init.d
#sed -i "s~/usr/local/php7~$PHP7_DIR~g" /etc/init.d/php7-fpm
#chmod +x /etc/init.d/spreed-webrtc
#
#wget -O /etc/systemd/system/spreed-webrtc.service https://github.com/spreedbox-packaging/spreed-webrtc-debian/raw/ubuntu/trusty/debian/spreed-webrtc.service
#sed -i "s~/usr/local/php7~$PHP7_DIR~g" /etc/systemd/system/php-fpm.service
#
## Reload systemd
#systemctl daemon-reload
#systemctl enable spreed-webrtc
## Start Spreed WebRTC
#systemctl start spreed-webrtc
}
do_install_go_source() {
do_ask_username
mkdir -p $GPATH
cd $GPATH
# Download Go
wget -P $GPATH $SOURCE_GO$VERSION_GO.tar.gz
tar -xzf $VERSION_GO.tar.gz
mv $GPATH/go/ /usr/local
#nano /etc/profile
sed -i 's~export PATH~PATH=$PATH:/usr/local/go/bin\nexport PATH~g' /etc/profile
export PATH=$PATH:/usr/local/go/bin
}
do_configure_spreed_webrtc_gateway() {
if [ ! -f $LOCK_DIR/configure_gateway-installed.lock ]; then
echo && echo "Please try configuring Spreed WebRTC gateway again after setting up the gateway. Skipping..." && echo && sleep 1
elif [ -f $LOCK_DIR/spreed_webrtc-gateway-installed.lock ]; then
echo && echo "Spreed WebRTC gateway is already installed and configured. Continuing..." && echo && sleep 1
else
#nano /etc/nginx/conf.d/gateway.conf
ex /etc/nginx/conf.d/gateway.conf << END_EX_COMMANDS
" Find the mark
/NEW_SITE
" Delete the marker line
d
" Add the complex, multi-line text
a
#### Spreed WebRTC ####
location ^~ /webrtc {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \$connection_upgrade;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_buffering on;
proxy_ignore_client_abort off;
proxy_redirect off;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_next_upstream error timeout invalid_header http_502 http_503 http_504;
}
# NEW_SITE
.
" The '.' terminates the a-command. Write out changed file.
w!
q
END_EX_COMMANDS
service nginx restart && service spreed restart
sleep 1
touch $LOCK_DIR/spreed_webrtc-gateway-installed.lock
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment