From 32dd929fea2f0b098d8e55828461daec8886ce88 Mon Sep 17 00:00:00 2001 From: "chenjiahao (A)" Date: Fri, 9 Aug 2024 17:19:00 +0800 Subject: [PATCH] adapt DevKit RC2 --- scripts/devkit/common.sh | 151 +++++++++++++++++++------------ scripts/devkit/install_devkit.sh | 148 ++++++++++++++++++++++-------- scripts/install_devkit.sh | 37 ++++---- 3 files changed, 219 insertions(+), 117 deletions(-) diff --git a/scripts/devkit/common.sh b/scripts/devkit/common.sh index ae19834..3cee71f 100755 --- a/scripts/devkit/common.sh +++ b/scripts/devkit/common.sh @@ -82,7 +82,9 @@ function recommended_os() { read -t "${TIMEOUT}" -r number if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" - exit ${SUCCESS} + return_install_info "install" "Error" "Input timeout" "devkit" + EXIT_FLAG="FALSE" + exit ${ERROR} fi if [[ "$number" == "1" ]]; then echo_and_log "You have selected the CentOS series. We will continue installation tool with CentOS 7.6." "${SUCCESS}" "${log_file_path}" @@ -105,10 +107,12 @@ function recommended_os() { elif [[ "$(input_value_check ${number})" == "no" ]]; then echo_and_log "\nOperation aborted." "${DOING}" "${log_file_path}" echo_and_log "\nEnvironment check canceled." "${DOING}" "${log_file_path}" - exit ${SUCCESS} + EXIT_FLAG="FALSE" + exit ${ERROR} else echo_and_log "\nInvalid input. Environment check canceled." "${DOING}" "${log_file_path}" - exit ${SUCCESS} + EXIT_FLAG="FALSE" + exit ${ERROR} fi elif [[ "${os_support_status}" == 2 ]]; then @@ -133,19 +137,15 @@ function recommended_os() { fi echo -n -e "The default OS version(default os:$os_name) will be used to install the Kunpeng DevKit. Do you want to continue?[y/N]: " echo "The default OS version(default os:$os_name) will be used to install the Kunpeng DevKit. Do you want to continue?[y/N]: " >> ${log_file_path} - read -t "${TIMEOUT}" -r input - if [[ "$?" -gt 128 ]]; then - echo_and_log "Input timeout." "${ERROR}" - exit ${SUCCESS} - fi - local input=$(input_value_check ${input}) + local input="yes" if [[ "${input}" == "yes" ]]; then echo " your selected is ${input}" >> ${log_file_path} echo_and_log "\nContinue the environment check..." "${DOING}" "${log_file_path}" elif [[ "${input}" == "no" ]]; then echo " your selected is ${input}" >> ${log_file_path} echo_and_log "Environment check canceled." "${DOING}" "${log_file_path}" - exit ${SUCCESS} + EXIT_FLAG="FALSE" + exit ${ERROR} else echo_and_log "Invalid input. Environment check canceled." "${ERROR}" "${log_file_path}" fi @@ -157,6 +157,8 @@ function get_os_version() { local install_log_path=$2 # 检查或者安装记录日志 if [[ ${os_type} == "OpenEulerOS" ]]; then os_version=$(cat /etc/os-release |grep VERSION= |awk -F '"' '{print$2}' |awk -F ' ' '{print$1$2}') + elif [[ ${os_type} == "ctyunOS" ]]; then + os_version=$(cat /etc/os-release |grep VERSION= |awk -F '"' '{print$2}' |awk -F ' ' '{print$1$2}') elif [[ ${os_type} == "uosEulerOS" ]]; then os_version=$(cat /etc/os-release |grep VERSION_ID= |awk -F '"' '{print$2}') elif [[ ${os_type} == "EulerOS" ]]; then @@ -305,8 +307,8 @@ function close_opened_ports() { function displaying_check_items(){ echo_and_log "\nInstallation environment check result:" "${ECHO}" "${INSTALL_LOG}" - printf "%-20s %-35s %-14s %-20s\n" " SequenceNumber" "CheckItem" "CheckResult" "Suggestion" - printf "%-2s %-2s %-20s %-35s %-14s %-20s\n" "[$(date "+%Y-%m-%d %H:%M:%S")]" "[INFO]" "SequenceNumber" "CheckItem" "CheckResult" "Suggestion" >> ${INSTALL_LOG} + printf "%-20s %-36s %-20s %-20s\n" " SequenceNumber" "CheckItem" "CheckResult" "Suggestion" + printf "%-2s %-2s %-20s %-36s %-20s %-20s\n" "[$(date "+%Y-%m-%d %H:%M:%S")]" "[INFO]" "SequenceNumber" "CheckItem" "CheckResult" "Suggestion" >> ${INSTALL_LOG} for ((i=0;i<${#CHECK_ITEM[@]};i++)); do if [ "${CheckResult[i]}" == "fail" ]; then local color=31 @@ -316,8 +318,8 @@ function displaying_check_items(){ if [[ "$i" == "${#CHECK_ITEM[@]}" ]]; then return 0 fi - printf "%-20s %-35s \033[1;${color}m%-14s\033[0m \033[1;${color}m%-20s\033[0m\n" " [$((i+1))]" "${CHECK_ITEM[i]}" "${CheckResult[i]}" "${Suggestion[i]}" - printf "%-2s %-2s %-20s %-35s \033[1;${color}m%-14s\033[0m \033[1;${color}m%-20s\033[0m\n" "[$(date "+%Y-%m-%d %H:%M:%S")]" "[INFO]" "[$((i+1))]" "${CHECK_ITEM[i]}" "${CheckResult[i]}" "${Suggestion[i]}" >> ${INSTALL_LOG} + printf "%-20s %-36s \033[1;${color}m%-20s\033[0m \033[1;${color}m%-20s\033[0m\n" " [$((i+1))]" "${CHECK_ITEM[i]}" "${CheckResult[i]}" "${Suggestion[i]}" + printf "%-2s %-2s %-20s %-36s \033[1;${color}m%-20s\033[0m \033[1;${color}m%-20s\033[0m\n" "[$(date "+%Y-%m-%d %H:%M:%S")]" "[INFO]" "[$((i+1))]" "${CHECK_ITEM[i]}" "${CheckResult[i]}" "${Suggestion[i]}" >> ${INSTALL_LOG} done echo "" } @@ -337,13 +339,14 @@ function get_user_choice(){ read -t "${TIMEOUT}" -p "Do you want to authorize the tool to handle the items failed in the installation environment check?[y/N]: " input if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" exit ${ERROR} fi echo "The installation environment is checked. View the handling suggestions for the items that fail to pass the check" >> "${INSTALL_LOG}" echo "Do you want to authorize the tool to handle the items failed in the installation environment check? You input is:$y_n" >> "${INSTALL_LOG}" echo "Installation Start Phase:Clearable=True" >> ${INSTALL_LOG} local input=$(input_value_check ${input}) - if [[ "${input}" == "yes" ]] || [[ -z "${input}" ]]; then + if [[ "${input}" == "yes" ]]; then user_choice=yes return 0 elif [[ "${input}" == "no" ]]; then @@ -432,7 +435,7 @@ function init_need_install_lib() { essential_need_install_lib_print[${#essential_need_install_lib_print[@]}]=${i} done all_need_install_lib=(${essential_need_install_lib_print[@]}) - install_missing_dependence 'install' + install_missing_dependence 'install' 'plugin' } function plugin_lost_dependency_install() { @@ -483,17 +486,23 @@ function resolve_fail_checklist(){ show_dependencies_to_install if [ ${framework_dependencies_status} = 1 ]; then # 执行安装时 - install_missing_dependence 'install' + install_missing_dependence 'install' "framework" if [ $? -ne 0 ]; then - exit ${SUCCESS} + EXIT_FLAG="FALSE" + exit ${ERROR} fi fi plugin_lost_dependency_install + # 先处理重复安装的清理,否则会影响/etc/sudoers配置 + if [[ "${CheckResult[7]}" = "fail" || ${status_of_install_folders} == 2 ]]; then + # 可以判定为用户已经安装了工具,删除安装路径 执行清理动作,删除目录,删除各种配置文件 + close_opened_ports "${old_install_path}/DevKit/config/install.ini" "${INSTALL_LOG}" + init_env_common "reinstall" + fi if [[ "${CheckResult[4]}" = "fail" ]]; then deal_devkit_sudoers_config logger "The /etc/sudoers.d/devkit_sudoers is configured successfully." fi - if [[ "${CheckResult[5]}" = "fail" ]]; then # 删除devkit的定时任务 which crontab >/dev/null 2>&1 @@ -513,11 +522,7 @@ function resolve_fail_checklist(){ # 清理/home/devkit [[ -d "/home/devkit" ]] && rm_rf "/home/devkit" fi - if [[ "${CheckResult[7]}" = "fail" || ${status_of_install_folders} == 2 ]]; then - # 可以判定为用户已经安装了工具,删除安装路径 执行清理动作,删除目录,删除各种配置文件 - close_opened_ports "${install_ini}" "${INSTALL_LOG}" - init_env_common - fi + } @@ -606,6 +611,7 @@ function firewall_status_of_debian(){ read -t "${TIMEOUT}" -p "Are you agree to install the ufw command?[y/N],(default:y): " input if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" return 0 fi # 默认为yes @@ -710,20 +716,33 @@ function prepare_check_result(){ CheckResult[0]='ok' Suggestion[0]=${install_user_is_root[1]} fi - if [[ ${sudo_has_s_permission} == 1 ]];then + + + if [[ ${sudo_uninstall_status} != 1 ]];then CheckResult[1]="fail" - Suggestion[1]=${sudo_s_fail_info[1]} + Suggestion[1]=${sudo_uninstall_info[1]} else - CheckResult[1]='ok' - Suggestion[1]=${sudo_s_success_info[1]} + if [[ ${sudo_has_s_permission} == 1 ]];then + CheckResult[1]="fail" + Suggestion[1]=${sudo_s_fail_info[1]} + else + CheckResult[1]='ok' + Suggestion[1]=${sudo_s_success_info[1]} + fi fi - if [[ ${su_has_s_permission} == 1 ]];then + if [[ ${su_uninstall_status} != 1 ]];then CheckResult[2]="fail" - Suggestion[2]=${su_s_fail_info[1]} + Suggestion[2]=${su_uninstall_info[1]} else - CheckResult[2]='ok' - Suggestion[2]=${su_s_success_info[1]} + if [[ ${su_has_s_permission} == 1 ]];then + CheckResult[2]="fail" + Suggestion[2]=${su_s_fail_info[1]} + else + CheckResult[2]='ok' + Suggestion[2]=${su_s_success_info[1]} + fi fi + if [[ ${pam_rootok_config_status} == 1 ]];then CheckResult[3]="fail" Suggestion[3]=${pam_rootok_fail_info[1]} @@ -950,7 +969,6 @@ function add_devkit_sudo_list(){ ) if [[ "${architecture}" == "aarch64" ]]; then # 提权脚本 - local perf_path=$(which perf 2>/dev/null) local lspci_path=$(which lspci 2>/dev/null) local numastat_path=$(which numastat 2>/dev/null) parameter_list+=( @@ -960,10 +978,10 @@ function add_devkit_sudo_list(){ "${DEVKIT_TOOL_PATH}/set_env.sh *" "${DEVKIT_TOOL_PATH}/pidstat.sh *" "${DEVKIT_TOOL_PATH}/perf record *" + "${DEVKIT_TOOL_PATH}/perf script *" "${DEVKIT_TOOL_PATH}/perf_archive" "${DEVKIT_TOOL_PATH}/directory_retrieval" "${DEVKIT_TOOL_PATH}/perf buildid-cache *" - "${perf_path} script *" "${lspci_path}" "${numastat_path}" ) @@ -1123,10 +1141,15 @@ function init_env_common(){ # recover_mount # 清理证书内容 delete_rsa_file ${install_path} - # 工具安装时添加的配置,卸载时删掉 if [[ "${sudoers_devkit_config_exists}" == "1" ]]; then - sed -i "/^#includedir \/etc\/sudoers.d$/d" /etc/sudoers + local install_ini="${install_path}/DevKit/config/install.ini" + if [ -f "${install_ini}" ]; then + sudoers_config=$(grep -w SUDOERS_CONFIG ${install_ini} | awk -F= '{if($2 !="") print $2}') + if [[ "${sudoers_config}" == "1" ]]; then + sed -i "/^#includedir \/etc\/sudoers.d$/d" /etc/sudoers + fi + fi fi # 清除工具添加的devkit_sudoers文件 if [ -f "/etc/sudoers.d/devkit_sudoers" ];then @@ -1255,15 +1278,20 @@ function check_sso_legitimate() { # 用户选择了所有的插件 function choose_all_plugin() { - install_tool=$(echo ${plugins_support_list[@]} | tr ' ' ',') + plugins_support_list=($(echo ${plugins_support_list[@]} | tr ' ' ' ')) + plugins_support_num=${#plugins_support_list[@]} if [[ ${architecture} != "aarch64" ]]; then - install_tool=${install_tool%,debugger,sys_perf,java_perf*} - install_tool=$(echo $install_tool | awk -F ",affinity" '{print $1$2}') + install_tool="porting,devtools" else - if [[ ${env_type} == 0 ]]; then - install_tool=$(echo $install_tool | awk -F ",affinity" '{print $1$2}') - fi + install_tool="" + for ((i = 0; i < ${plugins_support_num}; i++)); do + check_result=$(${CURRENT_DIR}/check_env ${plugins_support_list[i]}) + if [[ "$?" == 1 ]]; then + install_tool="${install_tool} ${plugins_support_list[i]}" + fi + done fi + install_tool=$(echo ${install_tool} | tr ' ' ',') } # 检查用户选择插件是否重复 @@ -1308,7 +1336,8 @@ function check_plugin_legitimate() { flag=1 fi done - if [[ ${flag} != 1 ]] || [[ ${env_type} == 0 && ${plugin_name} == "affinity" ]]; then + check_result=$(${CURRENT_DIR}/check_env ${plugin_name}) + if [[ "$?" == 0 ]]; then choose_plugin_invalid_tip fi fi @@ -1923,6 +1952,7 @@ function install_asm_dep() { change_asm_dep_permission ${install_path}/DevKit/devkitplugins/all_asm/lib/libpthread.so.0 change_asm_dep_permission ${install_path}/DevKit/devkitplugins/all_asm/lib/libdl.so.2 change_asm_dep_permission ${install_path}/DevKit/devkitplugins/all_asm/lib/ld-linux-aarch64.so.1 + change_asm_dep_permission ${install_path}/DevKit/devkitplugins/all_asm/lib/ld-linux-x86-64.so.2 fi if [ -d "${install_path}/DevKit/devkitplugins/inline_asm/remill/lib" ]; then chown ${USER_NAME}:${USER_NAME} "${install_path}"/DevKit/devkitplugins/inline_asm/remill/lib/* @@ -1931,6 +1961,7 @@ function install_asm_dep() { change_asm_dep_permission ${install_path}/DevKit/devkitplugins/inline_asm/remill/lib/libpthread.so.0 change_asm_dep_permission ${install_path}/DevKit/devkitplugins/inline_asm/remill/lib/libdl.so.2 change_asm_dep_permission ${install_path}/DevKit/devkitplugins/inline_asm/remill/lib/ld-linux-aarch64.so.1 + change_asm_dep_permission ${install_path}/DevKit/devkitplugins/inline_asm/remill/lib/ld-linux-x86-64.so.2 fi if [[ -n ${install_path} && -d "${install_path}/DevKit/devkitplugins/all_asm/tmp/rpm" ]]; then rm -rf "${install_path}"/DevKit/devkitplugins/all_asm/tmp/rpm/* @@ -2061,20 +2092,6 @@ function config_libffi() echo_and_log "The libffi path is configured successfully." "${SUCCESS}" "${log_file}" } -check_cpu_type(){ - # 获取操作系统 - if [[ -f "${CURRENT_DIR}/check_env" ]] ; then - return_type=$(${CURRENT_DIR}/check_env && echo $?) - if [[ "${return_type}" == 0 ]] ; then - env_type=1 - else - env_type=0 - fi - else - env_type=0 - fi -} - function get_cpu_id() { open_file_num=8192 } @@ -2296,13 +2313,29 @@ function is_orange_pi() { } function is_supported_arm() { + local check_type="$1" current_cpu_id="unknown" if [ -f "${CPU_ID_FILE}" ]; then current_cpu_id=$(cat "${CPU_ID_FILE}") fi - if [[ "${SUPPORTED_ARM[@]}" =~ "${current_cpu_id}" ]]; then - return "${SUCCESS}" + if [[ "${check_type}" == "agent" ]]; then + for value in "${SUPPORTED_ARM_AGENT[@]}" + do + if [[ "${current_cpu_id}" = "${value}" ]]; then + return "${SUCCESS}" + fi + done else + for value in "${SUPPORTED_ARM[@]}" + do + if [[ "${current_cpu_id}" = "${value}" ]]; then + return "${SUCCESS}" + fi + done + fi return "${ERROR}" + return "${ERROR}" + fi + return "${ERROR}" fi } diff --git a/scripts/devkit/install_devkit.sh b/scripts/devkit/install_devkit.sh index 4df494e..be51028 100755 --- a/scripts/devkit/install_devkit.sh +++ b/scripts/devkit/install_devkit.sh @@ -55,10 +55,32 @@ check_sudoers() { fi } +function sudo_cmd_check() { + sudo_uninstall_status=0 + su_uninstall_status=0 + # 检查sudo su命令是否存在 + if (sudo -h >/dev/null 2>&1); then + sudo_uninstall_status=1 + fi + if (su -h >/dev/null 2>&1); then + su_uninstall_status=1 + fi +} + +function get_cmd_path() { + local command="$1" + local cmd_path=$(type ${command} 2>&1 | awk -F " " '{print $NF}') + if [[ ${cmd_path} =~ '(' ]]; then + cmd_path=${cmd_path%)} + cmd_path=${cmd_path#(} + fi + echo ${cmd_path} +} + # sudo权限检查,必须有s权限 -function sudo_check_failed() { +function sudo_check_failed(){ local command="$1" - local sudo_path=$(which ${command}) + local sudo_path=$(get_cmd_path ${command}) if [[ "${sudo_path}" == "" ]]; then return "${SUCCESS}" fi @@ -113,16 +135,21 @@ function check_nOk_exit() { sudo_has_s_permission=0 su_has_s_permission=0 pam_rootok_config_status=0 - if (sudo_check_failed "sudo"); then - sudo_has_s_permission=1 - fi - if (sudo_check_failed "su"); then - su_has_s_permission=1 + sudo_cmd_check + if [[ "${sudo_uninstall_status}" == 1 ]]; then + if (sudo_check_failed "sudo"); then + sudo_has_s_permission=1 + fi fi + if [[ "${su_uninstall_status}" == 1 ]]; then + if (sudo_check_failed "su"); then + su_has_s_permission=1 + fi + fi + if (pam_rootok_failed); then pam_rootok_config_status=1 fi - } function record_plugin_lost_dependency() { @@ -175,6 +202,7 @@ function check_plugins_env(){ tar zxfm ${current_dir}/toolkit.tar.gz local cms_bin_path="${current_dir}/toolkit/cms" for plugin in $(echo ${plugins} | tr "," " ");do + plugin=${plugin##devkit.} local plugin_package_name=${PLUGIN_NAME_MAPPING["${plugin}"]} tar zxfm "${plugin_package_name}.tar.gz" cd ${current_dir}/${plugin_package_name} @@ -255,7 +283,7 @@ function get_available_port() { incremental_port continue else - if [[ "${plugin_gunicorn_port},${nginx_port}" =~ ${port} ]]; then + if [[ "${plugin_gunicorn_port},${nginx_port},${http_listen_port},${grpc_listen_port}" =~ ${port} ]]; then # 端口不能和任何一个有重复 incremental_port continue @@ -264,6 +292,7 @@ function get_available_port() { read -t "${TIMEOUT}" answer if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" exit ${ERROR} fi local answer=$(input_value_check ${answer}) @@ -335,7 +364,7 @@ function show_color_tip() { } function show_plugin_support() { - # Display the software supported by the current system user. + # Display the software supported by the current system user. # check_result_list 记录支持不支持状态 echo " " echo "Select the plugins to be installed::" ${TIP_COLOR_CHECKING} @@ -343,13 +372,14 @@ function show_plugin_support() { printf "%-20s %-20s %-20s\n" " SequenceNumber" "Plug-in" "Support" plugins_support_list=($(echo ${plugins_support_list[@]} | tr ' ' ' ')) plugins_support_num=${#plugins_support_list[@]} - if [[ ${env_type} == 0 || ${architecture} == "x86_64" ]]; then - check_result_list_arm_sso[1]='n' - check_result_list_x86_sso[1]='n' - check_result_list_arm[1]='n' - check_result_list_x86[1]='n' - fi for ((i = 0; i < ${plugins_support_num}; i++)); do + check_result=1 + if [[ "$?" == 0 ]]; then + check_result_list_arm_sso[i]='n' + check_result_list_arm[i]='n' + fi + done + for ((i = 0; i < ${plugins_support_num}; i++)); do if [[ "${architecture}" == "aarch64" ]]; then if [[ "${devkit_install_type}" == "2" ]]; then show_color_tip "${check_result_list_arm_sso[i]}" @@ -374,6 +404,7 @@ function show_plugin_support() { done } + function user_choose_plugin() { while true; do num=${#plugins_support_list[@]} @@ -383,6 +414,7 @@ function user_choose_plugin() { read -t "${TIMEOUT}" -r choose_install if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" exit ${ERROR} fi if [[ "${choose_install}" =~ ^[nN]$|^no$ ]]; then @@ -473,6 +505,7 @@ function choose_install_software() { read -t "${TIMEOUT}" install_tool if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" exit ${ERROR} fi fi @@ -518,6 +551,7 @@ function get_install_path() { read -t "${TIMEOUT}" install_path if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" exit ${ERROR} fi if [[ -z "${install_path}" ]]; then @@ -613,41 +647,49 @@ function get_install_port() { read -t "${TIMEOUT}" port if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" exit ${ERROR} fi fi if [[ "$1" == "nginx_port" ]]; then port=${port:="8086"} - echo -e " Selected Nginx port: ${port}" + port_type="Nginx" elif [[ "$1" == "grpc_listen_port" ]]; then port=${port:="50051"} - echo -e " Selected RPC cluster server port: ${port}" + port_type="RPC cluster server" elif [[ "$1" == "http_listen_port" ]]; then port=${port:="8002"} - echo -e " Selected HTTP server port: ${port}" + port_type="HTTP server" fi check_port_effective "${port}" if [[ "$?" != "${SUCCESS}" ]]; then continue else - port="${input_port}" check_port_is_occupied "${port}" if [[ "$?" != "${SUCCESS}" ]]; then get_available_port "${port}" port="${available_port}" break else - port=${input_port} + if [[ "${plugin_gunicorn_port},${nginx_port},${http_listen_port},${grpc_listen_port}" =~ ${input_port} ]]; then + # 端口不能和任何一个有重复 + echo " The default port ${port} of ${port_type} has been occupied. Select another port." + get_available_port "${port}" + port="${available_port}" + fi break fi fi done if [[ "$1" == "nginx_port" ]]; then nginx_port=${port} + echo -e " Selected Nginx port: ${nginx_port}" elif [[ "$1" == "grpc_listen_port" ]]; then grpc_listen_port=${port} + echo -e " Selected RPC cluster server port: ${grpc_listen_port}" elif [[ "$1" == "http_listen_port" ]]; then http_listen_port=${port} + echo -e " Selected HTTP server port: ${http_listen_port}" fi } @@ -658,7 +700,7 @@ function entry_interactive_mode() { } function entry_parameter_mode() { - echo_and_log "Entry parameter mode" "${DOING}" + echo_and_log "Entry parameter mode" "${ECHO}" while [ -n "$1" ]; do case "$1" in -d=* | --dir=*) @@ -781,6 +823,7 @@ function get_server_ip() { read -t "${TIMEOUT}" numb if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" exit ${ERROR} fi if [[ -z "${numb}" ]]; then @@ -808,8 +851,6 @@ function get_server_ip() { fi } - - # 获取安装参数 function get_install_params() { echo_and_log "\nStart obtaining installation parameters." "${ECHO}" "${INSTALL_LOG}" @@ -828,8 +869,6 @@ function get_install_params() { # 用户通过参数方式进入 # 若为香橙派则IP地址设为127.0.0.1 server_ip="127.0.0.1" - echo -e "${sure_info}${server_ip}\n" - if [ -z "${nginx_ip}" ]; then # 映射IP获取 get_install_ip "nginx_ip" @@ -923,6 +962,7 @@ function sso_install_type() { read -t "${TIMEOUT}" devkit_install_type if [[ "$?" -gt 128 ]]; then echo_and_log "Input timeout." "${ERROR}" + return_install_info "install" "Error" "Input timeout" "devkit" exit ${ERROR} fi if [[ "${devkit_install_type}" == "" ]] || [[ "${devkit_install_type}" == "1" ]] || [[ "${devkit_install_type}" == "2" ]]; then @@ -994,6 +1034,8 @@ function install_python() { local i=0 [[ -d "${tool_dir}" ]] && rm_rf "${tool_dir}" mkdir -p "${tool_dir}" + # 创建节点安装包目录 + mkdir "${tool_dir}/agent_install_packages" [[ -f "${tool_log}" ]] && rm_rf "${tool_log}" touch "${tool_log}" chmod 600 "${tool_log}" @@ -1126,7 +1168,6 @@ function deal_asm_package() { local all_asm_path="${install_path}/DevKit/devkitplugins/all_asm" local inline_asm_path="${install_path}/DevKit/devkitplugins/inline_asm" cp -rf ${all_asm_path}/bin/llc ${inline_asm_path}/remill/bin/ - mv ${all_asm_path}/bin/remill-lift-12.0 ${inline_asm_path}/remill/bin/ cp -rf ${all_asm_path}/lib/* ${inline_asm_path}/remill/lib/ } @@ -1160,7 +1201,8 @@ function copy_source() { fi popd > /dev/null fi - + # 汇编相关包文件处理 + deal_asm_package force_mk_dir "${tool_dir}/nginx/conf/location_conf" force_mk_dir "${tool_dir}/nginx/conf/server" force_mk_dir "${install_path}/DevKit/plugin_packages" @@ -1190,6 +1232,7 @@ function copy_source() { mv ${install_path}/DevKit/config/devkit_nginx.conf ${tool_dir}/nginx/conf # 拷贝install.ini 文件到安装目录下 cp_rf "${CURRENT_DIR}/${INSTALL_INI}" ${install_path}/DevKit/config + cp_rf "${CURRENT_DIR}/deployment_help_url.ini" ${install_path}/DevKit/config cp_rf "${CURRENT_DIR}/${INSTALL_INI}" ${install_path}/DevKit/config/install_devkit.ini cp_rf "${CURRENT_DIR}/${INSTALL_INI}" "${DEVKIT_TOOL_PATH}" chmod 400 "${DEVKIT_TOOL_PATH}/${INSTALL_INI}" @@ -1213,8 +1256,10 @@ function copy_source() { cp_rf "${CURRENT_DIR}/build_agent_plugins.sh" ${install_path}/DevKit/tools cp_rf "${CURRENT_DIR}/openssl_contents" ${install_path}/DevKit/tools cp_rf "${CURRENT_DIR}/agent_upgrade_entry.sh" ${install_path}/DevKit/tools + cp_rf "${CURRENT_DIR}/delete_plugin_tables.pyc" ${install_path}/DevKit/tools chmod 700 ${install_path}/DevKit/devkitframework/devkitframework/sock chmod 500 ${install_path}/DevKit/tools/*.sh ${install_path}/DevKit/tools/script_port/*.sh + chmod 500 "${install_path}/DevKit/tools/delete_plugin_tables.pyc" } # 配置venv中python及pip包路径 @@ -1222,7 +1267,7 @@ function config_venv_packages_path() { local install_path="${install_path}/DevKit" local config_python_path="${install_path}/tools/python3/bin/python3" local venv_python_path="${install_path}/tools/python_venv/bin/python3" - local config_list=(python3 django-admin django-admin.py gunicorn sqlformat) + local config_list=(python3 django-admin gunicorn sqlformat) echo_and_log "\nConfigure venv packages path" "${ECHO}" "${INSTALL_LOG}" cd "${install_path}/tools/python_venv/bin" for ((i = 0; i < ${#config_list[@]}; i++)); do @@ -1480,9 +1525,6 @@ function create_rpc_config() { mv ${install_path}/DevKit/tools/rpc_cluster/server/script/run_rpc_client.sh ${script_path} chown devkit:devkit ${script_path}/run_rpc_client.sh chmod 400 ${script_path}/run_rpc_client.sh - mv ${install_path}/DevKit/tools/rpc_cluster/server/script/run_node_devkitclient_by_sudo.sh ${script_path} - chown devkit:devkit ${script_path}/run_node_devkitclient_by_sudo.sh - chmod 400 ${script_path}/run_node_devkitclient_by_sudo.sh if [[ -f "${rpc_server_log_conf}" ]]; then sed_ini "${rpc_server_log_conf}" "/opt/DevKit" "${install_path}/DevKit" 1 fi @@ -1669,6 +1711,11 @@ function exit_clean() { clean_residue fi exit 1 + else + if [ ${exit_code} != 0 ]; then + return_install_info "install" "Error" "End" "devkit" + return_install_info "install" "Deployment_End" "failed" "Deployment_End" + fi fi } @@ -1783,7 +1830,6 @@ function generate_sign() { # 生成agent安装包 function generate_agent_package() { cd "${CURRENT_DIR}" - if [ ! -d "${CURRENT_DIR}/toolkit" ]; then if [ -e "${CURRENT_DIR}/toolkit.tar.gz" ]; then tar zxfm "${CURRENT_DIR}/toolkit.tar.gz" @@ -1822,7 +1868,10 @@ function generate_agent_package() { echo_and_log "File not exists: ${CURRENT_DIR}/${agent_package_list[$i]}, continue" "${DOING}" fi done - + local run_node_devkitclient_by_sudo="${CURRENT_DIR}/run_node_devkitclient_by_sudo.sh" + if [[ -f "${run_node_devkitclient_by_sudo}" ]]; then + mv "${run_node_devkitclient_by_sudo}" "${CURRENT_DIR}/agent_install_package" + fi local home_file_list=(lib libsqlite3 libssl include devkit_conf script) force_mk_dir "${CURRENT_DIR}/agent_install_package/devkit_home" for ((i = 0; i < ${#home_file_list[@]}; i++)); do @@ -1882,7 +1931,6 @@ function generate_agent_package() { if [ -d "${CURRENT_DIR}/agent_install_package" ]; then rm_rf "${CURRENT_DIR}/agent_install_package" fi - # 复制agent安装脚本到安装目录 local agent_deploy_script=(agent_install_entry.sh agent_uninstall_entry.sh agent_uninstall.expect) for ((i = 0; i < ${#agent_deploy_script[@]}; i++)); do @@ -1906,6 +1954,7 @@ function generate_agent_package() { function change_file_path_permission() { # 修改文件的权限 + cd ${install_path}/DevKit/ local devkit_logs_dir=${install_path}/DevKit/logs chmod 400 $(find ${install_path}/DevKit/ -regex ".*\.css\|.*\.js\|.*\.html\|.*\.png\|.*\.svg\|.*\.gif\|.*\.PNG\|.*\.ico\|.*\.md\|.*\.hhc\|.*\.hhk\|.*\.hhp\|.*\.cipher\|.*\.py\|.*\.pyc") chmod 500 $(find ${install_path}/DevKit/tools/python_venv/bin/ -type f) @@ -1978,7 +2027,9 @@ function change_file_path_permission() { chown root:root ${install_path}/DevKit chown root:root ${install_path}/DevKit/config/ chown root:root ${install_path}/DevKit/tools - chmod 600 ${install_path}/DevKit/config/install.ini ${install_path}/DevKit/config/install_devkit.ini + chown root:devkit ${install_path}/DevKit/tools/agent_install_packages + chmod 750 ${install_path}/DevKit/tools/agent_install_packages + chmod 600 ${install_path}/DevKit/config/install.ini ${install_path}/DevKit/config/deployment_help_url.ini ${install_path}/DevKit/config/install_devkit.ini # 更改rpc_cluster权限为最小 if [[ -d ${install_path}/DevKit/tools/rpc_cluster/ ]]; then chmod 700 $(find ${install_path}/DevKit/tools/rpc_cluster/ -type d) @@ -2036,10 +2087,28 @@ function create_record_installed_file() { echo "install_plugin=" > ${record_installed_file_path} } +function check_usr_input_port() { + port_list=(${plugin_gunicorn_port} ${nginx_port} ${http_listen_port} ${grpc_listen_port}) + new_port_list=() + for port in ${port_list[@]};do + if [ -n "${port}" ]; then + new_port_list+=(${port}) + fi + done + uniq_port_list=$(echo ${new_port_list[@]} | sed 's/ /\n/g' | sort | uniq |wc -l) + if [ ${#new_port_list[@]} != ${uniq_port_list} ]; then + echo_and_log "Check the port number. The port number must be unique." "${ERROR}" + exit ${SUCCESS} + fi +} + +function check_cpu_type() { + check_result=1 + function main() { check_vscode_install_tag "install" create_log "${INSTALL_LOG}" - check_cpu_type + check_cpu_type check_system_type check_architecture check_the_package_type @@ -2049,6 +2118,7 @@ function main() { get_package_tool "${INSTALL_LOG}" if [ "$#" != "0" ]; then entry_parameter_mode "$@" + check_usr_input_port fi # 安装方式选择 sso_install_type @@ -2120,6 +2190,8 @@ function main() { del_file_chattr "add" "${install_path}" create_record_installed_file devkit_tools_config_init + # 生成签名密钥,必须放在安装插件之前,因为安装插件时生成节点包需要签名 + generate_sign # 安装插件 install_plugin # 清理python缓存文件 @@ -2127,8 +2199,6 @@ function main() { record_installed_plugins # 任何针对chusbin的修改都会修改cap_setuid状态 setcap cap_setuid=eip ${install_path}/DevKit/tools/chusrbin - # 生成签名密钥 - generate_sign # 生成agent安装包 generate_agent_package # 展示已安装插件信息 diff --git a/scripts/install_devkit.sh b/scripts/install_devkit.sh index 64dc60f..932f8ad 100644 --- a/scripts/install_devkit.sh +++ b/scripts/install_devkit.sh @@ -8,11 +8,11 @@ DEVKIT_ROOT=${OUTPUT}/KunPengDevBoard-DevKit VSCODE_URL="https://vscode.download.prss.microsoft.com/dbazure/download/stable/e170252f762678dec6ca2cc69aba1570769a5d39/code-1.88.1-1712770627.el8.aarch64.rpm" CPPTOOLS_URL="${DEVKIT_ROOT}/cpptools-linux-aarch64.vsix" -KIT_PULGIN_URL="https://mirrors.huaweicloud.com/kunpeng/archive/DevKit/Packages/Kunpeng_DevKit_IDE/Kunpeng%20DevKit-24.0.2.vsix" +KIT_PULGIN_URL="${DEVKIT_ROOT}/kunpengfamily.kunpeng-dev-kit-24.0.2.vsix" MSCEINT_URL="${DEVKIT_ROOT}/MS-CEINTL.vscode-language-pack-zh-hans-1.88.2024041009.vsix" GPC_URL="${DEVKIT_ROOT}/kunpeng-gpc-1.0.0-1.aarch64.rpm" GPC_DEVEL_URL="${DEVKIT_ROOT}/kunpeng-gpc-devel-1.0.0-1.aarch64.rpm" -DEVKIT_URL="https://mirrors.huaweicloud.com/kunpeng/archive/DevKit/Packages/Kunpeng_DevKit/DevKit-All-24.0.T10-Linux-Kunpeng.tar.gz" +DEVKIT_URL="https://mirrors.huaweicloud.com/kunpeng/archive/DevKit/Packages/Kunpeng_DevKit/DevKit-All-24.0.RC2-Linux-Kunpeng.tar.gz" execute_user="openEuler" @@ -26,7 +26,6 @@ function install_kitdeps() git clone ${DEVKIT_REPO} popd fi - download_file ${KIT_PULGIN_URL} ${DEVKIT_ROOT} } function install_plugins() @@ -70,15 +69,15 @@ function install_kunpeng_sdk() function modify_guncorn_service_file() { - sed -i "s%#INSTALL_PATH#%/opt%g" ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/gunicorn_plugin.service - sed -i "s%#INSTALL_PATH#%/opt%g" ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/gunicorn_framework.service - sed -i "s%#INSTALL_PATH#%/opt%g" ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/devkit_nginx.service - sed -i "s%#USER_PATH#%/home/devkit%g" ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/gunicorn_plugin.service - sed -i "s%#USER_PATH#%/home/devkit%g" ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/gunicorn_framework.service - sed -i "s%#USER_PATH#%/home/devkit%g" ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/devkit_nginx.service - cp -f ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/devkit_nginx.service ${ROOTFS}/usr/lib/systemd/system/devkit_nginx.service - cp -f ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/gunicorn_plugin.service ${ROOTFS}/usr/lib/systemd/system/gunicorn_plugin.service - cp -f ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/config/gunicorn_framework.service ${ROOTFS}/usr/lib/systemd/system/gunicorn_framework.service + sed -i "s%#INSTALL_PATH#%/opt%g" ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/gunicorn_plugin.service + sed -i "s%#INSTALL_PATH#%/opt%g" ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/gunicorn_framework.service + sed -i "s%#INSTALL_PATH#%/opt%g" ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/devkit_nginx.service + sed -i "s%#USER_PATH#%/home/devkit%g" ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/gunicorn_plugin.service + sed -i "s%#USER_PATH#%/home/devkit%g" ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/gunicorn_framework.service + sed -i "s%#USER_PATH#%/home/devkit%g" ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/devkit_nginx.service + cp -f ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/devkit_nginx.service ${ROOTFS}/usr/lib/systemd/system/devkit_nginx.service + cp -f ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/gunicorn_plugin.service ${ROOTFS}/usr/lib/systemd/system/gunicorn_plugin.service + cp -f ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/config/gunicorn_framework.service ${ROOTFS}/usr/lib/systemd/system/gunicorn_framework.service run_on_rootfs "systemctl enable gunicorn_plugin.service" run_on_rootfs "systemctl enable gunicorn_framework.service" @@ -89,19 +88,19 @@ function modify_guncorn_service_file() { function install_kit() { download_file "$DEVKIT_URL" "${DEVKIT_ROOT}" - tar zxf ${DEVKIT_ROOT}/DevKit-All-24.0.T10-Linux-Kunpeng.tar.gz -C ${OUTPUT}/ - tar zxf ${OUTPUT}/DevKit-All-24.0.T10-Linux-Kunpeng/DevKit-All-24.0.T10-Linux-Kunpeng.tar.gz -C ${OUTPUT}/ - mv ${OUTPUT}/DevKit-All-24.0.T10-Linux-Kunpeng ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng - cp -f ${SRC}/scripts/devkit/common.sh ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/common.sh - cp -f ${SRC}/scripts/devkit/install_devkit.sh ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng/install_devkit.sh + tar zxf ${DEVKIT_ROOT}/DevKit-All-24.0.RC2-Linux-Kunpeng.tar.gz -C ${OUTPUT}/ + tar zxf ${OUTPUT}/DevKit-All-24.0.RC2-Linux-Kunpeng/DevKit-All-24.0.RC2-Linux-Kunpeng.tar.gz -C ${OUTPUT}/ + mv ${OUTPUT}/DevKit-All-24.0.RC2-Linux-Kunpeng ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng + cp -f ${SRC}/scripts/devkit/common.sh ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/common.sh + cp -f ${SRC}/scripts/devkit/install_devkit.sh ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng/install_devkit.sh cp -f ${SRC}/scripts/devkit/deploy_devkit.sh ${ROOTFS}/tmp/deploy_devkit.sh mount_chroot ${ROOTFS} - run_on_rootfs "expect /tmp/deploy_devkit.sh /tmp/DevKit-All-24.0.T10-Linux-Kunpeng" + run_on_rootfs "expect /tmp/deploy_devkit.sh /tmp/DevKit-All-24.0.RC2-Linux-Kunpeng" modify_guncorn_service_file umount_chroot ${ROOTFS} - rm -rf ${ROOTFS}/tmp/DevKit-All-24.0.T10-Linux-Kunpeng + rm -rf ${ROOTFS}/tmp/DevKit-All-24.0.RC2-Linux-Kunpeng } -- Gitee