install_client.sh 9.4 KB
Newer Older
H
hzcheng 已提交
1
#!/bin/bash
L
lihui 已提交
2 3 4
#
# This file is used to install TDengine client on linux systems. The operating system
# is required to use systemd to manage services at boot
H
hzcheng 已提交
5

L
lihui 已提交
6 7 8 9
set -e
#set -x

# -----------------------Variables definition---------------------
S
slguan 已提交
10

Z
change  
zyyang 已提交
11 12 13 14 15 16 17 18 19 20 21
dataDir="/var/lib/taos"
logDir="/var/log/taos"
productName="TDengine"
installDir="/usr/local/taos"
configDir="/etc/taos"
serverName="taosd"
clientName="taos"
uninstallScript="rmtaos"
configFile="taos.cfg"
tarName="taos.tar.gz"

S
slguan 已提交
22
osType=Linux
L
lihui 已提交
23
pagMode=full
S
slguan 已提交
24 25

if [ "$osType" != "Darwin" ]; then
Z
change  
zyyang 已提交
26 27 28 29
  script_dir=$(dirname $(readlink -f "$0"))
  # Dynamic directory
  data_dir=${dataDir}
  log_dir=${logDir}
S
slguan 已提交
30
else
Z
change  
zyyang 已提交
31 32 33 34 35
  script_dir=$(dirname $0)
  cd ${script_dir}
  script_dir="$(pwd)"
  data_dir=${dataDir}
  log_dir=~/${productName}/log
S
slguan 已提交
36
fi
L
lihui 已提交
37

Z
change  
zyyang 已提交
38
log_link_dir="${installDir}/log"
L
lihui 已提交
39

Z
change  
zyyang 已提交
40
cfg_install_dir="${configDir}"
L
lihui 已提交
41

S
slguan 已提交
42
if [ "$osType" != "Darwin" ]; then
Z
change  
zyyang 已提交
43 44 45 46
  bin_link_dir="/usr/bin"
  lib_link_dir="/usr/lib"
  lib64_link_dir="/usr/lib64"
  inc_link_dir="/usr/include"
S
slguan 已提交
47
else
Z
change  
zyyang 已提交
48 49 50
  bin_link_dir="/usr/local/bin"
  lib_link_dir="/usr/local/lib"
  inc_link_dir="/usr/local/include"
S
slguan 已提交
51
fi
L
lihui 已提交
52 53

#install main path
Z
change  
zyyang 已提交
54
install_main_dir="${installDir}"
L
lihui 已提交
55 56

# old bin dir
Z
change  
zyyang 已提交
57
bin_dir="${installDir}/bin"
L
lihui 已提交
58 59 60 61 62 63 64 65 66

# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'

csudo=""
Z
change  
zyyang 已提交
67 68
if command -v sudo >/dev/null; then
  csudo="sudo "
L
lihui 已提交
69 70 71 72 73
fi

update_flag=0

function kill_client() {
Z
change  
zyyang 已提交
74
  pid=$(ps -ef | grep "${clientName}" | grep -v "grep" | awk '{print $2}')
L
lihui 已提交
75
  if [ -n "$pid" ]; then
Z
change  
zyyang 已提交
76
    ${csudo}kill -9 $pid || :
L
lihui 已提交
77 78 79 80
  fi
}

function install_main_path() {
Z
change  
zyyang 已提交
81 82 83 84 85 86 87 88 89
  #create install main dir and all sub dir
  ${csudo}rm -rf ${install_main_dir} || :
  ${csudo}mkdir -p ${install_main_dir}
  ${csudo}mkdir -p ${install_main_dir}/cfg
  ${csudo}mkdir -p ${install_main_dir}/bin
  ${csudo}mkdir -p ${install_main_dir}/connector
  ${csudo}mkdir -p ${install_main_dir}/driver
  ${csudo}mkdir -p ${install_main_dir}/examples
  ${csudo}mkdir -p ${install_main_dir}/include
L
lihui 已提交
90 91 92
}

