#!/usr/bin/env bash # UnOfficial FOS-Streaming Automated Installation Script # ============================================= # # This program is free software: you can redistribute it and/or modify # it under the terms of the MIT License as published by # the Open Source Foundation # # 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 # MIT License for more details. # # You should have received a copy of the MIT License # along with this program. If not, see . # # Supported Operating Systems: # Ubuntu server14.04 # 32bit and 64bit # # Contributions installer from: # # Tyfix (sevan@tyfix.nl) # Andy kimpe (andykimpe@gmail.com) # FOS_STREAMING_CORE/INSTALLER_VERSION # master - latest unstable # 1.0.0 - example stable tag ## FOS_STREAMING_INSTALLER_VERSION="master" FOS_STREAMING_CORE_VERSION="master" #--- Display the 'welcome' splash/user warning info.. echo "" echo "############################################################" echo "# Welcome to the UnOfficial FOS-Streaming Installer $FOS_STREAMING_INSTALLER_VERSION #" echo "############################################################" echo -e "\nChecking that minimal requirements are ok" # Ensure the OS is compatible with the launcher if [ -f /etc/centos-release ]; then OS="CentOs" VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release) VER=${VERFULL:0:1} # return 6 or 7 elif [ -f /etc/lsb-release ]; then OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//') VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//') elif [ -f /etc/os-release ]; then OS=$(grep -w ID /etc/os-release | sed 's/^.*=//') VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"\(.*\)"/\1/') else OS=$(uname -s) VER=$(uname -r) fi ARCH=$(uname -m) echo "Detected : $OS $VER $ARCH" if [[ "$OS" = "Ubuntu" && "$VER" = "14.04" ]] ; then echo "Ok." else echo "Sorry, this OS is not supported by FOS-Streaming." exit 1 fi if [[ "$ARCH" == "i386" || "$ARCH" == "i486" || "$ARCH" == "i586" || "$ARCH" == "i686" ]]; then ARCH="i386" elif [[ "$ARCH" == "x86_64" || "$ARCH" == "amd64" ]]; then ARCH="x86_64" else echo "Unexpected architecture name was returned ($ARCH ). :-(" echo "The installer have been designed for i[3-6]8- and x86_64' architectures. If you" echo " think it may work on your, please report it to the Issue." exit 1 fi # Check if the user is 'root' before allowing installation to commence if [ $UID -ne 0 ]; then echo "Install failed: you must be logged in as 'root' to install." echo "Use command 'sudo -i', then enter root password and then try again." exit 1 fi # Check for some common control panels that we know will affect the installation/operating of FOS-Streaming. if [ -e /usr/local/cpanel ] || [ -e /usr/local/directadmin ] || [ -e /usr/local/solusvm/www ] || [ -e /usr/local/home/admispconfig ] || [ -e /usr/local/lxlabs/kloxo ] || [ -e /etc/zpanel ] || [ -e /etc/zpanelx ] || [ -e /etc/sentora ] ; then echo "It appears that a control panel is already installed on your server; This installer" echo "is designed to install and configure FOS-Streaming on a clean OS installation only." echo -e "\nPlease re-install your OS before attempting to install using this script." exit 1 fi # Check for some common packages that we know will affect the installation/operating of FOS-Streaming. PACKAGE_INSTALLER="apt-get -yqq install" PACKAGE_REMOVER="apt-get -yqq remove" inst() { dpkg -l "$1" 2> /dev/null | grep '^ii' &> /dev/null } DB_PCKG="mysql-server-5.5 mysql-server-core-5.5" HTTP_PCKG="apache2 libapache2-mod-php5 phpmyadmin" PHP_PCKG="php5 php5-mysql php5-fpm php5-curl" MY_CNF_PATH="/etc/mysql/my.cnf" pkginst="n" pkginstlist="" for package in "$DB_PCKG" "$HTTP_PCKG" "$PHP_PCKG" ; do if (inst "$package"); then pkginst="y" # At least one package is installed pkginstlist="$package $pkginstlist" fi done if [ $pkginst = "y" ]; then echo "It appears that the folowing package(s) are already installed:" echo "$pkginstlist" echo "This installer is designed to install and configure FOS-Streaming on a clean OS installation only!" echo -e "\nPlease re-install your OS before attempting to install using this script." exit 1 fi unset pkginst unset pkginstlist # ************************************************* #--- Prepare or query informations required to install # Update repositories and Install wget and util used to grab server IP echo -e "\n-- Installing wget and dns utils required to manage inputs" apt-get -yqq update #ensure we can install $PACKAGE_INSTALLER dnsutils wget extern_ip="$(wget -qO- http://andy.kimpe.free.fr/ip.php)" #local_ip=$(ifconfig eth0 | sed -En 's|.*inet [^0-9]*(([0-9]*\.){3}[0-9]*).*$|\1|p') local_ip=$(ip addr show | awk '$1 == "inet" && $3 == "brd" { sub (/\/.*/,""); print $2 }') if [[ "$tz" == "" ]] ; then # Propose selection list for the time zone echo "Preparing to select timezone, please wait a few seconds..." $PACKAGE_INSTALLER tzdata # setup server timezone dpkg-reconfigure tzdata tz=$(cat /etc/timezone) fi # clear timezone information to focus user on important notice clear # Installer parameters if [[ "$PUBLIC_IP" == "" ]] ; then PUBLIC_IP=$extern_ip while true; do echo "" if [[ "$PUBLIC_IP" != "$local_ip" ]]; then echo -e "\nThe public IP of the server is $PUBLIC_IP. Its local IP is $local_ip" echo " For a production server, the PUBLIC IP must be used." fi read -e -p "Enter (or confirm) the public IP for this server: " -i "$PUBLIC_IP" PUBLIC_IP echo "" if [[ "$PUBLIC_IP" != "$extern_ip" && "$PUBLIC_IP" != "$local_ip" ]]; then echo -e -n "\e[1;31mWARNING: $PUBLIC_IP does not match detected IP !\e[0m" echo " FOS-Streaming will not work with this IP..." confirm="true" fi echo "" # if any warning, ask confirmation to continue or propose to change if [[ "$confirm" != "" ]] ; then echo "There are some warnings..." echo "Are you really sure that you want to setup FOS-Streaming with these parameters?" read -e -p "(y):Accept and install, (n):Change IP, (q):Quit installer? " yn case $yn in [Yy]* ) break;; [Nn]* ) continue;; [Qq]* ) exit;; esac else read -e -p "All is ok. Do you want to install FOS-Streaming now (y/n)? " yn case $yn in [Yy]* ) break;; [Nn]* ) exit;; esac fi done fi # *************************************** # Installation really starts here #--- Set custom logging methods so we create a log file in the current working directory. logfile=$(date +%Y-%m-%d_%H.%M.%S_fos_streaming_install.log) touch "$logfile" exec > >(tee "$logfile") exec 2>&1 echo "Installer version $FOS_STREAMING_INSTALLER_VERSION" echo "FOS-Streaming core version $FOS_STREAMING_CORE_VERSION" echo "" echo "Installing FOS-Streaming $FOS_STREAMING_CORE_VERSION at http://$PUBLIC_IP:8000" echo "on server under: $OS $VER $ARCH" uname -a # Function to disable a file by appending its name with _disabled disable_file() { mv -f "$1" "$1_disabled_by_fos_streaming" &> /dev/null } # Function to save a file save_file() { cp -f "$1" "$1_saved_by_fos_streaming" &> /dev/null } passwordgen() { l=$1 [ "$l" == "" ] && l=16 tr -dc A-Za-z0-9 < /dev/urandom | head -c ${l} | xargs } #--- AppArmor must be disabled to avoid problems [ -f /etc/init.d/apparmor ] if [ $? = "0" ]; then echo -e "\n-- Disabling and removing AppArmor, please wait..." /etc/init.d/apparmor stop &> /dev/null update-rc.d -f apparmor remove &> /dev/null apt-get purge -y apparmor* &> /dev/null disable_file /etc/init.d/apparmor &> /dev/null echo -e "AppArmor has been removed." fi mkdir -p "/etc/apt/sources.list.d.save" cp -Rf "/etc/apt/sources.list.d/*" "/etc/apt/sources.list.d.save" &> /dev/null rm -rf "/etc/apt/sources.list/*" save_file "/etc/apt/sources.list" cat > /etc/apt/sources.list <> /etc/sudoers; fi if ! grep -q "www-data ALL = (root) NOPASSWD: /usr/local/bin/ffprobe" /etc/sudoers; then echo "www-data ALL = (root) NOPASSWD: /usr/local/bin/ffprobe" >> /etc/sudoers; fi mkdir -p /home/fos-streaming/fos/www/hl chmod -R 777 /home/fos-streaming/fos/www/hl mkdir -p /home/fos-streaming/fos/www/cache chmod -R 777 /home/fos-streaming/fos/www/cache mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/nginx.conf /home/fos-streaming/fos/nginx/conf/nginx.conf mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/fastcgi.conf /home/fos-streaming/fos/nginx/conf/fastcgi.conf chown www-data:www-data /home/fos-streaming/fos/nginx/conf/ rm -rf /home/fos-streaming/fos/php/lib/php.ini /home/fos-streaming/fos/php/etc/pear.conf /home/fos-streaming/fos/php/etc/php-fpm.conf mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/php.ini /home/fos-streaming/fos/php/lib/php.ini mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/pear.conf /home/fos-streaming/fos/php/etc/pear.conf mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/php-fpm.conf /home/fos-streaming/fos/php/etc/php-fpm.conf mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/ubuntu/FOS-nginx /etc/init.d/FOS-nginx mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/ubuntu/FOS-php-fpm /etc/init.d/FOS-php-fpm mkdir -p /home/fos-streaming/fos/php/etc/pool.d/ /home/fos-streaming/fos/logs/ mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/www.conf /home/fos-streaming/fos/php/etc/pool.d/www.conf chmod +x /etc/init.d/FOS-nginx chmod +x /etc/init.d/FOS-php-fpm update-rc.d FOS-nginx defaults update-rc.d FOS-php-fpm defaults ### database import service FOS-nginx start service FOS-php-fpm start echo "done" echo "##Downloading and conpile ffmpeg and dependency##" cd /usr/src/ echo -e "\n-- Downloading fdk-aac, Please wait, this may take several minutes, the installer will continue after this is complete!" # Get latest fdk-aac while true; do wget -nv -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master if [[ -f fdk-aac.tar.gz ]]; then break; else echo "Failed to download fdk-aac" echo "If you quit now, you can run again the installer later." read -e -p "Press r to retry or q to quit the installer? " resp case $resp in [Rr]* ) continue;; [Qq]* ) exit 3;; esac fi done tar xzvf fdk-aac.tar.gz rm -rf fdk-aac.tar.gz cd mstorsjo-fdk-aac* autoreconf -fiv ./configure --disable-shared make make install cd /usr/src/ rm -rf mstorsjo-fdk-aac* echo -e "\n-- Downloading libvpx, Please wait, this may take several minutes, the installer will continue after this is complete!" # Get latest libvpx : version 1.5.0 while true; do wget -nv -O libvpx-1.5.0.tar.bz2 http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.5.0.tar.bz2 if [[ -f libvpx-1.5.0.tar.bz2 ]]; then break; else echo "Failed to download libvpx" echo "If you quit now, you can run again the installer later." read -e -p "Press r to retry or q to quit the installer? " resp case $resp in [Rr]* ) continue;; [Qq]* ) exit 3;; esac fi done tar xjvf libvpx-1.5.0.tar.bz2 rm -rf libvpx-1.5.0.tar.bz2 cd libvpx-1.5.0 ./configure --disable-examples --disable-unit-tests make make install cd /usr/src/ rm -rf libvpx-1.5.0 echo -e "\n-- Downloading vo-aacenc, Please wait, this may take several minutes, the installer will continue after this is complete!" # Get latest vo-aacenc : version 0.1.3 while true; do wget -nv -O vo-aacenc-0.1.3.tar.gz https://sourceforge.net/projects/opencore-amr/files/vo-aacenc/vo-aacenc-0.1.3.tar.gz if [[ -f vo-aacenc-0.1.3.tar.gz ]]; then break; else echo "Failed to download vo-aacenc" echo "If you quit now, you can run again the installer later." read -e -p "Press r to retry or q to quit the installer? " resp case $resp in [Rr]* ) continue;; [Qq]* ) exit 3;; esac fi done tar -xvf vo-aacenc-0.1.3.tar.gz rm -rf vo-aacenc-0.1.3.tar.gz cd vo-aacenc-0.1.3 ./configure make make install ldconfig cd /usr/src/ rm -rf vo-aacenc-0.1.3 echo -e "\n-- Downloading ffmpeg 2.8 on GitHub, Please wait, this may take several minutes, the installer will continue after this is complete!" # Get latest ffmpeg : version 2.8 while true; do wget -nv -O FFmpeg-release-2.8.tar.gz https://github.com/FFmpeg/FFmpeg/archive/release/2.8.tar.gz if [[ -f FFmpeg-release-2.8.tar.gz ]]; then break; else echo "Failed to download ffmpeg from GitHub" echo "If you quit now, you can run again the installer later." read -e -p "Press r to retry or q to quit the installer? " resp case $resp in [Rr]* ) continue;; [Qq]* ) exit 3;; esac fi done tar xvf FFmpeg-release-2.8.tar.gz rm -rf FFmpeg-release-2.8.tar.gz cd FFmpeg-release-2.8 ./configure \ --pkg-config-flags="--static" \ --enable-gpl \ --enable-libass \ --enable-libfdk-aac \ --enable-libfreetype \ --enable-libmp3lame \ --enable-libopus \ --enable-libtheora \ --enable-libvorbis \ --enable-libvpx \ --enable-libx264 \ --enable-libx265 \ --enable-nonfree \ --enable-version3 \ --enable-libvo-aacenc make rm -rf /usr/local/bin/ffmpeg rm -rf /usr/local/bin/ffprobe make install cd .. rm -rf FFmpeg-release-2.8 if [ -z "$mysqlpassword" ]; then mysqlpassword=$(passwordgen); mysqladmin -u root password "$mysqlpassword" fi # small cleaning of mysql access mysql -u root -p"$mysqlpassword" -e "DELETE FROM mysql.user WHERE User='root' AND Host != 'localhost'"; mysql -u root -p"$mysqlpassword" -e "DELETE FROM mysql.user WHERE User=''"; mysql -u root -p"$mysqlpassword" -e "FLUSH PRIVILEGES"; # remove test table that is no longer used mysql -u root -p"$mysqlpassword" -e "DROP DATABASE IF EXISTS test"; # secure SELECT "hacker-code" INTO OUTFILE sed -i "s|\[mysqld\]|&\nsecure-file-priv = /var/tmp|" $MY_CNF_PATH mysql -u root -p"$mysqlpassword" < /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/install.sql adminpassword=$(passwordgen) adminpasswordmd5=$(echo -n $adminpassword | md5sum | awk '{print $1}') rm -rf /home/fos-streaming/fos/www/config.php mv /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/config.php /home/fos-streaming/fos/www/config.php sed -i "s|YOUR_ROOT_MYSQL_PASSWORD|$mysqlpassword|" /home/fos-streaming/fos/www/config.php sed -i "s|YOUR_ADMIN_MYSQL_PASSWORD|$adminpasswordmd5|" /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/password.sql mysql -u root -p"$mysqlpassword" < /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/password.sql rm -rf /usr/src/FOS-Streaming-installers-$FOS_STREAMING_INSTALLER_VERSION/ #--- Store the passwords for user reference echo "Server IP address : $PUBLIC_IP" >> /root/passwords.txt echo "Panel URL : http://$PUBLIC_IP:8000" >> /root/passwords.txt echo "admin Password : $adminpassword" >> /root/passwords.txt echo "" >> /root/passwords.txt echo "MySQL Root Password : $mysqlpassword" >> /root/passwords.txt #--- Advise the admin that FOS-Streaming is now installed and accessible. echo "########################################################" >/dev/tty echo " Congratulations FOS-Streaming has now been installed on your" >/dev/tty echo " server. Please review the log file left in /root/ for " >/dev/tty echo " any errors encountered during installation." >/dev/tty echo "" >/dev/tty echo " Login to FOS-Streaming at http://$PUBLIC_IP:8000" >/dev/tty echo " FOS-Streaming Username : admin" >/dev/tty echo " FOS-Streaming Password : $adminpassword" >/dev/tty echo "" >/dev/tty echo " MySQL Root Password : $mysqlpassword" >/dev/tty echo " (theses passwords are saved in /root/passwords.txt)" >/dev/tty echo "########################################################" >/dev/tty echo "" >/dev/tty # Wait until the user have read before restarts the server... if [[ "$INSTALL" != "auto" ]] ; then while true; do read -e -p "Restart your server now to complete the install (y/n)? " rsn case $rsn in [Yy]* ) break;; [Nn]* ) exit; esac done shutdown -r now fi