install_client.sh 9.9 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 11

osType=Linux
L
lihui 已提交
12
pagMode=full
S
slguan 已提交
13 14 15 16 17 18 19 20 21 22 23

if [ "$osType" != "Darwin" ]; then
    script_dir=$(dirname $(readlink -f "$0"))
    # Dynamic directory
    data_dir="/var/lib/taos"
    log_dir="/var/log/taos"
else
    script_dir=`dirname $0`
    cd ${script_dir}
    script_dir="$(pwd)"
    data_dir="/var/lib/taos"
S
TD-2837  
slguan 已提交
24
    log_dir=~/TDengine/log
S
slguan 已提交
25
fi
L
lihui 已提交
26 27 28 29 30

log_link_dir="/usr/local/taos/log"

cfg_install_dir="/etc/taos"

S
slguan 已提交
31 32 33
if [ "$osType" != "Darwin" ]; then
    bin_link_dir="/usr/bin"
    lib_link_dir="/usr/lib"
H
Hui Li 已提交
34
    lib64_link_dir="/usr/lib64"
S
slguan 已提交
35 36 37 38 39 40
    inc_link_dir="/usr/include"
else
    bin_link_dir="/usr/local/bin"
    lib_link_dir="/usr/local/lib"
    inc_link_dir="/usr/local/include"
fi
L
lihui 已提交
41 42 43 44 45 46 47

#install main path
install_main_dir="/usr/local/taos"

# old bin dir
bin_dir="/usr/local/taos/bin"

S
slguan 已提交
48
# v1.5 jar dir
H
Hui Li 已提交
49
#v15_java_app_dir="/usr/local/lib/taos"
L
lihui 已提交
50 51 52 53 54 55 56 57 58 59

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

csudo=""
if command -v sudo > /dev/null; then
60
    csudo="sudo "
L
lihui 已提交
61 62 63 64 65 66 67
fi

update_flag=0

function kill_client() {
  pid=$(ps -ef | grep "taos" | grep -v "grep" | awk '{print $2}')
  if [ -n "$pid" ]; then
68
    ${csudo}kill -9 $pid   || :
L
lihui 已提交
69 70 71 72 73
  fi
}

