release.sh 8.3 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5
#!/bin/bash
#
# Generate the deb package for ubunt, or rpm package for centos, or tar.gz package for other linux os

set -e
S
slguan 已提交
6
#set -x
L
lihui 已提交
7

L
lihui 已提交
8 9
# releash.sh  -v [cluster | edge]  
#             -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
#             -n [2.0.0.3]
L
lihui 已提交
14 15

# set parameters by default value
L
lihui 已提交
16
verMode=edge     # [cluster, edge]
L
lihui 已提交
17 18
verType=stable   # [stable, beta]
cpuType=x64      # [aarch32 | aarch64 | x64 | x86 | mips64 ...]
H
Hui Li 已提交
19
osType=Linux     # [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...]
L
lihui 已提交
20
pagMode=full     # [full | lite]
H
Hui Li 已提交
21
verNumber=""
L
lihui 已提交
22

H
Hui Li 已提交
23
while getopts "hv:V:c:o:l:n:" arg
L
lihui 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37
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 已提交
38 39 40 41
    l)
      #echo "pagMode=$OPTARG"
      pagMode=$(echo $OPTARG)
      ;;
H
Hui Li 已提交
42 43 44 45
    n)
      #echo "verNumber=$OPTARG"
      verNumber=$(echo $OPTARG)
      ;;
L
lihui 已提交
46 47 48 49 50
    o)
      #echo "osType=$OPTARG"
      osType=$(echo $OPTARG)
      ;;
    h)
H
Hui Li 已提交
51 52
      echo "Usage: `basename $0` -v [cluster | edge] "
      echo "                  -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] "
H
Hui Li 已提交
53
      echo "                  -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...] "
H
Hui Li 已提交
54 55 56
      echo "                  -V [stable | beta] "
      echo "                  -l [full | lite] "
      echo "                  -n [version number] "
L
lihui 已提交
57 58 59 60 61 62 63 64 65
      exit 0
      ;;
    ?) #unknow option 
      echo "unkonw argument"
      exit 1
      ;;
  esac
done

H
Hui Li 已提交
66
echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType} pagMode=${pagMode} verNumber=${verNumber}"
H
hzcheng 已提交
67 68

curr_dir=$(pwd)
S
slguan 已提交
69 70 71 72 73 74 75 76 77 78 79

if [ "$osType" != "Darwin" ]; then
    script_dir="$(dirname $(readlink -f $0))"
    top_dir="$(readlink -f ${script_dir}/..)"
else
    script_dir=`dirname $0`
    cd ${script_dir}
    script_dir="$(pwd)"
    top_dir=${script_dir}/..
fi

S
slguan 已提交
80
versioninfo="${top_dir}/src/util/src/version.c"
H
hzcheng 已提交
81

P
plum-lihui 已提交
82
csudo=""
H
Hui Li 已提交
83 84 85
#if command -v sudo > /dev/null; then
#    csudo="sudo"
#fi
P
plum-lihui 已提交
86

H
hzcheng 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
function is_valid_version() {
    [ -z $1 ] && return 1 || :

    rx='^([0-9]+\.){3}(\*|[0-9]+)$'
    if [[ $1 =~ $rx ]]; then
        return 0
    fi
    return 1
}

