From 3b54f03a309ea92bc2d4ce4ab7727e6697f27abd Mon Sep 17 00:00:00 2001 From: BianTanggui Date: Mon, 5 Dec 2022 15:57:14 +0800 Subject: [PATCH] Match-id-c9c7f28b3c953429ce8fd29743f5a9f40542dba1 --- build/conf/ascend-docker-plugin.yaml | 4 +++ build/scripts/run_main.sh | 43 ++++++++++++++++++++++++++-- install/deb/src/main.go | 30 ++++++++++--------- 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/build/conf/ascend-docker-plugin.yaml b/build/conf/ascend-docker-plugin.yaml index 5ce85c7..9d16006 100644 --- a/build/conf/ascend-docker-plugin.yaml +++ b/build/conf/ascend-docker-plugin.yaml @@ -92,6 +92,10 @@ package: - "{{ systemEnv.workspace }}/ascend-docker-plugin/opensource/makeself-release-2.4.2/makeself.sh" - "{{ systemEnv.workspace }}/ascend-docker-plugin/opensource/makeself-release-2.4.2/makeself-header.sh" des: "{{ systemEnv.workspace }}/ascend-docker-plugin/build/conf/scripts/" + - sed: + option: "-i" + srcstr: 's/%{PACKAGE_VERSION}%/{{ version }}/g' + curfile: '{{ systemEnv.workspace }}/ascend-docker-plugin/build/run_pkg/run_main.sh' - commands: - command: "chmod 550 {{ systemEnv.workspace }}/ascend-docker-plugin/build/run_pkg/run_main.sh" diff --git a/build/scripts/run_main.sh b/build/scripts/run_main.sh index d0edd77..6fcd42a 100644 --- a/build/scripts/run_main.sh +++ b/build/scripts/run_main.sh @@ -6,6 +6,24 @@ set -e ASCEND_RUNTIME_CONFIG_DIR=/etc/ascend-docker-runtime.d DOCKER_CONFIG_DIR=/etc/docker INSTALL_PATH=/usr/local/Ascend/Ascend-Docker-Runtime +readonly PACKAGE_VERSION=%{PACKAGE_VERSION}% + + +function save_install_args() { + if [ -f "${INSTALL_PATH}"/ascend_docker_runtime_install.info ]; then + rm "${INSTALL_PATH}"/ascend_docker_runtime_install.info + fi + { + echo -e "version=${PACKAGE_VERSION}" + echo -e "arch=$(uname -m)" + echo -e "os=linux" + echo -e "path=${INSTALL_PATH}" + echo -e "build=Ascend-docker-runtime_${PACKAGE_VERSION}-$(uname -m)" + echo -e "a500=${a500}" + echo -e "a200=${a200}" + echo -e "a200isoc=${a200isoc}" + } >> "${INSTALL_PATH}"/ascend_docker_runtime_install.info +} function install() { @@ -76,12 +94,15 @@ function install() mv ${SRC} ${DST} chmod 600 ${DST} echo 'create damom.json success' + save_install_args + echo "[INFO]: Ascend Docker Runtime has been installed in: ${INSTALL_PATH}" + echo "[INFO]: The version of Ascend Docker Runtime is: ${PACKAGE_VERSION}" echo 'please reboot docker daemon to take effect' } function uninstall() { - echo 'uninstalling ascend docker runtime' + echo "[INFO]: Uninstalling ascend docker runtime ${PACKAGE_VERSION}" if [ ! -d "${INSTALL_PATH}" ]; then echo 'WARNING: the specified install path does not exist, skipping' @@ -120,16 +141,32 @@ function upgrade() cp -f ./ascend-docker-plugin-install-helper ${INSTALL_PATH}/ascend-docker-plugin-install-helper cp -f ./ascend-docker-destroy ${INSTALL_PATH}/ascend-docker-destroy cp -f ./uninstall.sh ${INSTALL_PATH}/script/uninstall.sh - cp -f ./base.list ${ASCEND_RUNTIME_CONFIG_DIR}/base.list chmod 550 ${INSTALL_PATH}/ascend-docker-runtime chmod 550 ${INSTALL_PATH}/ascend-docker-hook chmod 550 ${INSTALL_PATH}/ascend-docker-cli chmod 550 ${INSTALL_PATH}/ascend-docker-plugin-install-helper chmod 550 ${INSTALL_PATH}/ascend-docker-destroy chmod 500 ${INSTALL_PATH}/script/uninstall.sh + if [ -f "${INSTALL_PATH}"/ascend_docker_runtime_install.info ]; then + if [ "$(grep "a500=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "a500=y" ];then + a500=y + cp -f ./base.list_A500 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + elif [ "$(grep "a200=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "a200=y" ]; then + a200=y + cp -f ./base.list_A200 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + elif [ "x$(grep "a200isoc=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "xa200isoc=y" ]; then + a200isoc=y + cp -f ./base.list_A200ISoC ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + else + cp -f ./base.list ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + fi + save_install_args + fi chmod 440 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - echo 'upgrade ascend docker runtime success' + echo "[INFO]: Ascend Docker Runtime has been installed in: ${INSTALL_PATH}" + echo '[INFO]: upgrade ascend docker runtime success' + echo "[INFO]: The version of Ascend Docker Runtime is: ${PACKAGE_VERSION}" } INSTALL_FLAG=n diff --git a/install/deb/src/main.go b/install/deb/src/main.go index e60f34b..1a4c40c 100644 --- a/install/deb/src/main.go +++ b/install/deb/src/main.go @@ -52,7 +52,7 @@ func main() { if err != nil { log.Fatal(err) } - hwlog.OpLog.Infof("%v installer started", logPrefixWords) + hwlog.OpLog.Infof("%v start running script", logPrefixWords) if !mindxcheckutils.StringChecker(strings.Join(os.Args, " "), 0, maxCommandLength, mindxcheckutils.DefaultWhiteList+" ") { @@ -60,12 +60,12 @@ func main() { log.Fatal("command error") } - err = process() + err, behavior := process() if err != nil { - hwlog.OpLog.Errorf("%v run install failed: %v", logPrefixWords, err) + hwlog.OpLog.Errorf("%v run script failed: %v", logPrefixWords, err) log.Fatal(fmt.Errorf("error in installation")) } - hwlog.OpLog.Infof("%v run install success", logPrefixWords) + hwlog.OpLog.Infof("%v run %v success", logPrefixWords, behavior) } func initLogModule(ctx context.Context) error { @@ -85,7 +85,7 @@ func initLogModule(ctx context.Context) error { return nil } -func process() error { +func process() (error, string) { const helpMessage = "\tadd \n" + "\t rm \n" + "\t -h help command" @@ -93,38 +93,40 @@ func process() error { flag.Parse() if *helpFlag { _, err := fmt.Println(helpMessage) - return err + return err, "" } command := flag.Args() if len(command) == 0 { - return fmt.Errorf("error param") + return fmt.Errorf("error param"), "" } - action := command[actionPosition] + action, behavior := command[actionPosition], "" correctParam := false if action == addCommand && len(command) == addCommandLength { correctParam = true + behavior = "install" } if action == rmCommand && len(command) == rmCommandLength { correctParam = true + behavior = "uninstall" } if !correctParam { - return fmt.Errorf("error param") + return fmt.Errorf("error param"), "" } srcFilePath := command[srcFilePosition] if _, err := os.Stat(srcFilePath); os.IsNotExist(err) { if _, err := mindxcheckutils.RealDirChecker(filepath.Dir(srcFilePath), true, false); err != nil { - return err + return err, behavior } } else { if _, err := mindxcheckutils.RealFileChecker(srcFilePath, true, false, mindxcheckutils.DefaultSize); err != nil { - return err + return err, behavior } } destFilePath := command[destFilePosition] if _, err := mindxcheckutils.RealDirChecker(filepath.Dir(destFilePath), true, false); err != nil { - return err + return err, behavior } runtimeFilePath := "" if len(command) == addCommandLength { @@ -134,9 +136,9 @@ func process() error { // check file permission writeContent, err := createJsonString(srcFilePath, runtimeFilePath, action) if err != nil { - return err + return err, behavior } - return writeJson(destFilePath, writeContent) + return writeJson(destFilePath, writeContent), behavior } func createJsonString(srcFilePath, runtimeFilePath, action string) ([]byte, error) {