function install_main_path() {
    #create install main dir and all sub dir
74 75 76 77 78 79 80 81
    ${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 已提交
82 83 84
}

function install_bin() {
S
slguan 已提交
85
  # Remove links
86
  ${csudo}rm -f ${bin_link_dir}/taos         || :
87
  if [ "$osType" != "Darwin" ]; then
88
      ${csudo}rm -f ${bin_link_dir}/taosdemo || :
S
slguan 已提交
89
  fi
90 91
  ${csudo}rm -f ${bin_link_dir}/rmtaos       || :
  ${csudo}rm -f ${bin_link_dir}/set_core     || :
L
lihui 已提交
92

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

H
Hui Li 已提交
95
  #Make link
96
  [ -x ${install_main_dir}/bin/taos ] && ${csudo}ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos                 || :
97
  if [ "$osType" != "Darwin" ]; then
98
      [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
S
slguan 已提交
99
  fi
100 101
  [ -x ${install_main_dir}/bin/remove_client.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client.sh ${bin_link_dir}/rmtaos || :
  [ -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 已提交
102 103 104
}

function clean_lib() {
S
slguan 已提交
105
    sudo rm -f /usr/lib/libtaos.* || :
L
lihui 已提交
106 107 108 109 110
    sudo rm -rf ${lib_dir} || :
}

function install_lib() {
    # Remove links
111 112 113
    ${csudo}rm -f ${lib_link_dir}/libtaos.*         || :
    ${csudo}rm -f ${lib64_link_dir}/libtaos.*       || :
    #${csudo}rm -rf ${v15_java_app_dir}              || :
S
slguan 已提交
114

115
    ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/*
L
lihui 已提交
116

S
slguan 已提交
117
    if [ "$osType" != "Darwin" ]; then
118 119
        ${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
120

H
Hui Li 已提交
121
        if [ -d "${lib64_link_dir}" ]; then
122 123
            ${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               || :
124
        fi
S
slguan 已提交
125
    else
126 127
        ${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
S
slguan 已提交
128
    fi
129

130
    if [ "$osType" != "Darwin" ]; then
131
        ${csudo}ldconfig
132
    else
133
        ${csudo}update_dyld_shared_cache
134
    fi
L
lihui 已提交
135 136 137
}

function install_header() {
138 139 140 141 142
    ${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 已提交
143 144
}

145 146 147 148
function install_jemalloc() {
    jemalloc_dir=${script_dir}/jemalloc

    if [ -d ${jemalloc_dir} ]; then
149
        ${csudo}/usr/bin/install -c -d /usr/local/bin
150 151

        if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then
152
            ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin
153 154
        fi
        if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then
155
            ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin
156 157
        fi
        if [ -f ${jemalloc_dir}/bin/jeprof ]; then
158
            ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin
159 160
        fi
        if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then
161 162
            ${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
163 164
        fi
        if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then
165 166 167 168
            ${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
169
            if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then
170
                ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib
171 172
            fi
            if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then
173
                ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib
174 175
            fi
            if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then
176 177
                ${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
178 179 180
            fi
        fi
        if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then
181 182
            ${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
183 184
        fi
        if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then
185 186
            ${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
187
        fi
188 189

        if [ -d /etc/ld.so.conf.d ]; then
190 191
            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
192 193 194
        else
            echo "/etc/ld.so.conf.d not found!"
        fi
195 196 197
    fi
}

L
lihui 已提交
198
function install_config() {
199
    #${csudo}rm -f ${install_main_dir}/cfg/taos.cfg     || :
S
slguan 已提交
200

L
lihui 已提交
201
    if [ ! -f ${cfg_install_dir}/taos.cfg ]; then
202 203 204
        ${csudo}mkdir -p ${cfg_install_dir}
        [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo}cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir}
        ${csudo}chmod 644 ${cfg_install_dir}/*
S
slguan 已提交
205 206
    fi

207 208
    ${csudo}cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org
    ${csudo}ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg
L
lihui 已提交
209 210 211 212
}


function install_log() {
213
    ${csudo}rm -rf ${log_dir}  || :
S
slguan 已提交
214 215

    if [ "$osType" != "Darwin" ]; then
216
        ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
S
slguan 已提交
217
    else
218
        mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
S
slguan 已提交
219
    fi
220
    ${csudo}ln -s ${log_dir} ${install_main_dir}/log
L
lihui 已提交
221 222 223
}

function install_connector() {
224
    ${csudo}cp -rf ${script_dir}/connector/ ${install_main_dir}/
L
lihui 已提交
225 226 227 228
}

function install_examples() {
    if [ -d ${script_dir}/examples ]; then
229
        ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples
L
lihui 已提交
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
    fi
}

function update_TDengine() {
    # Start to update
    if [ ! -e taos.tar.gz ]; then
        echo "File taos.tar.gz does not exist"
        exit 1
    fi
    tar -zxf taos.tar.gz

    echo -e "${GREEN}Start to update TDengine client...${NC}"
    # Stop the client shell if running
    if pidof taos &> /dev/null; then
        kill_client
        sleep 1
    fi
S
slguan 已提交
247

L
lihui 已提交
248 249 250 251 252
    install_main_path

    install_log
    install_header
    install_lib
253
    install_jemalloc
L
lihui 已提交
254 255 256
    if [ "$pagMode" != "lite" ]; then
      install_connector
    fi
L
lihui 已提交
257 258 259
    install_examples
    install_bin
    install_config
S
slguan 已提交
260

L
lihui 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    echo
    echo -e "\033[44;32;1mTDengine client is updated successfully!${NC}"

    rm -rf $(tar -tf taos.tar.gz)
}

function install_TDengine() {
    # Start to install
    if [ ! -e taos.tar.gz ]; then
        echo "File taos.tar.gz does not exist"
        exit 1
    fi
    tar -zxf taos.tar.gz

    echo -e "${GREEN}Start to install TDengine client...${NC}"
S
slguan 已提交
276

277
    install_main_path
S
slguan 已提交
278
    install_log
L
lihui 已提交
279 280
    install_header
    install_lib
281
    install_jemalloc
L
lihui 已提交
282 283 284
    if [ "$pagMode" != "lite" ]; then
      install_connector
    fi
L
lihui 已提交
285 286 287
    install_examples
    install_bin
    install_config
S
slguan 已提交
288

L
lihui 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301
    echo
    echo -e "\033[44;32;1mTDengine client is installed successfully!${NC}"

    rm -rf $(tar -tf taos.tar.gz)
}


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

L
lihui 已提交
304 305 306 307 308 309
  if [ -x ${bin_dir}/taos ]; then
      update_flag=1
      update_TDengine
  else
      install_TDengine
  fi