281
csrc/scripts/package/common/sh/check_version_required.awk
Normal file
281
csrc/scripts/package/common/sh/check_version_required.awk
Normal file
@@ -0,0 +1,281 @@
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
function strip(input) {
|
||||
sub("^ +", "", input)
|
||||
sub(" +$", "", input)
|
||||
return input
|
||||
}
|
||||
|
||||
function check_compatible_le(version_arr, len_version_arr, require_arr, len_require_arr, i) {
|
||||
for (i = 1; i <= len_require_arr; i++) {
|
||||
if (require_arr[i] == "") {
|
||||
continue
|
||||
}
|
||||
# len_version_arr lt len_require_arr
|
||||
if (i > len_version_arr) {
|
||||
return 1
|
||||
}
|
||||
if (version_arr[i] < require_arr[i]) {
|
||||
return 1
|
||||
}
|
||||
if (version_arr[i] > require_arr[i]) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
if (len_version_arr > len_require_arr) {
|
||||
return 1
|
||||
}
|
||||
# len_version_arr eq len_require_arr
|
||||
return 1
|
||||
}
|
||||
|
||||
function check_compatible_lt(version_arr, len_version_arr, require_arr, len_require_arr, i) {
|
||||
for (i = 1; i <= len_require_arr; i++) {
|
||||
if (require_arr[i] == "") {
|
||||
continue
|
||||
}
|
||||
# len_version_arr lt len_require_arr
|
||||
if (i > len_version_arr) {
|
||||
return 1
|
||||
}
|
||||
if (version_arr[i] < require_arr[i]) {
|
||||
return 1
|
||||
}
|
||||
if (version_arr[i] > require_arr[i]) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
if (len_version_arr > len_require_arr) {
|
||||
return 0
|
||||
}
|
||||
# len_version_arr eq len_require_arr
|
||||
return 0
|
||||
}
|
||||
|
||||
function check_compatible_ge(version_arr, len_version_arr, require_arr, len_require_arr, i) {
|
||||
for (i = 1; i <= len_require_arr; i++) {
|
||||
if (require_arr[i] == "") {
|
||||
continue
|
||||
}
|
||||
# len_version_arr lt len_require_arr
|
||||
if (i > len_version_arr) {
|
||||
return 0
|
||||
}
|
||||
if (version_arr[i] < require_arr[i]) {
|
||||
return 0
|
||||
}
|
||||
if (version_arr[i] > require_arr[i]) {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
if (len_version_arr > len_require_arr) {
|
||||
return 1
|
||||
}
|
||||
# len_version_arr eq len_require_arr
|
||||
return 1
|
||||
}
|
||||
|
||||
function check_compatible_gt(version_arr, len_version_arr, require_arr, len_require_arr, i) {
|
||||
for (i = 1; i <= len_require_arr; i++) {
|
||||
if (require_arr[i] == "") {
|
||||
continue
|
||||
}
|
||||
# len_version_arr lt len_require_arr
|
||||
if (i > len_version_arr) {
|
||||
return 0
|
||||
}
|
||||
if (version_arr[i] < require_arr[i]) {
|
||||
return 0
|
||||
}
|
||||
if (version_arr[i] > require_arr[i]) {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
if (len_version_arr > len_require_arr) {
|
||||
return 1
|
||||
}
|
||||
# len_version_arr eq len_require_arr
|
||||
return 0
|
||||
}
|
||||
|
||||
function check_compatible_eq(version_arr, len_version_arr, require_arr, len_require_arr, i) {
|
||||
for (i = 1; i <= len_require_arr; i++) {
|
||||
if (require_arr[i] == "") {
|
||||
continue
|
||||
}
|
||||
# len_version_arr lt len_require_arr
|
||||
if (i > len_version_arr) {
|
||||
return 0
|
||||
}
|
||||
if (version_arr[i] != require_arr[i]) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
if (len_version_arr > len_require_arr) {
|
||||
return 1
|
||||
}
|
||||
# len_version_arr eq len_require_arr
|
||||
return 1
|
||||
}
|
||||
|
||||
function check_compatible(version_arr, len_version_arr, require, require_arr, len_require_arr, pos) {
|
||||
len_require_arr = split(require, require_arr, ".")
|
||||
|
||||
pos = match(require_arr[1], /^>=/)
|
||||
if (pos != 0) {
|
||||
require_arr[1] = substr(require_arr[1], pos + RLENGTH)
|
||||
return check_compatible_ge(version_arr, len_version_arr, require_arr, len_require_arr)
|
||||
}
|
||||
|
||||
pos = match(require_arr[1], /^>/)
|
||||
if (pos != 0) {
|
||||
require_arr[1] = substr(require_arr[1], pos + RLENGTH)
|
||||
return check_compatible_gt(version_arr, len_version_arr, require_arr, len_require_arr)
|
||||
}
|
||||
|
||||
pos = match(require_arr[1], /^<=/)
|
||||
if (pos != 0) {
|
||||
require_arr[1] = substr(require_arr[1], pos + RLENGTH)
|
||||
return check_compatible_le(version_arr, len_version_arr, require_arr, len_require_arr)
|
||||
}
|
||||
|
||||
pos = match(require_arr[1], /^</)
|
||||
if (pos != 0) {
|
||||
require_arr[1] = substr(require_arr[1], pos + RLENGTH)
|
||||
return check_compatible_lt(version_arr, len_version_arr, require_arr, len_require_arr)
|
||||
}
|
||||
|
||||
return check_compatible_eq(version_arr, len_version_arr, require_arr, len_require_arr)
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
len_all_required_arr = split(all_required, all_required_arr, ",")
|
||||
|
||||
compated = 0
|
||||
|
||||
in_gt = 0
|
||||
matched_gt = 0
|
||||
|
||||
len_version_arr = split(version, version_arr, ".")
|
||||
|
||||
for (i = 1; i <= len_all_required_arr; i++) {
|
||||
all_required_arr[i] = strip(all_required_arr[i])
|
||||
one_compated = check_compatible(version_arr, len_version_arr, all_required_arr[i])
|
||||
|
||||
pos = match(all_required_arr[i], /^>/)
|
||||
if (pos != 0) {
|
||||
gt_require = 1
|
||||
lt_require = 0
|
||||
eq_require = 0
|
||||
} else {
|
||||
pos = match(all_required_arr[i], /^</)
|
||||
if (pos != 0) {
|
||||
gt_require = 0
|
||||
lt_require = 1
|
||||
eq_require = 0
|
||||
} else {
|
||||
gt_require = 0
|
||||
lt_require = 0
|
||||
eq_require = 1
|
||||
}
|
||||
}
|
||||
|
||||
if (matched_gt) {
|
||||
if (one_compated) {
|
||||
# gt after gt, all compated.
|
||||
if (gt_require) {
|
||||
matched_gt = 1
|
||||
in_gt = 1
|
||||
continue
|
||||
}
|
||||
# lt after gt, all compated.
|
||||
if (lt_require) {
|
||||
compated = 1
|
||||
matched_gt = 0
|
||||
in_gt = 0
|
||||
break
|
||||
}
|
||||
# eq after gt, all compated.
|
||||
if (eq_require) {
|
||||
# eq compated, go.
|
||||
compated = 1
|
||||
break
|
||||
}
|
||||
} else {
|
||||
# miscompated.
|
||||
# gt after gt, compated first gt. miscompated second gt.
|
||||
if (gt_require) {
|
||||
matched_gt = 0
|
||||
in_gt = 1
|
||||
continue
|
||||
}
|
||||
# lt after gt, compated first gt. miscompated second lt.
|
||||
if (lt_require) {
|
||||
matched_gt = 0
|
||||
in_gt = 0
|
||||
continue
|
||||
}
|
||||
# eq after gt, compated first gt. miscompated second eq.
|
||||
if (eq_require) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (one_compated) {
|
||||
if (gt_require) {
|
||||
matched_gt = 1
|
||||
in_gt = 1
|
||||
continue
|
||||
}
|
||||
if (lt_require) {
|
||||
if (in_gt) {
|
||||
matched_gt = 0
|
||||
in_gt = 0
|
||||
continue
|
||||
} else {
|
||||
compated = 1
|
||||
break
|
||||
}
|
||||
}
|
||||
if (eq_require) {
|
||||
# eq compated, go.
|
||||
compated = 1
|
||||
break
|
||||
}
|
||||
} else {
|
||||
# miscompated.
|
||||
if (gt_require) {
|
||||
matched_gt = 0
|
||||
in_gt = 1
|
||||
continue
|
||||
}
|
||||
if (lt_require) {
|
||||
matched_gt = 0
|
||||
in_gt = 0
|
||||
continue
|
||||
}
|
||||
if (eq_require) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (matched_gt) {
|
||||
compated = 1
|
||||
}
|
||||
|
||||
if (compated == 0) {
|
||||
printf("F")
|
||||
} else {
|
||||
printf("T")
|
||||
}
|
||||
}
|
||||
14
csrc/scripts/package/common/sh/cleanup.sh
Normal file
14
csrc/scripts/package/common/sh/cleanup.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
set -e
|
||||
|
||||
rm -rf $(pwd)
|
||||
1269
csrc/scripts/package/common/sh/common_func.inc
Normal file
1269
csrc/scripts/package/common/sh/common_func.inc
Normal file
File diff suppressed because it is too large
Load Diff
1729
csrc/scripts/package/common/sh/common_func_v2.inc
Normal file
1729
csrc/scripts/package/common/sh/common_func_v2.inc
Normal file
File diff suppressed because it is too large
Load Diff
55
csrc/scripts/package/common/sh/common_installer.inc
Normal file
55
csrc/scripts/package/common/sh/common_installer.inc
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 通知latest管理器创建版本软链
|
||||
notify_latest_manager_create_version_softlink() {
|
||||
local curpath install_path version_dir var_path
|
||||
|
||||
set_comm_log "Notifier"
|
||||
|
||||
curpath="$(dirname $(readlink -f "${BASH_SOURCE:-$0}"))"
|
||||
install_path="$(readlink -f "$curpath/..")"
|
||||
version_dir="$(basename "$curpath")"
|
||||
var_path="$install_path/$LATEST_DIR/var"
|
||||
|
||||
if [ ! -f "$var_path/manager.sh" ]; then
|
||||
comm_log "ERROR" "$var_path/manager.sh doesn't exist!"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! "$var_path/manager.sh" --version-dir "$version_dir" create_version_softlink; then
|
||||
comm_log "ERROR" "create version softlink failed!"
|
||||
exit 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# 通知latest管理器删除latest软链
|
||||
notify_latest_manager_remove_latest_softlink() {
|
||||
local curpath install_path var_path
|
||||
|
||||
set_comm_log "Notifier"
|
||||
|
||||
curpath="$(dirname $(readlink -f "${BASH_SOURCE:-$0}"))"
|
||||
install_path="$(readlink -f "$curpath/..")"
|
||||
var_path="$install_path/$LATEST_DIR/var"
|
||||
|
||||
if [ ! -f "$var_path/manager.sh" ]; then
|
||||
comm_log "ERROR" "$var_path/manager.sh doesn't exist!"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! "$var_path/manager.sh" remove_latest_softlink; then
|
||||
comm_log "ERROR" "remove latest softlink failed!"
|
||||
exit 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
37
csrc/scripts/package/common/sh/common_interface.csh
Normal file
37
csrc/scripts/package/common/sh/common_interface.csh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/csh
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
set func_name = "$1"
|
||||
switch ( "$func_name" )
|
||||
case "mk_custom_path":
|
||||
if ( "`id -u`" == 0 ) then
|
||||
exit 0
|
||||
endif
|
||||
set file_path = "$2"
|
||||
foreach line ("` cat $file_path `")
|
||||
set custom_path = "`echo '$line' | cut --only-delimited -d= -f2`"
|
||||
if ( "$custom_path" == "" ) then
|
||||
continue
|
||||
endif
|
||||
set custom_path = "` eval echo $custom_path `"
|
||||
if ( ! -d "$custom_path" ) then
|
||||
mkdir -p "$custom_path"
|
||||
if ( $status != 0 ) then
|
||||
set cur_date = "`date +'%Y-%m-%d %H:%M:%S'`"
|
||||
echo "[Common] [$cur_date] [ERROR]: create $custom_path failed."
|
||||
exit 1
|
||||
endif
|
||||
endif
|
||||
end
|
||||
breaksw
|
||||
default:
|
||||
breaksw
|
||||
endsw
|
||||
33
csrc/scripts/package/common/sh/common_interface.fish
Normal file
33
csrc/scripts/package/common/sh/common_interface.fish
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env fish
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
function mk_custom_path
|
||||
set -l custom_file_path $argv[1]
|
||||
if test (id -u) -eq 0
|
||||
return 0
|
||||
end
|
||||
while read line
|
||||
set -l _custom_path (echo "$line" | cut --only-delimited -d= -f2)
|
||||
if test -z $_custom_path
|
||||
continue
|
||||
end
|
||||
set -l _custom_path (eval echo "$_custom_path")
|
||||
if not test -d $_custom_path
|
||||
mkdir -p "$_custom_path"
|
||||
if not test $status -eq 0
|
||||
set -l cur_date (date +"%Y-%m-%d %H:%M:%S")
|
||||
echo "[Common] [$cur_date] [ERROR]: create $_custom_path failed."
|
||||
return 1
|
||||
end
|
||||
end
|
||||
end < $custom_file_path
|
||||
return 0
|
||||
end
|
||||
61
csrc/scripts/package/common/sh/common_interface.sh
Normal file
61
csrc/scripts/package/common/sh/common_interface.sh
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/bin/sh
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
mk_custom_path() {
|
||||
if [ $(id -u) -eq 0 ]; then
|
||||
return 0
|
||||
fi
|
||||
local _custom_path_file="$1"
|
||||
while read line || [ -n "$line" ]
|
||||
do
|
||||
local _custom_path="$(echo "$line" | cut --only-delimited -d= -f2)"
|
||||
if [ -z "$_custom_path" ]; then
|
||||
continue
|
||||
fi
|
||||
eval "_custom_path=$_custom_path"
|
||||
if [ ! -d "$_custom_path" ]; then
|
||||
mkdir -p "$_custom_path"
|
||||
if [ $? -ne 0 ]; then
|
||||
cur_date="$(date +"%Y-%m-%d %H:%M:%S")"
|
||||
echo "[Common] [$cur_date] [ERROR]: create $_custom_path failed."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
done < $_custom_path_file
|
||||
return 0
|
||||
}
|
||||
|
||||
py_version_check(){
|
||||
local pyver_set="3.7 3.8 3.9 3.10 3.11 3.12"
|
||||
local cur_date="$(date +"%Y-%m-%d %H:%M:%S")"
|
||||
which python3 > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
local python_version="$(python3 --version 2>&1 | head -n 1)"
|
||||
local python3_version=$(echo "$python_version" | sed -n 's/.*[^\.0-9]\([0-9]\+\.[0-9]\+\).*/\1/p')
|
||||
if [ "x$python3_version" != "x" ]; then
|
||||
for ver in $pyver_set; do
|
||||
if [ "x$ver" = "x$python3_version" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[Common] [$cur_date] [WARNING]: $python_version is not in Python3.7.x, Python3.8.x, Python3.9.x, Python3.10.x, Python3.11.x, Python3.12.x"
|
||||
return 1
|
||||
else
|
||||
echo "[Common] [$cur_date] [WARNING]: $python_version cannot be identified as a standard version, please check manually."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "[Common] [$cur_date] [WARNING]: python3 is not found."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
2192
csrc/scripts/package/common/sh/install_common_parser.sh
Normal file
2192
csrc/scripts/package/common/sh/install_common_parser.sh
Normal file
File diff suppressed because it is too large
Load Diff
305
csrc/scripts/package/common/sh/multi_version.inc
Normal file
305
csrc/scripts/package/common/sh/multi_version.inc
Normal file
@@ -0,0 +1,305 @@
|
||||
#!/bin/sh
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 多版本函数库
|
||||
# 创建版本目录
|
||||
create_version_dir() {
|
||||
local install_path="$1"
|
||||
local version_dir="$2"
|
||||
local username="$3"
|
||||
local usergroup="$4"
|
||||
local install_for_all="$5"
|
||||
local ret
|
||||
|
||||
if [ ! -d "${install_path}/${version_dir}" ]; then
|
||||
make_dir "${install_path}/${version_dir}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
fi
|
||||
|
||||
# 约束版本号目录权限
|
||||
change_mod "${install_path}/${version_dir}" "750" "${install_for_all}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
change_own "${install_path}/${version_dir}" "${username}:${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 检查版本包安装结果
|
||||
check_version_install() {
|
||||
local install_path="$1"
|
||||
local version_dir="$2"
|
||||
local package="$3"
|
||||
local version_info_path
|
||||
|
||||
get_package_version_info "version_info_path" "$install_path" "$version_dir" "$package"
|
||||
|
||||
if [ ! -f "$version_info_path" ]; then
|
||||
comm_log "ERROR" "$version_info_path doesn't exist in check version install!"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# 安装latest管理器
|
||||
install_latest_manager() {
|
||||
local var_path="$1"
|
||||
shift 1
|
||||
sh latest_manager/install.sh --install-path="$var_path" "$@"
|
||||
}
|
||||
|
||||
# 卸载latest管理器
|
||||
uninstall_latest_manager_for_upgrade() {
|
||||
local var_path="$1"
|
||||
${var_path}/manager/uninstall.sh --upgrade
|
||||
}
|
||||
|
||||
# 升级latest管理器
|
||||
upgrade_latest_manager() {
|
||||
local var_path="$1"
|
||||
local latest_version_info latest_manager_version local_manager_version
|
||||
|
||||
latest_version_info="$var_path/manager/version.info"
|
||||
if [ -f "$latest_version_info" ]; then
|
||||
get_version latest_manager_version "$latest_version_info"
|
||||
get_version local_manager_version "latest_manager/version.info"
|
||||
|
||||
set_default "latest_manager_version" "$latest_manager_version" "0"
|
||||
set_default "local_manager_version" "$local_manager_version" "0"
|
||||
|
||||
if [ "$latest_manager_version" -lt "$local_manager_version" ]; then
|
||||
uninstall_latest_manager_for_upgrade "$var_path"
|
||||
install_latest_manager "$var_path" "--upgrade"
|
||||
fi
|
||||
else
|
||||
install_latest_manager "$var_path"
|
||||
fi
|
||||
}
|
||||
|
||||
get_install_for_all_param() {
|
||||
local _outvar="$1"
|
||||
local _install_for_all="$2"
|
||||
local _result=""
|
||||
|
||||
if [ "$_install_for_all" = "y" ]; then
|
||||
_result="--install-for-all"
|
||||
fi
|
||||
|
||||
eval "${_outvar}=\"${_result}\""
|
||||
}
|
||||
|
||||
get_docker_root_param() {
|
||||
local _outvar="$1"
|
||||
local _docker_root="$2"
|
||||
local _result=""
|
||||
|
||||
if [ "$_docker_root" != "" ]; then
|
||||
_result="--docker-root \\\"$_docker_root\\\""
|
||||
fi
|
||||
|
||||
eval "${_outvar}=\"${_result}\""
|
||||
}
|
||||
|
||||
# 通知latest管理器
|
||||
notify_latest_manager() {
|
||||
local var_path="$1"
|
||||
local package="$2"
|
||||
local version="$3"
|
||||
local version_dir="$4"
|
||||
local install_for_all="$5"
|
||||
local docker_root="$6"
|
||||
local ext_params="$7"
|
||||
local operation="$8"
|
||||
local ret package_dir install_for_all_param docker_root_param
|
||||
|
||||
if [ ! -f "$var_path/manager.sh" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${USE_SHARE_INFO}" == "y" ]; then
|
||||
ext_params="$ext_params --use-share-info"
|
||||
fi
|
||||
|
||||
get_package_dir package_dir "$package"
|
||||
get_install_for_all_param "install_for_all_param" "$install_for_all"
|
||||
get_docker_root_param "docker_root_param" "$docker_root"
|
||||
|
||||
eval "\"$var_path/manager.sh\"" --version "\"$version\"" --version-dir "\"$version_dir\"" \
|
||||
--package "\"$package\"" --package-dir "\"$package_dir\"" \
|
||||
"$install_for_all_param" "$docker_root_param" "$ext_params" "$operation"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 通知latest管理器安装完成
|
||||
notify_latest_manager_installed() {
|
||||
local local_manager_version
|
||||
local ext_params
|
||||
|
||||
get_version local_manager_version "latest_manager/version.info"
|
||||
set_default "local_manager_version" "$local_manager_version" "0"
|
||||
|
||||
if [ "$INCREMENT" = "y" ]; then
|
||||
ext_params="--serial $local_manager_version --increment"
|
||||
else
|
||||
ext_params="--serial $local_manager_version"
|
||||
fi
|
||||
|
||||
notify_latest_manager "$@" "$ext_params" "package_installed"
|
||||
}
|
||||
|
||||
# 通知latest管理器创建软链
|
||||
# 老版本全部卸载后,latest回滚到新版本时,会用老版本的install_common_parser.sh,
|
||||
# 调用新版本的--create-package-latest-softlink,会走到这个流程。
|
||||
notify_latest_manager_create_softlink() {
|
||||
notify_latest_manager "$@" "" "package_create_softlink"
|
||||
}
|
||||
|
||||
# 通知latest管理器删除软链
|
||||
notify_latest_manager_remove_softlink() {
|
||||
notify_latest_manager "$@" "" "package_remove_softlink"
|
||||
}
|
||||
|
||||
# 通知latest管理器准备卸载
|
||||
notify_latest_manager_pre_uninstall() {
|
||||
notify_latest_manager "$@" "" "package_pre_uninstall"
|
||||
}
|
||||
|
||||
# 通知latest管理器卸载完成
|
||||
notify_latest_manager_uninstalled() {
|
||||
local is_recreate_softlink="$1"
|
||||
local recreate_softlink=""
|
||||
local ret
|
||||
shift 1
|
||||
|
||||
if [ "$is_recreate_softlink" = "y" ]; then
|
||||
recreate_softlink="--recreate-softlink"
|
||||
fi
|
||||
|
||||
notify_latest_manager "$@" "$recreate_softlink" "package_uninstalled"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 多版本安装流程
|
||||
multi_version_install() {
|
||||
local install_type="$1"
|
||||
local install_path="$2"
|
||||
local filelist_path="$3"
|
||||
local package="$4"
|
||||
local feature_param="$5"
|
||||
local version="$6"
|
||||
local version_dir="$7"
|
||||
local username="$8"
|
||||
local usergroup="$9"
|
||||
local setenv="${10}"
|
||||
local is_upgrade="${11}"
|
||||
local docker_root="${12}"
|
||||
local custom_options="${13}"
|
||||
local install_for_all="${14}"
|
||||
local ret total_ret="0" pkg_running_version version_pair_arr last_version last_version_dir
|
||||
|
||||
create_version_dir "${install_path}" "${version_dir}" "${username}" "${usergroup}" "${install_for_all}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
version_install "${install_type}" "${install_path}" "${filelist_path}" "${package}" "${feature_param}" \
|
||||
"${version_dir}" "${username}" "${usergroup}" "${setenv}" "${is_upgrade}" "${docker_root}" "${custom_options}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
check_version_install "$install_path" "$version_dir" "$package"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
return ${total_ret}
|
||||
}
|
||||
|
||||
# 删除latest下空目录
|
||||
del_empty_dirs_in_latest() {
|
||||
local install_type="$1"
|
||||
local install_path="$2"
|
||||
local latest_dir="$3"
|
||||
local filelist_path="$4"
|
||||
local feature_param="$5"
|
||||
local ret
|
||||
|
||||
create_stash_mod "${install_path}/${latest_dir}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
foreach_filelist "filter_common_dirs" "reset_mod_dirs_with_stash_mod" "${install_type}" "${install_path}/${latest_dir}" "mkdir" \
|
||||
"${filelist_path}" "${feature_param}" "no" "normal"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
foreach_filelist "filter_common_dirs" "remove_install_dirs" "${install_type}" "${install_path}/${latest_dir}" "mkdir" \
|
||||
"${filelist_path}" "${feature_param}" "reverse" "normal"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
foreach_stashmod "restore_stash_mod" "${install_path}/${latest_dir}" "reverse"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
remove_stash_mod "${install_path}/${latest_dir}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 多版本卸载流程
|
||||
multi_version_uninstall() {
|
||||
local install_type="$1"
|
||||
local install_path="$2"
|
||||
local filelist_path="$3"
|
||||
local package="$4"
|
||||
local feature_param="$5"
|
||||
local version="$6"
|
||||
local version_dir="$7"
|
||||
local username="$8"
|
||||
local usergroup="$9"
|
||||
local docker_root="${10}"
|
||||
local custom_options="${11}"
|
||||
local is_recreate_softlink="${12}"
|
||||
local tmp_root tmp_filelist_path
|
||||
local ret total_ret=0 install_path_full="" is_running="" is_upgrade
|
||||
local running_packages is_final_running="false"
|
||||
|
||||
check_param_not_empty "usergroup" "need set usergroup parameter in multi version uninstall!"
|
||||
ret="$?" && [ ${ret} -ne 0 ] && return ${ret}
|
||||
|
||||
get_tmp_root "tmp_root"
|
||||
tmp_filelist_path=$(mktemp "$tmp_root/filelist_XXXXXX" || exit 1)
|
||||
cp -f "${filelist_path}" "${tmp_filelist_path}"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "cp -f ${filelist_path} ${tmp_filelist_path} failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
del_tmp_filelist="rm -f \"${tmp_filelist_path}\""
|
||||
|
||||
version_uninstall "${install_type}" "${install_path}" "${filelist_path}" "${package}" "${feature_param}" \
|
||||
"${version_dir}" "${username}" "${docker_root}" "${custom_options}"
|
||||
if [ $? -ne 0 ]; then
|
||||
eval "${del_tmp_filelist}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 删除临时文件tmp_filelist_path
|
||||
eval "${del_tmp_filelist}"
|
||||
|
||||
# 删除版本空目录
|
||||
is_dir_empty "${install_path}/${version_dir}"
|
||||
if [ $? -eq 0 ]; then
|
||||
remove_dir_icp "${install_path}/${version_dir}"
|
||||
ret="$?" && [ $ret -ne 0 ] && total_ret="1"
|
||||
fi
|
||||
|
||||
return ${total_ret}
|
||||
}
|
||||
469
csrc/scripts/package/common/sh/script_operator.inc
Normal file
469
csrc/scripts/package/common/sh/script_operator.inc
Normal file
@@ -0,0 +1,469 @@
|
||||
#!/bin/sh
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 公共脚本操作库
|
||||
ENV_SHELL_TYPES="bash csh fish"
|
||||
|
||||
# 检查参数。
|
||||
__check_param() {
|
||||
local name="$1"
|
||||
local value
|
||||
|
||||
value="$(eval echo \${${name}})"
|
||||
|
||||
if [ "${value}" = "" ]; then
|
||||
log "ERROR" "need set ${name} parameter!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 设置用户家目录路径
|
||||
__set_userpath() {
|
||||
local username="$1"
|
||||
local docker_root="$2"
|
||||
|
||||
if [ -z "${docker_root}" ] || [ "${docker_root}" = "/" ]; then
|
||||
userpath="$(eval echo "~${username}")"
|
||||
else
|
||||
if [ "${username}" = "root" ]; then
|
||||
userpath="${docker_root}/root"
|
||||
else
|
||||
userpath="${docker_root}/home/${username}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 获取setenv.[shell]路径正则
|
||||
get_setenv_path_regex() {
|
||||
local _outvar="$1"
|
||||
local _package="$2"
|
||||
local _shell_type="$3"
|
||||
# setenv传入路径正则规则
|
||||
# 必须以/开头(绝对路径)
|
||||
# 必须以/${package}/bin/setenv.${shell_type}结尾
|
||||
local _path_regex="\/\(.\+\/\)\?${_package}\/bin\/setenv.${_shell_type}"
|
||||
|
||||
eval "${_outvar}=\"${_path_regex}\""
|
||||
}
|
||||
|
||||
# 创建setenv文件
|
||||
__create_setenv_file() {
|
||||
local file="$1"
|
||||
local shell_type="$2"
|
||||
local add_multi_version_param="$3"
|
||||
local install_path="$4"
|
||||
local ret
|
||||
|
||||
if [ ! -f "${file}" ]; then
|
||||
echo "#!/usr/bin/env ${shell_type}" > ${file}
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
if [ "${add_multi_version_param}" = "true" ]; then
|
||||
if [ "${shell_type}" = "bash" ]; then
|
||||
echo "export ASCEND_HOME_PATH=\"${install_path}\"" >> "${file}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
elif [ "${shell_type}" = "fish" ]; then
|
||||
echo "set -gx ASCEND_HOME_PATH \"${install_path}\"" >> "${file}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
elif [ "${shell_type}" = "csh" ]; then
|
||||
echo "setenv ASCEND_HOME_PATH \"${install_path}\"" >> "${file}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# 是否存在ASCEND_HOME_PATH环境变量
|
||||
has_ascend_home_path_env() {
|
||||
local file="$1"
|
||||
[ ! -f "${file}" ] && return 0
|
||||
grep "\<ASCEND_HOME_PATH\>" "${file}" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# 添加ASCEND_HOME_PATH环境变量
|
||||
add_ascend_home_path_env() {
|
||||
local file="$1"
|
||||
local shell_type="$2"
|
||||
local install_path="$3"
|
||||
|
||||
if [ "${shell_type}" = "bash" ]; then
|
||||
sed -i "1aexport ASCEND_HOME_PATH=\"${install_path}\"" "${file}"
|
||||
elif [ "${shell_type}" = "fish" ]; then
|
||||
sed -i "1aset -gx ASCEND_HOME_PATH \"${install_path}\"" "${file}"
|
||||
elif [ "${shell_type}" = "csh" ]; then
|
||||
sed -i "1asetenv ASCEND_HOME_PATH \"${install_path}\"" "${file}"
|
||||
fi
|
||||
}
|
||||
|
||||
# 删除rcfile中的source <path>
|
||||
__remove_path_regex() {
|
||||
local path_regex="$1"
|
||||
local rcfile="$2"
|
||||
|
||||
if [ -f "${rcfile}" ]; then
|
||||
sed -i "/source ${path_regex}\( \"multi_version\"\)\?$/d" "${rcfile}"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "remove ${rcfile} source command failed!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 获取setenv.${shell_type}文件路径
|
||||
get_setenv_filepath() {
|
||||
local _outvar="$1"
|
||||
local _install_path="$2"
|
||||
local _shell_type="$3"
|
||||
|
||||
eval "${_outvar}=\"${_install_path}/bin/setenv.${_shell_type}\""
|
||||
}
|
||||
|
||||
# setenv.[shell]总脚本中添加一条语句
|
||||
add_setenv_cmd() {
|
||||
local install_path="$1"
|
||||
local setenv_filepath="$2"
|
||||
local package="$3"
|
||||
local shell_type="$4"
|
||||
local username="$5"
|
||||
local usergroup="$6"
|
||||
local add_multi_version_param="$7"
|
||||
local path_regex config_path multi_version_param ret
|
||||
|
||||
get_setenv_path_regex "path_regex" "${package}" "${shell_type}"
|
||||
|
||||
get_setenv_filepath "config_path" "$install_path" "$shell_type"
|
||||
__create_setenv_file "${config_path}" "${shell_type}" "${add_multi_version_param}" "${install_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
change_own "${config_path}" "${username}:${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
change_mod "${config_path}" "${SETENV_WRITEABLE_MOD}" ""
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__remove_path_regex "${path_regex}" "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
if [ "${add_multi_version_param}" = "true" ]; then
|
||||
multi_version_param=" \"multi_version\""
|
||||
fi
|
||||
|
||||
if [ "${shell_type}" = "bash" ] || [ "${shell_type}" = "fish" ]; then
|
||||
echo "source ${setenv_filepath}${multi_version_param}" >> "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
elif [ "${shell_type}" = "csh" ]; then
|
||||
echo "set argv=(\"${setenv_filepath}\"${multi_version_param}); source ${setenv_filepath}" >> "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
fi
|
||||
change_mod "${config_path}" "${SETENV_MOD}" "${INSTALL_FOR_ALL}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 修改路径的own
|
||||
__chown_path() {
|
||||
local path="$1"
|
||||
local username="$2"
|
||||
local usergroup="$3"
|
||||
|
||||
if [ "${username}" != "" ] && [ "${usergroup}" != "" ]; then
|
||||
chown -h "${username}:${usergroup}" "${path}"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "${path} chown failed!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 创建配置所在目录
|
||||
__create_config_dir() {
|
||||
local dir="$1"
|
||||
local username="$2"
|
||||
local usergroup="$3"
|
||||
local ret
|
||||
|
||||
if [ ! -d "${dir}" ]; then
|
||||
mkdir -p "${dir}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__chown_path "${dir}" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 创建配置文件
|
||||
__create_config_file() {
|
||||
local file="$1"
|
||||
local username="$2"
|
||||
local usergroup="$3"
|
||||
local ret
|
||||
|
||||
if [ ! -f "${file}" ]; then
|
||||
touch "${file}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__chown_path "${file}" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 为bash添加rc配置
|
||||
add_bash_env_rc() {
|
||||
local userpath="$1"
|
||||
local username="$2"
|
||||
local usergroup="$3"
|
||||
local path_regex="$4"
|
||||
local setenv_filepath="$5"
|
||||
local config_path="${userpath}/.bashrc"
|
||||
local ret
|
||||
|
||||
__create_config_dir "${userpath}" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__create_config_file "${config_path}" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__remove_path_regex "${path_regex}" "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
echo "source ${setenv_filepath}" >> "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
}
|
||||
|
||||
# 为fish添加rc配置
|
||||
add_fish_env_rc() {
|
||||
local userpath="$1"
|
||||
local username="$2"
|
||||
local usergroup="$3"
|
||||
local path_regex="$4"
|
||||
local setenv_filepath="$5"
|
||||
local config_path="${userpath}/.config/fish/config.fish"
|
||||
local ret
|
||||
|
||||
__create_config_dir "${userpath}" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__create_config_dir "${userpath}/.config" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__create_config_dir "${userpath}/.config/fish" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__create_config_file "${config_path}" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__remove_path_regex "${path_regex}" "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
echo "source ${setenv_filepath}" >> "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
}
|
||||
|
||||
# 为csh添加rc配置
|
||||
add_csh_env_rc() {
|
||||
local userpath="$1"
|
||||
local username="$2"
|
||||
local usergroup="$3"
|
||||
local path_regex="$4"
|
||||
local setenv_filepath="$5"
|
||||
local config_path="${userpath}/.cshrc"
|
||||
local ret
|
||||
|
||||
__create_config_dir "${userpath}" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__create_config_file "${config_path}" "${username}" "${usergroup}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__remove_path_regex "${path_regex}" "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
echo "set argv=(\"${setenv_filepath}\"); source ${setenv_filepath}" >> "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
}
|
||||
|
||||
# 添加source setenv.[shell]脚本到rc文件中
|
||||
add_env_rc() {
|
||||
local install_path="$1"
|
||||
local setenv_filepath="$2"
|
||||
local package="$3"
|
||||
local shell_type="$4"
|
||||
local setenv="$5"
|
||||
local username="$6"
|
||||
local usergroup="$7"
|
||||
local add_multi_version_param="$8"
|
||||
local docker_root="$9"
|
||||
local path_suffix="${package}/bin/setenv.${shell_type}"
|
||||
local path_regex
|
||||
local matched
|
||||
local userpath
|
||||
local config_path
|
||||
local ret
|
||||
|
||||
__check_param "package"
|
||||
__check_param "username"
|
||||
__check_param "usergroup"
|
||||
|
||||
echo "${shell_type}" | grep -E "^(bash|fish|csh)$" > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "shell type ${shell_type} not support!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
get_setenv_path_regex "path_regex" "${package}" "${shell_type}"
|
||||
|
||||
matched="$(echo "${setenv_filepath}" | sed -n "/^${path_regex}$/p")"
|
||||
if [ -z "${matched}" ]; then
|
||||
log "ERROR" "setenv filepath is illegal, should endswith ${path_suffix}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${setenv}" = "y" ]; then
|
||||
__set_userpath "${username}" "${docker_root}"
|
||||
case "${shell_type}" in
|
||||
bash) add_bash_env_rc "${userpath}" "${username}" "${usergroup}" "${path_regex}" "${setenv_filepath}" ;;
|
||||
fish) add_fish_env_rc "${userpath}" "${username}" "${usergroup}" "${path_regex}" "${setenv_filepath}" ;;
|
||||
csh) add_csh_env_rc "${userpath}" "${username}" "${usergroup}" "${path_regex}" "${setenv_filepath}" ;;
|
||||
esac
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
fi
|
||||
|
||||
# 如果bin目录不存在,则不处理
|
||||
[ ! -d "${install_path}/bin" ] && return 0
|
||||
|
||||
add_setenv_cmd "${install_path}" "${setenv_filepath}" "${package}" "${shell_type}" "${username}" "${usergroup}" "${add_multi_version_param}"
|
||||
}
|
||||
|
||||
# 删除setenv文件,如果已经没有setenv内容
|
||||
__remove_setenv_file_if_no_content() {
|
||||
local file="$1"
|
||||
local shell_type="$2"
|
||||
local num
|
||||
|
||||
if [ ! -f "${file}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
num=$(grep "setenv.${shell_type}" ${file} | wc -l)
|
||||
if [ ${num} -eq 0 ]; then
|
||||
rm -f "${file}" > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
log "WARNING" "Delete file:${file} failed, please delete it by yourself."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 从rc文件中删除source setenv.[shell]
|
||||
del_env_rc() {
|
||||
local install_path="$1"
|
||||
local setenv_filepath="$2"
|
||||
local shell_type="$3"
|
||||
local username="$4"
|
||||
local docker_root="$5"
|
||||
local path_regex
|
||||
local userpath
|
||||
local config_path
|
||||
local oldmod
|
||||
|
||||
__check_param "username"
|
||||
|
||||
echo "${shell_type}" | grep -E "^(bash|fish|csh)$" > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "shell type ${shell_type} not support!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
__set_userpath "${username}" "${docker_root}"
|
||||
|
||||
# 将路径中的/转换为\/
|
||||
path_to_regex "path_regex" "${setenv_filepath}"
|
||||
|
||||
if [ "${shell_type}" = "bash" ]; then
|
||||
__remove_path_regex "${path_regex}" "${userpath}/.bashrc"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
elif [ "${shell_type}" = "fish" ]; then
|
||||
__remove_path_regex "${path_regex}" "${userpath}/.config/fish/config.fish"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
elif [ "${shell_type}" = "csh" ]; then
|
||||
__remove_path_regex "${path_regex}" "${userpath}/.cshrc"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
fi
|
||||
|
||||
get_setenv_filepath "config_path" "$install_path" "$shell_type"
|
||||
|
||||
if [ ! -f "${config_path}" ]; then
|
||||
# 如果文件不存在,则不处理
|
||||
return 0
|
||||
fi
|
||||
|
||||
get_file_mod "oldmod" "${config_path}"
|
||||
change_mod "${config_path}" "${SETENV_WRITEABLE_MOD}" ""
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__remove_path_regex "${path_regex}" "${config_path}"
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
change_mod "${config_path}" "${oldmod}" ""
|
||||
ret="$?" && [ $ret -ne 0 ] && return $ret
|
||||
|
||||
__remove_setenv_file_if_no_content "${config_path}" "${shell_type}"
|
||||
}
|
||||
|
||||
# 移除路径中的docker_root
|
||||
remove_path_docker_root() {
|
||||
local _outvar="$1"
|
||||
local _path="$2"
|
||||
local _docker_root="$3"
|
||||
local _path_rpdr="$(echo "${_path}" | sed "s/^.\{${#_docker_root}\}//")"
|
||||
|
||||
eval "${_outvar}=\"${_path_rpdr}\""
|
||||
}
|
||||
|
||||
# 获取脚本路径与脚本真实路径(docker_root)
|
||||
get_shell_path_and_shell_path_real() {
|
||||
local _outvar="$1"
|
||||
local _install_path="$2"
|
||||
local _package="$3"
|
||||
local _shell_filename="$4"
|
||||
local _docker_root="$5"
|
||||
local _package_dirpath _shell_path _shell_path_real
|
||||
|
||||
get_package_dirpath "_package_dirpath" "${_package}"
|
||||
_shell_path_real="${_install_path}/${_package_dirpath}/bin/${_shell_filename}"
|
||||
|
||||
if [ "${_docker_root}" != "" ]; then
|
||||
# 移除脚本路径中的docker_root前缀
|
||||
remove_path_docker_root "_shell_path" "${_shell_path_real}" "${_docker_root}"
|
||||
else
|
||||
_shell_path="${_shell_path_real}"
|
||||
fi
|
||||
|
||||
eval "${_outvar}=\"${_shell_path} ${_shell_path_real}\""
|
||||
}
|
||||
|
||||
|
||||
# 设置环境变量
|
||||
add_setenv() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# 删除环境变量
|
||||
del_setenv() {
|
||||
return 0
|
||||
}
|
||||
1075
csrc/scripts/package/common/sh/version_cfg.inc
Normal file
1075
csrc/scripts/package/common/sh/version_cfg.inc
Normal file
File diff suppressed because it is too large
Load Diff
174
csrc/scripts/package/common/sh/version_compatiable.inc
Normal file
174
csrc/scripts/package/common/sh/version_compatiable.inc
Normal file
@@ -0,0 +1,174 @@
|
||||
#!/bin/sh
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 获取版本号,用于版本兼容性对比
|
||||
get_package_compat_version() {
|
||||
local _outvar="$1"
|
||||
local _version_info_path="$2"
|
||||
local _result
|
||||
|
||||
if [ ! -f "${_version_info_path}" ]; then
|
||||
read -r "$_outvar" <<EOF
|
||||
EOF
|
||||
return 1
|
||||
fi
|
||||
|
||||
read -r "$_outvar" <<EOF
|
||||
$(grep "^Version=" "$_version_info_path" | cut -d= -f2- | cut -d- -f1 | cut -d. -f-3)
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取正式包名
|
||||
get_formal_package_name() {
|
||||
local _outvar="$1"
|
||||
local _package="$2"
|
||||
read -r "$_outvar" <<EOF
|
||||
$(echo "$_package" | sed 's/_/-/g')
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取非正式包名
|
||||
get_informal_package_name() {
|
||||
local _outvar="$1"
|
||||
local _package="$2"
|
||||
read -r "$_outvar" <<EOF
|
||||
$(echo "$_package" | sed 's/-/_/g')
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取需求包列表。
|
||||
_get_required_packages() {
|
||||
local _version_info_path="$1"
|
||||
|
||||
if [ ! -f "$_version_info_path" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
awk '
|
||||
function join(items, len, sep, result, i) {
|
||||
if (len >= 1) {
|
||||
result = items[1]
|
||||
for (i = 2; i <= len; i++) {
|
||||
result = sprintf("%s%s%s", result, sep, items[i])
|
||||
}
|
||||
return result
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
/^required_package_.+_version=/ {
|
||||
split($0, line_tokens, "=")
|
||||
len_require_tokens = split(line_tokens[1], require_tokens, "_")
|
||||
len_package_names = 0
|
||||
for (i = 3; i < len_require_tokens; i++) {
|
||||
len_package_names++
|
||||
package_names[len_package_names] = require_tokens[i]
|
||||
}
|
||||
package_name = join(package_names, len_package_names, "_")
|
||||
print package_name
|
||||
}
|
||||
' "${_version_info_path}"
|
||||
}
|
||||
|
||||
# 获取需求包信息。
|
||||
_get_required_package_info() {
|
||||
local _outvar="$1"
|
||||
local _version_info_path="$2"
|
||||
local _pkg_name="$3"
|
||||
local _required_pkg_name
|
||||
local _required_value
|
||||
|
||||
if [ ! -f "${_version_info_path}" ]; then
|
||||
eval "${_outvar}=\"\""
|
||||
return 1
|
||||
fi
|
||||
|
||||
_required_pkg_name="required_package_${_pkg_name}_version"
|
||||
_required_value="$(grep "^${_required_pkg_name}=" "${_version_info_path}" | cut -d= -f2-)"
|
||||
# _required_value取得的值带有双引号,eval时不可以在外侧再添加双引号
|
||||
|
||||
eval "${_outvar}=${_required_value}"
|
||||
}
|
||||
|
||||
# 检查版本与需求版本兼容性。
|
||||
# 兼容返回0,不兼容返回1
|
||||
_check_version_required() {
|
||||
local version="$1"
|
||||
local require="$2"
|
||||
local script_dir="$3"
|
||||
local src_pkg="$4"
|
||||
local dst_pkg="$5"
|
||||
local result
|
||||
|
||||
result=$(awk -f "${script_dir}/check_version_required.awk" -v version="${version}" -v all_required="${require}")
|
||||
if [ "${result}" = "T" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Version compatibility check failed, $src_pkg required $dst_pkg version $require, but $dst_pkg version is $version!"
|
||||
return 1
|
||||
}
|
||||
|
||||
# 检查版本兼容性。
|
||||
_check_version_compatiable() {
|
||||
local package="$1"
|
||||
local install_path="$2"
|
||||
local script_dir="$3"
|
||||
local version_info_path="$script_dir/../version.info"
|
||||
local err_msgs package_formal self_version src_pkg src_pkg_formal dst_pkg dst_pkg_formal
|
||||
local installed_version_info pkg_version_info_path
|
||||
|
||||
get_formal_package_name "package_formal" "$package"
|
||||
get_package_compat_version "self_version" "$version_info_path"
|
||||
|
||||
if [ -d "$install_path/share/info" ]; then
|
||||
err_msgs="$(
|
||||
ls "$install_path/share/info" | grep -v "^${package}$" | while read src_pkg; do
|
||||
get_formal_package_name "src_pkg_formal" "$package"
|
||||
installed_version_info="$install_path/share/info/$src_pkg/version.info"
|
||||
grep "^required_package_${package_formal}_version=" "$installed_version_info" | cut -d= -f2- | tr -d '"' | while read required; do
|
||||
_check_version_required "$self_version" "$required" "$script_dir" "$src_pkg_formal" "$package_formal"
|
||||
done
|
||||
done
|
||||
)"
|
||||
if [ "$err_msgs" != "" ]; then
|
||||
while read err_msg; do
|
||||
comm_log "ERROR" "$err_msg"
|
||||
done <<EOF
|
||||
$err_msgs
|
||||
EOF
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
err_msgs="$(
|
||||
_get_required_packages "${version_info_path}" | while read dst_pkg_formal; do
|
||||
get_informal_package_name "dst_pkg" "$dst_pkg_formal"
|
||||
pkg_version_info_path="$install_path/share/info/$dst_pkg_formal/version.info"
|
||||
if [ ! -f "$pkg_version_info_path" ]; then
|
||||
pkg_version_info_path="$install_path/share/info/$dst_pkg/version.info"
|
||||
fi
|
||||
if [ -f "$pkg_version_info_path" ]; then
|
||||
get_package_compat_version "pkg_version" "$pkg_version_info_path"
|
||||
_get_required_package_info "required" "$version_info_path" "$dst_pkg_formal"
|
||||
_check_version_required "$pkg_version" "$required" "$script_dir" "$package_formal" "$dst_pkg_formal"
|
||||
fi
|
||||
done
|
||||
)"
|
||||
if [ "$err_msgs" != "" ]; then
|
||||
while read err_msg; do
|
||||
comm_log "ERROR" "$err_msg"
|
||||
done <<EOF
|
||||
$err_msgs
|
||||
EOF
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user