X7ROOT File Manager
Current Path:
/var/VMOptimizationToolsLinux
var
/
VMOptimizationToolsLinux
/
📁
..
📄
LinuxUpdate.XML
(645 B)
📄
SangforVMSTool
(3.11 KB)
📄
SangforVMSTool.service
(194 B)
📄
action_common.sh
(13.34 KB)
📄
busybox_cmd_ln.sh
(2.24 KB)
📄
collect_test_data.sh
(1.16 KB)
📄
common_config.sh
(278 B)
📄
data_test_tool.sh
(12.59 KB)
📄
debian_vmconfig.sh
(10.74 KB)
📄
guest_system_config.sh
(1.82 KB)
📄
log.sh
(1.36 KB)
📄
mod_test.sh
(3.69 KB)
📄
mod_test1.sh
(914 B)
📄
net_common.sh
(915 B)
📄
redhat_vmconfig.sh
(11.14 KB)
📄
sangfor_guest_datareport
(21.66 KB)
📄
sangfor_heartalive.sh
(2.37 KB)
📄
sangfor_module_update
(28.11 KB)
📄
sangfor_set_network.sh
(504 B)
📄
sangfor_sfping
(3.85 KB)
📄
sangfor_sshkey_gen
(1.29 KB)
📄
sangfor_update_ipc_callback
(5.29 KB)
📄
sangfor_vm_proxyd
(3.45 KB)
📄
sangfor_vm_proxyd_r
(4.4 KB)
📄
sangfor_vm_proxyd_w
(1.32 KB)
📄
sangfor_vmconfig
(2.4 KB)
📄
sangfor_vmconfig_common
(27.99 KB)
📄
sangfor_vmconfig_ipc_callback
(4.75 KB)
📄
sangfor_watchdog
(3.95 KB)
📄
sfping.c
(15.68 KB)
📄
sfping.pl
(6.15 KB)
📄
startall
(1.78 KB)
📄
stopall
(1.11 KB)
📄
suse_vmconfig.sh
(6.19 KB)
📁
tools_x64
📁
tools_x86
📄
uni_test.sh
(2.59 KB)
📄
update_common_func
(4.35 KB)
📄
update_common_header
(4.86 KB)
📄
update_config
(2.89 KB)
📄
update_install
(28.84 KB)
📄
virtio_nic_attr_set.sh
(2.42 KB)
📄
virtio_nic_compat.sh
(5.28 KB)
📄
vm_ip_recover.sh
(16.66 KB)
📄
vm_ipc.sh
(9.06 KB)
📄
vmconfig_common_func
(10.76 KB)
📄
vmconfig_common_header
(3.37 KB)
📄
vmconfig_config
(805 B)
📄
vmtools-install.sh
(31.16 KB)
📄
watch_test.sh
(313 B)
📄
watchdog.sh
(1.39 KB)
📁
x64
📁
x86
Editing: update_install
#!/bin/bash #SnagforVMTools install program shell_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) if [ -L "${shell_dir}" ];then shell_dir=$( cd "$(readlink "${shell_dir}")" && pwd ) fi args="$1" . "${shell_dir}/update_config" . "${shell_dir}/log.sh" . "${shell_dir}/update_common_func" . "${shell_dir}/watchdog.sh" . "${shell_dir}/common_config.sh" . "${shell_dir}/vmconfig_config" #update args declare -r g_update_args="update" #install directory declare g_tools_install_dir="${g_sangfor_vmtools_install_dir}" #current directory declare g_current_dir="${shell_dir}" # 从环境变量BACKEND中获取运行环境标识,目前有值可能是 libguestfs declare g_backend_type=${BACKEND} #Checks the integrity of the file #$1 directory one #$2 directory one #Return 0 if all the file in the two directory are the same,otherwise return 1. check_all_files(){ local compare_result="" if [ $# -ne 2 ];then log_error "check_all_files:args error!" return 1 fi if [ ! -d "$1" -o ! -d "$2" ];then log_error "$1 or $2 is not a directory!" return 1 fi if [ x"$1" = x"$2" ];then return 0 fi compare_result=`diff -Nuarp "$1" "$2"` if [ x"${compare_result}" = x"" ];then log_debug "All files in the two dir is the same." return 0 else log_error "All files in the two dir is not the same!" log_debug "${compare_result}" return 1 fi } TEST_check_all_files(){ log_debug "TEST_check_all_files" mkdir -p "${g_current_dir}/../check_file_temp" rm -f "${g_current_dir}/../check_file_temp"/* cp -rf "${g_current_dir}"/* "${g_current_dir}/../check_file_temp" check_all_files "${g_current_dir}" "${g_current_dir}/../check_file_temp" if [ $? -ne 0 ];then log_error "TEST_check_all_files failed!" rm -rf "${g_current_dir}/../check_file_temp" return 1 fi check_all_files "${g_current_dir}" if [ $? -ne 1 ];then log_error "TEST_check_all_files failed!" rm -rf "${g_current_dir}/../check_file_temp" return 1 fi rm -rf "${g_current_dir}/../check_file_temp"/* check_all_files "${g_current_dir}" "${g_current_dir}/../check_file_temp" if [ $? -ne 1 ];then log_error "TEST_check_all_files failed!" rm -rf "${g_current_dir}/../check_file_temp" return 1 fi rm -rf "${g_current_dir}/../check_file_temp" return 0 } #Check whether the command exists check_command() { type ${1} > /dev/null 2>&1 if [ $? -eq 0 ]; then log_info "command:${1} exist." return 0; else log_error "command:${1} not exist" return 1; fi } # TEST check_command TEST_check_command(){ log_debug "TEST_check_command" check_command if [ $? -ne 0 ];then log_error "check_command failed!" log_error "TEST_check_command failed!" return 1 fi check_command "" if [ $? -ne 0 ];then log_error "check_command failed!" log_error "TEST_check_command failed!" return 1 fi check_command "sh" if [ $? -ne 0 ];then log_error "check_command failed!" log_error "TEST_check_command failed!" return 1 fi check_command "nonononononononon" if [ $? -ne 1 ];then log_error "check_command failed!" log_error "TEST_check_command failed!" return 1 fi return 0 } # Check whether the shell command exists # exist return 0 # not exist return 1 check_shell_tools(){ local exit_code=1 #check base64 check_command "base64" if [ $? -ne 0 ]; then log_error "base64 not exist" return 1; fi #check diff check_command "diff" if [ $? -ne 0 ]; then log_error "diff not exist" return 1; fi #check sed check_command "sed" if [ $? -ne 0 ]; then log_error "sed not exist" return 1; fi #check readlink and ln check_command "readlink" if [ $? -ne 0 ]; then log_error "readlink not exist" return 1; fi check_command "ln" if [ $? -ne 0 ]; then log_error "ln not exist" return 1; fi #check awk check_command "awk" if [ $? -ne 0 ]; then log_error "awk not exist" return 1; fi # return 0 } TEST_check_shell_tools(){ log_debug "TEST_check_shell_tools" check_shell_tools if [ $? -ne 0 ];then log_error "check_shell_tools failed!" log_error "TEST_check_shell_tools success or failed! Please make sure!" return 1 fi return 0 } #Check whether it meets the installation environment #yes return 0, no return 1 #check some command check_env(){ local exit_code=1 #check command # base64 sed ... check_shell_tools exit_code=$? if [ ${exit_code} -eq 0 ];then log_info "some shell command is necessary." else log_error "lack of some shell command!" return 1 fi #check whether the virtio port exist. local vport_file="/dev/virtio-ports/channelser.virtserial0.0" if [ ! -e "${vport_file}" ]; then log_error "${vport_file} not exist" return 0 fi # check others return 0 } # TEST check_env TEST_check_env(){ log_debug "TEST_check_env" check_env if [ $? -ne 0 ];then log_error "check_env failed!" log_error "TEST_check_env success or failed! Please make sure!" return 1 fi return 0 } # 判断一个给定的路径是否是符号链接 # td 62717, 不再判断符号链接是否有效,如果是符号链接,则表明是旧版本,就应该在上层做删除处理 # return: 1 无效符号链接, 0 其他 judge_symbolic_link() { symbolic_file=$1 if [ -L ${symbolic_file} ]; then return 1 fi return 0 } startall_redflag() { local add_boot_link_service="${g_sangfor_vmtools_install_dir}/${g_boot_shell_file}.service" local add_usr_link_service="${g_systemd_usr_dir}/${g_boot_shell_file}.service" local add_etc_link_service="${g_systemd_etc_dir}/${g_boot_shell_file}.service" local add_lib_link_service="${g_systemd_lib_dir}/${g_boot_shell_file}.service" if [ -d "${g_systemd_usr_dir}" ]; then judge_symbolic_link "${add_usr_link_service}" if [ $? -ne 0 ]; then rm -f "${add_usr_link_service}" fi cp -f "${add_boot_link_service}" "${add_usr_link_service}" log_debug "cp -f ${add_boot_link_service} ${add_usr_link_service}" fi if [ -d "${g_systemd_lib_dir}" ]; then judge_symbolic_link "${add_lib_link_service}" if [ $? -ne 0 ]; then rm -f "${add_lib_link_service}" fi cp -f "${add_boot_link_service}" "${add_lib_link_service}" log_debug "cp -f ${add_boot_link_service} ${add_lib_link_service}" fi #TD 73898 避免已存在service文件且不是软链接,可能引起systemctl reenable执行失败 if [ -d "${g_systemd_etc_dir}" ]; then rm -f "${add_etc_link_service}" fi systemctl reenable "${g_boot_shell_file}" log_debug "systemctl reenable ${g_boot_shell_file}.service" sync 2>/dev/null } #add start all startall(){ local add_boot_file_path="" local link_file_path="" local rc_dir="" # check whether the init.d directory is exist if [ ! -d "${g_init_d_dir}" ]; then #if the system is redflag, then exec the other process if [ "${g_is_redflag}" = "1" ]; then if [ -d "${g_systemd_usr_dir}" ]; then startall_redflag return 0 fi fi return 1 fi #check whther system support systemd,including centos 7 or higher centos version if [ ${g_need_systemd} -eq 1 ];then #handle this as same as redflag startall_redflag return 0 fi add_boot_file_path="${g_tools_install_dir}/${g_boot_shell_file}" link_file_path="${g_init_d_dir}/${g_boot_shell_file}" ln -s -f "${add_boot_file_path}" "${link_file_path}" log_debug "ln -s -f ${add_boot_file_path} ${link_file_path}" add_boot_file_path="${g_init_d_dir}/${g_boot_shell_file}" if [ -d "${g_rcd_rc_dir[1]}" ]; then rc_dir_list=${g_rcd_rc_dir[@]} else rc_dir_list=${g_rc_dir[@]} fi for rc_dir in ${rc_dir_list} do # check whether the rc directory is exist if [ ! -d "${rc_dir}" ]; then return 1 fi link_file_path="${rc_dir}/${g_boot_link_file_name}" ln -s -f "${add_boot_file_path}" "${link_file_path}" log_debug "ln -s -f ${add_boot_file_path} ${link_file_path}" done return 0 } stopall(){ test -z "${g_boot_shell_file}" && return 1 if [ ! -d "${g_init_d_dir}" ]; then if [ "${g_is_redflag}" = "1" ]; then if [ -d "${g_systemd_usr_dir}" ]; then rm -f "${g_systemd_usr_dir}/${g_boot_shell_file}.service" log_debug "delete ${g_systemd_usr_dir}/${g_boot_shell_file}.service" fi if [ -d "${g_systemd_etc_dir}" ]; then rm -f "${g_systemd_etc_dir}/${g_boot_shell_file}.service" log_debug "delete ${g_systemd_etc_dir}/${g_boot_shell_file}.service" fi if [ -d "${g_systemd_lib_dir}" ]; then rm -f "${g_systemd_lib_dir}/${g_boot_shell_file}.service" log_info "delete ${g_systemd_lib_dir}/${g_boot_shell_file}.service" fi return 0 fi return 1 fi if [ ${g_need_systemd} -eq 1 ];then systemctl disable "${g_boot_shell_file}.service" log_debug "systemctl disable ${g_boot_shell_file}.service" if [ -d "${g_systemd_usr_dir}" ]; then rm -f "${g_systemd_usr_dir}/${g_boot_shell_file}.service" log_debug "delete ${g_systemd_usr_dir}/${g_boot_shell_file}.service" fi #TD 73898 避免已存在service文件且不是软链接,可能引起systemctl disable执行失败 if [ -d "${g_systemd_etc_dir}" ]; then rm -f "${g_systemd_etc_dir}/${g_boot_shell_file}.service" log_debug "delete ${g_systemd_etc_dir}/${g_boot_shell_file}.service" fi if [ -d "${g_systemd_lib_dir}" ]; then rm -f "${g_systemd_lib_dir}/${g_boot_shell_file}.service" log_info "delete ${g_systemd_lib_dir}/${g_boot_shell_file}.service" fi return 0 fi local link_file_path="" local rc_dir="" test -z "${g_boot_link_file_name}" && return 1 if [ -d "${g_rcd_rc_dir[1]}" ]; then rc_dir_list=${g_rcd_rc_dir[@]} else rc_dir_list=${g_rc_dir[@]} fi for rc_dir in ${rc_dir_list} do test -z "${rc_dir}" && continue link_file_path="${rc_dir}/${g_boot_link_file_name}" rm -f "${link_file_path}" log_debug "delete ${link_file_path}" done test -z "${g_init_d_dir}" && return 1 link_file_path="${g_init_d_dir}/${g_boot_shell_file}" rm -f "${link_file_path}" log_debug "delete ${link_file_path}" return 0 } # TEST startall TEST_startall(){ log_debug "TEST_startall" local rc_dir="" local link_file_path="" startall if [ -L "${g_init_d_dir}/${g_boot_shell_file}" ];then if [ "$(readlink "${g_init_d_dir}/${g_boot_shell_file}")" = "${g_tools_install_dir}/${g_boot_shell_file}" ];then log_debug "${g_init_d_dir}/${g_boot_shell_file} success!" fi else log_error "${g_init_d_dir}/${g_boot_shell_file} failed!" log_error "TEST_startall failed!" stopall return 1 fi if [ -d "${g_rcd_rc_dir[1]}" ]; then rc_dir_list=${g_rcd_rc_dir[@]} else rc_dir_list=${g_rc_dir[@]} fi for rc_dir in ${rc_dir_list} do link_file_path="${rc_dir}/${g_boot_link_file_name}" if [ -L "${link_file_path}" ];then if [ "$(readlink "${link_file_path}")" = "${g_init_d_dir}/${g_boot_shell_file}" ];then log_debug "${g_init_d_dir}/${g_boot_shell_file} success!" fi else log_error "${link_file_path} failed!" log_error "TEST_startall failed!" stopall return 1 fi done stopall return 0 } # TEST stopall TEST_stopall(){ log_debug "TEST_stopall" local link_file_path="" local rc_dir="" startall stopall if [ -d "${g_rcd_rc_dir[1]}" ]; then rc_dir_list=${g_rcd_rc_dir[@]} else rc_dir_list=${g_rc_dir[@]} fi for rc_dir in ${rc_dir_list} do link_file_path="${rc_dir}/${g_boot_link_file_name}" if [ -e "${link_file_path}" ];then log_error "${link_file_path} failed" log_error "TEST_stopall failed!" return 1 fi done link_file_path="${g_init_d_dir}/${g_boot_shell_file}" if [ -e "${link_file_path}" ];then log_error "${link_file_path} failed" log_error "TEST_stopall failed!" return 1 fi return 0 } #monitor server monitor_server(){ # monitor services local service_name="" for service_name in ${g_sangfor_services[@]} do watchdog_reg_proccess "${service_name}" log_debug "watch ${service_name}" done return 0 } #cancel monitor server unmonitor_server(){ local service_name="" for service_name in ${g_sangfor_services[@]} do watchdog_unreg_process "${service_name}" log_debug "watchdog_unreg_process ${service_name}" done return 0 } TEST_monitor_server(){ log_debug "TEST_monitor_server" monitor_server local dog_dir="/var/sangfor/watchdog" #这个路径来源于监控服务 local service_name="" for service_name in ${g_sangfor_services[@]} do if [ ! -e "${dog_dir}/${service_name}" ];then log_error "${dog_dir}/${service_name} is not exist!" log_error "TEST_monitor_server failed!" unmonitor_server return 1 fi done unmonitor_server return 0 } TEST_unmonitor_server(){ log_debug "TEST_unmonitor_server" monitor_server unmonitor_server local dog_dir="/var/sangfor/watchdog" #这个路径来源于监控服务 local service_name="" for service_name in ${g_sangfor_services[@]} do if [ -e "${dog_dir}/${service_name}" ];then log_error "${dog_dir}/${service_name} is exist!" log_error "TEST_unmonitor_server failed!" return 1 fi done return 0 } sfping_gcc() { local sfping_new_dir=$1 if [ -z "$sfping_new_dir" ]; then log_error "sfping_new_dir = $sfping_new_dir is illegal!" return 1 fi local sfping_c_src="$sfping_new_dir/sfping.c" local sfping_c_dst="$sfping_new_dir/sfping" #判断是否支持gcc local gcc_path=`which gcc` if [ -z "$gcc_path" ]; then log_debug "gcc is not support!" return 0 fi echo "$gcc_path" | grep "no gcc"; if [ $? -eq 0 ]; then log_debug "gcc is not support!" return 0 fi #编译 gcc -o "$sfping_c_dst" "$sfping_c_src" if [ $? -ne 0 ]; then log_error "gcc -o $sfping_c_dst $sfping_c_src failed!" return 0 fi return 0 } #从当前的虚拟化工具同步配置文件到新安装的虚拟化工具目录,例如保存的IP信息配置文件。 #Fix TD 92167,把保存的IP信息文件同步到新安装的虚拟化工具目录下,否则IP设置流程会重新根据Host上的虚拟机设置IP sync_config_file(){ local cur_install_dir=$1 local new_install_dir=$2 local cur_network_configfile="${cur_install_dir}/${g_network_config_file_name}" if [ ! -e "${cur_install_dir}" ] || [ ! -e "${new_install_dir}" ];then log_error "[sync_config_file]${cur_install_dir} or ${new_install_dir} not exit" return 1 fi if [ -e "$cur_network_configfile" ];then log_info "[sync_config_file]copy ${cur_network_configfile} to ${new_install_dir}" cp "${cur_network_configfile}" "${new_install_dir}" if [ $? -ne 0 ]; then log_error "[sync_config_file]copy ${cur_network_configfile} to ${new_install_dir} failed!" return 1 fi fi return 0; } #install tools install_tools(){ local current_version="" local new_version="" local current_install_path="" local new_install_path="" local real_install_path="" if [ -L "${g_tools_install_dir}" ];then real_install_path="$(readlink "${g_tools_install_dir}")" else real_install_path="${g_tools_install_dir}" fi log_debug "real_install_path:${real_install_path}" new_version=`grep -oP '(?<=\<Version\>)[^\<]+' "${g_current_dir}/${g_xml_file_name}" 2>/dev/null` if [ -z "$new_version" ];then new_version=$(sed -n 's/.*<Version>\(.*\)<\/Version>/\1/p' "${g_current_dir}/${g_xml_file_name}" 2>/dev/null) fi if [ "${new_version}" = "" ];then log_error "get version failed! new_version is:${new_version}. " return 1 fi new_install_path="${g_tools_install_dir}_${new_version}" #replace files #Don't replace files if the install program running in the install directory. # g_current_dir is the real install path. g_tools_install_dir is a link if [ "${g_current_dir}" = "${real_install_path}" ];then log_debug "run in the install dir!" else #创建之前先删除一下临时目录 if [ -e "${new_install_path}" ]; then rm -rf "${new_install_path}" fi create_dir "${new_install_path}" cp -rf "${g_current_dir}"/* "${new_install_path}" 2>/dev/null if [ $? -ne 0 ];then log_error "copy file to install directory failed!" show_error "copy file to install directory failed! Please retry." rm -rf "${new_install_path}" return 1 fi check_all_files "${g_current_dir}" "${new_install_path}" if [ $? -ne 0 ];then log_error "copy file success but the file is not the same!" show_error "copy file success but the file is not the same! Please retry." # The copyed file is not same with the src file. rm -rf "${new_install_path}" return 1 fi sfping_gcc "${new_install_path}" #rm sfping.c rm -f "${new_install_path}/sfping.c" if [ ! -e "${g_tools_install_dir}" ];then # not exist. The first installation. current_install_path="${g_tools_install_dir}_no_exist" #Special treatment for delete. (grep) else # exist if [ ! -L "${g_tools_install_dir}" ];then # not a link current_version=`grep -oP '(?<=\<Version\>)[^\<]+' "${g_tools_install_dir}/${g_xml_file_name}" 2>/dev/null` if [ -z "$current_version" ];then current_version=$(sed -n 's/.*<Version>\(.*\)<\/Version>/\1/p' "${g_tools_install_dir}/${g_xml_file_name}" 2>/dev/null) fi if [ "${current_version}" = "" ];then # get version failed current_install_path="${g_tools_install_dir}_0.0.0" else current_install_path="${g_tools_install_dir}_${current_version}" fi mv -f "${g_tools_install_dir}" "${current_install_path}" 2>/dev/null #不存在的时候会报错 else #It is a link. current_install_path="$(readlink "${g_tools_install_dir}")" fi fi #Fix TD 92167,虚拟化工具升级时候,需要把之前保存的IP信息文件同步到新安装的虚拟化工具目录下,否则IP设置流程会重新根据Host上的虚拟机设置IP if [ -d "${current_install_path}" ];then sync_config_file "${current_install_path}" "${new_install_path}" if [ $? -ne 0 ];then log_error "sync config file from ${current_install_path} to ${new_install_path} failed!" show_error "sync config file from ${current_install_path} to ${new_install_path} failed." rm -rf "${new_install_path}" return 1 fi fi # flush NEW version of vmtools into disk sync 2>/dev/null # change the link ln -s -n -f "${new_install_path}" "${g_tools_install_dir}" if [ $? -ne 0 ];then log_error "ln -s -f ${new_install_path} ${g_tools_install_dir} failed!" ln -s -n -f "${current_install_path}" "${g_tools_install_dir}" rm -rf "${new_install_path}" return 1 fi # flush the changes of vmtools into disk sync 2>/dev/null # Delete files. find "${g_sangfor_vmtools_parent_dir}" -wholename "${g_tools_install_dir}_*" | grep -v "${new_install_path}" | grep -v "${current_install_path}" |xargs -i rm -rf {} fi # stop the old version of vmtools before starting NEW version. unmonitor_server stop_services # 如果是从libguestfs环境启动安装脚本,则不运行服务 if [ x"${g_backend_type}" != x"libguestfs" ];then start_services fi return 0 } #start all services start_services(){ #start all local service_name="" # start all Sangfor vmtools' services for service_name in ${g_sangfor_services[@]} do #"${g_tools_install_dir}/${service_name}" >/dev/null 2>&1 & "${g_tools_install_dir}/${service_name}" >/dev/null 2>/var/"${service_name}"_error.log & #测试,最后要换成上面代码 log_debug "start ${g_tools_install_dir}/${service_name}" done return 0 } stop_services(){ local service_name="" for service_name in ${g_sangfor_services[@]} do kill_process "${service_name}" 2>/dev/null log_debug "stop ${service_name}" done #stop watch kill_process "${g_watchdog_shell_file}" 2>/dev/null log_debug "stop ${g_watchdog_shell_file}" return 0 } TEST_start_services(){ log_debug "TEST_start_services" start_services sleep 5 #start all services need time local service_name="" local str="" for service_name in ${g_sangfor_services[@]} do str=`ps aux|grep "${service_name}" |grep -v grep` if [ "${str}" = "" ];then log_error "${service_name} not exist!" log_error "TEST_start_services failed!" stop_services return 1 fi done stop_services return 0 } TEST_stop_services(){ log_debug "TEST_stop_services" start_services stop_services sleep 5 #start all services need time local service_name="" local str="" for service_name in ${g_sangfor_services[@]} do str=`ps aux|grep "${service_name}" |grep -v grep` if [ "${str}" != "" ];then log_error "${service_name} exist!" log_error "TEST_start_services failed!" return 1 fi done return 0 } # clean all clean_all(){ #stop monitor unmonitor_server #stop services stop_services #delete boot file stopall #delete file in the install directory. # rm -Rf "${g_tools_install_dir}" 2>/dev/null find "${g_sangfor_vmtools_parent_dir}" -wholename "${g_tools_install_dir}*" |xargs -i rm -rf {} log_debug "delete all file in install dir." return 0 } TEST_clean_all(){ log_debug "TEST_clean_all" clean_all if [ -e "${g_tools_install_dir}" ];then log_error "${g_tools_install_dir} exist!" log_error "TEST_clean_all failed!" return 1 fi return 0 } #trap kill signal signal_term(){ log_error "SIGTERM signal,exit..." exit 1 } #trap int signal signal_int(){ log_error "INT signal,exit..." exit 1 } #Ubuntu系统能支持systemd的最低发行版本 declare -i g_ubuntu_systemd_least_support_version_main=15 #check_whether the redhat or ubuntu system support systemd check_need_systemd(){ local is_ubuntu="" local version_number="" local main_version=0 is_ubuntu="`cat /etc/issue | grep -i \"Ubuntu\"`" if [ x"${is_ubuntu}" != x"" ]; then log_info "the system is ${is_ubuntu}" version_number=`echo ${is_ubuntu} | sed s/[^0-9.]//g` main_version=`echo ${version_number} | tr "." " " | awk '{print $1}'` if [ ${main_version} -lt ${g_ubuntu_systemd_least_support_version_main} ]; then log_info "the system dosen't support systemd" return 1; fi if [ ! -e ${g_systemd_etc_dir} ];then log_info "the system dosen't support systemd" return 1 fi return 0; fi # TD52004 # suse12 sp部分版本/usr/local目录的服务开机读取失败,需要以systemd方式注册 if [ -e /etc/SuSE-release ];then is_suse12=`cat /etc/SuSE-release |grep VERSION |grep 12` is_dir_mounted=`mount | grep "/usr/local"` if [ x"${is_suse12}" != x"" ] && [ x"${is_dir_mounted}" != x"" ]; then log_info "suse system need systemd" return 0 fi fi # TD66909 # suse15 suse15安装vmtools失败,需要以systemd方式注册 if [ -e /etc/os-release ]; then source /etc/os-release 2>/dev/null echo $ID | grep -Ei 'suse|sles' if [ $? -eq 0 ]; then local major_version=${VERSION%%.*} if [ $major_version -ge 12 ]; then log_info "suse system need systemd" return 0 fi fi fi if [ ! -e /etc/redhat-release ];then log_info "the system is not CentOS" return 1 fi if [ ! -e ${g_systemd_usr_dir} ];then log_info "the system dosen't support systemd" return 1 fi log_info "the system is Centos whitch support systemd" return 0 } main(){ local exit_code=1 local is_update=1 g_need_systemd=0 set_log_filepath "/var/log/${g_install_shell_file}.log" #To determine whether the root permissions if [ $UID -ne 0 ]; then log_error "Please re-run this program as the super user." exit 1 fi trap signal_term SIGTERM trap signal_int SIGINT kill_process "${g_install_shell_file}" 2>/dev/null #kill other install process. test -z "${g_tools_install_dir}" && return 1 test -z "${g_current_dir}" && return 1 #rm send directory [ -d "$SEND_DIR__" ] && rm $SEND_DIR__ -rf #rm received directory [ -d "$RECV_DIR__" ] && rm $RECV_DIR__ -rf #check whether the system is redflag local system_type=`cat /etc/issue` [[ "${system_type}" =~ "Red Flag" ]] && g_is_redflag=1 #check whether os support systemd check_need_systemd exit_code=$? if [ ${exit_code} -eq 0 ];then g_need_systemd=1 fi if [ x"$1" = x"uninstall" ];then clean_all return 0 fi if [ x"$1" = x"${g_update_args}" ];then #is update is_update=0 fi # check environment check_env exit_code=$? if [ ${exit_code} -ne 0 ];then log_error "Current environment is not for install!" return 1 fi #To install install_tools exit_code=$? if [ ${exit_code} -ne 0 ];then log_error "Install sangforVMTools failed!" if [ ${is_update} -eq 1 ];then # is install # clean environment clean_all fi return 1 fi log_info "Install sangforVMTools success." #add monitor monitor_server exit_code=$? if [ ${exit_code} -ne 0 ];then log_error "Monitor servers failed!" if [ ${is_update} -eq 1 ];then # install # clean environment clean_all fi return 1 fi log_info "Monitor servers success!" #add boot file startall exit_code=$? if [ ${exit_code} -ne 0 ];then log_error "Add boot failed!" if [ ${is_update} -eq 1 ];then # install # clean environment clean_all fi return 1 fi #TD24457 虚拟化工具在5.4.1版本改名了,如果从5.3及以下版本升级上来的话会冗余旧 #的vmtools,这里做一个清理,删掉SangforVMSTool*的文件 log_info "Remove /user/local/SangforVMSTool files." rm -rf "${g_sangfor_vmtools_parent_dir}/SangforVMSTool"* log_info "Install all success." return 0 } TEST(){ set_log_filepath "/var/log/${g_install_shell_file}.log" mkdir -p "${g_tools_install_dir}_0.0.0" ln -s -n -f "${g_tools_install_dir}_0.0.0" "${g_tools_install_dir}" cp -rf "${g_current_dir}"/* "${g_tools_install_dir}" TEST_check_command || return 1 TEST_check_shell_tools || return 1 TEST_check_env || return 1 TEST_monitor_server || return 1 TEST_unmonitor_server || return 1 TEST_startall || return 1 TEST_stopall || return 1 TEST_start_services || return 1 TEST_stop_services || return 1 TEST_check_all_files || return 1 TEST_clean_all || return 1 log_debug "TEST all success!" return 0 } if [ "$args" = "TEST" ];then TEST exit $? else main "$args" exit $? fi
Upload File
Create Folder