release.sh 6.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
#             -s [static | dynamic]
H
Hui Li 已提交
14
#             -n [2.0.0.3]
H
Hui Li 已提交
15
#             -m [2.0.0.0]
L
lihui 已提交
16 17

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

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

H
Hui Li 已提交
80
echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType} pagMode=${pagMode} soMode=${soMode} verNumber=${verNumber} verNumberComp=${verNumberComp}"
H
hzcheng 已提交
81 82

curr_dir=$(pwd)
S
slguan 已提交
83 84

if [ "$osType" != "Darwin" ]; then
H
Hui Li 已提交
85 86
  script_dir="$(dirname $(readlink -f $0))"
  top_dir="$(readlink -f ${script_dir}/..)"
S
slguan 已提交
87
else
H
Hui Li 已提交
88 89 90 91
  script_dir=`dirname $0`
  cd ${script_dir}
  script_dir="$(pwd)"
  top_dir=${script_dir}/..
S
slguan 已提交
92 93
fi

P
plum-lihui 已提交
94
csudo=""
H
Hui Li 已提交
95
#if command -v sudo > /dev/null; then
H
Hui Li 已提交
96
#  csudo="sudo"
H
Hui Li 已提交
97
#fi
P
plum-lihui 已提交
98

H
hzcheng 已提交
99
function is_valid_version() {
H
Hui Li 已提交
100
  [ -z $1 ] && return 1 || :
H
hzcheng 已提交
101

H
Hui Li 已提交
102 103 104 105 106
  rx='^([0-9]+\.){3}(\*|[0-9]+)$'
  if [[ $1 =~ $rx ]]; then
    return 0
  fi
  return 1
H
hzcheng 已提交
107 108 109
}

function vercomp () {
H
Hui Li 已提交
110
  if [[ $1 == $2 ]]; then
H
hzcheng 已提交
111
    echo 0
H
Hui Li 已提交
112 113 114 115 116 117 118 119 120 121
    exit 0
  fi
  
  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 已提交
122

H
Hui Li 已提交
123 124 125 126 127 128 129 130 131 132 133 134
  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 已提交
135 136
    fi
  done
H
Hui Li 已提交
137 138 139 140 141 142 143 144
  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 已提交
145

H
Hui Li 已提交
146
echo "=======================new version number: ${verNumber}, compatible version: ${verNumberComp}======================================"
H
hzcheng 已提交
147 148

build_time=$(date +"%F %R")
H
Hui Li 已提交
149 150 151 152 153 154 155

# get commint id from git
gitinfo=$(git rev-parse --verify HEAD)
enterprise_dir="${top_dir}/../enterprise"
cd ${enterprise_dir}
gitinfoOfInternal=$(git rev-parse --verify HEAD)
cd ${curr_dir}
L
lihui 已提交
156

H
hzcheng 已提交
157
# 2. cmake executable file
L
lihui 已提交
158
compile_dir="${top_dir}/debug"
H
hzcheng 已提交
159
if [ -d ${compile_dir} ]; then
H
Hui Li 已提交
160
  ${csudo} rm -rf ${compile_dir}
H
hzcheng 已提交
161 162
fi

S
slguan 已提交
163
if [ "$osType" != "Darwin" ]; then
H
Hui Li 已提交
164
  ${csudo} mkdir -p ${compile_dir}
S
slguan 已提交
165
else
H
Hui Li 已提交
166
  mkdir -p ${compile_dir}
S
slguan 已提交
167
fi
H
hzcheng 已提交
168
cd ${compile_dir}
L
lihui 已提交
169

L
lihui 已提交
170 171
# check support cpu type
if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "mips64" ]] ; then
H
Hui Li 已提交
172 173 174 175 176
  if [ "$verMode" != "cluster" ]; then
    cmake ../    -DCPUTYPE=${cpuType} -DOSTYPE=${osType} -DSOMODE=${soMode} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp} -DPAGMODE=${pagMode}
  else
    cmake ../../ -DCPUTYPE=${cpuType} -DOSTYPE=${osType} -DSOMODE=${soMode} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp}
  fi
L
lihui 已提交
177
else
H
Hui Li 已提交
178 179
  echo "input cpuType=${cpuType} error!!!"
  exit 1
L
lihui 已提交
180 181 182
fi

make
H
hzcheng 已提交
183 184 185

cd ${curr_dir}

H
Hui Li 已提交
186
# 3. Call the corresponding script for packaging
S
slguan 已提交
187
if [ "$osType" != "Darwin" ]; then
H
Hui Li 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200 201
  if [[ "$verMode" != "cluster" ]] && [[ "$cpuType" == "x64" ]]; then
    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}

    echo "====do rpm package for the centos system===="
    output_dir="${top_dir}/rpms"
    if [ -d ${output_dir} ]; then
      ${csudo} rm -rf ${output_dir}
S
slguan 已提交
202
    fi
H
Hui Li 已提交
203 204 205 206
    ${csudo} mkdir -p ${output_dir}
    cd ${script_dir}/rpm
    ${csudo} ./makerpm.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType}
  fi
S
slguan 已提交
207
	
H
Hui Li 已提交
208 209 210 211 212 213
  echo "====do tar.gz package for all systems===="
  cd ${script_dir}/tools
  
	${csudo} ./makepkg.sh    ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode}
	${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}
S
slguan 已提交
214
else
H
Hui Li 已提交
215 216
  cd ${script_dir}/tools
  ./makeclient.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType}
H
hzcheng 已提交
217 218
fi