release.sh 9.1 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
S
slguan 已提交
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 | power | tq ]
H
Hui Li 已提交
15
#             -n [2.0.0.3]
H
Hui Li 已提交
16
#             -m [2.0.0.0]
L
lihui 已提交
17 18

# set parameters by default value
L
lihui 已提交
19
verMode=edge     # [cluster, edge]
L
lihui 已提交
20 21
verType=stable   # [stable, beta]
cpuType=x64      # [aarch32 | aarch64 | x64 | x86 | mips64 ...]
H
Hui Li 已提交
22
osType=Linux     # [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...]
L
lihui 已提交
23
pagMode=full     # [full | lite]
H
Hui Li 已提交
24
soMode=dynamic   # [static | dynamic]
25
dbName=taos      # [taos | power | tq | pro]
26
allocator=glibc  # [glibc | jemalloc]
H
Hui Li 已提交
27
verNumber=""
28
verNumberComp="1.0.0.0"
L
lihui 已提交
29

30
while getopts "hv:V:c:o:l:s:d:a:n:m:" arg
L
lihui 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44
do
  case $arg in
    v)
      #echo "verMode=$OPTARG"
      verMode=$( echo $OPTARG )
      ;;
    V)
      #echo "verType=$OPTARG"
      verType=$(echo $OPTARG)
      ;;
    c)
      #echo "cpuType=$OPTARG"
      cpuType=$(echo $OPTARG)
      ;;
L
lihui 已提交
45 46 47 48
    l)
      #echo "pagMode=$OPTARG"
      pagMode=$(echo $OPTARG)
      ;;
H
Hui Li 已提交
49 50 51 52
    s)
      #echo "soMode=$OPTARG"
      soMode=$(echo $OPTARG)
      ;;
H
Hui Li 已提交
53 54 55 56
    d)
      #echo "dbName=$OPTARG"
      dbName=$(echo $OPTARG)
      ;;
57 58 59 60
    a)
      #echo "allocator=$OPTARG"
      allocator=$(echo $OPTARG)
      ;;
H
Hui Li 已提交
61 62 63 64
    n)
      #echo "verNumber=$OPTARG"
      verNumber=$(echo $OPTARG)
      ;;
H
Hui Li 已提交
65 66 67 68
    m)
      #echo "verNumberComp=$OPTARG"
      verNumberComp=$(echo $OPTARG)
      ;;
L
lihui 已提交
69 70 71 72 73
    o)
      #echo "osType=$OPTARG"
      osType=$(echo $OPTARG)
      ;;
    h)
H
Hui Li 已提交
74 75
      echo "Usage: `basename $0` -v [cluster | edge] "
      echo "                  -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] "
H
Hui Li 已提交
76
      echo "                  -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...] "
H
Hui Li 已提交
77 78
      echo "                  -V [stable | beta] "
      echo "                  -l [full | lite] "
79
      echo "                  -a [glibc | jemalloc] "
H
Hui Li 已提交
80
      echo "                  -s [static | dynamic] "
81
      echo "                  -d [taos | power | tq | pro] "
H
Hui Li 已提交
82
      echo "                  -n [version number] "
H
Hui Li 已提交
83
      echo "                  -m [compatible version number] "
L
lihui 已提交
84 85
      exit 0
      ;;
86
    ?) #unknow option
L
lihui 已提交
87 88 89 90 91 92
      echo "unkonw argument"
      exit 1
      ;;
  esac
done

93
echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType} pagMode=${pagMode} soMode=${soMode} dbName=${dbName} allocator=${allocator} verNumber=${verNumber} verNumberComp=${verNumberComp}"
H
hzcheng 已提交
94 95

curr_dir=$(pwd)
S
slguan 已提交
96 97

if [ "$osType" != "Darwin" ]; then
H
Hui Li 已提交
98 99
  script_dir="$(dirname $(readlink -f $0))"
  top_dir="$(readlink -f ${script_dir}/..)"
S
slguan 已提交
100
else
H
Hui Li 已提交
101 102 103 104
  script_dir=`dirname $0`
  cd ${script_dir}
  script_dir="$(pwd)"
  top_dir=${script_dir}/..
S
slguan 已提交
105 106
fi

P
plum-lihui 已提交
107
csudo=""
H
Hui Li 已提交
108
#if command -v sudo > /dev/null; then
H
Hui Li 已提交
109
#  csudo="sudo"
H
Hui Li 已提交
110
#fi
P
plum-lihui 已提交
111

H
hzcheng 已提交
112
function is_valid_version() {
H
Hui Li 已提交
113
  [ -z $1 ] && return 1 || :
H
hzcheng 已提交
114

H
Hui Li 已提交
115 116 117 118 119
  rx='^([0-9]+\.){3}(\*|[0-9]+)$'
  if [[ $1 =~ $rx ]]; then
    return 0
  fi
  return 1
H
hzcheng 已提交
120 121 122
}

