已合并
feat: 新增deb/rpm包custom_postinst.sh和custom_prerm.sh #1196
liu-wei创建于 7月29日
feat: 新增deb/rpm包custom_postinst.sh和custom_prerm.sh #1196
已合并
共 2 个文件变更+121-0
| @@ -0,0 +1,66 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | + | ||
| 12 | +sourcedir="${INSTALL_PATH}" | ||
| 13 | +WHL_INSTALL_DIR_PATH="${sourcedir}/python/site-packages" | ||
| 14 | +unset PYTHONPATH | ||
| 15 | +export PIP_BREAK_SYSTEM_PACKAGES=1 | ||
| 16 | + | ||
| 17 | +run_pip() { python3 -m pip "$@" || pip3 "$@"; } | ||
| 18 | + | ||
| 19 | +# install es_cv whl | ||
| 20 | +whl_dir="${sourcedir}/ops_cv/es_packages/whl" | ||
| 21 | +if [ -d "${whl_dir}" ]; then | ||
| 22 | + for whl in "${whl_dir}"/*.whl; do | ||
| 23 | + if [ -f "${whl}" ]; then | ||
| 24 | + echo "[ops-cv] installing ${whl}" | ||
| 25 | + chmod u+w "${WHL_INSTALL_DIR_PATH}" 2>/dev/null | ||
| 26 | + run_pip install --disable-pip-version-check --upgrade --no-deps --force-reinstall -t "${WHL_INSTALL_DIR_PATH}" "${whl}" \ | ||
| 27 | + && rm -f "${whl}" || true | ||
| 28 | + fi | ||
| 29 | + done | ||
| 30 | +fi | ||
| 31 | + | ||
| 32 | +# clean up ops_cv source directory after whl install | ||
| 33 | +if [ -d "${sourcedir}/ops_cv" ]; then | ||
| 34 | + rm -rf "${sourcedir}/ops_cv" | ||
| 35 | +fi | ||
| 36 | + | ||
| 37 | +# touch __init__.py for ops_cv impl | ||
| 38 | +built_in_impl_path="${sourcedir}/opp/built-in/op_impl/ai_core/tbe/impl/ops_cv" | ||
| 39 | +if [ -d "${built_in_impl_path}" ]; then | ||
| 40 | + if [ "$(id -u)" != "0" ] && [ ! -w "${built_in_impl_path}" ]; then | ||
| 41 | + chmod u+w -R "${built_in_impl_path}" 2>/dev/null | ||
| 42 | + fi | ||
| 43 | + touch "${built_in_impl_path}/__init__.py" | ||
| 44 | + [ -d "${built_in_impl_path}/dynamic" ] && touch "${built_in_impl_path}/dynamic/__init__.py" | ||
| 45 | +fi | ||
| 46 | + | ||
| 47 | +# cross-arch so copy: copy graph/host so to actual arch dir when arch mismatches | ||
| 48 | +pkg_arch_name="${PKG_ARCH_NAME}" | ||
| 49 | +actual_arch=$(uname -m) | ||
| 50 | +if [ -n "${pkg_arch_name}" ] && [ "${actual_arch}" != "${pkg_arch_name}" ]; then | ||
| 51 | + graph_so_src="${sourcedir}/opp/built-in/op_graph/lib/linux/${pkg_arch_name}/libopgraph_cv.so" | ||
| 52 | + graph_so_dst_dir="${sourcedir}/opp/built-in/op_graph/lib/linux/${actual_arch}" | ||
| 53 | + host_so_src="${sourcedir}/opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${pkg_arch_name}/libophost_cv.so" | ||
| 54 | + host_so_dst_dir="${sourcedir}/opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${actual_arch}" | ||
| 55 | + | ||
| 56 | + for so_src in "${graph_so_src}" "${host_so_src}"; do | ||
| 57 | + if [ -f "${so_src}" ]; then | ||
| 58 | + dst_dir=$(dirname "${so_src}" | sed "s|/${pkg_arch_name}$|/${actual_arch}|") | ||
| 59 | + if [ ! -d "${dst_dir}" ]; then | ||
| 60 | + mkdir -p "${dst_dir}" | ||
| 61 | + fi | ||
| 62 | + cp -f "${so_src}" "${dst_dir}/" | ||
| 63 | + chmod 755 "${dst_dir}/$(basename "${so_src}")" | ||
| 64 | + fi | ||
| 65 | + done | ||
| 66 | +fi | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | + | ||
| 12 | +sourcedir="${INSTALL_PATH}" | ||
| 13 | +WHL_INSTALL_DIR_PATH="${sourcedir}/python/site-packages" | ||
| 14 | +export PYTHONPATH="${WHL_INSTALL_DIR_PATH}" | ||
| 15 | +export PIP_BREAK_SYSTEM_PACKAGES=1 | ||
| 16 | + | ||
| 17 | +run_pip() { python3 -m pip "$@" || pip3 "$@"; } | ||
| 18 | +run_pip uninstall -y es_cv >/dev/null 2>&1 || true | ||
| 19 | + | ||
| 20 | +rm -rf "${WHL_INSTALL_DIR_PATH}/es_cv" 2>/dev/null | ||
| 21 | +rm -rf "${WHL_INSTALL_DIR_PATH}/es_cv-"*.dist-info 2>/dev/null | ||
| 22 | + | ||
| 23 | +# remove __init__.py | ||
| 24 | +built_in_impl_path="${sourcedir}/opp/built-in/op_impl/ai_core/tbe/impl/ops_cv" | ||
| 25 | +if [ -d "${built_in_impl_path}" ]; then | ||
| 26 | + rm -f "${built_in_impl_path}/__init__.py" 2>/dev/null | ||
| 27 | + rm -f "${built_in_impl_path}/dynamic/__init__.py" 2>/dev/null | ||
| 28 | +fi | ||
| 29 | + | ||
| 30 | +# remove cross-arch so files | ||
| 31 | +pkg_arch_name="${PKG_ARCH_NAME}" | ||
| 32 | +actual_arch=$(uname -m) | ||
| 33 | +if [ -n "${pkg_arch_name}" ] && [ "${actual_arch}" != "${pkg_arch_name}" ]; then | ||
| 34 | + graph_so_path="${sourcedir}/opp/built-in/op_graph/lib/linux/${actual_arch}/libopgraph_cv.so" | ||
| 35 | + host_so_path="${sourcedir}/opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux/${actual_arch}/libophost_cv.so" | ||
| 36 | + for so_path in "${graph_so_path}" "${host_so_path}"; do | ||
| 37 | + so_dir=$(dirname "${so_path}") | ||
| 38 | + if [ -f "${so_path}" ]; then | ||
| 39 | + rm -f "${so_path}" | ||
| 40 | + fi | ||
| 41 | + if [ -d "${so_dir}" ] && [ -z "$(ls -A "${so_dir}")" ]; then | ||
| 42 | + rmdir "${so_dir}" 2>/dev/null || true | ||
| 43 | + fi | ||
| 44 | + done | ||
| 45 | +fi | ||
| 46 | + | ||
| 47 | +# clean up whl and empty directories | ||
| 48 | +rm -f "${sourcedir}"/ops_cv/es_packages/whl/*.whl 2>/dev/null | ||
| 49 | +rmdir "${sourcedir}"/ops_cv/es_packages/whl 2>/dev/null || true | ||
| 50 | +rmdir "${sourcedir}"/ops_cv/es_packages 2>/dev/null || true | ||
| 51 | +rmdir "${sourcedir}"/ops_cv 2>/dev/null || true | ||
| 52 | + | ||
| 53 | +rmdir "${WHL_INSTALL_DIR_PATH}" 2>/dev/null || true | ||
| 54 | +parent=$(dirname "${WHL_INSTALL_DIR_PATH}") | ||
| 55 | +[ -d "${parent}" ] && rmdir "${parent}" 2>/dev/null || true | ||