Match-id-333af697bff0299c9522aeb1f41de79301684546

This commit is contained in:
BianTanggui
2020-09-15 20:25:32 +08:00
parent 0bc154112c
commit 694c4a0845
8 changed files with 541 additions and 165 deletions

158
build/scripts/run_main.sh Normal file
View File

@@ -0,0 +1,158 @@
#!/bin/bash
DOCKER_CONFIG_DIR=/etc/docker
INSTALL_PATH=/usr/local/Ascend/Ascend-Docker-Runtime
function install()
{
echo 'installing ascend docker runtime'
if [ ! -d "${INSTALL_PATH}" ]; then
mkdir -p ${INSTALL_PATH}
fi
cp -f ./ascend-docker-runtime ${INSTALL_PATH}/ascend-docker-runtime
cp -f ./ascend-docker-hook ${INSTALL_PATH}/ascend-docker-hook
cp -f ./ascend-docker-cli ${INSTALL_PATH}/ascend-docker-cli
chmod 550 ${INSTALL_PATH}/ascend-docker-runtime
chmod 550 ${INSTALL_PATH}/ascend-docker-hook
chmod 550 ${INSTALL_PATH}/ascend-docker-cli
echo 'install executable files success'
if [ ! -d "${DOCKER_CONFIG_DIR}" ]; then
mkdir -p ${DOCKER_CONFIG_DIR}
fi
SRC="${DOCKER_CONFIG_DIR}/daemon.json.${PPID}"
DST="${DOCKER_CONFIG_DIR}/daemon.json"
./ascend-docker-plugin-install-helper add ${DST} ${SRC} ${INSTALL_PATH}/ascend-docker-runtime
if [ "$?" != "0" ]; then
echo 'create damon.json failed'
exit 1
fi
mv ${SRC} ${DST}
echo 'create damom.json success'
echo 'please reboot docker daemon to take effect'
}
function uninstall()
{
echo 'uninstalling ascend docker runtime'
if [ ! -d "${INSTALL_PATH}" ]; then
echo 'WARNING: the specified install path does not exist, skipping'
exit 0
fi
rm -rf ${INSTALL_PATH}
echo 'remove executable files success'
SRC="${DOCKER_CONFIG_DIR}/daemon.json.${PPID}"
DST="${DOCKER_CONFIG_DIR}/daemon.json"
if [ ! -f "${DST}" ]; then
exit 0
fi
./ascend-docker-plugin-install-helper rm ${DST} ${SRC}
if [ "$?" != "0" ]; then
echo 'ERROR: del damon.json failed'
exit 1
fi
mv ${SRC} ${DST}
echo 'del damom.json success'
}
function upgrade()
{
echo 'upgrading ascend docker runtime'
if [ ! -d "${INSTALL_PATH}" ]; then
echo 'ERROR: the specified install path does not exist, stopping upgrading'
exit 1
fi
cp -f ./ascend-docker-runtime ${INSTALL_PATH}/ascend-docker-runtime
cp -f ./ascend-docker-hook ${INSTALL_PATH}/ascend-docker-hook
cp -f ./ascend-docker-cli ${INSTALL_PATH}/ascend-docker-cli
chmod 550 ${INSTALL_PATH}/ascend-docker-runtime
chmod 550 ${INSTALL_PATH}/ascend-docker-hook
chmod 550 ${INSTALL_PATH}/ascend-docker-cli
echo 'upgrade ascend docker runtime success'
}
INSTALL_FLAG=n
INSTALL_PATH_FLAG=n
UNINSTALL_FLAG=n
UPGRADE_FLAG=n
DEVEL_FLAG=n
while true
do
case "$3" in
--install)
INSTALL_FLAG=y
shift
;;
--uninstall)
UNINSTALL_FLAG=y
shift
;;
--install-path=*)
INSTALL_PATH_FLAG=y
INSTALL_PATH=`echo $3 | cut -d"=" -f2 `
INSTALL_PATH=`echo ${INSTALL_PATH} | sed "s/\/*$//g"`
shift
;;
--upgrade)
UPGRADE_FLAG=y
shift
;;
--devel)
DEVEL_FLAG=y
shift
;;
*)
break
;;
esac
done
# 安装为相对路径时报错
if [ "${INSTALL_PATH}" == ".." ] || [ "${INSTALL_PATH}" == "." ]; then
echo "error :Please follow the installation address after the --install-path=<Absolute path>"
exit 1
fi
# 单纯只有--install-path的判定处理
if [ "${INSTALL_PATH_FLAG}" == "y" ] && \
[ "${INSTALL_FLAG}" == "n" ] && \
[ "${UNINSTALL_FLAG}" == "n" ] && \
[ "${UPGRADE_FLAG}" == "n" ] && \
[ "${DEVEL_FLAG}" == "n" ]; then
echo "Error:only input <install_path> command. When use --install-path you also need intput --install or --uninstall or --upgrade or --devel"
exit 1
fi
# 需root用户权限
if [ "${USER}" != "root" ]; then
echo 'please run with root permission'
exit 1
fi
if [ "${INSTALL_FLAG}" == "y" ] || [ "${DEVEL_FLAG}" == "y" ]; then
install
exit 0
fi
if [ "${UNINSTALL_FLAG}" == "y" ]; then
uninstall
exit 0
fi
if [ "${UPGRADE_FLAG}" == "y" ]; then
upgrade
exit 0
fi