#!/bin/sh VERSION=1.9.54 TESTING=0 # set to 0 for production releases, 1 for development ########################################### # Is the user root? ########################################### RESULT=`/usr/bin/whoami` if [ ! "root" = "$RESULT" ]; then echo "Only root can run this script." exit 1; fi DPU_URL="ftp://ftp.unitrends.com/dpu/scripts/test_dpu" ARGS="$*" BP_URL="ftp://ftp.unitrends.com/dpu/scripts/.bp" BP_SOFT_DIR="/usr/local/bp_software" BP_SOFT_CONFIG="$BP_SOFT_DIR/.bp" SPECIALDOWNLOAD="NO" LOG_NUM=100 LOG_DIR=/var/log/dpu SCREEN_LENGTH=59 SETCOLOR_GREEN="echo -en \\033[1;32m" SETCOLOR_RED="echo -en \\033[1;31m" SETCOLOR_YELLOW="echo -en \\033[1;33m" SETCOLOR_NORMAL="echo -en \\033[0;39m" # These are to prevent utility functions from running # multiple times in one dpu script invocation. GET_SOFT_CONFIG_RUN=0 YUM_CONFIGURE_RUN=0 # These variables are related to downloading and installing # the 3DM2 module TDM2_FILE="3DM2_CLI-Linux-x86-9.5.1.tgz" TDM2_URL="ftp://ftp.unitrends.com/dpu/scripts/$TDM2_FILE" DEST_PATH="/tmp" ############################################ # # get the bp configure directory # ############################################ getBPdir() { if [ -f /etc/default/bp.ini ]; then BPDIR=`grep "BPDIR=" /etc/default/bp.ini | awk -F "=" '{print $2}'` if [ "" = "$BPDIR" ]; then echo "No Backup Professional Software has been detected." fi else echo "No Backup Professional Software has been detected." fi } ############################################ # # echo fixed length string # ############################################ echo_fixed() { str="$1" LENGTH=${#str} echo -n "$1" i=$((${SCREEN_LENGTH}-${LENGTH})) while [ $i -gt 0 ] do i=$((${i}-1)) echo -n " " done } ############################################ # # show color string # ############################################ colorstr() { if [ "$2" = "red" ]; then $SETCOLOR_RED elif [ "$2" = "green" ]; then $SETCOLOR_GREEN elif [ "$2" = "yellow" ]; then $SETCOLOR_YELLOW else $SETCOLOR_NORMAL fi echo -n $1 $SETCOLOR_NORMAL } ############################################ # # echo green string # ############################################ echo_success() { # calculate the number the string str=$1 LENGTH=${#str} # dispaly the string echo -n "[" if [ "$LENGTH" = "2" -o "$LENGTH" = "3" ]; then echo -n " " elif [ "$LENGTH" = "4" -o "$LENGTH" = "5" ]; then echo -n " " fi colorstr "$1" "green" if [ "$LENGTH" = "2" ]; then echo -n " " elif [ "$LENGTH" = "4" ]; then echo -n " " fi echo "]" return 0 } ############################################ # # echo red string # ############################################ echo_failure() { # calculate the number the string str=$1 LENGTH=${#str} # dispaly the string echo -n "[" if [ "$LENGTH" = "2" -o "$LENGTH" = "3" ]; then echo -n " " elif [ "$LENGTH" = "4" -o "$LENGTH" = "5" ]; then echo -n " " fi colorstr "$1" "red" if [ "$LENGTH" = "2" ]; then echo -n " " elif [ "$LENGTH" = "4" ]; then echo -n " " fi echo "]" return 0 } ############################################ # # get the DPU version # ############################################ version() { # Is this a new DPU system? DPUSTR=`grep Unitrends /etc/issue` if [ "" = "$DPUSTR" ]; then DPUSTR="Unitrends' DPU" fi RPMVERS=(`rpm -qa --queryformat '%{VERSION}-%{RELEASE}:%{NAME}\n' unitrends\* | grep -E '[0-9]+\.[0-9]+\.[0-9]+[-][0-9]+\.*\.' | \ grep -Ev 'unitrends-agentpush|unitrends-logos|unitrends-baremetal|unitrends-config' | sort -nr`) NEWRPM=`echo ${RPMVERS[0]} | cut -d':' -f2` echo "$DPUSTR Kernel "`uname -r` rpm -q --queryformat "Version %{version}-%{release}\nInstalled on %{INSTALLTIME:date}\n" $NEWRPM } ############################################ # # check some required programs # ############################################ checkProg() { PROG_WGET="/usr/bin/wget" if [ ! -x $PROG_WGET ]; then PROG_WGET="/usr/local/bin/wget" if [ ! -x $PROG_WGET ]; then echo "No wget is available." echo "Exit..." fi fi PROG_WGET="$PROG_WGET -T20" PROG_MD5SUM="/usr/bin/md5sum" if [ ! -x $PROG_MD5SUM ]; then PROG_MD5SUM="/usr/local/bin/md5sum" if [ ! -x $PROG_MD5SUM ]; then echo "No md5sum is available." echo "Exit..." fi fi } ############################################ # # check dpu script itself and see if there is a new version # ############################################ fca_push() { FC_DATA_FTP=ftp://ftp.unitrends.com/dpu/scripts/.fca FC_DATA=/tmp/FCA UT_ASSET=$(cat /etc/unitrends-asset) wget -q -O $FC_DATA $FC_DATA_FTP if [[ $? -eq 0 ]] then grep -q $UT_ASSET $FC_DATA if [[ $? -eq 0 ]] then echo "updating repo" sed -Ei "/include.*RecoveryOS.*/ s/\/pub\/(beta\/|fca\/|ce\/|)/\/pub\/fca\//" /etc/yum.repos.d/Unitrends-RecoveryOS-x86_64.repo fi rm -f $FC_DATA else echo "could not connect to ftp site" exit 1 fi } getBP_SOFT_CONFIG() { # if we're testing, skip this step if [ "$TESTING" -ne 0 ]; then return 0 fi # disallow DPU script updating for interested developers if [ -e /var/tmp/DPU_SCRIPT_DEVELOPER_MODE ]; then return 0 fi if [ "$GET_SOFT_CONFIG_RUN" -ne 0 ]; then # we've already run return 0 else GET_SOFT_CONFIG_RUN=1 fi # process arguments OPTIONAL=0 if [ "$1" = "optional" ]; then OPTIONAL=1 fi grep -q "^Metal" /etc/unitrends-asset if [ $? -ne 0 ]; then CentOSrepo=/etc/yum.repos.d/CentOS-Base.repo if [ -e $CentOSrepo ]; then mv -f ${CentOSrepo} ${CentOSrepo}.orig yum clean all fi fi grep -q "CE" /var/opt/unitrends/platform_capabilities if [ $? -eq 0 ]; then sed -Ei "/include.*RecoveryOS.*/ s/\/pub\/(beta\/|fca\/|ce\/|)/\/pub\/ce\//" /etc/yum.repos.d/Unitrends-RecoveryOS-x86_64.repo fi if [ ! -d $BP_SOFT_DIR ]; then mkdir $BP_SOFT_DIR fi ver_mjr=`rpm -qa | grep 'unitrends-rr-[0-9]' | awk -F"-" '{print $3}'` ver_mnr=`rpm -qa | grep 'unitrends-rr-[0-9]' | awk -F"-" '{print $4}' | cut -b1` ap_msg='Urgent software upgrade needed for your Unitrends appliance. Backups on the appliance may be at risk.' cat /var/www/html/recoveryconsole/index.php | grep -q "alert(" if [ $? -eq 1 ]; then if [ $ver_mjr = "8.2.0" ]; then if [ $ver_mnr -le 4 ]; then sed -i "0,/<\/head>/s/<\/head>/<\/head>\n