#!/usr/bin/env bash # Nice re/streamer setup script 2022 # Nice IPTV Team ################################################ calc_wt_size() { WT_HEIGHT=17 WT_WIDTH=$(tput cols) if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then WT_WIDTH=80 fi if [ "$WT_WIDTH" -gt 178 ]; then WT_WIDTH=120 fi WT_MENU_HEIGHT=$((WT_HEIGHT-7)) } ################################################ spinner(){ { i=1 while read -r line; do i=$(( i + 1 )) echo $i sleep 0.1 done } } ################################################ check_root(){ if [ "$(whoami)" != "root" ]; then whiptail --msgbox --fb "Sorry you are not root!" "$WT_HEIGHT" "$WT_WIDTH" exit fi } ################################################ update(){ verpro=$(dpkg --list | grep nodenice-pro | awk '{print $3}') if [ -z "$verpro" ]; then whiptail --title "Restreamer Files Missing" --msgbox --fb " Nice re/streamer not installed! Nothing to update!" "$WT_HEIGHT" "$WT_WIDTH" exit fi if ! wget -q nice.minimal103.com/nodenice-update.deb -P /tmp; then whiptail --title "Restreamer Update" --msgbox --fb "Update Source Missing !! No Update for Now...." "$WT_HEIGHT" "$WT_WIDTH" exit else verup=$(dpkg-deb -W /tmp/nodenice-update.deb | awk '{print $2}') fi if [ "$verpro" = "$verup" ] ; then whiptail --title "Restreamer Update" --msgbox --fb " Latest Version: [ $verpro ] is equal to Update Pakage : [ $verup ]\n \n " "$WT_HEIGHT" "$WT_WIDTH" rm -r /tmp/nodenice-update.deb > /dev/null 2>&1 exit fi mv /nice/nodenice-pro /nice/nodenice-pro.old > /dev/null 2>&1 dpkg --unpack --force-all /tmp/nodenice-update.deb > /dev/null 2>&1 | whiptail --title "Restreamer Updating..." --gauge "Updating [ $verpro ] to [ $verup ]......" 6 60 0 rm -r /tmp/nodenice-update.deb > /dev/null 2>&1 whiptail --title "Restreamer Update" --msgbox --fb "\n Update Nice re/streamer to [ $verup ] Done\n Please Restart Nice re/streamer from WEB interface...." "$WT_HEIGHT" "$WT_WIDTH" clear exit #fi } ################################################ remove(){ MENU=$(whiptail --title "Nice re/streamer PRO Remover" --menu " \nPlease Select from following options" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --fb --ok-button Select --nocancel \ "1 " "[ Remove Restreamer ]" \ "2 " "[ Completly Remove Restreamer ]" \ "3 " "[ Back to Setup Menu ]" \ "4 " "[ Exit ]" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$MENU" in 1\ *) rem_restreamer ;; 2\ *) rem_full ;; 3\ *) do_tools ;; 4\ *) exit ;; *) whiptail --msgbox " error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $MENU" 20 60 1 fi exit } ################################################ rem_restreamer(){ mysqlex=$(pidof /usr/sbin/mysqld) if [ $mysqlex > 0 ]; then unset sqlpasswd whiptail --title "MySQL Run Check" --msgbox "MySQL server running with PID:$mysqlex" "$WT_HEIGHT" "$WT_WIDTH" sqlpasswd=$(whiptail --title "MySQL password (Required) " --passwordbox "Insert Existing MySQL password (Required)." 10 60 3>&1 1>&2 2>&3) fi if [ -z "$sqlpasswd" ]; then whiptail --title "MySQL Run Check" --msgbox --fb "MySQL not running..Removing just re/streamer files !" "$WT_HEIGHT" "$WT_WIDTH" /nice/restream.sh stop > /dev/null 2>&1 rm -r /nice > /dev/null 2>&1 dpkg -r nodenice-update | spinner | whiptail --title "Removing update pakages...." --gauge "Removing ...." 6 60 0 dpkg -r nodenice-pro | spinner | whiptail --title "Removing re/streamer pakages...." --gauge "Removing ...." 6 60 0 whiptail --title "Restreamer Remover" --msgbox "Removing Installation Pakages Done" "$WT_HEIGHT" "$WT_WIDTH" else /nice/restream.sh stop > /dev/null 2>&1 rm -r /nice > /dev/null 2>&1 mysql -u root -p$sqlpasswd -e 'drop database db_login;' > /dev/null 2>&1 dpkg -r nodenice-update | spinner | whiptail --title "Removing pakages...." --gauge "Removing ...." 6 60 0 dpkg -r nodenice-pro | spinner | whiptail --title "Removing pakages...." --gauge "Removing ...." 6 60 0 whiptail --title "Restreamer Remover" --msgbox --fb " Removing re/streamer Installation and MySQL Database Done" "$WT_HEIGHT" "$WT_WIDTH" fi rm -r /etc/cron.d/restreamer > /dev/null 2>&1 exit } ################################################ rem_full(){ whiptail --title "!! WARNING !!" --msgbox --fb "\ FULL REMOVE will DELETE\n \n Completly MySQL installattion and Databases and Nice re/streamer files\n" "$WT_HEIGHT" "$WT_WIDTH" /nice/restream.sh stop > /dev/null 2>&1 rm -r /nice > /dev/null 2>&1 dpkg -r nodenice-update | spinner | whiptail --title "Removing update pakages...." --gauge "Removing ...." 6 60 0 dpkg -r nodenice-pro | spinner | whiptail --title "Removing re/streamer pakages...." --gauge "Removing ...." 6 60 0 service mysql stop #apt-get purge -y ubuntu-restricted-extras > /dev/null 2>&1 apt-get -y purge mysql* | spinner | whiptail --title "Removing Completly MySQL installattion and Databases" --gauge "Removing ...." 6 60 0 rm -rf /etc/apparmor.d/abstractions/mysql /etc/apparmor.d/cache/usr.sbin.mysqld /etc/mysql /var/lib/mysql /var/log/mysql* /var/log/upstart/mysql.log* /var/run/mysqld ~/.mysql_history apt-get -y autoremove | spinner | whiptail --title "Removing Completly MySQL installattion and Databases" --gauge "Removing ...." 6 60 0 sudo apt-get -y autoclean | spinner | whiptail --title "Removing Completly MySQL installattion and Databases" --gauge "Removing ...." 6 60 0 whiptail --title "Restreamer Remover" --msgbox --fb " Full Removing re/streamer Installation and MySQL Database Done" "$WT_HEIGHT" "$WT_WIDTH" rm -r /etc/cron.d/restreamer > /dev/null 2>&1 exit } ################################################ linuxver(){ if [ -f /etc/lsb-release ]; then . /etc/lsb-release whiptail --title "Linux Distribution" --msgbox --fb --ok-button "Start" " Installing on\n DISTRIB_ID = $DISTRIB_ID\n DISTRIB_RELEASE = $DISTRIB_RELEASE\n DISTRIB_CODENAME = $DISTRIB_CODENAME\n DISTRIB_DESCRIPTION = $DISTRIB_DESCRIPTION\n " "$WT_HEIGHT" "$WT_WIDTH" elif [ -f "/etc/os-release" ]; then dist_id=$(grep -w NAME /etc/os-release | sed 's/NAME=//g' | tr -d '="'| awk '{ print $1}') ver_id=$(grep -w VERSION /etc/os-release | sed 's/VERSION=//g' | tr -d '="') distroname=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME=//g' | tr -d '="') codename=$(grep VERSION_CODENAME /etc/os-release | sed 's/VERSION_CODENAME=//g' | tr -d '="') whiptail --title "Linux Distribution" --msgbox --fb "Installing on\n DISTRIB_ID = $dist_id\n DISTRIB_RELEASE = $ver_id\n DISTRIB_CODENAME = $codename\n DISTRIB_DESCRIPTION = $distroname\n " "$WT_HEIGHT" "$WT_WIDTH" else whiptail --title "Linux Distribution" --msgbox --fb "Cannot Install\n DISTRIB_ID = Not Supported\n " "$WT_HEIGHT" "$WT_WIDTH" exit fi } ################################################ installexist(){ verup=$(dpkg --list | grep nodenice-update | awk '{print $3}') verpro=$(dpkg --list | grep nodenice-pro | awk '{print $3}') if [ -z "$verup" ];then vvv=$verpro else vvv=$verup fi if [ -d "/nice" ]; then MENU=$(whiptail --title "Nice re/streamer $vvv PRO installation Exist" --menu " Please Select from following options" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --fb --ok-button Select --nocancel \ "1 " "[ Remove Restreamer ]" \ "2 " "[ Completly Remove Restreamer ]" \ "3 " "[ Go to Setup Menu ]" \ "4 " "[ Exit ]" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$MENU" in 1\ *) rem_restreamer ;; 2\ *) rem_full ;; 3\ *) do_tools ;; 4\ *) exit ;; *) whiptail --msgbox --fb" error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox --fb "There was an error running option $MENU" 20 60 1 fi exit fi } ################################################ get_available_interfaces(){ unset ipaddress if [[ "$DISTRIB_ID" = "Ubuntu" ]] || [[ "$DISTRIB_RELEASE" > "17" ]];then IPV4_ADDRESS=$(ip addr | grep -v 127.0.0.1 | grep -v inet6 | grep 'inet ' | awk '{ print $2}' | cut -d/ -f -1) elif [ "$dist_id" = "Debian" ];then IPV4_ADDRESS=$(ip addr | grep -v 127.0.0.1 | grep -v inet6 | grep 'inet ' | awk '{ print $2}' | cut -d/ -f -1) else IPV4_ADDRESS=$(ifconfig | grep -v 127.0.0.1 | grep -v inet6 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') fi while [[ ! ${ipaddress} =~ [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ ]]; do install_interface=$(whiptail --title "Interface Setup" --inputbox --nocancel --fb " \nAvailable network interface(s)\n \n$IPV4_ADDRESS\n \nEnter IP address for re/streamer (Required) :" 20 60 3>&1 1>&2 2>&3) if [ $? -eq 0 ]; then ipaddress=$(echo $install_interface | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+') fi if [ ! $ipaddress ]; then whiptail --msgbox --fb " Please enter valid ip address" "$WT_HEIGHT" "$WT_WIDTH" else whiptail --msgbox --fb " You have enter $ipaddress" "$WT_HEIGHT" "$WT_WIDTH" fi done } ################################################ # segmenter(){ # apt-get update | spinner | whiptail --title "APT update" --gauge "Please wait while apt update..." 6 60 0 # wget -qN nice.minimal103.com/libavcodec.so.54.71.100 -O /usr/lib/x86_64-linux-gnu/libavcodec.so.54 # wget -qN nice.minimal103.com/libavformat.so.54.36.100 -O /usr/lib/x86_64-linux-gnu/libavformat.so.54 # wget -qN nice.minimal103.com/libavutil.so.52.6.100 -O /usr/lib/x86_64-linux-gnu/libavutil.so.52 | spinner | whiptail --title "Installing Needed Library ...." --gauge "Please wait while Installing Needed Library ...." 6 60 0 # ldconfig > /dev/null 2>&1 # whiptail --msgbox --fb "Library's is now installed..." "$WT_HEIGHT" "$WT_WIDTH" # do_tools # } ################################################ crontabs(){ whiptail --msgbox --fb "\ Crontab for automatic backup,check and restart Restreamer\n Backups will be made at /nice/backup folder everyday at 04:00 AM\n User also can fill user and pass for MEGA.NZ in /nice/backup.sh script\n and backup file will be send to Mega Cloud !\ " "$WT_HEIGHT" "$WT_WIDTH" MENU=$(whiptail --title "Backup Options" --menu " Please Select from following options" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --fb --ok-button Select --nocancel \ "1 " "[ Crontab insert ]" \ "2 " "[ Crontab Remove ]" \ "3 " "[ Do nothing - Exit ]" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$MENU" in 1\ *) rm -r /etc/cron.d/restreamer > /dev/null 2>&1 cat << EOF > /etc/cron.d/restreamer */1 * * * * root /nice/restream.sh check > /dev/null 2>&1 & 2 2 * * * root /nice/backup.sh 3 4 * * * root echo 3 > /proc/sys/vm/drop_caches #4 4 * * * root /nice/restream.sh restart >/dev/null 2>&1 EOF whiptail --msgbox --fb " Crontabs Inserted..." "$WT_HEIGHT" "$WT_WIDTH" ;; 2\ *) rm -r /etc/cron.d/restreamer > /dev/null 2>&1 whiptail --msgbox --fb " Crontabs Removed..." "$WT_HEIGHT" "$WT_WIDTH" ;; 3\ *) exit ;; *) whiptail --msgbox " error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $MENU" 20 60 1 fi } ################################################ installpro(){ mkdir /nice > /dev/null 2>&1 if ! wget -q nice.minimal103.com/nodenice-install.deb -P /tmp | spinner | whiptail --title "Installing Restreamer" --gauge "Please wait..." 6 60 0; then whiptail --title "Sources Check" --msgbox --fb "Installation Sources Missing !! Please contact us at niceiptvpanel@gmail.com" "$WT_HEIGHT" "$WT_WIDTH" exit fi verpro=$(dpkg --list | grep nodenice-pro | awk '{print $3}') dpkg -i /tmp/nodenice-install.deb | spinner | whiptail --title "Installing Nice re/streamer $verpro" --gauge "Please wait while Installing..." 6 60 0 rm -r /tmp/nodenice-install.deb > /dev/null 2>&1 sqldatabase="db_login" sqluname="root" mysqlex=$(pidof /usr/sbin/mysqld) if [ $mysqlex > 0 ]; then unset sqlpasswd whiptail --title "MySQL Check" --msgbox --fb "MySQL server running with PID : $mysqlex" "$WT_HEIGHT" "$WT_WIDTH" sqlpasswd=$(whiptail --title "MySQL password (Required) " --passwordbox --nocancel "Insert Existing MySQL password (Required)" 10 60 3>&1 1>&2 2>&3) debconf-set-selections <<< 'mysql-server mysql-server/root_password password $sqlpasswd' debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password $sqlpasswd' else unset sqlpasswd sqlpasswd=$(whiptail --title "MySQL password (If blank = 12345678) " --passwordbox --nocancel --fb "Enter your MySQL password" 10 60 3>&1 1>&2 2>&3) if [ -z "$sqlpasswd" ]; then sqlpasswd="12345678" whiptail --msgbox --fb " Password is blank! Default MySQL password set: $sqlpasswd" "$WT_HEIGHT" "$WT_WIDTH" else whiptail --msgbox --fb " You entered MySQL password: $sqlpasswd" "$WT_HEIGHT" "$WT_WIDTH" fi # debian check for mysql if [ "$dist_id" = "Debian" ];then export DEBIAN_FRONTEND=noninteractive apt-get install -y gnupg curl > /dev/null 2>&1 ; cd /tmp wget https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb > /dev/null 2>&1 #echo "mysql-apt-config mysql-apt-config/select-server select mysql-8.0" | debconf-set-selections debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/select-server select mysql-8.0' debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/select-product select Ok' dpkg -i mysql-apt-config* > /dev/null 2>&1 apt update > /dev/null 2>&1 apt-get install -y mysql-server | spinner | whiptail --title "Installing MySQL server for Debian" --gauge "Please wait ..." 6 60 0 whiptail --msgbox --fb " MySQL server for Debian is now installed..." "$WT_HEIGHT" "$WT_WIDTH" else echo "mysql-server mysql-server/root_password password $sqlpasswd" | debconf-set-selections echo "mysql-server mysql-server/root_password_again password $sqlpasswd" | debconf-set-selections apt-get install -y mysql-server | spinner | whiptail --title "Installing MySQL server for Ubuntu" --gauge "Please wait ..." 6 60 0 whiptail --msgbox --fb " MySQL server for Ubuntu is now installed..." "$WT_HEIGHT" "$WT_WIDTH" fi fi mysqladmin -u root -p$sqlpasswd create $sqldatabase > /dev/null 2>&1 #mysql -u root -p$sqlpasswd $sqldatabase < /nice/db_login.sql > /dev/null 2>&1 sed -i 's/xxx/'$sqlpasswd'/g' /nice/config.json sed -i 's/yyy/'$ipaddress'/g' /nice/config.json sed -i 's/66666/'$ipaddress'/g' /nice/config.json sed -i 's/jjj/0/g' /nice/config.json sed -i 's/lll/0/g' /nice/config.json sed -i 's/tttt/'$sqlpasswd'/g' /nice/backup.sh whiptail --title "! Nice re/streamer PRO $verpro setup ..All set !" --msgbox --fb "Nice re/streamer Pro run on http://$ipaddress:4300 -- Demo/Trial will be automaticly activated on FIRST CLEAN install. ! It will run ONE TIME per server for 15 Days ! Restreamer will start in 'RED mode' if DEMO expired or license is not valid! -- Default login for web interface admin:admin After Login please do setup in web interface [Tools]-->[Config] Script Usage /nice/restream.sh start | stop | restart | check | uptime -- Problems with running re/streamer ?! CHECK log files in /nice/ folder !! For FAQ Please visit our website http://nice-panel.com/index.html" "$WT_HEIGHT" "$WT_WIDTH" /nice/restream.sh start > /dev/null 2>&1 crontabs exit } do_about() { whiptail --msgbox --fb --ok-button "continue" "\ == Welcome to Nice Restreamer Setup ==\n \n You can install,remove and set backup options for Nice re/streamer.\n \n == Nice IPTV Team 2018 ==\ " "$WT_HEIGHT" "$WT_WIDTH" } ################################################ whiptailexist(){ if dpkg -l | grep whiptail > /dev/null 2>&1 ; then TERM=ansi whiptail --title "whiptail" --infobox " PASS" 8 15 sleep 2 else TERM=ansi whiptail --title "whiptail" --infobox "Installing whiptail" 8 28 if [[ "$DISTRIB_RELEASE" < "18" ]]; then echo "Installing whiptail" apt-get -y --force-yes install whiptail > /dev/null 2>&1 else apt-get -y --allow-change-held-packages install whiptail > /dev/null 2>&1 fi fi } ubuntu_minimal(){ if dpkg -l | grep psmisc > /dev/null 2>&1 ; then TERM=ansi whiptail --title "Ubuntu minimal" --infobox " PASS" 8 22 sleep 2 else TERM=ansi whiptail --title "Ubuntu minimal" --infobox "Installing psmisc" 8 28 if [[ "$DISTRIB_RELEASE" < "18" ]]; then apt-get -y --force-yes update > /dev/null 2>&1 && apt-get -y --force-yes upgrade > /dev/null 2>&1 apt-get -y --force-yes install psmisc > /dev/null 2>&1 else apt-get -y --allow-change-held-packages update > /dev/null 2>&1 && apt-get -y --allow-change-held-packages upgrade > /dev/null 2>&1 apt-get -y --allow-change-held-packages install psmisc > /dev/null 2>&1 fi fi } ubuntu_apt() { if [ -n "$(apt-cache search mysql-server)" ] > /dev/null 2>&1 ; then TERM=ansi whiptail --title "MySQL check" --infobox " PASS" 8 20 sleep 2 else if [[ "$DISTRIB_RELEASE" < "18" ]]; then TERM=ansi whiptail --title "MySQL check" --infobox "Ubuntu16 apt ...updating" 8 28 apt-get -y --force-yes update > /dev/null 2>&1 else TERM=ansi whiptail --title "MySQL check" --infobox "Ubuntu18+ apt ...updating" 8 29 apt-get -y --allow-change-held-packages update > /dev/null 2>&1 fi fi } ################################################ xzutilsexist(){ if dpkg -l | grep xz-utils > /dev/null 2>&1 ; then TERM=ansi whiptail --title "xz-utils" --infobox " PASS" 8 15 sleep 2 else TERM=ansi whiptail --title "xz-utils" --infobox "Installing xz-utils" 8 26 if [[ "$DISTRIB_RELEASE" < "18" ]]; then apt-get -y --force-yes install xz-utils > /dev/null 2>&1 else apt-get -y --allow-change-held-packages install xz-utils > /dev/null 2>&1 fi fi } ipsetexist(){ if dpkg -l | grep ipset > /dev/null 2>&1 ; then TERM=ansi whiptail --title "ipset" --infobox " PASS" 8 16 sleep 2 else TERM=ansi whiptail --title "ipset" --infobox " Installing ipset" 8 26 if [[ "$DISTRIB_RELEASE" < "18" ]]; then apt-get -y --force-yes install ipset > /dev/null 2>&1 else apt-get -y --allow-change-held-packages install ipset > /dev/null 2>&1 fi fi } ################################################ do_tools() { MENU=$(whiptail --title "Nice re/streamer PRO Setup" --menu " Please Select from following options" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --fb --cancel-button Exit --ok-button Select \ "1 " "[ Install ]" \ "2 " "[ Remove ]" \ "3 " "[ Update ]" \ "4 " "[ Backup ]" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$MENU" in 1\ *) installexist # linuxver get_available_interfaces installpro ;; 2\ *) remove ;; 3\ *) update ;; 4\ *) crontabs ;; *) whiptail --msgbox " error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $MENU" 20 60 1 fi } ################################################ clear linuxver check_root ubuntu_minimal ubuntu_apt whiptailexist xzutilsexist ipsetexist clear do_about do_tools