Bart Simons

installation

A 3 post collection


IceWarp Installation Script

 •  Filed under icewarp, installation, deployment, script, automation

Are you currently searching for an easy way to install IceWarp Business Mail Server on Linux, preferably a Debian-based distribution? There's an easy way to automate that! I've written this awesome script in less than one hour:

#!/bin/bash

# IceWarp Download And Deployment Script
# Created by Bart Simons, 2016

# Dependencies:
#  - wget
#  - pv

echo "Downloading IceWarp..."  
wget http://www.icewarp.com/download/server/Ubuntu/Ubuntu16/icewarp11/IceWarpServer-11.4.5_UBUNTU16_x64.tar.gz -q --show-progress -O icewarp.tar.gz

echo "Creating working directory..."  
mkdir icewarp

echo "Extracting IceWarp..."  
pv icewarp.tar.gz | tar -xzf - --strip-components=1 -C icewarp

echo "Changing directory to working directory..."  
cd icewarp

echo "Executing installer..."  
./install.sh

echo "Removing installation files..."  
cd ..  
rm icewarp.tar.gz  
rm -rf icewarp

echo "Done!"  

This should work, good luck with your brand new IceWarp installation!

Node.js Linux Deployment Script

 •  Filed under installation, node.js, nodejs, linux, deployment, script

Need an easy solution to deploy the latest version of Node.js on Linux? This Bash script that I made does exactly that, and nothing more. There might be more elegant and better ways to deploy Node.js but I needed something lightweight and still as functional as solutions like nvm and n. The only things this script depends on are bash,curl,sed,grep and tar. These tools come preinstalled on almost all Linux distributions,

#!/bin/bash

# Node.js deployment script (automatically fetches the latest version)

CPUARCH="x64"  
LINK="https://nodejs.org/dist/latest/"  
DESTINATIONDIR="/opt/nodejs"

DOWNLOAD=$(curl -s $LINK | grep -o '<a .*href=.*>' | sed -e 's/<a /\<a /g' | sed -e 's/<a .*href=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d' | grep 'linux' | grep "$CPUARCH" | grep ".tar.gz")  
LINK=$LINK$DOWNLOAD

echo "[*] Downloading the latest version of Node.js .."

$(curl -s $LINK -o $DOWNLOAD)

echo "[*] Node.js has been downloaded .."  
echo "[*] Creating folder in /opt and unpacking Node.js there .."

$([ -d $DESTINATIONDIR ] && rm -rf $DESTINATIONDIR )
$(mkdir -p $DESTINATIONDIR)
$(tar -xf $DOWNLOAD -C $DESTINATIONDIR --strip-components=1)
$(rm $DOWNLOAD)

echo "[*] Symlinking Node.js and npm into /usr/bin .."

$([ -f /usr/bin/node ] && rm /usr/bin/node)
$([ -f /usr/bin/nodejs ] && rm /usr/bin/nodejs)
$([ -f /usr/bin/npm ] && rm /usr/bin/npm)
$(ln -s $DESTINATIONDIR/bin/node /usr/bin/node)
$(ln -s $DESTINATIONDIR/bin/node /usr/bin/nodejs)
$(ln -s $DESTINATIONDIR/bin/npm /usr/bin/npm)

echo "[*] All done!"  

I'd much rather program something like this in Python, but this actually works pretty good! I'm happy with the results 🍻

Node.js Linux Deployment Script

Tip: you can change https://nodejs.org/dist/latest/ to https://nodejs.org/dist/latest-boron/ to change the distribution channel to the latest LTS release of Node.js 😉

NGINX RTMP Streaming Server Installation Guide

 •  Filed under tutorial, nginx, rtmp, streaming, server, installation, guide

Personally, I find NGINX the best choice as a web server, and so this website runs on NGINX too. Today I found out about the NGINX RTMP module, originally developed by Roman Arutyunyan. This module allows you to expand NGINX with RTMP capabilities so you can use NGINX as a media streaming server! You can build it by compiling NGINX with a separate module which can be done manually or by using this bash script:

#!/bin/bash

echo  
echo   NGINX RTMP SERVER INSTALLER V2  
echo   COPYLEFT BARTSIMONS.ME, 2016  
echo 

## CHECKING FOR ROOT ACCESS...
user=$(whoami)  
if [[ $user != "root" ]]; then  
    echo "You are not root. Please run this script as superuser!"
    exit
fi

## GLOBAL VARIABLES AND PACKAGE CACHE UPDATE
nginx_url="http://nginx.org/download/nginx-1.11.4.tar.gz"  
nginx_tar="nginx-1.11.4.tar.gz"  
nginx_fld="nginx-1.11.4"  
rtmp_url="https://github.com/arut/nginx-rtmp-module.git"

echo "Updating package cache..."  
apt -qqq update

## CONTINUE WHEN USER IS ROOT & INSTALL WGET IF NOT INSTALLED...
long_out_wget_check=$(dpkg-query --list | grep wget)  
short_out_wget_check=${long_out_wget_check:0:2}  
wget_installed=0

