Files
resatennis_tyroltenn/IDrive/.scripts/binaryChk.sh

290 lines
9.3 KiB
Bash
Executable File

#!/bin/sh
#-------------------------------------------------------------------------------
# IDrive Utility Binary Checker
#
# Version: 1.0
# Created By : Sabin Cheruvattil @ IDrive Inc
# Reviewed By: Deepak Chaurasia @ IDrive Inc
#-------------------------------------------------------------------------------
# Optional Parameters:
# --path : To which directory EVS binaries get copied
# --machine: Type of the machine we are runinning the test. [synology, qnap, asustor, netgear]
# Usage:
# ./binaryChk.sh
# ./binaryChk.sh --path="/tmp/" --machine=synology
utilurl="https://www.idrivedownloads.com/downloads/linux/download-options";
EvsSynoArmBin="$utilurl/IDrive_synology_ARM.zip";
EvsSynoBin32_64="$utilurl/IDrive_synology_64bit.zip";
EvsSynoAlphine="$utilurl/IDrive_synology_Alpine.zip";
EvsSynoAarch64="$utilurl/IDrive_synology_aarch64.zip";
EvsBin32="$utilurl/IDrive_linux_32bit.zip";
EvsBin64="$utilurl/IDrive_linux_64bit.zip";
EvsQnapArmBin="$utilurl/IDrive_QNAP_ARM.zip";
EvsQnapBin64="$utilurl/IDrive_QNAP_64bit.zip";
EvsQnapBin32="$utilurl/IDrive_QNAP_32bit.zip";
EvsNetgArmBin="$utilurl/IDrive_Netgear_ARM.zip";
EvsVaultBin64="$utilurl/IDrive_Vault_64bit.zip";
libLink="https://www.idrivedownloads.com/downloads/linux/nas-servers/libpopt.so.0.0.0";
while [ "$#" -gt 0 ]; do
case "$1" in
--machine|--path|--machine=|--path=) echo "$1 requires an argument" >&2; exit 1;;
--machine=*) machineType="${1#*=}"; shift 1;;
--path=*) binaryPath="${1#*=}"; shift 1;;
-*) echo "Unknown option: $1" >&2; exit 1;;
*) junk="$1"; shift 1;;
esac
done
currentDir=$PWD;
tracelog="$currentDir/trace.log";
mcuser=`whoami`;
if [ "${binaryPath}" = "" ]; then
binaryPath=$currentDir"/idevsutil_IDrive";
else
binaryPath=$binaryPath"/idevsutil_IDrive";
fi
wgetPath=`which wget 2>/dev/null`;
if [ "${wgetPath}" = "" ]; then
wgetPath="/usr/bin/wget";
if [ ! -e "${wgetPath}" ]; then
sudocmd="";
sudomsg="Please provide sudo password for installing wget";
sudopath=`which sudo 2>/dev/null`;
if [ "${mcuser}" != "root" ] && [ "${sudopath}" != "" ]; then
sudocmd="sudo ";
fi
sudopmpt="";
procver="/proc/version";
if [ -e "${procver}" ]; then
procverc=`cat $procver`;
case "$procverc" in
*ubuntu*|*gentoo*) sudopmpt=" -p '${sudomsg}' ";;
esac
fi
# Try to install wget if missing
pkgmgrs="ipkg opkg yum apt-get pkg pacman zypper";
for mgr in $pkgmgrs; do
mgrpath=`which $mgr 2>/dev/null`;
if [ "${mgrpath}" != "" ]; then
if [ $mgr != "pacman" ]; then
instcmd="$mgr install wget";
else
instcmd="$mgr -S wget";
fi
echo "Installing wget. Please wait...";
if [ "${sudocmd}" != "" ]; then
if [ "${sudomsg}" != "" ]; then
instcmd="$sudocmd$sudopmpt$instcmd";
else
echo "${sudomsg}";
instcmd="$sudocmd$instcmd";
fi
fi
`$instcmd`;
wgetPath=`which wget 2>/dev/null`;
break;
fi
done
if [ "${wgetPath}" = "" ]; then
echo "No wget found" >> $tracelog;
echo "No wget found";
exit;
fi
fi
fi
MACHINE_ARCH=$(uname -m);
MACHINE_ARCH_DATA=$(uname -a);
if [ "${machineType}" = "synology" ]; then
# check machine type and create library link for evs if required
if [ ! -e "/lib32/libpopt.so.0" ] && [ "${MACHINE_ARCH}" = "x86_64" ] && [ -e "/lib32/" ]; then
rm "/lib32/libpopt.so.0" 2>>/dev/null;
libFile=`echo "$libLink" | cut -d/ -f7`;
pathSep="/";
dum="${currentDir}${pathSep}${libFile}";
rm "$dum" 2>>/dev/null;
$wgetPath --no-check-certificate --no-proxy $libLink;
cmd="ln -s $dum /lib32/libpopt.so.0";
`$cmd`;
fi
fi
idevsUrls="";
if [ "${machineType}" = "synology" ]; then
if [ `echo "${MACHINE_ARCH_DATA}" | grep -c "alpine" ` -gt 0 ]; then
idevsUrls="$EvsSynoAlphine $EvsSynoArmBin $EvsQnapArmBin $EvsNetgArmBin";
elif [ `echo "${MACHINE_ARCH}" | grep -i 'armv'` ]; then
idevsUrls="$EvsSynoArmBin $EvsSynoAlphine $EvsQnapArmBin $EvsNetgArmBin";
elif [ "${MACHINE_ARCH}" = 'x86' ] || [ "${MACHINE_ARCH}" = 'i686' ] || [ "${MACHINE_ARCH}" = 'i386' ] || [ "${MACHINE_ARCH}" = 'i586' ]; then
idevsUrls="$EvsQnapBin32 $EvsBin32 $EvsSynoBin32_64";
elif [ "${MACHINE_ARCH}" = 'x86_64' ] || [ "${MACHINE_ARCH}" = 'amd64' ]; then
idevsUrls="$EvsSynoBin32_64 $EvsBin64 $EvsBin32 $EvsQnapBin64 $EvsVaultBin64 $EvsQnapBin32";
elif [ "${MACHINE_ARCH}" = "aarch64" ]; then
idevsUrls="$EvsSynoAarch64 $EvsSynoAlphine $EvsSynoArmBin $EvsQnapArmBin $EvsNetgArmBin";
fi
elif [ "${machineType}" = "qnap" ]; then
if [ `echo "${MACHINE_ARCH}" | grep -i 'armv'` ]; then
idevsUrls="$EvsQnapArmBin $EvsSynoArmBin $EvsSynoAlphine $EvsNetgArmBin";
elif [ "${MACHINE_ARCH}" = 'x86' ] || [ "${MACHINE_ARCH}" = 'i686' ] || [ "${MACHINE_ARCH}" = 'i386' ] || [ "${MACHINE_ARCH}" = 'i586' ]; then
idevsUrls="$EvsQnapBin32 $EvsBin32 $EvsSynoBin32_64";
elif [ "${MACHINE_ARCH}" = 'aarch64' ]; then
idevsUrls="$EvsSynoAarch64 $EvsSynoAlphine $EvsSynoArmBin $EvsQnapArmBin $EvsNetgArmBin";
elif [ "${MACHINE_ARCH}" = 'x86_64' ] || [ "${MACHINE_ARCH}" = 'amd64' ]; then
idevsUrls="$EvsQnapBin64 $EvsQnapBin32 $EvsSynoBin32_64 $EvsBin64 $EvsBin32 $EvsVaultBin64";
fi
elif [ "${machineType}" = "netgear" ]; then
if [ `echo "${MACHINE_ARCH}" | grep -i 'armv'` ]; then
idevsUrls="$EvsNetgArmBin $EvsSynoArmBin $EvsSynoAlphine $EvsQnapArmBin";
elif [ "${MACHINE_ARCH}" = 'x86_64' ] || [ "${MACHINE_ARCH}" = 'amd64' ]; then
idevsUrls="$EvsSynoBin32_64 $EvsBin32 $EvsBin64 $EvsQnapBin64 $EvsQnapBin32 $EvsVaultBin64";
elif [ "${MACHINE_ARCH}" = 'x86' ] || [ "${MACHINE_ARCH}" = 'i686' ] || [ "${MACHINE_ARCH}" = 'i386' ] || [ "${MACHINE_ARCH}" = 'i586' ]; then
idevsUrls="$EvsBin32 $EvsQnapBin32 $EvsSynoBin32_64 $EvsBin64 $EvsQnapBin64";
fi
elif [ "${machineType}" = "Asustor" ]; then
if [ "${MACHINE_ARCH}" = 'x86_64' ] || [ "${MACHINE_ARCH}" = 'amd64' ]; then
idevsUrls="$EvsBin64 $EvsBin32 $EvsSynoBin32_64 $EvsQnapBin64 $EvsQnapBin32 $EvsVaultBin64";
elif [ "${MACHINE_ARCH}" = 'x86' ] || [ "${MACHINE_ARCH}" = 'i686' ] || [ "${MACHINE_ARCH}" = 'i386' ] || [ "${MACHINE_ARCH}" = 'i586' ]; then
idevsUrls="$EvsBin32 $EvsQnapBin32 $EvsSynoBin32_64";
fi
else
if [ "${MACHINE_ARCH}" = 'x86_64' ] || [ "${MACHINE_ARCH}" = 'amd64' ]; then
idevsUrls="$EvsBin64 $EvsBin32 $EvsSynoBin32_64 $EvsQnapBin64 $EvsVaultBin64 $EvsQnapBin32";
elif [ "${MACHINE_ARCH}" = 'x86' ] || [ "${MACHINE_ARCH}" = 'i686' ] || [ "${MACHINE_ARCH}" = 'i386' ] || [ "${MACHINE_ARCH}" = 'i586' ]; then
idevsUrls="$EvsBin32 $EvsQnapBin32 $EvsSynoBin32_64";
elif [ "${MACHINE_ARCH}" = 'aarch64' ]; then
idevsUrls="$EvsSynoAarch64 $EvsQnapArmBin $EvsSynoArmBin $EvsSynoAlphine $EvsNetgArmBin";
elif [ `echo "${MACHINE_ARCH}" | grep -i 'armv'` ]; then
idevsUrls="$EvsSynoArmBin $EvsSynoAlphine $EvsQnapArmBin $EvsNetgArmBin";
elif [ `echo "${MACHINE_ARCH_DATA}" | grep -c "alpine" ` -gt 0 ]; then
idevsUrls="$EvsSynoAlphine $EvsSynoArmBin $EvsQnapArmBin $EvsNetgArmBin";
fi
fi
if [ "${idevsUrls}" = "" ]; then
idevsUrls="$EvsSynoArmBin $EvsSynoAlphine $EvsSynoAarch64 $EvsQnapArmBin $EvsNetgArmBin $EvsBin32 $EvsBin64 $EvsSynoBin32_64 $EvsQnapBin32 $EvsQnapBin64 $EvsVaultBin64";
fi
# Get zip/unzip type
sevenUnzip=`which 7z 2>/dev/null`;
if [ $sevenUnzip ]; then
unzip="$sevenUnzip x";
else
unzip=`which unzip 2>/dev/null`;
fi
if [ "${unzip}" = "" ]; then
echo "No unzip available";
echo "No unzip available" >> $tracelog;
exit;
fi
verify_binary () {
zipName="${idevsUrl##*/}";
# check if zip already exist and if so then remove
if [ -e "${zipName}" ]; then
rm "$zipName";
fi
for i in 1 2 3 4 5; do
$wgetPath --no-check-certificate --no-proxy $idevsUrl;
if [ ! -f "${zipName}" ]; then
echo "Failed to download: $zipName" >> $tracelog;
if [ $i -eq 5 ]; then
echo "Failed to download: $zipName";
exit;
fi
sleep 3;
else
break;
fi
done
# check if evs directory already exist before unzip and if so then remove
zipFullPath=`echo "$zipName" | cut -d. -f1`;
evsDir="$currentDir/$zipFullPath";
if [ -e "${evsDir}" ] && [ "${zipFullPath}" != "" ] && [ "${zipFullPath}" != "/" ]; then
rm -rf "$evsDir";
fi
$unzip "$zipName";
rm "$zipName";
evs_nondedup="$evsDir/idevsutil";
evs_dedup="$evsDir/idevsutil_dedup";
chmod 0755 "$evs_nondedup";
chmod 0755 "$evs_dedup";
evs_ndh_res=`"$evs_nondedup" -h 2>/dev/null`;
evs_ndh_exit=`echo $?`;
evs_dh_res=`"$evs_dedup" -h 2>/dev/null`;
evs_dh_exit=`echo $?`;
if [ "${evs_ndh_exit}" = '0' ] && [ "${evs_dh_exit}" = '0' ]; then
cp $evs_nondedup "$binaryPath";
cp $evs_dedup $binaryPath"_Dedup";
evs_check_stat="both";
elif [ "${evs_ndh_exit}" = '0' ]; then
cp $evs_nondedup "$binaryPath";
evs_check_stat="non-dedup";
elif [ "${evs_dh_exit}" = '0' ]; then
cp $evs_dedup $binaryPath"_Dedup";
evs_check_stat="dedup";
fi
if [ -e "${evsDir}" ] && [ "${zipFullPath}" != "" ] && [ "${zipFullPath}" != "/" ]; then
rm -rf "$evsDir";
fi
}
evs_check_stat="";
for i in $idevsUrls
do
idevsUrl=$i;
verify_binary
if [ "${evs_check_stat}" != "" ]; then
break;
fi
done
echo "";
echo "";
echo "Send the below details to support:";
echo "------------------------------------";
if [ "${machineType}" != "" ]; then
echo "Machine Details: ${machineType}";
fi
echo "OS Details: ${MACHINE_ARCH_DATA}";
if [ $evs_check_stat = "both" ]; then
echo "Working zip is $zipName";
elif [ $evs_check_stat = "non-dedup" ]; then
echo "Working non dedup zip is $zipName";
elif [ $evs_check_stat = "dedup" ]; then
echo "Working dedup zip is $zipName";
else
echo "Unable to find compatible evs binary";
fi