install_client_power.sh 9.8 KB
Newer Older
H
Hui Li 已提交
1 2 3 4 5 6 7 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 47 48 49 50 51 52 53 54 55 56 57 58 59
#!/bin/bash
#
# This file is used to install PowerDB client on linux systems. The operating system
# is required to use systemd to manage services at boot

set -e
#set -x

# -----------------------Variables definition---------------------

osType=Linux
pagMode=full

if [ "$osType" != "Darwin" ]; then
    script_dir=$(dirname $(readlink -f "$0"))
    # Dynamic directory
    data_dir="/var/lib/power"
    log_dir="/var/log/power"
else
    script_dir=`dirname $0`
    cd ${script_dir}
    script_dir="$(pwd)"
    data_dir="/var/lib/power"
    log_dir="~/PowerDBLog"
fi

log_link_dir="/usr/local/power/log"

cfg_install_dir="/etc/power"

if [ "$osType" != "Darwin" ]; then
    bin_link_dir="/usr/bin"
    lib_link_dir="/usr/lib"
    lib64_link_dir="/usr/lib64"
    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

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

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

# v1.5 jar dir
#v15_java_app_dir="/usr/local/lib/power"

# 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 "
H
Hui Li 已提交
61 62 63 64 65 66 67
fi

update_flag=0

function kill_client() {
  pid=$(ps -ef | grep "power" | grep -v "grep" | awk '{print $2}')
  if [ -n "$pid" ]; then
68
    ${csudo}kill -9 $pid   || :
H
Hui Li 已提交
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
H
Hui Li 已提交
82 83 84 85
}

function install_bin() {
  # Remove links
86
  ${csudo}rm -f ${bin_link_dir}/power         || :
87
  if [ "$osType" != "Darwin" ]; then
88 89
      ${csudo}rm -f ${bin_link_dir}/powerdemo  || :
      ${csudo}rm -f ${bin_link_dir}/powerdump  || :
H
Hui Li 已提交
90
  fi
91 92
  ${csudo}rm -f ${bin_link_dir}/rmpower       || :
  ${csudo}rm -f ${bin_link_dir}/set_core      || :
H
Hui Li 已提交
93

94
  ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/*
H
Hui Li 已提交
95 96

  #Make link
97
  [ -x ${install_main_dir}/bin/power ] && ${csudo}ln -s ${install_main_dir}/bin/power ${bin_link_dir}/power                 || :
98
  if [ "$osType" != "Darwin" ]; then
99 100
      [ -x ${install_main_dir}/bin/powerdemo ] && ${csudo}ln -s ${install_main_dir}/bin/powerdemo ${bin_link_dir}/powerdemo || :
      [ -x ${install_main_dir}/bin/powerdump ] && ${csudo}ln -s ${install_main_dir}/bin/powerdump ${bin_link_dir}/powerdump || :
H
Hui Li 已提交
101
  fi
102 103
  [ -x ${install_main_dir}/bin/remove_client_power.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client_power.sh ${bin_link_dir}/rmpower || :
  [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
H
Hui Li 已提交
104 105 106 107 108 109 110 111 112
}

function clean_lib() {
    sudo rm -f /usr/lib/libtaos.* || :
    sudo rm -rf ${lib_dir} || :
}

function install_lib() {
    # Remove links
113 114 115
    ${csudo}rm -f ${lib_link_dir}/libtaos.*         || :
    ${csudo}rm -f ${lib64_link_dir}/libtaos.*       || :
    #${csudo}rm -rf ${v15_java_app_dir}              || :
H
Hui Li 已提交
116

117
    ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/*
H
Hui Li 已提交
118 119

    if [ "$osType" != "Darwin" ]; then
120 121
        ${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
122

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

132
    ${csudo}ldconfig
H
Hui Li 已提交
133 134 135
}

function install_header() {
136 137 138 139 140
    ${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
H
Hui Li 已提交
141 142
}

143 144 145 146
function install_jemalloc() {
    jemalloc_dir=${script_dir}/jemalloc

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

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

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

H
Hui Li 已提交
196
function install_config() {
197
    if [ ! -f ${cfg_install_dir}/power.cfg ]; then
198 199 200
        ${csudo}mkdir -p ${cfg_install_dir}
        [ -f ${script_dir}/cfg/power.cfg ] && ${csudo}cp ${script_dir}/cfg/power.cfg ${cfg_install_dir}
        ${csudo}chmod 644 ${cfg_install_dir}/*
H
Hui Li 已提交
201 202
    fi

203 204
    ${csudo}cp -f ${script_dir}/cfg/power.cfg ${install_main_dir}/cfg/power.cfg.org
    ${csudo}ln -s ${cfg_install_dir}/power.cfg ${install_main_dir}/cfg
H
Hui Li 已提交
205 206 207 208
}


function install_log() {
209
    ${csudo}rm -rf ${log_dir}  || :
H
Hui Li 已提交
210 211

    if [ "$osType" != "Darwin" ]; then
212
        ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
H
Hui Li 已提交
213
    else
214
        mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
H
Hui Li 已提交
215
    fi
216
    ${csudo}ln -s ${log_dir} ${install_main_dir}/log
H
Hui Li 已提交
217 218 219
}

function install_connector() {
220
    ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector
H
Hui Li 已提交
221 222 223 224
}

function install_examples() {
    if [ -d ${script_dir}/examples ]; then
225
        ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples
H
Hui Li 已提交
226 227 228 229 230 231 232 233 234 235
    fi
}

function update_PowerDB() {
    # Start to update
    if [ ! -e power.tar.gz ]; then
        echo "File power.tar.gz does not exist"
        exit 1
    fi
    tar -zxf power.tar.gz
236
    install_jemalloc
H
Hui Li 已提交
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269

    echo -e "${GREEN}Start to update PowerDB client...${NC}"
    # Stop the client shell if running
    if pidof power &> /dev/null; then
        kill_client
        sleep 1
    fi

    install_main_path

    install_log
    install_header
    install_lib
    install_examples
    install_bin
    install_config

    echo
    echo -e "\033[44;32;1mPowerDB client is updated successfully!${NC}"

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

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

    echo -e "${GREEN}Start to install PowerDB client...${NC}"

270
    install_main_path
H
Hui Li 已提交
271 272 273
    install_log
    install_header
    install_lib
274
    install_jemalloc
H
Hui Li 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
    install_examples
    install_bin
    install_config

    echo
    echo -e "\033[44;32;1mPowerDB client is installed successfully!${NC}"

    rm -rf $(tar -tf power.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}/powerd ]; then
      echo -e "\033[44;32;1mThere are already installed PowerDB server, so don't need install client!${NC}"
      exit 0
  fi

  if [ -x ${bin_dir}/power ]; then
      update_flag=1
      update_PowerDB
  else
      install_PowerDB
  fi