release.sh 9.5 KB
Newer Older
H
hzcheng 已提交
1 2
#!/bin/bash
#
3
# Generate the deb package for ubuntu, or rpm package for centos, or tar.gz package for other linux os
H
hzcheng 已提交
4 5

set -e
6
#set -x
haoranc's avatar
haoranc 已提交
7 8 9 10 11 12 13
scriptDir=$(dirname $(readlink -f $0))

source $scriptDir/sed_power.sh
source $scriptDir/sed_tq.sh
source $scriptDir/sed_pro.sh
source $scriptDir/sed_kh.sh
source $scriptDir/sed_jh.sh
L
lihui 已提交
14

15
# release.sh  -v [cluster | edge]
16
#             -c [aarch32 | aarch64 | x64 | x86 | mips64 ...]
H
Hui Li 已提交
17
#             -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...]
L
lihui 已提交
18 19
#             -V [stable | beta]
#             -l [full | lite]
H
Hui Li 已提交
20
#             -s [static | dynamic]
21
#             -d [taos | power | tq | pro | kh | jh]
H
Hui Li 已提交
22
#             -n [2.0.0.3]
H
Hui Li 已提交
23
#             -m [2.0.0.0]
24
#             -H [ false | true]
L
lihui 已提交
25 26

# set parameters by default value
Z
change  
zyyang 已提交
27 28 29 30 31 32 33 34
verMode=edge    # [cluster, edge]
verType=stable  # [stable, beta]
cpuType=x64     # [aarch32 | aarch64 | x64 | x86 | mips64 ...]
osType=Linux    # [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...]
pagMode=full    # [full | lite]
soMode=dynamic  # [static | dynamic]
dbName=taos     # [taos | power | tq | pro | kh | jh]
allocator=glibc # [glibc | jemalloc]
H
Hui Li 已提交
35
verNumber=""
36
verNumberComp="1.0.0.0"
37
httpdBuild=false
L
lihui 已提交
38

Z
change  
zyyang 已提交
39
while getopts "hv:V:c:o:l:s:d:a:n:m:H:" arg; do
L
lihui 已提交
40
  case $arg in
Z
change  
zyyang 已提交
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 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 96 97 98 99 100 101 102
  v)
    #echo "verMode=$OPTARG"
    verMode=$(echo $OPTARG)
    ;;
  V)
    #echo "verType=$OPTARG"
    verType=$(echo $OPTARG)
    ;;
  c)
    #echo "cpuType=$OPTARG"
    cpuType=$(echo $OPTARG)
    ;;
  l)
    #echo "pagMode=$OPTARG"
    pagMode=$(echo $OPTARG)
    ;;
  s)
    #echo "soMode=$OPTARG"
    soMode=$(echo $OPTARG)
    ;;
  d)
    #echo "dbName=$OPTARG"
    dbName=$(echo $OPTARG)
    ;;
  a)
    #echo "allocator=$OPTARG"
    allocator=$(echo $OPTARG)
    ;;
  n)
    #echo "verNumber=$OPTARG"
    verNumber=$(echo $OPTARG)
    ;;
  m)
    #echo "verNumberComp=$OPTARG"
    verNumberComp=$(echo $OPTARG)
    ;;
  o)
    #echo "osType=$OPTARG"
    osType=$(echo $OPTARG)
    ;;
  H)
    #echo "httpdBuild=$OPTARG"
    httpdBuild=$(echo $OPTARG)
    ;;
  h)
    echo "Usage: $(basename $0) -v [cluster | edge] "
    echo "                  -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] "
    echo "                  -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...] "
    echo "                  -V [stable | beta] "
    echo "                  -l [full | lite] "
    echo "                  -a [glibc | jemalloc] "
    echo "                  -s [static | dynamic] "
    echo "                  -d [taos | power | tq | pro | kh | jh] "
    echo "                  -n [version number] "
    echo "                  -m [compatible version number] "
    echo "                  -H [false | true] "
    exit 0
    ;;
  ?) #unknow option
    echo "unkonw argument"
    exit 1
    ;;
