testpackage.sh 8.3 KB
Newer Older
haoranc's avatar
haoranc 已提交
1
#!/bin/sh
2
#parameter
3
scriptDir=$(dirname $(readlink -f $0))
haoranc's avatar
haoranc 已提交
4 5 6 7 8 9
packgeName=$1
version=$2
originPackageName=$3
originversion=$4
testFile=$5
subFile="taos.tar.gz"
haoranc's avatar
haoranc 已提交
10
password=$6
haoranc's avatar
haoranc 已提交
11

12 13 14 15 16 17 18 19 20 21 22
# Color setting
RED='\033[41;30m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
GREEN_DARK='\033[0;32m'
YELLOW_DARK='\033[0;33m'
BLUE_DARK='\033[0;34m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'

haoranc's avatar
haoranc 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36
if [ ${testFile} = "server" ];then
    tdPath="TDengine-server-${version}"
    originTdpPath="TDengine-server-${originversion}"
    installCmd="install.sh"
elif [ ${testFile} = "client" ];then
    tdPath="TDengine-client-${version}"
    originTdpPath="TDengine-client-${originversion}"
    installCmd="install_client.sh"    
elif [ ${testFile} = "tools" ];then
    tdPath="taosTools-${version}"
    originTdpPath="taosTools-${originversion}"
    installCmd="install-taostools.sh"
fi

haoranc's avatar
haoranc 已提交
37
function cmdInstall {
38 39 40
command=$1
if command -v ${command} ;then
    echoColor YD  "${command} is already installed" 
haoranc's avatar
haoranc 已提交
41 42
else 
    if command -v apt ;then
43
        apt-get install ${command} -y 
haoranc's avatar
haoranc 已提交
44
    elif command -v yum ;then
45 46
        yum -y install ${command} 
        echoColor YD "you should install ${command} manually"
haoranc's avatar
haoranc 已提交
47 48 49 50
    fi
fi
}

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
function echoColor {
color=$1    
command=$2

if [ ${color} = 'Y' ];then
    echo -e  "${YELLOW}${command}${NC}" 
elif [ ${color} = 'YD' ];then
    echo -e  "${YELLOW_DARK}${command}${NC}" 
elif [ ${color} = 'R' ];then
    echo -e  "${RED}${command}${NC}" 
elif [ ${color} = 'G' ];then
    echo  -e  "${GREEN}${command}${NC}\r\n" 
elif [ ${color} = 'B' ];then
    echo  -e  "${BLUE}${command}${NC}" 
elif [ ${color} = 'BD' ];then
    echo  -e  "${BLUE_DARK}${command}${NC}" 
fi
}


echoColor G "===== install basesoft ====="

cmdInstall tree
cmdInstall wget
cmdInstall sshpass
haoranc's avatar
haoranc 已提交
76

77
echoColor G "===== Uninstall all components of TDeingne ====="
haoranc's avatar
haoranc 已提交
78 79

if command -v rmtaos ;then
80
    echoColor YD "uninstall all components of TDeingne:rmtaos"
haoranc's avatar
haoranc 已提交
81
    rmtaos 
haoranc's avatar
haoranc 已提交
82
else 
83
     echoColor YD "os doesn't include TDengine"
haoranc's avatar
haoranc 已提交
84 85 86
fi

if command -v rmtaostools ;then
87
    echoColor YD "uninstall all components of TDeingne:rmtaostools"
haoranc's avatar
haoranc 已提交
88
    rmtaostools
haoranc's avatar
haoranc 已提交
89
else 
90
    echoColor YD "os doesn't include rmtaostools "
haoranc's avatar
haoranc 已提交
91 92
fi

haoranc's avatar
haoranc 已提交
93 94


95 96

echoColor G "===== new workroom path ====="
haoranc's avatar
haoranc 已提交
97 98 99 100
installPath="/usr/local/src/packageTest"
oriInstallPath="/usr/local/src/packageTest/3.1"

if [ ! -d ${installPath} ] ;then
101
    echoColor BD "mkdir -p ${installPath}"
haoranc's avatar
haoranc 已提交
102 103
    mkdir -p ${installPath}
else  
104
    echoColor YD "${installPath} already exists"
haoranc's avatar
haoranc 已提交
105 106
fi

