release.sh 6.0 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
L
lihui 已提交
6 7
# set -x

L
lihui 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
# releash.sh -v [cluster | lite]  -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | ...]  -V [stable | beta]

# set parameters by default value
verMode=lite     # [cluster, lite]
verType=stable   # [stable, beta]
cpuType=x64      # [aarch32 | aarch64 | x64 | x86 | mips64 ...]
osType=Linux     # [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | ...]

while getopts "hv:V:c:o:" arg
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)
      ;;
    o)
      #echo "osType=$OPTARG"
      osType=$(echo $OPTARG)
      ;;
    h)
      echo "Usage: `basename $0` -v [cluster | lite]  -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | ...]  -V [stable | beta]"
      exit 0
      ;;
    ?) #unknow option 
      echo "unkonw argument"
      exit 1
      ;;
  esac
done

echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType}"
H
hzcheng 已提交
47 48 49

curr_dir=$(pwd)
script_dir="$(dirname $(readlink -f $0))"
F
Frozen 已提交
50
top_dir="$(readlink -f ${script_dir}/..)"
S
slguan 已提交
51
versioninfo="${top_dir}/src/util/src/version.c"
H
hzcheng 已提交
52

P
plum-lihui 已提交
53 54 55 56 57
csudo=""
if command -v sudo > /dev/null; then
    csudo="sudo"
fi

H
hzcheng 已提交
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
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
    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

    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
        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)

while true; do
  read -p "Do you want to release a new version? [y/N]: " is_version_change

  if [[ ( "${is_version_change}" == "y") || ( "${is_version_change}" == "Y") ]]; then
      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
  elif [[ ( "${is_version_change}" == "n") || ( "${is_version_change}" == "N") ]]; then
      echo "Use old version: ${version} compatible version: ${compatible_version}."
      break
  else
      continue
  fi
done

# output the version info to the buildinfo file.
build_time=$(date +"%F %R")
L
lihui 已提交
147 148 149 150
echo "char version[64] = \"${version}\";"                             > ${versioninfo}
echo "char compatible_version[64] = \"${compatible_version}\";"      >> ${versioninfo}
echo "char gitinfo[128] = \"$(git rev-parse --verify HEAD)\";"       >> ${versioninfo}
echo "char gitinfoOfInternal[128] = \"\";"                           >> ${versioninfo}
H
hzcheng 已提交
151 152
echo "char buildinfo[512] = \"Built by ${USER} at ${build_time}\";"  >> ${versioninfo}

L
lihui 已提交
153 154 155 156
echo ""                                                              >> ${versioninfo}
tmp_version=$(echo $version | tr -s "." "_")
echo "void libtaos_edge_${tmp_version}_${osType}_${cpuType}() {};"   >> ${versioninfo}

H
hzcheng 已提交
157 158
# 2. cmake executable file

L
lihui 已提交
159
compile_dir="${top_dir}/debug"
H
hzcheng 已提交
160
if [ -d ${compile_dir} ]; then
L
lihui 已提交
161
    ${csudo} rm -rf ${compile_dir}
H
hzcheng 已提交
162 163
fi

P
plum-lihui 已提交
164
${csudo} mkdir -p ${compile_dir}
H
hzcheng 已提交
165
cd ${compile_dir}
L
lihui 已提交
166

L
lihui 已提交
167 168 169
# check support cpu type
if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "mips64" ]] ; then
  cmake ../ -DCPUTYPE=${cpuType}
L
lihui 已提交
170
else
L
lihui 已提交
171 172
  echo "input cpuType=${cpuType} error!!!"
  exit 1
L
lihui 已提交
173 174 175
fi

make
H
hzcheng 已提交
176 177 178 179

cd ${curr_dir}

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

L
lihui 已提交
184
echo "====do deb package for the ubuntu system===="
H
[NONE]  
huili 已提交
185 186 187 188 189 190
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
L
lihui 已提交
191
${csudo} ./makedeb.sh ${compile_dir} ${output_dir} ${version} ${cpuType} ${osType} ${verMode} ${verType}
S
slguan 已提交
192
  
L
lihui 已提交
193
echo "====do rpm package for the centos system===="
H
[NONE]  
huili 已提交
194 195 196
output_dir="${top_dir}/rpms"
if [ -d ${output_dir} ]; then
  ${csudo} rm -rf ${output_dir}
H
hzcheng 已提交
197
fi
H
[NONE]  
huili 已提交
198 199
${csudo} mkdir -p ${output_dir}  
cd ${script_dir}/rpm
L
lihui 已提交
200
${csudo} ./makerpm.sh ${compile_dir} ${output_dir} ${version} ${cpuType} ${osType} ${verMode} ${verType}
S
slguan 已提交
201

L
lihui 已提交
202
echo "====do tar.gz package for all systems===="  
H
hzcheng 已提交
203
cd ${script_dir}/tools
L
lihui 已提交
204 205
${csudo} ./makepkg.sh    ${compile_dir} ${version} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType}
${csudo} ./makeclient.sh ${compile_dir} ${version} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType}
H
hzcheng 已提交
206 207

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