已合并
feat(install): 新增 --check 选项用于安装前依赖版本校验 #3439
songkai111创建于 6月18日
feat(install): 新增 --check 选项用于安装前依赖版本校验 #3439
已合并
songkai111创建于 6月18日
1 个文件变更+84-2
@@ -325,7 +325,7 @@ get_opts() {
325 325 
326 if [ "$*" = "" ]; then326 if [ "$*" = "" ]; then
327 echo "[OpsMath] [ERROR]: ERR_NO:${PARAM_INVALID};ERR_DES:\327 echo "[OpsMath] [ERROR]: ERR_NO:${PARAM_INVALID};ERR_DES:\
328- only support one type: full/upgrade/uninstall, operation execute failed!\328+ only support one type: full/upgrade/uninstall/check, operation execute failed!\
329 Please use [--help] to see the usage."329 Please use [--help] to see the usage."
330 exitlog330 exitlog
331 exit 1331 exit 1
@@ -350,6 +350,11 @@ get_opts() {
350 CONFLICT_CMD_NUMS=$(expr $CONFLICT_CMD_NUMS + 1)350 CONFLICT_CMD_NUMS=$(expr $CONFLICT_CMD_NUMS + 1)
351 shift351 shift
352 ;;352 ;;
353+ --check)
354+ IS_CHECK="y"
355+ CONFLICT_CMD_NUMS=$(expr $CONFLICT_CMD_NUMS + 1)
356+ shift
357+ ;;
353 --install-path=*)358 --install-path=*)
354 IS_INPUT_PATH="y"359 IS_INPUT_PATH="y"
355 IN_INSTALL_PATH=$(echo ${1} | cut -d"=" -f2-)360 IN_INSTALL_PATH=$(echo ${1} | cut -d"=" -f2-)
@@ -389,7 +394,7 @@ check_opts() {
389 394 
390 if [ "${CONFLICT_CMD_NUMS}" != 1 ]; then395 if [ "${CONFLICT_CMD_NUMS}" != 1 ]; then
391 echo "[OpsMath] [ERROR]: ERR_NO:${PARAM_INVALID};ERR_DES:\396 echo "[OpsMath] [ERROR]: ERR_NO:${PARAM_INVALID};ERR_DES:\
392- only support one type: full/upgrade/uninstall, operation execute failed!\397+ only support one type: full/upgrade/uninstall/check, operation execute failed!\
393 Please use [--help] to see the usage."398 Please use [--help] to see the usage."
394 exitlog399 exitlog
395 exit 1400 exit 1
@@ -651,6 +656,76 @@ pre_check_only() {
651 fi656 fi
652}657}
653 658 
659+check_dependencies() {
660+ local version_info_file="$1"
661+ local failed=0
662+ 
663+ logandprint "[INFO]: Start checking dependencies from ${version_info_file}"
664+ 
665+ if [ ! -f "${version_info_file}" ]; then
666+ logandprint "[ERROR]: version.info not found at ${version_info_file}"
667+ return 1
668+ fi
669+ 
670+ local dep_lines
671+ dep_lines=$(grep "^required_package_" "${version_info_file}")
672+ 
673+ if [ -z "${dep_lines}" ]; then
674+ logandprint "[INFO]: All dependency checks passed."
675+ return 0
676+ fi
677+ 
678+ while IFS= read -r line; do
679+ local component=$(echo "${line}" | sed -n 's/^required_package_\(.*\)_version=.*/\1/p')
680+ local req_version=$(echo "${line}" | cut -d= -f2- | tr -d '"')
681+ 
682+ if [ -z "${component}" ] || [ -z "${req_version}" ]; then
683+ continue
684+ fi
685+ 
686+ local ascend_home="${ASCEND_HOME_PATH:-${TARGET_VERSION_DIR}}"
687+ local info_file="${ascend_home}/share/info/${component}/version.info"
688+ if [ ! -f "${info_file}" ]; then
689+ logandprint "[ERROR]: ${component} version.info not found at ${info_file}"
690+ failed=1
691+ continue
692+ fi
693+ 
694+ local actual_version=$(grep "^Version=" "${info_file}" | cut -d= -f2-)
695+ 
696+ if [ -z "${actual_version}" ]; then
697+ logandprint "[ERROR]: Failed to get version of ${component} from ${info_file}"
698+ failed=1
699+ continue
700+ fi
701+ 
702+ local op=$(echo "${req_version}" | sed 's/[0-9].*//')
703+ local ver=$(echo "${req_version}" | sed 's/^[^0-9]*//')
704+ 
705+ if [ "${op}" = ">=" ]; then
706+ local first=$(printf '%s\n%s\n' "${actual_version}" "${ver}" | sort -V | head -n 1)
707+ 
708+ if [ "$first" = "${ver}" ]; then
709+ logandprint "[INFO]: ${component} version ${actual_version} satisfies requirement ${req_version}"
710+ else
711+ logandprint "[ERROR]: ${component} version ${actual_version} does not satisfy requirement ${req_version}"
712+ failed=1
713+ fi
714+ else
715+ logandprint "[ERROR]: Unsupported version operator '${op}' for ${component}, skipping"
716+ fi
717+ done <<EOF
718+${dep_lines}
719+EOF
720+ 
721+ if [ "${failed}" -eq 0 ]; then
722+ logandprint "[INFO]: All dependency checks passed."
723+ else
724+ logandprint "[ERROR]: Some dependency checks failed."
725+ fi
726+ return ${failed}
727+}
728+ 
654main() {729main() {
655 730 
656 get_run_path "$@"731 get_run_path "$@"
@@ -663,6 +738,13 @@ main() {
663 738 
664 init_env739 init_env
665 740 
741+ if [ "${IS_CHECK}" = "y" ]; then
742+ check_dependencies "${VERSION_INFO_FILE}"
743+ local check_ret=$?
744+ exitlog
745+ exit ${check_ret}
746+ fi
747+ 
666 check_pre_install748 check_pre_install
667 749 
668 mkdir_install_path750 mkdir_install_path