release.sh 9.4 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 7 8 9 10 11
#set -x
source ./sed_power.sh
source ./sed_tq.sh
source ./sed_pro.sh
source ./sed_kh.sh
source ./sed_jh.sh
L
lihui 已提交
12

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

# set parameters by default value
Z
change  
zyyang 已提交
25 26 27 28 29 30 31 32
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 已提交
33
verNumber=""
34
verNumberComp="1.0.0.0"
35
httpdBuild=false
L
lihui 已提交
36

Z
change  
zyyang 已提交
37
while getopts "hv:V:c:o:l:s:d:a:n:m:H:" arg; do
L
lihui 已提交
38
  case $arg in
Z
change  
zyyang 已提交
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 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
  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 已提交
101 102 103
  esac
done

104
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 已提交
105 106

curr_dir=$(pwd)
S
slguan 已提交
107 108

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

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

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

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

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

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

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

Z
change  
zyyang 已提交
147
  for ((i = 0; i < ${#ver1[@]}; i++)); do
H
Hui Li 已提交
148 149 150 151 152 153 154 155 156 157 158
    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 已提交
159 160
    fi
  done
H
Hui Li 已提交
161 162 163 164
  echo 0
}

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

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

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

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

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

H
Hui Li 已提交
185
cd ${curr_dir}
L
lihui 已提交
186

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

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

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

206 207
if [[ "$dbName" != "taos" ]]; then
  replace_community_$dbName
208 209
fi

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

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

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

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

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

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

cd ${curr_dir}

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

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

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

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

  ${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}
314

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