if [[ $short_out_wget_check == "ii" ]]; then  
    wget_installed=1
else  
    echo "Installing wget..."
    apt install -qqq -y wget
fi

## INSTALL BUILD-ESSENTIAL IF NOT INSTALLED...
long_out_be_check=$(dpkg-query --list | grep build-essential)  
short_out_be_check=${long_out_be_check:0:2}  
be_installed=0

if [[ $short_out_be_check == "ii" ]]; then  
    be_installed=1
else  
    echo "Installing build-essential..."
    apt install -qqq -y build-essential
fi

## INSTALL LIBPCRE3 DEV HEADERS IF NOT INSTALLED...
long_out_pcre_dev_check=$(dpkg-query --list | grep libpcre3-dev)  
short_out_pcre_dev_check=${long_out_pcre_dev_check:0:2}  
pcre_dev_installed=0

if [[ $short_out_pcre_dev_check == "ii" ]]; then  
    pcre_dev_installed=1
else  
    echo "Installing libpcre3 development headers..."
    apt install -qqq -y libpcre3-dev
fi

## INSTALL LIBPCRE IF NOT INSTALLED...
long_out_pcre_check=$(dpkg-query --list | grep libpcre3-dev)  
short_out_pcre_check=${long_out_pcre_check:0:2}  
pcre_installed=0

if [[ $short_out_pcre_check == "ii" ]]; then  
    pcre_installed=1
else  
    echo "Installing libpcre3..."
    apt install -qqq -y libpcre3
fi

## INSTALL GIT IF NOT INSTALLED
long_out_git_check=$(dpkg-query --list | grep "git ")  
short_out_git_check=${long_out_git_check:0:2}  
git_installed=0

if [[ $short_out_git_check == "ii" ]]; then  
    git_installed=1
else  
    echo "Installing git..."
    apt install -qqq -y git
fi

## INSTALL LIBSSL DEV HEADERS IF NOT INSTALLED...
long_out_libssl_dev_check=$(dpkg-query --list | grep libssl-dev)  
short_out_libssl_dev_check=${long_out_libssl_dev_check:0:2}  
libssl_dev_installed=0

if [[ $short_out_libssl_dev_check == "ii" ]]; then  
    libssl_dev_installed=1
else  
    echo "Installing libssl-dev..."
    apt install -qqq -y libssl-dev
fi

## DOWNLOAD AND UNTAR NGINX SOURCE CODE
echo "Downloading nginx source code..."  
wget --quiet $nginx_url  
echo "Unpacking nginx source code..."  
tar -xzf $nginx_tar

## CLONE NGINX-RTMP-MODULE
echo "Cloning nginx RTMP module git repository..."  
git clone $rtmp_url

## CONFIGURE, COMPILE AND INSTALL!
cd $nginx_fld  
./configure --add-module=../nginx-rtmp-module
make  
make install

## CLEANUP TIME!
echo "Cleaning up left over folders & files..."  
rm -rf $nginx_fld  
rm -rf $nginx_tar  
rm -rf nginx-rtmp-module

if [[ $git_installed == 0 ]]; then  
    echo "git was not installed earlier. Uninstalling git"
    apt remove --purge -qqq git
fi

if [[ $pcre_dev_installed == 0 ]]; then  
    echo "libpcre3-dev was not installed earlier. Uninstalling libpcre3-dev..."
    apt remove --purge -qqq libpcre3-dev
fi

if [[ $be_installed == 0 ]]; then  
    echo "build-essential was not installed earlier. Uninstalling build-essential..."
    apt remove --purge -qqq build-essential
fi

if [[ $wget_installed == 0 ]]; then  
    echo "wget was not installed earlier. Uninstalling wget..."
    apt remove --purge -qqq wget
fi

if [[ $pcre_installed == 0 ]]; then  
    echo "libpcre3 was not installed earlier. Uninstalling libpcre..."
    apt remove --purge -qqq libpcre3
fi

if [[ $libssl_dev_installed == 0 ]]; then  
    echo "libssl-dev was not installed earlier. Uninstalling libssl-dev..."
    apt remove --purge -qqq libssl-dev
fi

echo " "  
echo "NGINX and the RTMP server module has been installed on your system!"  

Please note that this script has been built for Debian-based operating system. Compiling it manually on other systems is not that difficult at all: you just need to include the module with a flag for the configure script.

Configuring NGINX

Once you've got the modified NGINX version installed on your server, it's time to edit the NGINX configuration so that NGINX will serve RTMP traffic.

The default configuration file location for NGINX is /usr/local/nginx/conf/nginx.conf
Add the following configuration to the end of this file:

rtmp {  
    server {
        listen 1935;
        chunk_size 8192;

        application stream {
            live on;
            record off;

            allow publish 127.0.0.1;
            deny publish all;
            allow play all;
        }
    }
}

Now you are ready to go, you can start nginx on your server

/usr/local/nginx/sbin/nginx


You can stop nginx like this:

/usr/local/nginx/sbin/nginx -s stop


Thanks for reading and have fun streaming!