L
lihui 已提交
103 104 105
  esac
done

106
echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType} pagMode=${pagMode} soMode=${soMode} dbName=${dbName} allocator=${allocator} verNumber=${verNumber} verNumberComp=${verNumberComp} httpdBuild=${httpdBuild}"
H
hzcheng 已提交
107 108

curr_dir=$(pwd)
S
slguan 已提交
109 110

if [ "$osType" != "Darwin" ]; then
H
Hui Li 已提交
111 112
  script_dir="$(dirname $(readlink -f $0))"
  top_dir="$(readlink -f ${script_dir}/..)"
S
slguan 已提交
113
else
Z
change  
zyyang 已提交
114
  script_dir=$(dirname $0)
H
Hui Li 已提交
115 116 117
  cd ${script_dir}
  script_dir="$(pwd)"
  top_dir=${script_dir}/..
S
slguan 已提交
118 119
fi

P
plum-lihui 已提交
120
csudo=""
H
Hui Li 已提交
121
#if command -v sudo > /dev/null; then
122
#  csudo="sudo "
H
Hui Li 已提交
123
#fi
P
plum-lihui 已提交
124

H
hzcheng 已提交
125
function is_valid_version() {
H
Hui Li 已提交
126
  [ -z $1 ] && return 1 || :
H
hzcheng 已提交
127

H
Hui Li 已提交
128 129 130 131 132
  rx='^([0-9]+\.){3}(\*|[0-9]+)$'
  if [[ $1 =~ $rx ]]; then
    return 0
  fi
  return 1
H
hzcheng 已提交
133 134
}

