testpackage.sh 8.9 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 10
packgeName=$1
version=$2
originPackageName=$3
originversion=$4
testFile=$5
subFile="taos.tar.gz"

11 12 13 14 15 16 17 18 19 20 21
# 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 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35
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 已提交
36
function cmdInstall {
37 38 39
command=$1
if command -v ${command} ;then
    echoColor YD  "${command} is already installed" 
haoranc's avatar
haoranc 已提交
40 41
else 
    if command -v apt ;then
42
        apt-get install ${command} -y 
haoranc's avatar
haoranc 已提交
43
    elif command -v yum ;then
44 45
        yum -y install ${command} 
        echoColor YD "you should install ${command} manually"
haoranc's avatar
haoranc 已提交
46 47 48 49
    fi
fi
}

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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
}


haoranc's avatar
haoranc 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
function wgetFile {

file=$1

if [ ! -f  ${file}  ];then
    echoColor  BD "wget https://www.taosdata.com/assets-download/3.0/${file}"
    wget https://www.taosdata.com/assets-download/3.0/${file}
else
    echoColor  YD "${file} already exists "
fi
}

function newPath {

buildPath=$1

if [ ! -d ${buildPath} ] ;then
    echoColor BD "mkdir -p ${buildPath}"
    mkdir -p ${buildPath}
else  
    echoColor YD "${buildPath} already exists"
fi

}


96 97 98 99
echoColor G "===== install basesoft ====="

cmdInstall tree
cmdInstall wget
haoranc's avatar
haoranc 已提交
100
cmdInstall expect
haoranc's avatar
haoranc 已提交
101

102
echoColor G "===== Uninstall all components of TDeingne ====="
haoranc's avatar
haoranc 已提交
103 104

if command -v rmtaos ;then
105
    echoColor YD "uninstall all components of TDeingne:rmtaos"
haoranc's avatar
haoranc 已提交
106
    rmtaos 
haoranc's avatar
haoranc 已提交
107
else 
108
     echoColor YD "os doesn't include TDengine"
haoranc's avatar
haoranc 已提交
109 110 111
fi

if command -v rmtaostools ;then
112
    echoColor YD "uninstall all components of TDeingne:rmtaostools"
haoranc's avatar
haoranc 已提交
113
    rmtaostools
haoranc's avatar
haoranc 已提交
114
else 
115
    echoColor YD "os doesn't include rmtaostools "
haoranc's avatar
haoranc 已提交
116 117
fi

haoranc's avatar
haoranc 已提交
118 119


120 121

echoColor G "===== new workroom path ====="
haoranc's avatar
haoranc 已提交
122 123 124
installPath="/usr/local/src/packageTest"
oriInstallPath="/usr/local/src/packageTest/3.1"

haoranc's avatar
haoranc 已提交
125
newPath ${installPath}
haoranc's avatar
haoranc 已提交
126

haoranc's avatar
haoranc 已提交
127
newPath ${oriInstallPath}
haoranc's avatar
haoranc 已提交
128 129