function install_bin() {
S
slguan 已提交
93
  # Remove links
Z
change  
zyyang 已提交
94
  ${csudo}rm -f ${bin_link_dir}/${clientName} || :
95
  if [ "$osType" != "Darwin" ]; then
Z
change  
zyyang 已提交
96
    ${csudo}rm -f ${bin_link_dir}/taosdemo || :
S
slguan 已提交
97
  fi
Z
change  
zyyang 已提交
98 99
  ${csudo}rm -f ${bin_link_dir}/${uninstallScript} || :
  ${csudo}rm -f ${bin_link_dir}/set_core || :
L
lihui 已提交
100

101
  ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/*
L
lihui 已提交
102

H
Hui Li 已提交
103
  #Make link
Z
change  
zyyang 已提交
104
  [ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || :
105
  if [ "$osType" != "Darwin" ]; then
Z
change  
zyyang 已提交
106
    [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
S
slguan 已提交
107
  fi
Z
change  
zyyang 已提交
108
  [ -x ${install_main_dir}/bin/remove_client.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client.sh ${bin_link_dir}/${uninstallScript} || :
109
  [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
L
lihui 已提交
110 111 112
}

function clean_lib() {
Z
change  
zyyang 已提交
113 114
  sudo rm -f /usr/lib/libtaos.* || :
  sudo rm -rf ${lib_dir} || :
L
lihui 已提交
115 116 117
}

function install_lib() {
Z
change  
zyyang 已提交
118 119 120
  # Remove links
  ${csudo}rm -f ${lib_link_dir}/libtaos.* || :
  ${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
S
slguan 已提交
121

Z
change  
zyyang 已提交
122
  ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/*
L
lihui 已提交
123

Z
change  
zyyang 已提交
124 125 126
  if [ "$osType" != "Darwin" ]; then
    ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1
    ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so
127

Z
change  
zyyang 已提交
128 129 130
    if [ -d "${lib64_link_dir}" ]; then
      ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || :
      ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || :
S
slguan 已提交
131
    fi
Z
change  
zyyang 已提交
132 133 134 135
  else
    ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib
    ${csudo}ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib
  fi
136

Z
change  
zyyang 已提交
137 138 139 140 141
  if [ "$osType" != "Darwin" ]; then
    ${csudo}ldconfig
  else
    ${csudo}update_dyld_shared_cache
  fi
L
lihui 已提交
142 143 144
}

function install_header() {
Z
change  
zyyang 已提交
145 146 147 148 149
  ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || :
  ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/*
  ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h
  ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h
  ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
L
lihui 已提交
150 151
}

152
function install_jemalloc() {
Z
change  
zyyang 已提交
153
  jemalloc_dir=${script_dir}/jemalloc
154

Z
change  
zyyang 已提交
155 156
  if [ -d ${jemalloc_dir} ]; then
    ${csudo}/usr/bin/install -c -d /usr/local/bin
S
slguan 已提交
157

Z
change  
zyyang 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then
      ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin
    fi
    if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then
      ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin
    fi
    if [ -f ${jemalloc_dir}/bin/jeprof ]; then
      ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin
    fi
    if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then
      ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc
      ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc
    fi
    if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then
      ${csudo}/usr/bin/install -c -d /usr/local/lib
      ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib
      ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so
      ${csudo}/usr/bin/install -c -d /usr/local/lib
      if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then
        ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib
      fi
      if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then
        ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib
      fi
      if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then
        ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig
        ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig
      fi
    fi
    if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then
      ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc
      ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc
    fi
    if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then
      ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3
      ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3
S
slguan 已提交
194 195
    fi

Z
change  
zyyang 已提交
196 197 198 199 200 201 202
    if [ -d /etc/ld.so.conf.d ]; then
      echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf"
      ${csudo}ldconfig
    else
      echo "/etc/ld.so.conf.d not found!"
    fi
  fi
L
lihui 已提交
203 204
}

Z
change  
zyyang 已提交
205 206 207 208 209 210 211 212 213 214
function install_config() {
  if [ ! -f ${cfg_install_dir}/${configFile} ]; then
    ${csudo}mkdir -p ${cfg_install_dir}
    [ -f ${script_dir}/cfg/${configFile} ] && ${csudo}cp ${script_dir}/cfg/${configFile} ${cfg_install_dir}
    ${csudo}chmod 644 ${cfg_install_dir}/*
  fi

  ${csudo}cp -f ${script_dir}/cfg/${configFile} ${install_main_dir}/cfg/${configFile}.org
  ${csudo}ln -s ${cfg_install_dir}/${configFile} ${install_main_dir}/cfg
}
L
lihui 已提交
215 216

function install_log() {
Z
change  
zyyang 已提交
217
  ${csudo}rm -rf ${log_dir} || :
S
slguan 已提交
218

Z
change  
zyyang 已提交
219 220 221 222 223 224
  if [ "$osType" != "Darwin" ]; then
    ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
  else
    mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
  fi
  ${csudo}ln -s ${log_dir} ${install_main_dir}/log
L
lihui 已提交
225 226 227
}

function install_connector() {
Z
change  
zyyang 已提交
228
  ${csudo}cp -rf ${script_dir}/connector/ ${install_main_dir}/
L
lihui 已提交
229 230 231
}

function install_examples() {
Z
change  
zyyang 已提交
232 233 234
  if [ -d ${script_dir}/examples ]; then
    ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples
  fi
L
lihui 已提交
235 236 237
}

function update_TDengine() {
Z
change  
zyyang 已提交
238 239 240 241 242 243
  # Start to update
  if [ ! -e ${tarName} ]; then
    echo "File ${tarName} does not exist"
    exit 1
  fi
  tar -zxf ${tarName}
L
lihui 已提交
244

Z
change  
zyyang 已提交
245 246 247 248 249 250
  echo -e "${GREEN}Start to update ${productName} client...${NC}"
  # Stop the client shell if running
  if pidof ${clientName} &>/dev/null; then
    kill_client
    sleep 1
  fi
S
slguan 已提交
251

Z
change  
zyyang 已提交
252
  install_main_path
L
lihui 已提交
253

Z
change  
zyyang 已提交
254 255 256 257 258 259 260 261 262 263
  install_log
  install_header
  install_lib
  install_jemalloc
  if [ "$pagMode" != "lite" ]; then
    install_connector
  fi
  install_examples
  install_bin
  install_config
S
slguan 已提交
264

Z
change  
zyyang 已提交
265 266
  echo
  echo -e "\033[44;32;1m${productName} client is updated successfully!${NC}"
L
lihui 已提交
267

Z
change  
zyyang 已提交
268
  rm -rf $(tar -tf ${tarName})
L
lihui 已提交
269 270 271
}

function install_TDengine() {
Z
change  
zyyang 已提交
272 273 274 275 276 277
  # Start to install
  if [ ! -e ${tarName} ]; then
    echo "File ${tarName} does not exist"
    exit 1
  fi
  tar -zxf ${tarName}
L
lihui 已提交
278

Z
change  
zyyang 已提交
279
  echo -e "${GREEN}Start to install ${productName} client...${NC}"
S
slguan 已提交
280

Z
change  
zyyang 已提交
281 282 283 284 285 286 287 288 289 290 291
  install_main_path
  install_log
  install_header
  install_lib
  install_jemalloc
  if [ "$pagMode" != "lite" ]; then
    install_connector
  fi
  install_examples
  install_bin
  install_config
S
slguan 已提交
292

Z
change  
zyyang 已提交
293 294
  echo
  echo -e "\033[44;32;1m${productName} client is installed successfully!${NC}"
L
lihui 已提交
295

Z
change  
zyyang 已提交
296
  rm -rf $(tar -tf ${tarName})
L
lihui 已提交
297 298 299 300 301
}

## ==============================Main program starts from here============================
# Install or updata client and client
# if server is already install, don't install client
Z
change  
zyyang 已提交
302 303 304 305
if [ -e ${bin_dir}/${serverName} ]; then
  echo -e "\033[44;32;1mThere are already installed ${productName} server, so don't need install client!${NC}"
  exit 0
fi
S
slguan 已提交
306

Z
change  
zyyang 已提交
307 308 309 310 311 312
if [ -x ${bin_dir}/${clientName} ]; then
  update_flag=1
  update_TDengine
else
  install_TDengine
fi