testpackage.sh 11.7 KB
Newer Older
haoranc's avatar
haoranc 已提交
1
#!/bin/sh
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17


function usage() {
    echo "$0"
    echo -e "\t -f test file type,server/client/tools/"
    echo -e "\t -m pacakage version Type,community/enterprise"
    echo -e "\t -l package type,lite or not"
    echo -e "\t -c operation type,x64/arm64"
    echo -e "\t -v pacakage version,3.0.1.7"
    echo -e "\t -o pacakage version,3.0.1.7"
    echo -e "\t -s source Path,web/nas"
    echo -e "\t -t package Type,tar/rpm/deb"
    echo -e "\t -h help"
}


18
#parameter
19
scriptDir=$(dirname $(readlink -f $0))
20 21 22 23 24 25 26 27
version="3.0.1.7"
originversion="3.0.1.7"
testFile="server"
verMode="communtity"
sourcePath="nas"
cpuType="x64"
lite="true"
packageType="tar"
sangshuduo's avatar
sangshuduo 已提交
28
subFile="package.tar.gz"
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
while getopts "m:c:f:l:s:o:t:v:h" opt; do
    case $opt in
        m)
            verMode=$OPTARG
            ;;
        v)
            version=$OPTARG
            ;;
        f)
            testFile=$OPTARG
            ;;
        l)
            lite=$OPTARG
            ;;
        s)
            sourcePath=$OPTARG
            ;;
        o)
            originversion=$OPTARG
            ;;
        c)
            cpuType=$OPTARG
            ;;
        t)
            packageType=$OPTARG
            ;;
        h)
            usage
            exit 0
            ;;
        ?)
            echo "Invalid option: -$OPTARG"
            usage
            exit 0
            ;;
    esac
done



echo "testFile:${testFile},verMode:${verMode},lite:${lite},cpuType:${cpuType},packageType:${packageType},version-${version},originversion:${originversion},sourcePath:${sourcePath}"
70 71 72 73 74 75 76 77 78 79 80
# 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'

81
if [[ ${verMode} = "enterprise" ]];then
sangshuduo's avatar
sangshuduo 已提交
82
    prePackage="TDengine-enterprise-${testFile}"
83
elif [ ${verMode} = "community" ];then
sangshuduo's avatar
sangshuduo 已提交
84
    prePackage="TDengine-${testFile}"
85 86 87 88 89 90 91 92 93 94
fi
if [ ${lite} = "true" ];then
    packageLite="-Lite"
elif [ ${lite} = "false"  ];then
    packageLite=""
fi
if [[ "$packageType" = "tar" ]] ;then
    packageType="tar.gz"
fi

sangshuduo's avatar
sangshuduo 已提交
95 96
tdPath="${prePackage}-${version}"
originTdpPath="${prePackage}-${originversion}"
97

sangshuduo's avatar
sangshuduo 已提交
98
packageName="${tdPath}-Linux-${cpuType}${packageLite}.${packageType}"
99 100 101
originPackageName="${originTdpPath}-Linux-${cpuType}${packageLite}.${packageType}"

if [ "$testFile" == "server" ] ;then
haoranc's avatar
haoranc 已提交
102 103 104 105 106 107
    installCmd="install.sh"
elif [ ${testFile} = "client" ];then
    installCmd="install_client.sh"    
elif [ ${testFile} = "tools" ];then
    tdPath="taosTools-${version}"
    originTdpPath="taosTools-${originversion}"
sangshuduo's avatar
sangshuduo 已提交
108
    packageName="${tdPath}-Linux-${cpuType}${packageLite}.${packageType}"
109
    originPackageName="${originTdpPath}-Linux-${cpuType}${packageLite}.${packageType}"    
110
    installCmd="install-taostools.sh"
haoranc's avatar
haoranc 已提交
111 112
fi

113

sangshuduo's avatar
sangshuduo 已提交
114
echo "tdPath:${tdPath},originTdpPath:${originTdpPath},packageName:${packageName},originPackageName:${originPackageName}"
haoranc's avatar
haoranc 已提交
115
function cmdInstall {
116 117 118
command=$1
if command -v ${command} ;then
    echoColor YD  "${command} is already installed" 
haoranc's avatar
haoranc 已提交
119 120
else 
    if command -v apt ;then
121
        apt-get install ${command} -y 
haoranc's avatar
haoranc 已提交
122
    elif command -v yum ;then
123 124
        yum -y install ${command} 
        echoColor YD "you should install ${command} manually"
haoranc's avatar
haoranc 已提交
125 126 127 128
    fi
fi
}

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
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
}