130
if [ -d ${oriInstallPath}/${originTdpPath} ] ;then
haoranc's avatar
haoranc 已提交
131 132
    echoColor BD "rm -rf ${oriInstallPath}/${originTdpPath}/*"
    rm -rf  ${oriInstallPath}/${originTdpPath}/*  
133
fi
haoranc's avatar
haoranc 已提交
134

haoranc's avatar
haoranc 已提交
135 136 137 138
if [ -d ${installPath}/${tdPath} ] ;then
    echoColor BD "rm -rf ${installPath}/${tdPath}/*"
    rm -rf ${installPath}/${tdPath}/*
fi
haoranc's avatar
haoranc 已提交
139

140
echoColor G "===== download  installPackage ====="
haoranc's avatar
haoranc 已提交
141 142
cd ${installPath} && wgetFile ${packgeName}
cd  ${oriInstallPath}  && wgetFile ${originPackageName}
haoranc's avatar
haoranc 已提交
143 144

cd ${installPath}
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
cp -r ${scriptDir}/debRpmAutoInstall.sh   . 

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 已提交
164 165
fi

166 167 168

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

haoranc's avatar
haoranc 已提交
169
if [[ ${packgeName} =~ "deb" ]];then
haoranc's avatar
haoranc 已提交
170
    cd ${installPath}
haoranc's avatar
haoranc 已提交
171 172 173
    dpkg -r taostools
    dpkg -r tdengine
    if [[ ${packgeName} =~ "TDengine" ]];then
174
        echoColor BD "./debRpmAutoInstall.sh ${packgeName}  ${packageSuffix}" &&   chmod 755 debRpmAutoInstall.sh &&  ./debRpmAutoInstall.sh  ${packgeName}  ${packageSuffix}
haoranc's avatar
haoranc 已提交
175
    else
176
        echoColor BD "dpkg  -i ${packgeName}" &&   dpkg  -i ${packgeName}
haoranc's avatar
haoranc 已提交
177
    fi
haoranc's avatar
haoranc 已提交
178
elif [[ ${packgeName} =~ "rpm" ]];then
haoranc's avatar
haoranc 已提交
179
    cd ${installPath}
haoranc's avatar
haoranc 已提交
180 181
    sudo rpm -e tdengine
    sudo rpm -e taostools
182
    if [[ ${packgeName} =~ "TDengine" ]];then
183
        echoColor BD "./debRpmAutoInstall.sh ${packgeName}  ${packageSuffix}" &&   chmod 755 debRpmAutoInstall.sh &&  ./debRpmAutoInstall.sh  ${packgeName}  ${packageSuffix}
184
    else
185
        echoColor BD "rpm  -ivh ${packgeName}" &&   rpm  -ivh ${packgeName}
186
    fi
haoranc's avatar
haoranc 已提交
187
elif [[ ${packgeName} =~ "tar" ]];then
188
    echoColor G "===== check installPackage File of tar ====="
haoranc's avatar
haoranc 已提交
189 190
    cd  ${oriInstallPath}
    if [ ! -f  {originPackageName}  ];then
191
        echoColor YD "download  base installPackage"
haoranc's avatar
haoranc 已提交
192
        wgetFile ${originPackageName}
haoranc's avatar
haoranc 已提交
193
    fi
194 195
    echoColor YD "unzip the base installation package" 
    echoColor BD "tar -xf ${originPackageName}" && tar -xf ${originPackageName} 
haoranc's avatar
haoranc 已提交
196
    cd ${installPath} 
197 198
    echoColor YD "unzip the new installation package" 
    echoColor BD "tar -xf ${packgeName}" && tar -xf ${packgeName} 
haoranc's avatar
haoranc 已提交
199 200

    if [ ${testFile} != "tools" ] ;then
201 202
        cd ${installPath}/${tdPath} && tar xf ${subFile}
        cd  ${oriInstallPath}/${originTdpPath}  && tar xf ${subFile}
haoranc's avatar
haoranc 已提交
203 204
    fi

haoranc's avatar
haoranc 已提交
205 206
    cd  ${oriInstallPath}/${originTdpPath} && tree -I "driver" >  ${installPath}/base_${originversion}_checkfile
    cd ${installPath}/${tdPath}   && tree -I "driver" > ${installPath}/now_${version}_checkfile
haoranc's avatar
haoranc 已提交
207
    
haoranc's avatar
haoranc 已提交
208
    cd ${installPath} 
haoranc's avatar
haoranc 已提交
209
    diff  ${installPath}/base_${originversion}_checkfile   ${installPath}/now_${version}_checkfile  > ${installPath}/diffFile.log
haoranc's avatar
haoranc 已提交
210
    diffNumbers=`cat ${installPath}/diffFile.log |wc -l `
haoranc's avatar
haoranc 已提交
211

haoranc's avatar
haoranc 已提交
212
    if [ ${diffNumbers} != 0 ];then
213
        echoColor R "The number and names of files is different from the previous installation package"
214
        echoColor Y `cat ${installPath}/diffFile.log`
haoranc's avatar
haoranc 已提交
215
        exit -1
216 217
    else 
        echoColor G "The number and names of files are the same as previous installation packages"
218
        rm -rf ${installPath}/diffFile.log
haoranc's avatar
haoranc 已提交
219
    fi
haoranc's avatar
haoranc 已提交
220 221 222 223 224 225 226 227 228
    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
229
fi  
haoranc's avatar
haoranc 已提交
230

231
cd ${installPath}
232

233
if [[ ${packgeName} =~ "Lite" ]]  ||   ([[ ${packgeName} =~ "x64" ]] && [[ ${packgeName} =~ "client" ]]) ||  ([[ ${packgeName} =~ "deb" ]] && [[ ${packgeName} =~ "server" ]])  || ([[ ${packgeName} =~ "rpm" ]] && [[ ${packgeName} =~ "server" ]]) ;then
234
    echoColor G "===== install taos-tools when package is lite or client ====="
235
    cd ${installPath}
haoranc's avatar
haoranc 已提交
236 237
    wgetFile taosTools-2.1.3-Linux-x64.tar.gz .
    tar xf taosTools-2.1.3-Linux-x64.tar.gz
haoranc's avatar
haoranc 已提交
238
    cd taosTools-2.1.3 && bash install-taostools.sh
239
elif  ([[ ${packgeName} =~ "arm64" ]] && [[ ${packgeName} =~ "client" ]]);then
240
    echoColor G "===== install taos-tools arm when package is arm64-client ====="
241
    cd ${installPath}
haoranc's avatar
haoranc 已提交
242 243 244
    wgetFile taosTools-2.1.3-Linux-arm64.tar.gz .
    tar xf taosTools-2.1.3-Linux-arm64.tar.gz
    cd taosTools-2.1.3 && bash install-taostools.sh
245
fi
haoranc's avatar
haoranc 已提交
246

247 248 249 250 251 252
echoColor G  "===== start TDengine ====="

if [[ ${packgeName} =~ "server" ]] ;then
    echoColor BD " rm -rf /var/lib/taos/* &&  systemctl restart taosd "
    rm -rf /var/lib/taos/*
    systemctl restart taosd
253
fi
254

255 256 257
rm -rf ${installPath}/${packgeName}
rm -rf ${installPath}/${tdPath}/

haoranc's avatar
haoranc 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
# if ([[ ${packgeName} =~ "Lite" ]] &&  [[ ${packgeName} =~ "tar" ]]) ||   [[ ${packgeName} =~ "client" ]] ;then
#     echoColor G "===== install taos-tools when package is lite or client ====="
#     cd ${installPath}
#     wgetFile 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
#     echoColor G "===== install taos-tools when package is lite or client ====="
#     cd ${installPath}
#     wgetFile 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} =~ "rpm" ]]  ;then
#     echoColor G "===== install taos-tools when package is lite or client ====="
#     cd ${installPath}
#     wgetFile 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
# fi