function vercomp () {
H
Hui Li 已提交
123
  if [[ $1 == $2 ]]; then
H
hzcheng 已提交
124
    echo 0
H
Hui Li 已提交
125 126
    exit 0
  fi
127

H
Hui Li 已提交
128 129 130 131 132 133 134
  local IFS=.
  local i ver1=($1) ver2=($2)

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

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

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

H
Hui Li 已提交
159
echo "=======================new version number: ${verNumber}, compatible version: ${verNumberComp}======================================"
H
hzcheng 已提交
160 161

build_time=$(date +"%F %R")
H
Hui Li 已提交
162 163 164

# get commint id from git
gitinfo=$(git rev-parse --verify HEAD)
P
plum-lihui 已提交
165 166 167 168 169 170 171 172

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

H
Hui Li 已提交
174
cd ${curr_dir}
L
lihui 已提交
175

H
hzcheng 已提交
176
# 2. cmake executable file
L
lihui 已提交
177
compile_dir="${top_dir}/debug"
H
hzcheng 已提交
178
if [ -d ${compile_dir} ]; then
H
Hui Li 已提交
179
  ${csudo} rm -rf ${compile_dir}
H
hzcheng 已提交
180 181
fi

S
slguan 已提交
182
if [ "$osType" != "Darwin" ]; then
H
Hui Li 已提交
183
  ${csudo} mkdir -p ${compile_dir}
S
slguan 已提交
184
else
H
Hui Li 已提交
185
  mkdir -p ${compile_dir}
S
slguan 已提交
186
fi
H
hzcheng 已提交
187
cd ${compile_dir}
L
lihui 已提交
188

189 190 191 192 193 194
if [[ "$allocator" == "jemalloc" ]]; then
    allocator_macro="-DJEMALLOC_ENABLED=true"
else
    allocator_macro=""
fi

195 196 197 198
if [[ "$dbName" == "pro" ]]; then
    sed -i "s/taos config/prodb config/g"   ${top_dir}/src/util/src/tconfig.c
fi

199 200 201 202
echo "build ${pagMode} package ..."
if [[ "$pagMode" == "lite" ]]; then
    BUILD_HTTP=true
fi
203

L
lihui 已提交
204 205
# check support cpu type
if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "mips64" ]] ; then
H
Hui Li 已提交
206
  if [ "$verMode" != "cluster" ]; then
207
    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} ${allocator_macro}
H
Hui Li 已提交
208
  else
209
    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} ${allocator_macro}
H
Hui Li 已提交
210
  fi
L
lihui 已提交
211
else
H
Hui Li 已提交
212 213
  echo "input cpuType=${cpuType} error!!!"
  exit 1
L
lihui 已提交
214 215
fi

216
make
H
hzcheng 已提交
217 218 219

cd ${curr_dir}

H
Hui Li 已提交
220
# 3. Call the corresponding script for packaging
S
slguan 已提交
221
if [ "$osType" != "Darwin" ]; then
H
Hui Li 已提交
222
  if [[ "$verMode" != "cluster" ]] && [[ "$cpuType" == "x64" ]] && [[ "$dbName" == "taos" ]]; then
223
    ret='0'
P
plum-lihui 已提交
224
    command -v dpkg >/dev/null 2>&1 || { ret='1'; }
225
    if [ "$ret" -eq 0 ]; then
P
plum-lihui 已提交
226 227 228 229 230 231 232 233 234 235
      echo "====do deb package for the ubuntu system===="
      output_dir="${top_dir}/debs"
      if [ -d ${output_dir} ]; then
        ${csudo} rm -rf ${output_dir}
      fi
      ${csudo} mkdir -p ${output_dir}
      cd ${script_dir}/deb
      ${csudo} ./makedeb.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType}
    else
      echo "==========dpkg command not exist, so not release deb package!!!"
H
Hui Li 已提交
236
    fi
P
plum-lihui 已提交
237

238
    ret='0'
P
plum-lihui 已提交
239
    command -v rpmbuild >/dev/null 2>&1 || { ret='1'; }
240
    if [ "$ret" -eq 0 ]; then
P
plum-lihui 已提交
241 242 243 244 245 246 247 248 249 250
      echo "====do rpm package for the centos system===="
      output_dir="${top_dir}/rpms"
      if [ -d ${output_dir} ]; then
        ${csudo} rm -rf ${output_dir}
      fi
      ${csudo} mkdir -p ${output_dir}
      cd ${script_dir}/rpm
      ${csudo} ./makerpm.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType}
    else
      echo "==========rpmbuild command not exist, so not release rpm package!!!"
S
slguan 已提交
251
    fi
H
Hui Li 已提交
252
  fi
253

H
Hui Li 已提交
254 255
  echo "====do tar.gz package for all systems===="
  cd ${script_dir}/tools
256 257

  if [[ "$dbName" == "taos" ]]; then
258
    ${csudo} ./makepkg.sh    ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${verNumberComp}
H
Hui Li 已提交
259 260
    ${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}
261
  elif [[ "$dbName" == "tq" ]]; then
262
    ${csudo} ./makepkg_tq.sh    ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp}
263 264
    ${csudo} ./makeclient_tq.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName}
    ${csudo} ./makearbi_tq.sh   ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
265 266 267 268
  elif [[ "$dbName" == "pro" ]]; then
    ${csudo} ./makepkg_pro.sh    ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp}
    ${csudo} ./makeclient_pro.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName}
    ${csudo} ./makearbi_pro.sh   ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
H
Hui Li 已提交
269
  else
270
    ${csudo} ./makepkg_power.sh    ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp}
H
Hui Li 已提交
271 272 273
    ${csudo} ./makeclient_power.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName}
    ${csudo} ./makearbi_power.sh   ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
  fi
S
slguan 已提交
274
else
H
Hui Li 已提交
275
  cd ${script_dir}/tools
H
Hui Li 已提交
276
  ./makeclient.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${dbName}
H
hzcheng 已提交
277
fi