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]
Z
change  
zyyang 已提交
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
Z
change  
zyyang 已提交
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]
Z
change  
zyyang 已提交
26
dbName=taos     # [taos | ...]
Z
change  
zyyang 已提交
27
allocator=glibc # [glibc | jemalloc]
H
Hui Li 已提交
28
verNumber=""
29
verNumberComp="2.0.0.0"
30
httpdBuild=false
L
lihui 已提交
31

Z
change  
zyyang 已提交
32
while getopts "hv:V:c:o:l:s:d:a:n:m:H:" arg; do
L
lihui 已提交
33
  case $arg in
Z
change  
zyyang 已提交
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 | ...] "
Z
change  
zyyang 已提交
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
H
Hui Li 已提交
104 105
  script_dir="$(dirname $(readlink -f $0))"
  top_dir="$(readlink -f ${script_dir}/..)"
S
slguan 已提交
106
else
Z
change  
zyyang 已提交
107
  script_dir=$(dirname $0)
H
Hui Li 已提交
108 109 110
  cd ${script_dir}
  script_dir="$(pwd)"
  top_dir=${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
}

Z
change  
zyyang 已提交
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
Z
change  
zyyang 已提交
138
  for ((i = ${#ver1[@]}; i < ${#ver2[@]}; i++)); do
H
Hui Li 已提交
139 140
    ver1[i]=0
  done
H
hzcheng 已提交
141

Z
change  
zyyang 已提交
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
Z
change  
zyyang 已提交
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
Z
change  
zyyang 已提交
196
  allocator_macro="-DJEMALLOC_ENABLED=true"
197
else
Z
change  
zyyang 已提交
198
  allocator_macro=""
199 200
fi

Z
zyyang 已提交
201
# 3. replace product info
202
if [[ "$dbName" != "taos" ]]; then
Z
change  
zyyang 已提交
203
  source ${enterprise_dir}/packaging/oem/sed_$dbName.sh
204
  replace_community_$dbName
205 206
fi

207
if [[ "$httpdBuild" == "true" ]]; then
Z
change  
zyyang 已提交
208
  BUILD_HTTP=true
209
else
Z
change  
zyyang 已提交
210
  BUILD_HTTP=false
211 212
fi

213
if [[ "$verMode" == "cluster" ]]; then
Z
change  
zyyang 已提交
214
  BUILD_HTTP=internal
215 216
fi

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

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

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

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

cd ${curr_dir}

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

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

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

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

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

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