function vercomp () {
    if [[ $1 == $2 ]]; then
        echo 0
        exit 0
    fi
H
Hui Li 已提交
102
    
H
hzcheng 已提交
103 104
    local IFS=.
    local i ver1=($1) ver2=($2)
H
Hui Li 已提交
105

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

    for ((i=0; i<${#ver1[@]}; i++)); do
H
Hui Li 已提交
112
        if [[ -z ${ver2[i]} ]]; then
H
hzcheng 已提交
113 114 115
            # fill empty fields in ver2 with zeros
            ver2[i]=0
        fi
H
Hui Li 已提交
116
        if ((10#${ver1[i]} > 10#${ver2[i]})); then
H
hzcheng 已提交
117 118 119
            echo 1
            exit 0
        fi
H
Hui Li 已提交
120
        if ((10#${ver1[i]} < 10#${ver2[i]})); then
H
hzcheng 已提交
121 122 123 124 125 126 127 128 129 130 131
            echo 2
            exit 0
        fi
    done
    echo 0
}

# 1. Read version information
version=$(cat ${versioninfo} | grep " version" | cut -d '"' -f2)
compatible_version=$(cat ${versioninfo} | grep " compatible_version" | cut -d '"' -f2)

H
Hui Li 已提交
132 133 134
if [ -z ${verNumber} ]; then
  while true; do
    read -p "Do you want to release a new version? [y/N]: " is_version_change
H
hzcheng 已提交
135

H
Hui Li 已提交
136
    if [[ ( "${is_version_change}" == "y") || ( "${is_version_change}" == "Y") ]]; then
H
hzcheng 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
      read -p "Please enter the new version: " tversion
      while true; do
          if (! is_valid_version $tversion) || [ "$(vercomp $tversion $version)" = '2' ]; then
              read -p "Please enter a correct version: " tversion
              continue
          fi
          version=${tversion}
          break
      done

      echo

      read -p "Enter the oldest compatible version: " tversion
      while true; do

          if [ -z $tversion ]; then
              break
          fi

          if (! is_valid_version $tversion) || [ "$(vercomp $version $tversion)" = '2' ]; then
              read -p "enter correct compatible version: " tversion
          else
              compatible_version=$tversion
              break
          fi
      done

      break
H
Hui Li 已提交
165
    elif [[ ( "${is_version_change}" == "n") || ( "${is_version_change}" == "N") ]]; then
H
hzcheng 已提交
166 167
      echo "Use old version: ${version} compatible version: ${compatible_version}."
      break
H
Hui Li 已提交
168
    else
H
hzcheng 已提交
169
      continue
H
Hui Li 已提交
170 171 172 173 174 175 176 177 178 179 180 181 182
    fi
  done
else 
  echo "old version: $version, new version: $verNumber"
  #if ( ! is_valid_version $verNumber ) || [[ "$(vercomp $version $verNumber)" == '2' ]]; then
  #  echo "please enter correct version"
  #  exit 0
  #else
    version=${verNumber}
  #fi  
fi  

echo "=======================new version number: ${version}======================================"
H
hzcheng 已提交
183 184 185

# output the version info to the buildinfo file.
build_time=$(date +"%F %R")
H
Hui Li 已提交
186 187 188
echo "char version[12] = \"${version}\";"                             > ${versioninfo}
echo "char compatible_version[12] = \"${compatible_version}\";"      >> ${versioninfo}
echo "char gitinfo[48] = \"$(git rev-parse --verify HEAD)\";"       >> ${versioninfo}
S
slguan 已提交
189
if [ "$verMode" != "cluster" ]; then
H
Hui Li 已提交
190
  echo "char gitinfoOfInternal[48] = \"\";"                         >> ${versioninfo}
S
slguan 已提交
191 192 193
else
  enterprise_dir="${top_dir}/../enterprise"
  cd ${enterprise_dir}
H
Hui Li 已提交
194
  echo "char gitinfoOfInternal[48] = \"$(git rev-parse --verify HEAD)\";"  >> ${versioninfo}
S
slguan 已提交
195 196
  cd ${curr_dir}
fi
H
Hui Li 已提交
197
echo "char buildinfo[64] = \"Built by ${USER} at ${build_time}\";"  >> ${versioninfo}
L
lihui 已提交
198 199
echo ""                                                              >> ${versioninfo}
tmp_version=$(echo $version | tr -s "." "_")
L
lihui 已提交
200 201 202 203 204 205 206 207 208
if [ "$verMode" == "cluster" ]; then
  libtaos_info=${tmp_version}_${osType}_${cpuType}
else
  libtaos_info=edge_${tmp_version}_${osType}_${cpuType}
fi
if [ "$verType" == "beta" ]; then
  libtaos_info=${libtaos_info}_${verType}
fi
echo "void libtaos_${libtaos_info}() {};"        >> ${versioninfo}
L
lihui 已提交
209

H
hzcheng 已提交
210
# 2. cmake executable file
L
lihui 已提交
211
compile_dir="${top_dir}/debug"
H
hzcheng 已提交
212
if [ -d ${compile_dir} ]; then
L
lihui 已提交
213
    ${csudo} rm -rf ${compile_dir}
H
hzcheng 已提交
214 215
fi

S
slguan 已提交
216 217 218 219 220
if [ "$osType" != "Darwin" ]; then
    ${csudo} mkdir -p ${compile_dir}
else
    mkdir -p ${compile_dir}
fi
H
hzcheng 已提交
221
cd ${compile_dir}
L
lihui 已提交
222

L
lihui 已提交
223 224
# check support cpu type
if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "mips64" ]] ; then
S
slguan 已提交
225
    if [ "$verMode" != "cluster" ]; then
H
Hui Li 已提交
226
      cmake ../ -DCPUTYPE=${cpuType} -DPAGMODE=${pagMode} -DOSTYPE=${osType}
S
slguan 已提交
227
    else
H
Hui Li 已提交
228
      cmake ../../ -DCPUTYPE=${cpuType} -DOSTYPE=${osType} 
S
slguan 已提交
229
    fi
L
lihui 已提交
230
else
S
slguan 已提交
231 232
    echo "input cpuType=${cpuType} error!!!"
    exit 1
L
lihui 已提交
233 234 235
fi

make
H
hzcheng 已提交
236 237 238 239

cd ${curr_dir}

# 3. judge the operating system type, then Call the corresponding script for packaging
H
[NONE]  
huili 已提交
240
#osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
H
hzcheng 已提交
241 242 243
#osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2)
#echo "osinfo: ${osinfo}"

S
slguan 已提交
244
if [ "$osType" != "Darwin" ]; then
H
huili 已提交
245
    if [[ "$verMode" != "cluster" ]] && [[ "$cpuType" == "x64" ]]; then
S
slguan 已提交
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
        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} ${version} ${cpuType} ${osType} ${verMode} ${verType}

        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} ${version} ${cpuType} ${osType} ${verMode} ${verType}
    fi
	
    echo "====do tar.gz package for all systems===="
    cd ${script_dir}/tools
    
L
lihui 已提交
268 269
	${csudo} ./makepkg.sh    ${compile_dir} ${version} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
	${csudo} ./makeclient.sh ${compile_dir} ${version} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
H
Hui Li 已提交
270
	${csudo} ./makearbi.sh   ${compile_dir} ${version} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
S
slguan 已提交
271 272 273
else
    cd ${script_dir}/tools
    ./makeclient.sh ${compile_dir} ${version} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType}
H
hzcheng 已提交
274 275 276
fi

# 4. Clean up temporary compile directories
P
plum-lihui 已提交
277
#${csudo} rm -rf ${compile_dir}
H
hzcheng 已提交
278