149

haoranc's avatar
haoranc 已提交
150 151 152
function wgetFile {

file=$1
153 154
versionPath=$2
sourceP=$3
155
nasServerIP="192.168.1.131"
156
packagePath="/nas/TDengine/v${versionPath}/${verMode}"
157 158
if [ -f  ${file}  ];then
    echoColor  YD "${file} already exists ,it will delete it and download  it again "
159
    rm -rf ${file}
haoranc's avatar
haoranc 已提交
160
fi
161

162
if [[ ${sourceP} = 'web' ]];then
163 164
    echoColor  BD "====download====:wget https://www.taosdata.com/assets-download/3.0/${file}"
    wget https://www.taosdata.com/assets-download/3.0/${file}
165
elif [[ ${sourceP} = 'nas' ]];then
166 167
    echoColor  BD "====download====:scp root@${nasServerIP}:${packagePath}/${file} ."
    scp root@${nasServerIP}:${packagePath}/${file} .
168 169
fi

haoranc's avatar
haoranc 已提交
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
}

function newPath {

buildPath=$1

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

}


186 187 188 189
echoColor G "===== install basesoft ====="

cmdInstall tree
cmdInstall wget
haoranc's avatar
haoranc 已提交
190
cmdInstall expect
haoranc's avatar
haoranc 已提交
191

192
echoColor G "===== Uninstall all components of TDeingne ====="
haoranc's avatar
haoranc 已提交
193 194

if command -v rmtaos ;then
195
    echoColor YD "uninstall all components of TDeingne:rmtaos"
haoranc's avatar
haoranc 已提交
196
    rmtaos 
haoranc's avatar
haoranc 已提交
197
else 
198
     echoColor YD "os doesn't include TDengine"
haoranc's avatar
haoranc 已提交
199 200 201
fi

if command -v rmtaostools ;then
202
    echoColor YD "uninstall all components of TDeingne:rmtaostools"
haoranc's avatar
haoranc 已提交
203
    rmtaostools
haoranc's avatar
haoranc 已提交
204
else 
205
    echoColor YD "os doesn't include rmtaostools "
haoranc's avatar
haoranc 已提交
206 207
fi

haoranc's avatar
haoranc 已提交
208

sangshuduo's avatar
sangshuduo 已提交
209
if [[ ${packageName} =~ "server" ]] ;then
210 211 212
    echoColor BD " pkill -9 taosd "
    pkill -9 taosd
fi
haoranc's avatar
haoranc 已提交
213

214 215

echoColor G "===== new workroom path ====="
haoranc's avatar
haoranc 已提交
216 217 218
installPath="/usr/local/src/packageTest"
oriInstallPath="/usr/local/src/packageTest/3.1"

haoranc's avatar
haoranc 已提交
219
newPath ${installPath}
haoranc's avatar
haoranc 已提交
220

haoranc's avatar
haoranc 已提交
221
newPath ${oriInstallPath}
haoranc's avatar
haoranc 已提交
222 223


