release.sh 9.3 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
L
lihui 已提交
7

8
# release.sh  -v [cluster | edge]
9
#             -c [aarch32 | aarch64 | x64 | x86 | mips64 ...]
H
Hui Li 已提交
10
#             -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...]
L
lihui 已提交
11 12
#             -V [stable | beta]
#             -l [full | lite]
H
Hui Li 已提交
13
#             -s [static | dynamic]
14
#             -d [taos | ...]
H
Hui Li 已提交
15
#             -n [2.0.0.3]
H
Hui Li 已提交
16
#             -m [2.0.0.0]
17
#             -H [ false | true]
L
lihui 已提交
18 19

# set parameters by default value
20 21 22 23 24 25
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]
26
dbName=taos     # [taos | ...]
27
allocator=glibc # [glibc | jemalloc]
H
Hui Li 已提交
28
verNumber=""
29
verNumberComp="2.0.0.0"
30
httpdBuild=false
L
lihui 已提交
31

32
while getopts "hv:V:c:o:l:s:d:a:n:m:H:" arg; do
L
lihui 已提交
33
  case $arg in
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  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] "
86
    echo "                  -d [taos | ...] "
87 88 89 90 91 92 93 94 95
    echo "                  -n [version number] "
    echo "                  -m [compatible version number] "
    echo "                  -H [false | true] "
    exit 0
    ;;
  ?) #unknow option
    echo "unkonw argument"
    exit 1
    ;;
L
lihui 已提交
96 97 98
  esac
done

99
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 已提交
100 101

curr_dir=$(pwd)
S
slguan 已提交
102

103
if [ "$osType" == "Darwin" ]; then
104
  script_dir=$(dirname $0)
H
Hui Li 已提交
105 106 107
  cd ${script_dir}
  script_dir="$(pwd)"
  top_dir=${script_dir}/..
108 109 110
else
  script_dir="$(dirname $(readlink -f $0))"
  top_dir="$(readlink -f ${script_dir}/..)"
S
slguan 已提交
111 112
fi

P
plum-lihui 已提交
113
csudo=""
H
Hui Li 已提交
114
#if command -v sudo > /dev/null; then
115
#  csudo="sudo "
H
Hui Li 已提交
116
#fi
P
plum-lihui 已提交
117

H
hzcheng 已提交
118
function is_valid_version() {
H
Hui Li 已提交
119
  [ -z $1 ] && return 1 || :
H
hzcheng 已提交
120

H
Hui Li 已提交
121 122 123 124 125
  rx='^([0-9]+\.){3}(\*|[0-9]+)$'
  if [[ $1 =~ $rx ]]; then
    return 0
  fi
  return 1
H
hzcheng 已提交
126 127
}

128
function vercomp() {
H
Hui Li 已提交
129
  if [[ $1 == $2 ]]; then
H
hzcheng 已提交
130
    echo 0
H
Hui Li 已提交
131 132
    exit 0
  fi
133

H
Hui Li 已提交
134 135 136 137
  local IFS=.
  local i ver1=($1) ver2=($2)

  # fill empty fields in ver1 with zeros
138
  for ((i = ${#ver1[@]}; i < ${#ver2[@]}; i++)); do
H
Hui Li 已提交
139 140
    ver1[i]=0
  done
H
hzcheng 已提交
141

142
  for ((i = 0; i < ${#ver1[@]}; i++)); do
H
Hui Li 已提交
143 144 145 146 147 148 149 150 151 152 153
    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 已提交
154 155
    fi
  done
H
Hui Li 已提交
156 157 158 159
  echo 0
}

# 1. check version information
160
if ( (! is_valid_version $verNumber) || (! is_valid_version $verNumberComp) || [[ "$(vercomp $verNumber $verNumberComp)" == '2' ]]); then
H
Hui Li 已提交
161 162 163
  echo "please enter correct version"
  exit 0
fi
H
Hui Li 已提交
164

H
Hui Li 已提交
165
echo "=======================new version number: ${verNumber}, compatible version: ${verNumberComp}======================================"
H
hzcheng 已提交
166 167

build_time=$(date +"%F %R")
H
Hui Li 已提交
168 169 170

# get commint id from git
gitinfo=$(git rev-parse --verify HEAD)
P
plum-lihui 已提交
171 172 173 174 175 176 177 178

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

180
cd "${curr_dir}"
L
lihui 已提交
181

H
hzcheng 已提交
182
# 2. cmake executable file
L
lihui 已提交
183
compile_dir="${top_dir}/debug"
H
hzcheng 已提交
184
if [ -d ${compile_dir} ]; then
185
  ${csudo}rm -rf ${compile_dir}
H
hzcheng 已提交
186 187
fi

S
slguan 已提交
188
if [ "$osType" != "Darwin" ]; then
189
  ${csudo}mkdir -p ${compile_dir}
S
slguan 已提交
190
else
H
Hui Li 已提交
191
  mkdir -p ${compile_dir}
S
slguan 已提交
192
fi
H
hzcheng 已提交
193
cd ${compile_dir}
L
lihui 已提交
194

195
if [[ "$allocator" == "jemalloc" ]]; then
196
  allocator_macro="-DJEMALLOC_ENABLED=true"
197
else
198
  allocator_macro=""
199 200
fi

201
if [[ "$dbName" != "taos" ]]; then
202
  source ${enterprise_dir}/packaging/oem/sed_$dbName.sh
203
  replace_community_$dbName
204 205
fi

206
if [[ "$httpdBuild" == "true" ]]; then
207
  BUILD_HTTP=true
208
else
209
  BUILD_HTTP=false
210 211
fi

212
if [[ "$verMode" == "cluster" ]]; then
213
  BUILD_HTTP=internal
214 215
fi

216
if [[ "$pagMode" == "full" ]]; then
217
  BUILD_TOOLS=true
218
else
219
  BUILD_TOOLS=false
220
fi
221

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

238
CORES=$(grep -c ^processor /proc/cpuinfo)
239

240
if [[ "$allocator" == "jemalloc" ]]; then
241 242
  # jemalloc need compile first, so disable parallel build
  make -j ${CORES} && ${csudo}make install
243
else
244
  make -j ${CORES} && ${csudo}make install
245
fi
H
hzcheng 已提交
246 247 248

cd ${curr_dir}

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

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

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

H
Hui Li 已提交
304 305
  echo "====do tar.gz package for all systems===="
  cd ${script_dir}/tools
306

307 308 309
  ${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}
310

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