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

208 209
if [[ "$dbName" != "taos" ]]; then
  replace_community_$dbName
210 211
fi

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

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

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

L
lihui 已提交
228
# check support cpu type
Z
change  
zyyang 已提交
229
if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "mips64" ]]; then
H
Hui Li 已提交
230
  if [ "$verMode" != "cluster" ]; then
231
    # community-version compile
Z
change  
zyyang 已提交
232
    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 已提交
233
  else
234 235
    if [[ "$dbName" != "taos" ]]; then
      replace_enterprise_$dbName
236
    fi
237
    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 已提交
238
  fi
L
lihui 已提交
239
else
H
Hui Li 已提交
240 241
  echo "input cpuType=${cpuType} error!!!"
  exit 1
L
lihui 已提交
242 243
fi

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

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

cd ${curr_dir}

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

270
      if [[ "$pagMode" == "full" ]]; then
Z
change  
zyyang 已提交
271 272 273 274 275 276 277 278
        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
279
      fi
Z
change  
zyyang 已提交
280
    else
P
plum-lihui 已提交
281
      echo "==========dpkg command not exist, so not release deb package!!!"
H
Hui Li 已提交
282
    fi
283
    ret='0'
P
plum-lihui 已提交
284
    command -v rpmbuild >/dev/null 2>&1 || { ret='1'; }
285
    if [ "$ret" -eq 0 ]; then
P
plum-lihui 已提交
286 287 288
      echo "====do rpm package for the centos system===="
      output_dir="${top_dir}/rpms"
      if [ -d ${output_dir} ]; then
289
        ${csudo}rm -rf ${output_dir}
P
plum-lihui 已提交
290
      fi
291
      ${csudo}mkdir -p ${output_dir}
P
plum-lihui 已提交
292
      cd ${script_dir}/rpm
293
      ${csudo}./makerpm.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType}
294

295
      if [[ "$pagMode" == "full" ]]; then
Z
change  
zyyang 已提交
296 297 298 299 300 301 302 303
        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
304
      fi
Z
change  
zyyang 已提交
305
    else
P
plum-lihui 已提交
306
      echo "==========rpmbuild command not exist, so not release rpm package!!!"
S
slguan 已提交
307
    fi
H
Hui Li 已提交
308
  fi
309

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

  ${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} ${dbName}
  ${csudo} ./makearbi.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName}
316

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