224
if [ -d ${oriInstallPath}/${originTdpPath} ] ;then
haoranc's avatar
haoranc 已提交
225 226
    echoColor BD "rm -rf ${oriInstallPath}/${originTdpPath}/*"
    rm -rf  ${oriInstallPath}/${originTdpPath}/*  
227
fi
haoranc's avatar
haoranc 已提交
228

haoranc's avatar
haoranc 已提交
229 230 231 232
if [ -d ${installPath}/${tdPath} ] ;then
    echoColor BD "rm -rf ${installPath}/${tdPath}/*"
    rm -rf ${installPath}/${tdPath}/*
fi
haoranc's avatar
haoranc 已提交
233

234
echoColor G "===== download  installPackage ====="
sangshuduo's avatar
sangshuduo 已提交
235
cd ${installPath} && wgetFile ${packageName} ${version}  ${sourcePath}
236 237
cd  ${oriInstallPath}  && wgetFile ${originPackageName} ${originversion}   ${sourcePath}

haoranc's avatar
haoranc 已提交
238 239

cd ${installPath}
240 241
cp -r ${scriptDir}/debRpmAutoInstall.sh   . 

sangshuduo's avatar
sangshuduo 已提交
242
packageSuffix=$(echo ${packageName}  | awk -F '.' '{print $NF}')
243 244 245 246


if [ ! -f  debRpmAutoInstall.sh  ];then
    echo '#!/usr/bin/expect ' >  debRpmAutoInstall.sh
sangshuduo's avatar
sangshuduo 已提交
247
    echo 'set packageName [lindex $argv 0]' >>  debRpmAutoInstall.sh
248 249 250
    echo 'set packageSuffix [lindex $argv 1]' >>  debRpmAutoInstall.sh
    echo 'set timeout 3 ' >>  debRpmAutoInstall.sh
    echo 'if { ${packageSuffix} == "deb" } {' >>  debRpmAutoInstall.sh
sangshuduo's avatar
sangshuduo 已提交
251
    echo '    spawn  dpkg -i ${packageName} '  >>  debRpmAutoInstall.sh
252
    echo '} elseif { ${packageSuffix} == "rpm"} {' >>  debRpmAutoInstall.sh
sangshuduo's avatar
sangshuduo 已提交
253
    echo '    spawn rpm -ivh ${packageName}'  >>  debRpmAutoInstall.sh
254 255 256 257 258
    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 已提交
259 260
fi

261 262 263

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

sangshuduo's avatar
sangshuduo 已提交
264
if [[ ${packageName} =~ "deb" ]];then
haoranc's avatar
haoranc 已提交
265
    cd ${installPath}
haoranc's avatar
haoranc 已提交
266 267
    dpkg -r taostools
    dpkg -r tdengine
sangshuduo's avatar
sangshuduo 已提交
268 269
    if [[ ${packageName} =~ "TDengine" ]];then
        echoColor BD "./debRpmAutoInstall.sh ${packageName}  ${packageSuffix}" &&   chmod 755 debRpmAutoInstall.sh &&  ./debRpmAutoInstall.sh  ${packageName}  ${packageSuffix}
haoranc's avatar
haoranc 已提交
270
    else
sangshuduo's avatar
sangshuduo 已提交
271
        echoColor BD "dpkg  -i ${packageName}" &&   dpkg  -i ${packageName}
haoranc's avatar
haoranc 已提交
272
    fi
sangshuduo's avatar
sangshuduo 已提交
273
elif [[ ${packageName} =~ "rpm" ]];then
haoranc's avatar
haoranc 已提交
274
    cd ${installPath}
haoranc's avatar
haoranc 已提交
275 276
    sudo rpm -e tdengine
    sudo rpm -e taostools
sangshuduo's avatar
sangshuduo 已提交
277 278
    if [[ ${packageName} =~ "TDengine" ]];then
        echoColor BD "./debRpmAutoInstall.sh ${packageName}  ${packageSuffix}" &&   chmod 755 debRpmAutoInstall.sh &&  ./debRpmAutoInstall.sh  ${packageName}  ${packageSuffix}
279
    else
sangshuduo's avatar
sangshuduo 已提交
280
        echoColor BD "rpm  -ivh ${packageName}" &&   rpm  -ivh ${packageName}
281
    fi
sangshuduo's avatar
sangshuduo 已提交
282
elif [[ ${packageName} =~ "tar" ]];then
283
    echoColor G "===== check installPackage File of tar ====="
haoranc's avatar
haoranc 已提交
284 285
    cd  ${oriInstallPath}
    if [ ! -f  {originPackageName}  ];then
286
        echoColor YD "download  base installPackage"
287
        wgetFile ${originPackageName} ${originversion} ${sourcePath} 
haoranc's avatar
haoranc 已提交
288
    fi
289 290
    echoColor YD "unzip the base installation package" 
    echoColor BD "tar -xf ${originPackageName}" && tar -xf ${originPackageName} 
haoranc's avatar
haoranc 已提交
291
    cd ${installPath} 
292
    echoColor YD "unzip the new installation package" 
sangshuduo's avatar
sangshuduo 已提交
293
    echoColor BD "tar -xf ${packageName}" && tar -xf ${packageName} 
haoranc's avatar
haoranc 已提交
294 295

    if [ ${testFile} != "tools" ] ;then
296 297
        cd ${installPath}/${tdPath} && tar xf ${subFile}
        cd  ${oriInstallPath}/${originTdpPath}  && tar xf ${subFile}
haoranc's avatar
haoranc 已提交
298 299
    fi

haoranc's avatar
haoranc 已提交
300 301
    cd  ${oriInstallPath}/${originTdpPath} && tree -I "driver" >  ${installPath}/base_${originversion}_checkfile
    cd ${installPath}/${tdPath}   && tree -I "driver" > ${installPath}/now_${version}_checkfile
haoranc's avatar
haoranc 已提交
302
    
haoranc's avatar
haoranc 已提交
303
    cd ${installPath} 
haoranc's avatar
haoranc 已提交
304
    diff  ${installPath}/base_${originversion}_checkfile   ${installPath}/now_${version}_checkfile  > ${installPath}/diffFile.log
haoranc's avatar
haoranc 已提交
305
    diffNumbers=`cat ${installPath}/diffFile.log |wc -l `
haoranc's avatar
haoranc 已提交
306

haoranc's avatar
haoranc 已提交
307
    if [ ${diffNumbers} != 0 ];then
308
        echoColor R "The number and names of files is different from the previous installation package"
309 310
        diffLog=`cat ${installPath}/diffFile.log`
        echoColor Y "${diffLog}"
haoranc's avatar
haoranc 已提交
311
        exit -1
312 313
    else 
        echoColor G "The number and names of files are the same as previous installation packages"
314
        rm -rf ${installPath}/diffFile.log
haoranc's avatar
haoranc 已提交
315
    fi
haoranc's avatar
haoranc 已提交
316 317 318 319 320 321 322 323 324
    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
325
fi  
haoranc's avatar
haoranc 已提交
326

327
cd ${installPath}
328

sangshuduo's avatar
sangshuduo 已提交
329
if [[ ${packageName} =~ "Lite" ]]  ||   ([[ ${packageName} =~ "x64" ]] && [[ ${packageName} =~ "client" ]]) ||  ([[ ${packageName} =~ "deb" ]] && [[ ${packageName} =~ "server" ]])  || ([[ ${packageName} =~ "rpm" ]] && [[ ${packageName} =~ "server" ]]) ;then
330
    echoColor G "===== install taos-tools when package is lite or client ====="
331
    cd ${installPath}
332 333 334 335
    if [ ! -f "taosTools-2.1.3-Linux-x64.tar.gz " ];then
        wgetFile taosTools-2.1.3-Linux-x64.tar.gz v2.1.3 web
        tar xf taosTools-2.1.3-Linux-x64.tar.gz  
    fi
336
    cd taosTools-2.1.3 && bash install-taostools.sh
sangshuduo's avatar
sangshuduo 已提交
337
elif  ([[ ${packageName} =~ "arm64" ]] && [[ ${packageName} =~ "client" ]]);then
338
    echoColor G "===== install taos-tools arm when package is arm64-client ====="
339
    cd ${installPath}
340
    if [ ! -f "taosTools-2.1.3-Linux-x64.tar.gz " ];then
341
        wgetFile taosTools-2.1.3-Linux-arm64.tar.gz v2.1.3 web
342 343 344
        tar xf taosTools-2.1.3-Linux-arm64.tar.gz
    fi    
    
345
    cd taosTools-2.1.3 && bash install-taostools.sh
346
fi
haoranc's avatar
haoranc 已提交
347

348 349
echoColor G  "===== start TDengine ====="

sangshuduo's avatar
sangshuduo 已提交
350
if [[ ${packageName} =~ "server" ]] ;then
351 352 353
    echoColor BD " rm -rf /var/lib/taos/* &&  systemctl restart taosd "
    rm -rf /var/lib/taos/*
    systemctl restart taosd
354
fi
355

sangshuduo's avatar
sangshuduo 已提交
356
rm -rf ${installPath}/${packageName}
357 358
rm -rf ${installPath}/${tdPath}/

sangshuduo's avatar
sangshuduo 已提交
359
# if ([[ ${packageName} =~ "Lite" ]] &&  [[ ${packageName} =~ "tar" ]]) ||   [[ ${packageName} =~ "client" ]] ;then
haoranc's avatar
haoranc 已提交
360 361 362 363
#     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
364
#     cd taosTools-2.1.2 && bash install-taostools.sh
sangshuduo's avatar
sangshuduo 已提交
365
# elif [[ ${packageName} =~ "Lite" ]] &&  [[ ${packageName} =~ "deb" ]] ;then
haoranc's avatar
haoranc 已提交
366 367 368 369
#     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
370
#     cd taosTools-2.1.2 && bash install-taostools.sh
sangshuduo's avatar
sangshuduo 已提交
371
# elif [[ ${packageName} =~ "Lite" ]] &&  [[ ${packageName} =~ "rpm" ]]  ;then
haoranc's avatar
haoranc 已提交
372 373 374 375
#     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
376
#     cd taosTools-2.1.2 && bash install-taostools.sh
haoranc's avatar
haoranc 已提交
377 378
# fi