107
if [ -d ${installPath}/${tdPath} ] ;then
haoranc's avatar
haoranc 已提交
108 109
    echoColor BD "rm -rf ${installPath}/${tdPath}/*"
    rm -rf ${installPath}/${tdPath}/*
110
fi
haoranc's avatar
haoranc 已提交
111 112

if [ ! -d ${oriInstallPath} ] ;then
113
    echoColor BD "mkdir -p ${oriInstallPath}"
haoranc's avatar
haoranc 已提交
114 115
    mkdir -p ${oriInstallPath}
else  
116
    echoColor YD "${oriInstallPath} already exists"
haoranc's avatar
haoranc 已提交
117 118
fi

119
if [ -d ${oriInstallPath}/${originTdpPath} ] ;then
haoranc's avatar
haoranc 已提交
120 121
    echoColor BD "rm -rf ${oriInstallPath}/${originTdpPath}/*"
    rm -rf  ${oriInstallPath}/${originTdpPath}/*  
122
fi
haoranc's avatar
haoranc 已提交
123 124


125
echoColor G "===== download  installPackage ====="
haoranc's avatar
haoranc 已提交
126 127 128 129 130 131
# cd ${installPath}
# wget https://www.taosdata.com/assets-download/3.0/${packgeName}
# cd  ${oriInstallPath}
# wget https://www.taosdata.com/assets-download/3.0/${originPackageName}

cd ${installPath}
132 133
cp -r ${scriptDir}/debRpmAutoInstall.sh   . 

haoranc's avatar
haoranc 已提交
134
if [ ! -f  {packgeName}  ];then
135
    echoColor  BD "sshpass -p ${password} scp 192.168.1.131:/nas/TDengine3/v${version}/community/${packgeName}  ."
haoranc's avatar
haoranc 已提交
136 137
    sshpass -p ${password} scp 192.168.1.131:/nas/TDengine3/v${version}/community/${packgeName}  .
fi
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
packageSuffix=$(echo ${packgeName}  | awk -F '.' '{print $NF}')


if [ ! -f  debRpmAutoInstall.sh  ];then
    echo '#!/usr/bin/expect ' >  debRpmAutoInstall.sh
    echo 'set packgeName [lindex $argv 0]' >>  debRpmAutoInstall.sh
    echo 'set packageSuffix [lindex $argv 1]' >>  debRpmAutoInstall.sh
    echo 'set timeout 3 ' >>  debRpmAutoInstall.sh
    echo 'if { ${packageSuffix} == "deb" } {' >>  debRpmAutoInstall.sh
    echo '    spawn  dpkg -i ${packgeName} '  >>  debRpmAutoInstall.sh
    echo '} elseif { ${packageSuffix} == "rpm"} {' >>  debRpmAutoInstall.sh
    echo '    spawn rpm -ivh ${packgeName}'  >>  debRpmAutoInstall.sh
    echo '}' >>  debRpmAutoInstall.sh
    echo 'expect "*one:"' >>  debRpmAutoInstall.sh
    echo 'send  "\r"' >>  debRpmAutoInstall.sh
    echo 'expect "*skip:"' >>  debRpmAutoInstall.sh
    echo 'send  "\r" ' >>  debRpmAutoInstall.sh
haoranc's avatar
haoranc 已提交
156 157
fi

158 159 160

echoColor G "===== instal Package ====="

haoranc's avatar
haoranc 已提交
161
if [[ ${packgeName} =~ "deb" ]];then
haoranc's avatar
haoranc 已提交
162
    cd ${installPath}
haoranc's avatar
haoranc 已提交
163 164 165
    dpkg -r taostools
    dpkg -r tdengine
    if [[ ${packgeName} =~ "TDengine" ]];then
166
        echoColor BD "./debRpmAutoInstall.sh ${packgeName}  ${packageSuffix}" &&   chmod 755 debRpmAutoInstall.sh &&  ./debRpmAutoInstall.sh  ${packgeName}  ${packageSuffix}
haoranc's avatar
haoranc 已提交
167
    else
168
        echoColor BD "dpkg  -i ${packgeName}" &&   dpkg  -i ${packgeName}
haoranc's avatar
haoranc 已提交
169
    fi
haoranc's avatar
haoranc 已提交
170
elif [[ ${packgeName} =~ "rpm" ]];then
haoranc's avatar
haoranc 已提交
171
    cd ${installPath}
haoranc's avatar
haoranc 已提交
172 173
    sudo rpm -e tdengine
    sudo rpm -e taostools
174
    if [[ ${packgeName} =~ "TDengine" ]];then
175
        echoColor BD "./debRpmAutoInstall.sh ${packgeName}  ${packageSuffix}" &&   chmod 755 debRpmAutoInstall.sh &&  ./debRpmAutoInstall.sh  ${packgeName}  ${packageSuffix}
176
    else
177
        echoColor BD "rpm  -ivh ${packgeName}" &&   rpm  -ivh ${packgeName}
178
    fi
haoranc's avatar
haoranc 已提交
179
elif [[ ${packgeName} =~ "tar" ]];then
180
    echoColor G "===== check installPackage File of tar ====="
haoranc's avatar
haoranc 已提交
181 182
    cd  ${oriInstallPath}
    if [ ! -f  {originPackageName}  ];then
183 184
        echoColor YD "download  base installPackage"
        echoColor BD "sshpass -p ${password} scp 192.168.1.131:/nas/TDengine3/v${originversion}/community/${originPackageName} ."
haoranc's avatar
haoranc 已提交
185
        sshpass -p ${password} scp 192.168.1.131:/nas/TDengine3/v${originversion}/community/${originPackageName} .
haoranc's avatar
haoranc 已提交
186
    fi
187 188
    echoColor YD "unzip the base installation package" 
    echoColor BD "tar -xf ${originPackageName}" && tar -xf ${originPackageName} 
haoranc's avatar
haoranc 已提交
189
    cd ${installPath} 
190 191
    echoColor YD "unzip the new installation package" 
    echoColor BD "tar -xf ${packgeName}" && tar -xf ${packgeName} 
haoranc's avatar
haoranc 已提交
192 193

    if [ ${testFile} != "tools" ] ;then
194 195
        cd ${installPath}/${tdPath} && tar xf ${subFile}
        cd  ${oriInstallPath}/${originTdpPath}  && tar xf ${subFile}
haoranc's avatar
haoranc 已提交
196 197
    fi

haoranc's avatar
haoranc 已提交
198 199 200
    cd  ${oriInstallPath}/${originTdpPath} && tree  >  ${installPath}/base_${originversion}_checkfile
    cd ${installPath}/${tdPath}   && tree > ${installPath}/now_${version}_checkfile
    
haoranc's avatar
haoranc 已提交
201
    cd ${installPath} 
haoranc's avatar
haoranc 已提交
202
    diff  ${installPath}/base_${originversion}_checkfile   ${installPath}/now_${version}_checkfile  > ${installPath}/diffFile.log
haoranc's avatar
haoranc 已提交
203
    diffNumbers=`cat ${installPath}/diffFile.log |wc -l `
haoranc's avatar
haoranc 已提交
204

haoranc's avatar
haoranc 已提交
205
    if [ ${diffNumbers} != 0 ];then
206
        echoColor R "The number and names of files is different from the previous installation package"
207
        echoColor Y `cat ${installPath}/diffFile.log`
haoranc's avatar
haoranc 已提交
208
        exit -1
209 210
    else 
        echoColor G "The number and names of files are the same as previous installation packages"
haoranc's avatar
haoranc 已提交
211
    fi
haoranc's avatar
haoranc 已提交
212 213 214 215 216 217 218 219 220
    echoColor YD  "===== install Package of tar ====="
    cd ${installPath}/${tdPath}
    if [ ${testFile} = "server" ];then
        echoColor BD "bash ${installCmd}  -e no  "
        bash ${installCmd}  -e no  
    else
        echoColor BD "bash ${installCmd} "
        bash ${installCmd} 
    fi
221
fi  
haoranc's avatar
haoranc 已提交
222

223
cd ${installPath}
224 225

if ([[ ${packgeName} =~ "Lite" ]] &&  [[ ${packgeName} =~ "tar" ]]) ||   [[ ${packgeName} =~ "client" ]] ;then
226
    echoColor G "===== install taos-tools when package is lite or client ====="
227 228 229 230 231 232
    cd ${installPath}
    sshpass -p ${password}   scp 192.168.1.131:/nas/TDengine3/v${version}/community/taosTools-2.1.2-Linux-x64.tar.gz .
    # wget https://www.taosdata.com/assets-download/3.0/taosTools-2.1.2-Linux-x64.tar.gz
    tar xf taosTools-2.1.2-Linux-x64.tar.gz
    cd taosTools-2.1.2 && bash install-taostools.sh
elif [[ ${packgeName} =~ "Lite" ]] &&  [[ ${packgeName} =~ "deb" ]] ;then
233
    echoColor G "===== install taos-tools when package is lite or client ====="
234
    cd ${installPath}
235 236 237
    sshpass -p ${password}   scp 192.168.1.131:/nas/TDengine3/v${version}/community/taosTools-2.1.2-Linux-x64.tar.gz .
    tar xf taosTools-2.1.2-Linux-x64.tar.gz
    cd taosTools-2.1.2 && bash install-taostools.sh
238
elif [[ ${packgeName} =~ "Lite" ]] &&  [[ ${packgeName} =~ "rpm" ]]  ;then
239
    echoColor G "===== install taos-tools when package is lite or client ====="
240
    cd ${installPath}
241 242 243
    sshpass -p ${password}   scp 192.168.1.131:/nas/TDengine3/v${version}/community/taosTools-2.1.2-Linux-x64.tar.gz .
    tar xf taosTools-2.1.2-Linux-x64.tar.gz
    cd taosTools-2.1.2 && bash install-taostools.sh
244
fi
haoranc's avatar
haoranc 已提交
245