diff --git a/devkit-kunpeng-porting.spec b/devkit-kunpeng-porting.spec new file mode 100644 index 0000000000000000000000000000000000000000..1a0d2188470d5160e0482c666ccf2505b4e92bbd --- /dev/null +++ b/devkit-kunpeng-porting.spec @@ -0,0 +1,62 @@ +%define debug_package %{nil} + +Name: kunpeng-porting-advisor +Version: 2.5.0 +Release: 1 +Summary: kunpeng porting advisor +License: GPL + +BuildRequires: gcc +Requires: unzip rpm-build rpmdevtools java-devel sudo expect gcc make zlib-devel zlib pcre-devel pcre openssl-devel openssl wget cpio rpm acl lsof bzip2 libcap crontabs e2fsprogs + + +%description +Kunpeng Porting Advisor + +%prep +echo "prep..." + +%build +echo "build..." +cd %{_sourcedir} +wget https://kunpeng-repo.obs.cn-north-4.myhuaweicloud.com/Porting%20Advisor/Porting%20Advisor%202.5.0/Porting-advisor_2.5.0_linux-Kunpeng.tar.gz + +%install +echo "install..." +PortingDir=$RPM_BUILD_ROOT/home/devkit-porting +mkdir -p ${PortingDir} +cp %{_sourcedir}/Porting-advisor_2.5.0_linux-Kunpeng.tar.gz ${PortingDir} + +%files +/home/devkit-porting/Porting-advisor_2.5.0_linux-Kunpeng.tar.gz + +#%doc + +%pre +echo "pre install..." + +%post +echo "post install..." +PortingDir=/home/devkit-porting +PortingInstallDir=${PortingDir}/Porting-advisor_2.5.0_linux-Kunpeng +PortingEndInstallDir=${PortingDir}/Porting-advisor_2.5.0_linux-Kunpeng/Porting-advisor_2.5.0_linux-Kunpeng + +cd ${PortingDir} +tar -xf Porting-advisor_2.5.0_linux-Kunpeng.tar.gz + +cd ${PortingInstallDir} +tar -xf Porting-advisor_2.5.0_linux-Kunpeng.tar.gz +cd ${PortingEndInstallDir} +git am %{_specdir}/remove-the-interaction.patch +bash .install.sh web + +%preun +echo "pre uninstaller..." +bash /opt/portadv/tools/uninstall.sh + +%postun +echo "post uninstall..." + + +%changelog + diff --git a/remove-the-interaction.patch b/remove-the-interaction.patch new file mode 100644 index 0000000000000000000000000000000000000000..923fd1f167a3330450845954e4c7457488e7d10e --- /dev/null +++ b/remove-the-interaction.patch @@ -0,0 +1,535 @@ +From 6fa554432e1f0b3ed42439e82e3a5f87adf5aa6c Mon Sep 17 00:00:00 2001 +From: abc +Date: Tue, 7 Mar 2023 11:05:52 +0800 +Subject: [PATCH] remove the interaction + +--- + check_install_env.sh | 29 ++----- + common_func.sh | 57 ++++++-------- + common_path.sh | 47 ++---------- + const.conf | 3 +- + install_webfunc.sh | 179 ++++--------------------------------------- + start_install.sh | 2 +- + uninstall.sh | 51 ------------ + 7 files changed, 52 insertions(+), 316 deletions(-) + mode change 100755 => 100644 uninstall.sh + +diff --git a/check_install_env.sh b/check_install_env.sh +index 5a5f252..d963e6c 100644 +--- a/check_install_env.sh ++++ b/check_install_env.sh +@@ -135,8 +135,8 @@ get_user_choice(){ + if [[ "$j" == "1" ]]; then + logger "Warning: The installation environment check failed. Read the following carefully." ${TIP_COLOR_WARNING} + fi +- if [[ "$i" -le "2" ]]; then +- logger "The check items 1 to 3 fails, proceed according to the handling suggestions." ${TIP_COLOR_WARNING} ++ if [[ "$i" -le "1" ]]; then ++ logger "The check items 1 to 2 fails, proceed according to the handling suggestions." ${TIP_COLOR_WARNING} + logger "Failed to check the environment. Perform related operations based on the suggestions and reinstall the tool." "ERROR" + logger "Installation canceled." ${TIP_COLOR_SUCCESS} + exit 1 +@@ -150,26 +150,7 @@ get_user_choice(){ + else + logger "The check item 8 fails, the firewall port ${HTTPSPORT} is disabled. In this case, authorize the tool to enable the port or manually enable it." ${TIP_COLOR_WARNING} + fi +- while true; do +- read -p "Do you want to authorize the tool to handle the items failed in the installation environment check?(y/n)" y_n +- logger "Failed to check the installation environment. Read the suggestions for the items that fail the check." "WARNING" +- logger "Do you want to authorize the tool to handle the items failed in the installation environment check? You input is:$y_n" +- if [[ $y_n == "y" ]] || [[ $y_n == "Y" ]]; then +- user_choice=yes +- return 0 +- elif [[ $y_n == "n" ]] || [[ $y_n == "N" ]]; then +- if [[ "$check_result_flag" == "7" ]]; then +- no_of_firewall_info +- return 0 +- else +- logger "You have refused to authorize the tool to process failed items in the environment check. Tool installation canceled." ${TIP_COLOR_SUCCESS} +- logger "Installation failed." ${TIP_COLOR_FAILED} +- exit 1 +- fi +- else +- logger "Incorrect entered information." ${TIP_COLOR_WARNING} +- fi +- done ++ user_choice=yes + fi + fi + done +@@ -201,6 +182,10 @@ record_firewall_modification(){ + # 处理环境检查中的失败项 + resolve_fail_checklist(){ + if [[ "$user_choice" == "yes" ]]; then ++ ++ if [[ "${CheckResult[2]}" = "fail" ]]; then ++ setenforce 0 ++ fi + if [[ "$check_result_flag" -le "5" ]]; then + # 环境清理 防火墙待检测 + del_service_conf +diff --git a/common_func.sh b/common_func.sh +index f82c215..7d8b9de 100644 +--- a/common_func.sh ++++ b/common_func.sh +@@ -719,44 +719,33 @@ create_multi_user(){ + # 创建多用户之前先删除残留portworker + del_multi_user + # 添加多用户 只有安装涉及到此步骤,使用路径为全局变量$customize_path +- while true; do +- read -r -p "The tool will create 10 users (default portworker1-10) to execute background tasks. All the users belong to the porting user group and have the same user permissions. Do you agree?(y/n)" Y_N +- if [[ "${Y_N}" == "\\" ]]; then ++ logger "The tool will create 10 users (default portworker1-10) to execute background tasks. All the users belong to the porting user group and have the same user permissions." ++ j=1 ++ logger 'Start create multiple users' ++ echo -e '\n[ToolPortWokers]' >> $customize_path/portadv/config/serverinfo.conf ++ for (( i = 1; i < 11; i++ )); do ++ useradd -MN -g porting portworker${j} -c "porting_advisor_user" -s /sbin/nologin >/dev/null 2>&1 ++ local status_code=$? ++ if [[ "$status_code" == "0" ]]; then ++ # 创建的用户信息写入worker.json ++ uid=$(id -u portworker${j}) ++ sed -i "s/\"uid${i}\"/${uid}/g" $customize_path/portadv/tools/portal/resource/worker.json ++ sed -i "s/\"worker_name${i}\"/\"portworker${j}\"/g" $customize_path/portadv/tools/portal/resource/worker.json ++ echo "portworker${i}=portworker${j}" >> $customize_path/portadv/config/serverinfo.conf ++ logger "Create portworker${j} success" ++ ((j++)) ++ elif [[ "$status_code" == "9" ]]; then ++ # 已经存在了该用户 ++ ((j++)) ++ ((i--)) + continue +- elif [[ "${Y_N}" == "n" ]]; then +- # 退出安装并执行清理动作 +- logger "You do not agree to create multiple users to exit the installation and clean up the environment." TIP_COLOR_WARNING +- return 2 +- elif [[ "${Y_N}" == "y" ]]; then +- j=1 +- logger 'Start create multiple users' +- echo -e '\n[ToolPortWokers]' >> $customize_path/portadv/config/serverinfo.conf +- for (( i = 1; i < 11; i++ )); do +- useradd -MN -g porting portworker${j} -c "porting_advisor_user" -s /sbin/nologin >/dev/null 2>&1 +- local status_code=$? +- if [[ "$status_code" == "0" ]]; then +- # 创建的用户信息写入worker.json +- uid=$(id -u portworker${j}) +- sed -i "s/\"uid${i}\"/${uid}/g" $customize_path/portadv/tools/portal/resource/worker.json +- sed -i "s/\"worker_name${i}\"/\"portworker${j}\"/g" $customize_path/portadv/tools/portal/resource/worker.json +- echo "portworker${i}=portworker${j}" >> $customize_path/portadv/config/serverinfo.conf +- logger "Create portworker${j} success" +- ((j++)) +- elif [[ "$status_code" == "9" ]]; then +- # 已经存在了该用户 +- ((j++)) +- ((i--)) +- continue +- else +- del_multi_user +- return 2 +- fi +- done +- return 0 + else +- continue ++ del_multi_user ++ return 2 + fi + done ++ return 0 ++ + } + + del_multi_user(){ +diff --git a/common_path.sh b/common_path.sh +index 8c5de96..3ee028d 100644 +--- a/common_path.sh ++++ b/common_path.sh +@@ -699,7 +699,6 @@ get_install_user() + fi + } + +- + # 获取用户自定义安装路径 + get_customize_path() + { +@@ -712,47 +711,11 @@ get_customize_path() + else + default_path="${HOME}" + fi +- while [ "$pathflg" == "1" ] +- do +- read -p "Enter the installation path. The default path is $default_path : " YPATH +- if [ ! -n "$YPATH" ]; then +- pathflg='0' +- change_path_auth $default_path $install_way $tool_name +- check_avail_space $default_path +- CUSTOMIZE_PATH="$default_path" +- return '0' +- else +- res_str=$(check_input_string "$YPATH") +- if [[ "$?" == "1" ]];then +- pathflg='1' +- echo $res_str +- else +- install_path=$(check_install_path $YPATH) +- status_install_="$?" +- if [ "0" == "$status_install_" ];then +- pathflg='0' +- change_path_auth $install_path $install_way $tool_name +- CUSTOMIZE_PATH=$install_path +- return '0' +- elif [[ "1" == "$status_install_" ]];then +- if [[ "Permission_denied" =~ "$install_path" ]];then +- change_path_auth $YPATH $install_way $tool_name +- pathflg='0' +- CUSTOMIZE_PATH=$YPATH +- return '0' +- else +- pathflg='1' +- echo -e $install_path +- fi +- else +- pathflg='0' +- change_path_auth $install_path $install_way $tool_name +- CUSTOMIZE_PATH=$install_path +- return '0' +- fi +- fi +- fi +- done ++ change_path_auth $default_path $install_way $tool_name ++ check_avail_space $default_path ++ CUSTOMIZE_PATH="$default_path" ++ return '0' ++ + } + + get_user_path() +diff --git a/const.conf b/const.conf +index 1cc1691..cbe35ed 100644 +--- a/const.conf ++++ b/const.conf +@@ -15,10 +15,9 @@ debian10_iso=https://repo.huaweicloud.com/debian-cd/10.0.0/arm64/iso-dvd/debian- + euleros2.0(SP8)_repo=https://repo.huaweicloud.com/euler/2.8/os/aarch64/; + euleros2.0(SP8)_iso=None + kunpeng_software_support=https://support-it.huawei.com/kunpeng-software-support/#/index/search +-web_https_url=https://IP:HTTPSPORT/porting/#/login ++web_https_url=https://175.39.49.35:8084/porting/#/login + enable_port_tip=https://www.hikunpeng.com/document/detail/zh/kunpengdevps/porting/usermanual/kunpengpt_06_0017.html + nginx_systemctl_faild=https://www.hikunpeng.com/document/detail/zh/kunpengdevps/porting/usermanual/kunpengpt_06_0105.html +-support_upgrade_version=2.3.0;2.5.RC1; + support_change_disclaimer_version=2.3.0;2.5.RC1; # “用户免责声明”更新,老版本升级到当前版本要重新签署 + cpu_implementers=(0x48 0x41) # 鲲鹏平台特征值. 两个值必须同时存在例如0x48和0xd01 + cpu_parts=(0xd01 0xd08) +\ No newline at end of file +diff --git a/install_webfunc.sh b/install_webfunc.sh +index 175482c..72d8a1e 100644 +--- a/install_webfunc.sh ++++ b/install_webfunc.sh +@@ -50,35 +50,8 @@ check_port_conflict() + port_status='1' + occupy_port=$inport + logger "Invalid port. The port $occupy_port is in use." ${TIP_COLOR_FAILED} ++ exit 1 + fi +- systemport=$(lsof -i :$inport|grep -v "PID" | awk '{print $2}') +- while [ "$conflictflag" == "1" ] +- do +- if [ "$systemport" != "" ]; then +- inport=$(($inport+1)) +- else +- if [ "$toolportflg" == "0" ]; then +- if [ "$inport" == "$HTTPSPORT" ]; then +- inport=$(($inport+1)) +- else +- conflictflag='0' +- break +- fi +- else +- conflictflag='0' +- break +- fi +- fi +- if [ "$inport" == "65536" ]; then +- inport=1024 +- fi +- if [ "$inport" == "$originport" ]; then +- conflictflag='0' +- inport=65536 +- break +- fi +- systemport=$(lsof -i :$inport|grep -v "PID" | awk '{print $2}') +- done + if [ "$set_tool_port_flg" == "0" ]; then + TOOLPORT=$inport + elif [ "$set_tool_port_flg" == "1" ]; then +@@ -86,143 +59,30 @@ check_port_conflict() + fi + } + +-# 端口用户自定义化实现交互功能 +-user_customize_port(){ +- inputflag="1" +- while [ "$inputflag" == "1" ] +- do +- if [ "$port_status" == "0" ]; then +- tip_word="The $2 port $1 is valid. " +- else +- tip_word="The $2 port $occupy_port is in use." +- fi +- read -p "${tip_word} Set the $2 port to $1 (y/n default: y):" Y_N +- logger "${tip_word} Set the $2 port to $1 (y/n default: y), your input is ${Y_N}" +- if [ ! -n "$Y_N" ]; then +- Y_N='' +- inputflag="0" +- break +- elif [ "$Y_N" == "y" -o "$Y_N" == "n" ];then +- inputflag="0" +- break +- fi +- done +- if [ "$Y_N" = "n" ];then +- if [ "$2" = "tool" ]; then +- set_django_port $django_port +- else +- set_nginx_port $nginx_port +- fi +- else +- logger "Set the $2 port $1" ${TIP_COLOR_SUCCESS} +- fi +-} + + ip_input_customize(){ +- ipflg='1' +- while [ "$ipflg" == "1" ] +- do +- ip_addrs=$(ip addr | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}' | tr '/' ' ' | awk '{ print $1}') +- ip_list=($(echo $ip_addrs | tr '' ' ')) +- logger "Ip address list:" ${TIP_COLOR_ECHO} +- printf "%-20s %-20s %-25s\n" "sequence_number" "ip_address" "device" +- printf "%-2s %-2s %-20s %-20s %-25s\n" "[$(date "+%Y-%m-%d %H:%M:%S")]" "[INFO]" "sequence_number" "ip_address" "device" >> $log_file_of_abspath +- for((i=0;i<${#ip_list[@]};i++)); +- do +- device=$(ip addr | grep ${ip_list[i]} | awk '{ print $(NF) }') +- printf "%-20s %-20s %-25s\n" "$((i+1))" "${ip_list[i]}" "${device}" +- printf "%-2s %-2s %-20s %-20s %-25s\n" "[$(date "+%Y-%m-%d %H:%M:%S")]" "[INFO]" "$((i+1))" "${ip_list[i]}" "${device}" >> $log_file_of_abspath +- done +- read -p "Enter the sequence number of listed ip as web server ip(default: 1): " Ip_Number +- logger "Enter the sequence number of listed ip as web server ip(default: 1),your input is ${Ip_Number}" +- if [ -z "$Ip_Number" ];then +- Ip_Number=1 +- check_ip_address ${ip_list[0]} +- if [ "0" == "$?" ]; then +- ipflg='0' +- fi +- elif echo $Ip_Number | grep -E "^[0-9]+$" > /dev/null; then +- if [[ "$Ip_Number" -gt ${#ip_list[@]} ]] || [[ "$Ip_Number" -lt 1 ]] ; then +- logger "Incorrect entered information." ${TIP_COLOR_FAILED} +- else +- check_ip_address ${ip_list[$((Ip_Number-1))]} +- if [ "0" == "$?" ]; then +- ipflg='0' +- fi +- fi +- else +- logger "Incorrect entered information." ${TIP_COLOR_FAILED} +- fi +- done +- IP=${ip_list[$((Ip_Number-1))]} +- logger "Set the web server IP address ${ip_list[$((Ip_Number-1))]}" ${TIP_COLOR_SUCCESS} ++ ++ ip_addrs=$(ip addr | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}' | tr '/' ' ' | awk '{ print $1}') ++ ip_list=($(echo $ip_addrs | tr '' ' ')) ++ check_ip_address ${ip_list[0]} ++ IP=${ip_list[0]} ++ logger "Set the web server IP address ${ip_list[0]}" ${TIP_COLOR_SUCCESS} + } + + set_nginx_port(){ +- httpsportflg=1 + #获取Nginx端口 +- while [ "$httpsportflg" == "1" ] +- do +- read -p "Please enter HTTPS port(default: $nginx_port):" HTTPSPORT +- if [ ! -n "$HTTPSPORT" ]; then +- HTTPSPORT=$1 +- httpsportflg='0' +- else +- if [ "$HTTPSPORT" -gt 0 ] 2>/dev/null ;then +- if [[ "$HTTPSPORT" -ge 1024 && "$HTTPSPORT" -le 65535 ]]; then +- httpsportflg='0' +- else +- logger "Please enter correct HTTPS port! Port range from 1024 to 65535." ${TIP_COLOR_FAILED} +- fi +- else +- logger "Please enter a correct HTTPS port Number. The port number ranges from 1024 to 65535." ${TIP_COLOR_FAILED} +- fi +- fi +- done + #对Nginx端口进行检查 + set_tool_port_flg=1 +- check_port_conflict $HTTPSPORT +- if [ "$HTTPSPORT" == "65536" ]; then +- logger "There is no available port. Please check your system ports." ${TIP_COLOR_FAILED} +- logger "Installation failed." ${TIP_COLOR_FAILED} +- return 2 +- else +- user_customize_port $HTTPSPORT "HTTPS" +- fi ++ check_port_conflict $nginx_port ++ logger "Set the nginx server port $nginx_port" ${TIP_COLOR_SUCCESS} + } + + set_django_port(){ + #获取Django端口 +- toolportflg=1 +- default_tool_port="$1" +- while [ "$toolportflg" == "1" ] +- do +- read -p "Please enter tool port(default: $django_port):" TOOLPORT +- if [ ! -n "$TOOLPORT" ]; then +- TOOLPORT=$1 +- toolportflg='0' +- else +- if [ "$TOOLPORT" -gt 0 ] 2>/dev/null ;then +- if [[ "$TOOLPORT" -ge 1024 && "$TOOLPORT" -le 65535 ]]; then +- toolportflg='0' +- else +- logger "Please enter the correct tool port number. The port number ranges from 1024 to 65535. It cannot be same as the HTTPS port number." ${TIP_COLOR_FAILED} +- fi +- else +- logger "Please enter the correct tool port number. The port number ranges from 1024 to 65535. It cannot be same as the HTTPS port number." ${TIP_COLOR_FAILED} +- fi +- fi +- done + #对Django端口进行检查 + set_tool_port_flg=0 +- check_port_conflict $TOOLPORT +- if [ "$TOOLPORT" == "65536" ]; then +- logger "There is no available port. Please check your system ports." ${TIP_COLOR_FAILED} +- logger "Installation failed." ${TIP_COLOR_FAILED} +- exit 1 +- else +- user_customize_port $TOOLPORT "tool" +- fi ++ check_port_conflict $django_port ++ logger "Set the nginx server port $django_port" ${TIP_COLOR_SUCCESS} + } + + # config ip and port +@@ -237,24 +97,15 @@ ip_port_config(){ + set_django_port $django_port + #################### + if [ "$flg" -eq "0" ]; then +- https_ip_port=$HTTPSPORT ++ https_ip_port=$nginx_port + else +- https_ip_port=$IP:$HTTPSPORT ++ https_ip_port=$IP:$nginx_port + fi +- tool_port=$TOOLPORT ++ tool_port=$django_port + current_dir=$(cd $(dirname $0); pwd) +- sed -i "s/IP:HTTPSPORT/$IP:$HTTPSPORT/g" $current_dir/const.conf ++ sed -i "s/IP:HTTPSPORT/$IP:$nginx_port/g" $current_dir/const.conf + } + +-# cloud IDE 的django和nginx端口设置 +-set_django_nginx_port(){ +- # 设置NGINX端口 +- set_tool_port_flg=1 +- check_port_conflict 8084 +- # 设置django端口 +- set_tool_port_flg=0 +- check_port_conflict 7998 +-} + + check_installed(){ + architecture=$(uname -m) +diff --git a/start_install.sh b/start_install.sh +index 76c0a96..ed32ade 100644 +--- a/start_install.sh ++++ b/start_install.sh +@@ -160,7 +160,7 @@ start_install_process() + rm_file $new_path/unwind.h + platform=$(uname -a | awk -F " " '{print $(NF-1)}') + # 二进制文件验证的cms文件copy到tools下面 +- cp -rf $current_dir/../cms $customize_path/portadv/tools/ ++ cp -rf $current_dir/cms $customize_path/portadv/tools/ + # 解决方案移植模板放到resource/migration/目录下 + mkdir -p $customize_path/portadv/resource/migration + # 修改迁移模板中部分文件中的“/home/porting” +diff --git a/uninstall.sh b/uninstall.sh +old mode 100755 +new mode 100644 +index 16674e9..f171111 +--- a/uninstall.sh ++++ b/uninstall.sh +@@ -53,16 +53,6 @@ else + os_type="$DefaultOsType" + os_name="$DefaultOsName" + fi +-inputflag="1" +-while [ "$inputflag" == "1" ] +-do +- read -p "Are you sure you want to uninstall porting advisor?(y/n)" TO_DELETE +- if [ "$TO_DELETE" == "y" -o "$TO_DELETE" == "n" ] +- then +- inputflag="0" +- break +- fi +-done + + if [ "$TO_DELETE" == "n" ] + then +@@ -132,47 +122,6 @@ if [ ! -e "$first_path/portadv/tools/webui" ]; then + check_cmd_task + fi + +- +-# 检查web模式当前是否有任务进行 +-function check_web_task() +-{ +- # gunicorn切换启动方式目前只有一个进程 +- default_process_count=1 +- if [[ $os_name =~ (CentOS .* 6\.) || $os_name =~ (Red Hat .* 6\.) ]]; then +- process_nums=$(ps -ef | grep gunicorn | grep porting | wc -l) +- else +- process_nums=$(ps -ef | grep gunicorn | grep -v service_gunicorn | grep porting | wc -l) +- fi +- if (( $(($default_process_count+1)) < $process_nums )); then +- read -p "A task is running.Are you sure you want to uninstall porting advisor?(y/n)" DELETE_WEB +- if [ "$DELETE_WEB" == "n" ]; then +- exit 0 +- elif [ "$DELETE_WEB" == "y" ]; then +- echo -e "\e[1;32mThe Kunpeng Porting Advisor is uninstalling.\e[0m" +- else +- echo -e "\e[1;31mIncorrect entered information.\e[0m" +- exit 1 +- fi +- fi +- portworker_process_nums=$(ps -o ruser=userForLongName -e -o pid,ppid | grep portworker | wc -l) +- # 查看是否有僵尸portworkerX僵尸进程并清理 +- if [ ! -z "${portworker_process_nums}" ]; then +- # 查看portworkerX组是否为porting +- results=$(ps -o ruser=userForLongName -e -o pid | grep portworker | awk '{print $1"+"$2}') +- if [ ! -z "${results}" ]; then +- for res in ${results};do +- user=$(echo $res | cut -d "+" -f 1) +- process_id=$(echo $res | cut -d "+" -f 2) +- portworker_gid=(id -g $user) +- if [ "${portworker_gid}" == "${porting_uid}" ]; then +- kill -9 $process_id +- fi +- done +- fi +- fi +-} +-check_web_task +- + check_firewalld "$os_name" "$os_type" + + #web模式,关闭服务,移除开机启动 +-- +2.27.0 +