Z
change  
zyyang 已提交
135
function vercomp() {
H
Hui Li 已提交
136
  if [[ $1 == $2 ]]; then
H
hzcheng 已提交
137
    echo 0
H
Hui Li 已提交
138 139
    exit 0
  fi
140

H
Hui Li 已提交
141 142 143 144
  local IFS=.
  local i ver1=($1) ver2=($2)

  # fill empty fields in ver1 with zeros
Z
change  
zyyang 已提交
145
  for ((i = ${#ver1[@]}; i < ${#ver2[@]}; i++)); do
H
Hui Li 已提交
146 147
    ver1[i]=0
  done
H
hzcheng 已提交
148

Z
change  
zyyang 已提交
149
  for ((i = 0; i < ${#ver1[@]}; i++)); do
H
Hui Li 已提交
150 151 152 153 154 155 156 157 158 159 160
    if [[ -z ${ver2[i]} ]]; then
      # fill empty fields in ver2 with zeros
      ver2[i]=0
    fi
    if ((10#${ver1[i]} > 10#${ver2[i]})); then
      echo 1
      exit 0
    fi
    if ((10#${ver1[i]} < 10#${ver2[i]})); then
      echo 2
      exit 0
H
Hui Li 已提交
161 162
    fi
  done
H
Hui Li 已提交
163 164 165 166
  echo 0
}

# 1. check version information
Z
change  
zyyang 已提交
167
if ( (! is_valid_version $verNumber) || (! is_valid_version $verNumberComp) || [[ "$(vercomp $verNumber $verNumberComp)" == '2' ]]); then
H
Hui Li 已提交
168 169 170
  echo "please enter correct version"
  exit 0
fi
H
Hui Li 已提交
171

H
Hui Li 已提交
172
echo "=======================new version number: ${verNumber}, compatible version: ${verNumberComp}======================================"
H
hzcheng 已提交
173 174

build_time=$(date +"%F %R")
H
Hui Li 已提交
175 176 177

# get commint id from git
gitinfo=$(git rev-parse --verify HEAD)
P
plum-lihui 已提交
178 179 180 181 182 183 184 185

if [[ "$verMode" == "cluster" ]]; then
  enterprise_dir="${top_dir}/../enterprise"
  cd ${enterprise_dir}
  gitinfoOfInternal=$(git rev-parse --verify HEAD)
else
  gitinfoOfInternal=NULL
fi
186

H
Hui Li 已提交
187
cd ${curr_dir}
L
lihui 已提交
188

H
hzcheng 已提交
189
# 2. cmake executable file
L
lihui 已提交
190
compile_dir="${top_dir}/debug"
H
hzcheng 已提交
191
if [ -d ${compile_dir} ]; then
192
  ${csudo}rm -rf ${compile_dir}
H
hzcheng 已提交
193 194
fi

S
slguan 已提交
195
if [ "$osType" != "Darwin" ]; then
196
  ${csudo}mkdir -p ${compile_dir}
S
slguan 已提交
197
else
H
Hui Li 已提交
198
  mkdir -p ${compile_dir}
S
slguan 已提交
199
fi
H
hzcheng 已提交
200
cd ${compile_dir}
L
lihui 已提交
201

202
if [[ "$allocator" == "jemalloc" ]]; then
Z
change  
zyyang 已提交
203
  allocator_macro="-DJEMALLOC_ENABLED=true"
204
else
Z
change  
zyyang 已提交
205
  allocator_macro=""
206 207
fi

Z
zyyang 已提交
208
# 3. replace product info
209 210
if [[ "$dbName" != "taos" ]]; then
  replace_community_$dbName
211 212
fi

213
if [[ "$httpdBuild" == "true" ]]; then
Z
change  
zyyang 已提交
214
  BUILD_HTTP=true
215
else
Z
change  
zyyang 已提交
216
  BUILD_HTTP=false
217 218
fi

219
if [[ "$verMode" == "cluster" ]]; then
Z
change  
zyyang 已提交
220
  BUILD_HTTP=internal
221 222
fi

223
if [[ "$pagMode" == "full" ]]; then
Z
change  
zyyang 已提交
224
  BUILD_TOOLS=true
225
else
Z
change  
zyyang 已提交
226
  BUILD_TOOLS=false
227
fi
228

L
lihui 已提交
229
# check support cpu type
Z
change  
zyyang 已提交
230
if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "mips64" ]]; then
H
Hui Li 已提交
231
  if [ "$verMode" != "cluster" ]; then
232
    # community-version compile
Z
change  
zyyang 已提交
233
    cmake ../ -DCPUTYPE=${cpuType} -DOSTYPE=${osType} -DSOMODE=${soMode} -DDBNAME=${dbName} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp} -DPAGMODE=${pagMode} -DBUILD_HTTP=${BUILD_HTTP} -DBUILD_TOOLS=${BUILD_TOOLS} ${allocator_macro}
H
Hui Li 已提交
234
  else
235 236
    if [[ "$dbName" != "taos" ]]; then
      replace_enterprise_$dbName
237
    fi
238
    cmake ../../ -DCPUTYPE=${cpuType} -DOSTYPE=${osType} -DSOMODE=${soMode} -DDBNAME=${dbName} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp} -DBUILD_HTTP=${BUILD_HTTP} -DBUILD_TOOLS=${BUILD_TOOLS} ${allocator_macro}
H
Hui Li 已提交
239
  fi
L
lihui 已提交
240
else
H
Hui Li 已提交
241 242
  echo "input cpuType=${cpuType} error!!!"
  exit 1
L
lihui 已提交
243 244
fi

Z
change  
zyyang 已提交
245
CORES=$(grep -c ^processor /proc/cpuinfo)
246

247
if [[ "$allocator" == "jemalloc" ]]; then
Z
change  
zyyang 已提交
248 249
  # jemalloc need compile first, so disable parallel build
  make -j ${CORES} && ${csudo}make install
250
else
Z
change  
zyyang 已提交
251
  make -j ${CORES} && ${csudo}make install
252
fi
H
hzcheng 已提交
253 254 255

cd ${curr_dir}

H
Hui Li 已提交
256
# 3. Call the corresponding script for packaging
S
slguan 已提交
257
if [ "$osType" != "Darwin" ]; then
H
Hui Li 已提交
258
  if [[ "$verMode" != "cluster" ]] && [[ "$cpuType" == "x64" ]] && [[ "$dbName" == "taos" ]]; then
259
    ret='0'
P
plum-lihui 已提交
260
    command -v dpkg >/dev/null 2>&1 || { ret='1'; }
261
    if [ "$ret" -eq 0 ]; then
P
plum-lihui 已提交
262 263 264
      echo "====do deb package for the ubuntu system===="
      output_dir="${top_dir}/debs"
      if [ -d ${output_dir} ]; then
265
        ${csudo}rm -rf ${output_dir}
P
plum-lihui 已提交
266
      fi
267
      ${csudo}mkdir -p ${output_dir}
P
plum-lihui 已提交
268
      cd ${script_dir}/deb
269
      ${csudo}./makedeb.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType}
270

271
      if [[ "$pagMode" == "full" ]]; then
Z
change  
zyyang 已提交
272 273 274 275 276 277 278 279
        if [ -d ${top_dir}/src/kit/taos-tools/packaging/deb ]; then
          cd ${top_dir}/src/kit/taos-tools/packaging/deb
          [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0"

          taos_tools_ver=$(git describe --tags | sed -e 's/ver-//g' | awk -F '-' '{print $1}')
          ${csudo}./make-taos-tools-deb.sh ${top_dir} \
            ${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType}
        fi
280
      fi
Z
change  
zyyang 已提交
281
    else
P
plum-lihui 已提交
282
      echo "==========dpkg command not exist, so not release deb package!!!"
H
Hui Li 已提交
283
    fi
284
    ret='0'
P
plum-lihui 已提交
285
    command -v rpmbuild >/dev/null 2>&1 || { ret='1'; }
286
    if [ "$ret" -eq 0 ]; then
P
plum-lihui 已提交
287 288 289
      echo "====do rpm package for the centos system===="
      output_dir="${top_dir}/rpms"
      if [ -d ${output_dir} ]; then
290
        ${csudo}rm -rf ${output_dir}
P
plum-lihui 已提交
291
      fi
292
      ${csudo}mkdir -p ${output_dir}
P
plum-lihui 已提交
293
      cd ${script_dir}/rpm
294
      ${csudo}./makerpm.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType}
295

296
      if [[ "$pagMode" == "full" ]]; then
Z
change  
zyyang 已提交
297 298 299 300 301 302 303 304
        if [ -d ${top_dir}/src/kit/taos-tools/packaging/rpm ]; then
          cd ${top_dir}/src/kit/taos-tools/packaging/rpm
          [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0"

          taos_tools_ver=$(git describe --tags | sed -e 's/ver-//g' | awk -F '-' '{print $1}' | sed -e 's/-/_/g')
          ${csudo}./make-taos-tools-rpm.sh ${top_dir} \
            ${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType}
        fi
305
      fi
Z
change  
zyyang 已提交
306
    else
P
plum-lihui 已提交
307
      echo "==========rpmbuild command not exist, so not release rpm package!!!"
S
slguan 已提交
308
    fi
H
Hui Li 已提交
309
  fi
310

H
Hui Li 已提交
311 312
  echo "====do tar.gz package for all systems===="
  cd ${script_dir}/tools
Z
change  
zyyang 已提交
313

314 315 316 317 318
  if [ "$verMode" == "cluster" ]; then
    ${csudo} ./makepkg.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${verNumberComp} ${dbName}
#  ${csudo}./makeclient.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
#  ${csudo}./makearbi.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
  fi
319

S
slguan 已提交
320
else
321
  # only make client for Darwin
H
Hui Li 已提交
322
  cd ${script_dir}/tools
H
Hui Li 已提交
323
  ./makeclient.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${dbName}
H
hzcheng 已提交
324
fi