mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-18 20:04:52 +08:00
Match-id-333af697bff0299c9522aeb1f41de79301684546
This commit is contained in:
117
build/build.sh
117
build/build.sh
@@ -20,15 +20,6 @@ HOOKSRCNAME="main.go"
|
||||
RUNTIMEDIR=${ROOT}/runtime
|
||||
RUNTIMESRCNAME="main.go"
|
||||
|
||||
DEBPACK=${ROOT}/debpack
|
||||
BINDIR=${DEBPACK}/usr/bin
|
||||
DEBDIR=${DEBPACK}/DEBIAN
|
||||
|
||||
RPMPACK=${ROOT}/rpmpack
|
||||
RPMSOURCESDIR=${RPMPACK}/SOURCES
|
||||
RPMSPECDIR=${RPMPACK}/SPECS
|
||||
|
||||
|
||||
CLISRCPATH=`find ${CLIDIR} -name "${CLISRCNAME}"`
|
||||
CLISRCDIR=${CLISRCPATH%/${CLISRCNAME}}
|
||||
INSTALLHELPERSRCPATH=`find ${INSTALLHELPERDIR} -name "${INSTALLHELPERSRCNAME}"`
|
||||
@@ -38,13 +29,12 @@ HOOKSRCDIR=${HOOKSRCPATH%/${HOOKSRCNAME}}
|
||||
RUNTIMESRCPATH=`find ${RUNTIMEDIR} -name "${RUNTIMESRCNAME}"`
|
||||
RUNTIMESRCDIR=${RUNTIMESRCPATH%/${RUNTIMESRCNAME}}
|
||||
|
||||
SOFT_VERSION=`cat $TOP_DIR/CI/config/version.ini | grep "PackageName" | cut -d "=" -f 2`
|
||||
VERSION=$SOFT_VERSION
|
||||
RELEASE="1"
|
||||
PACKAGENAEM="ascend-docker-runtime"
|
||||
VERSION=`cat $TOP_DIR/CI/config/version.ini | grep "PackageName" | cut -d "=" -f 2`
|
||||
PACKAGENAME="Ascend-docker-runtime"
|
||||
CPUARCH=`uname -m`
|
||||
|
||||
funcbuild(){
|
||||
function build_bin()
|
||||
{
|
||||
echo "make cli"
|
||||
[ -d "${CLISRCDIR}/build" ] && rm -rf ${CLISRCDIR}/build
|
||||
mkdir ${CLISRCDIR}/build && cd ${CLISRCDIR}/build
|
||||
@@ -78,78 +68,56 @@ go build -ldflags "-buildid=IdNetCheck" -trimpath ../${RUNTIMESRCNAME}
|
||||
mv main ascend-docker-runtime
|
||||
}
|
||||
|
||||
fillcontrol(){
|
||||
sed -i "1i\Package: ${PACKAGENAEM}" ${DEBDIR}/control
|
||||
sed -i "2a\Architecture: all" ${DEBDIR}/control
|
||||
sed -i "3a\Version: ${VERSION}" ${DEBDIR}/control
|
||||
}
|
||||
|
||||
funcmakedeb(){
|
||||
function build_run_package()
|
||||
{
|
||||
cd ${BUILD}
|
||||
mkdir -pv {${DEBDIR},${BINDIR}}
|
||||
/bin/cp -f {${RUNTIMESRCDIR},${HOOKSRCDIR},${INSTALLHELPERSRCDIR},${CLISRCDIR}}/build/ascend-docker* ${BINDIR}
|
||||
FILECNT=`ls -l ${BINDIR} |grep "^-"|wc -l`
|
||||
mkdir run_pkg
|
||||
|
||||
/bin/cp -f {${RUNTIMESRCDIR},${HOOKSRCDIR},${INSTALLHELPERSRCDIR},${CLISRCDIR}}/build/ascend-docker* run_pkg
|
||||
FILECNT=`ls -l run_pkg |grep "^-"|wc -l`
|
||||
echo "prepare package $FILECNT bins"
|
||||
if [ $FILECNT -ne 4 ]; then
|
||||
exit 1
|
||||
fi
|
||||
CONPATH=`find ${INSTALLHELPERDIR} -name "control"`
|
||||
INSTPATH=`find ${INSTALLHELPERDIR} -name "postinst"`
|
||||
RMPATH=`find ${INSTALLHELPERDIR} -name "prerm"`
|
||||
/bin/cp -f ${CONPATH} ${INSTPATH} ${RMPATH} ${DEBDIR}
|
||||
echo ${INSTPATH}
|
||||
fillcontrol
|
||||
chmod 555 ${DEBDIR}/postinst
|
||||
chmod 555 ${DEBDIR}/prerm
|
||||
dpkg-deb -b ${DEBPACK} ${PACKAGENAEM}_${VERSION}-${RELEASE}_${CPUARCH}.deb
|
||||
DEBS=`find ${BUILD} -name "*.deb"`
|
||||
/bin/cp ${DEBS} ${OUTPUT}
|
||||
|
||||
/bin/cp -f scripts/run_main.sh run_pkg
|
||||
chmod 550 run_pkg/run_main.sh
|
||||
|
||||
RUN_PKG_NAME="${PACKAGENAME}-${CPUARCH}.run"
|
||||
DATE=`date -u "+%Y-%m-%d"`
|
||||
bash makeself.sh --nomd5 --nocrc --help-header scripts/help.info --packaging-date ${DATE} \
|
||||
--tar-extra "--mtime=${DATE}" run_pkg "${RUN_PKG_NAME}" ascend-docker-runtime ./run_main.sh
|
||||
mv ${RUN_PKG_NAME} ${OUTPUT}
|
||||
}
|
||||
|
||||
funcfillspec(){
|
||||
sed -i "4a\BuildArch: $CPUARCH" ${RPMSPECDIR}/*.spec
|
||||
}
|
||||
|
||||
funcmakerpm(){
|
||||
mkdir -pv ${RPMPACK}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
|
||||
/bin/cp -f {${RUNTIMESRCDIR},${HOOKSRCDIR},${INSTALLHELPERSRCDIR},${CLISRCDIR}}/build/ascend-docker* ${RPMSOURCESDIR}
|
||||
FILECNT=`ls -l ${RPMSOURCESDIR} |grep "^-"|wc -l`
|
||||
echo "prepare package $FILECNT bins"
|
||||
if [ $FILECNT -ne 4 ]; then
|
||||
exit 1
|
||||
fi
|
||||
SPECPATH=`find ${INSTALLHELPERDIR} -name "*.spec"`
|
||||
sed -i "2c Version: ${SOFT_VERSION}" ${SPECPATH}
|
||||
dos2unix ${SPECPATH}
|
||||
/bin/cp -f ${SPECPATH} ${RPMSPECDIR}
|
||||
funcfillspec
|
||||
rpmbuild --define "_topdir ${RPMPACK}"
|
||||
rpmbuild --showrc | grep topdir
|
||||
echo ${RPMPACK}
|
||||
echo "%_topdir ${RPMPACK}" > ~/.rpmmacros
|
||||
rpmbuild -bb ${RPMPACK}/SPECS/ascend-docker-plgugin.spec
|
||||
RPMS=`find ${RPMPACK} -name "*.rpm"`
|
||||
/bin/cp ${RPMS} ${OUTPUT}
|
||||
}
|
||||
|
||||
funcmakeclean(){
|
||||
[ -d "${RPMPACK}" ]&&rm -rf ${RPMPACK}
|
||||
[ -d "${DEBPACK}" ]&&rm -rf ${DEBPACK}
|
||||
function make_clean()
|
||||
{
|
||||
[ -d "${OUTPUT}" ] && cd ${OUTPUT}&&rm -rf *
|
||||
}
|
||||
|
||||
funcmakepull(){
|
||||
function make_pull()
|
||||
{
|
||||
cd ${OPENSRC}
|
||||
wget -O cJSON.tar.gz https://github.com/DaveGamble/cJSON/archive/v1.7.13.tar.gz --no-check-certificate
|
||||
}
|
||||
|
||||
funcmakeunzip(){
|
||||
function make_unzip()
|
||||
{
|
||||
cd ${OPENSRC}
|
||||
tar -xzvf cJSON*.tar.gz
|
||||
CJSONS=`find . -name "cJSON.*"`
|
||||
CJSONSLIB=${INSTALLHELPERDIR}/deb/src/cjson
|
||||
/bin/cp -f ${CJSONS} ${CJSONSLIB}
|
||||
|
||||
unzip makeself-release-*.zip
|
||||
rm -f makeself-release-*.zip
|
||||
MAKESELF_DIR=`find . -name "makeself-release-*"`
|
||||
/bin/cp -f ${MAKESELF_DIR}/makeself.sh ${BUILD}
|
||||
/bin/cp -f ${MAKESELF_DIR}/makeself-header.sh ${BUILD}
|
||||
cd ${BUILD} && /bin/cp -f scripts/mkselfmodify.patch ./
|
||||
patch -p0 < mkselfmodify.patch
|
||||
rm -f mkselfmodify.patch
|
||||
|
||||
cd ${PLATFORM}
|
||||
tar -xzvf HuaweiSecureC.tar.gz
|
||||
SECURECSRC=`find . -name "src"`
|
||||
@@ -164,18 +132,11 @@ SECURECLIB=${CLIDIR}/src/HuaweiSecureC
|
||||
/bin/cp -f ${SECURECINC}/* ${SECURECLIB}
|
||||
}
|
||||
|
||||
funcmakeclean
|
||||
make_clean
|
||||
if [ $1 == "pull" ]; then
|
||||
funcmakepull
|
||||
make_pull
|
||||
fi
|
||||
|
||||
funcmakeunzip
|
||||
funcbuild
|
||||
|
||||
if [ -f /etc/centos-release ]; then
|
||||
funcmakerpm
|
||||
fi
|
||||
|
||||
if [ -f /etc/debian_version ]; then
|
||||
funcmakedeb
|
||||
fi
|
||||
make_unzip
|
||||
build_bin
|
||||
build_run_package
|
||||
|
5
build/scripts/help.info
Normal file
5
build/scripts/help.info
Normal file
@@ -0,0 +1,5 @@
|
||||
--install Install into this system
|
||||
--install-path Specify the installation path (default: /usr/local/Ascend/Ascend-Docker-Runtime)
|
||||
--uninstall Uninstall the installed ascend-docker-runtime tool
|
||||
--upgrade Upgrade the installed ascend-docker-runtime tool
|
||||
--devel Install as devel mode
|
228
build/scripts/mkselfmodify.patch
Normal file
228
build/scripts/mkselfmodify.patch
Normal file
@@ -0,0 +1,228 @@
|
||||
--- makeself-header.sh 2020-04-27 18:59:03.000000000 +0800
|
||||
+++ makeself-header_new.sh 2020-07-09 18:04:43.044000000 +0800
|
||||
@@ -1,12 +1,9 @@
|
||||
cat << EOF > "$archname"
|
||||
-#!/bin/sh
|
||||
+#!/bin/bash
|
||||
# This script was generated using Makeself $MS_VERSION
|
||||
# The license covering this archive and its contents, if any, is wholly independent of the Makeself license (GPL)
|
||||
|
||||
ORIG_UMASK=\`umask\`
|
||||
-if test "$KEEP_UMASK" = n; then
|
||||
- umask 077
|
||||
-fi
|
||||
|
||||
CRCsum="$CRCsum"
|
||||
MD5="$MD5sum"
|
||||
@@ -16,6 +13,9 @@
|
||||
export USER_PWD
|
||||
ARCHIVE_DIR=`dirname \$0`
|
||||
export ARCHIVE_DIR
|
||||
+name_of_file="\$0 "
|
||||
+pwd_of_file="\$PWD "
|
||||
+
|
||||
|
||||
label="$LABEL"
|
||||
script="$SCRIPT"
|
||||
@@ -148,6 +148,24 @@
|
||||
MS_Help()
|
||||
{
|
||||
cat << EOH >&2
|
||||
+Usage: \$0 [options]
|
||||
+Options:
|
||||
+ --help | -h Print this message
|
||||
+ --info Print embedded info : title, default target directory, embedded script ...
|
||||
+ --list Print the list of files in the archive
|
||||
+ --check Checks integrity of the archive
|
||||
+ --quiet Quiet install mode, skip human-computer interactions
|
||||
+ --noexec Do not run embedded script
|
||||
+ --extract=<path> Extract directly to a target directory (absolute or relative)
|
||||
+ Usually used with --noexec to just extract files without running
|
||||
+ --tar arg1 [arg2 ...] Access the contents of the archive through the tar command
|
||||
+\${helpheader}
|
||||
+EOH
|
||||
+}
|
||||
+
|
||||
+MS_Help1()
|
||||
+{
|
||||
+ cat << EOH >&2
|
||||
\${helpheader}Makeself version $MS_VERSION
|
||||
1) Getting help or info about \$0 :
|
||||
\$0 --help Print this message
|
||||
@@ -212,7 +230,7 @@
|
||||
fi
|
||||
sha=\`echo \$SHA | cut -d" " -f\$i\`
|
||||
if test x"\$sha" = x0000000000000000000000000000000000000000000000000000000000000000; then
|
||||
- test x"\$verb" = xy && echo " \$1 does not contain an embedded SHA256 checksum." >&2
|
||||
+ test x"\$verb" = xy
|
||||
else
|
||||
shasum=\`MS_dd_Progress "\$1" \$offset \$s | eval "\$SHA_PATH \$SHA_ARG" | cut -b-64\`;
|
||||
if test x"\$shasum" != x"\$sha"; then
|
||||
@@ -230,7 +248,7 @@
|
||||
fi
|
||||
md5=\`echo \$MD5 | cut -d" " -f\$i\`
|
||||
if test x"\$md5" = x00000000000000000000000000000000; then
|
||||
- test x"\$verb" = xy && echo " \$1 does not contain an embedded MD5 checksum." >&2
|
||||
+ test x"\$verb" = xy
|
||||
else
|
||||
md5sum=\`MS_dd_Progress "\$1" \$offset \$s | eval "\$MD5_PATH \$MD5_ARG" | cut -b-32\`;
|
||||
if test x"\$md5sum" != x"\$md5"; then
|
||||
@@ -243,7 +261,7 @@
|
||||
fi
|
||||
fi
|
||||
if test x"\$crc" = x0000000000; then
|
||||
- test x"\$verb" = xy && echo " \$1 does not contain a CRC checksum." >&2
|
||||
+ test x"\$verb" = xy
|
||||
else
|
||||
sum1=\`MS_dd_Progress "\$1" \$offset \$s | CMD_ENV=xpg4 cksum | awk '{print \$1}'\`
|
||||
if test x"\$sum1" != x"\$crc"; then
|
||||
@@ -300,6 +318,22 @@
|
||||
eval \$finish; exit 15
|
||||
}
|
||||
|
||||
+Script_Args_Check()
|
||||
+{
|
||||
+ script_supported_args=\$(echo \${helpheader} | grep -o -P "\-\-[^ ]+" | awk -F"=" {'print \$1'})
|
||||
+ arg_to_test=\$(echo \$1|awk -F"=" {'print \$1'})
|
||||
+
|
||||
+ for arg in \${script_supported_args[@]};
|
||||
+ do
|
||||
+ if test x"\$arg_to_test" = x"\$arg" ;then
|
||||
+ return
|
||||
+ fi
|
||||
+ done
|
||||
+
|
||||
+ MS_Help
|
||||
+ exit 1
|
||||
+}
|
||||
+
|
||||
finish=true
|
||||
xterm_loop=
|
||||
noprogress=$NOPROGRESS
|
||||
@@ -312,7 +346,7 @@
|
||||
|
||||
initargs="\$@"
|
||||
|
||||
-while true
|
||||
+while [ -n "\$*" ]
|
||||
do
|
||||
case "\$1" in
|
||||
-h | --help)
|
||||
@@ -324,10 +358,6 @@
|
||||
noprogress=y
|
||||
shift
|
||||
;;
|
||||
- --accept)
|
||||
- accept=y
|
||||
- shift
|
||||
- ;;
|
||||
--info)
|
||||
echo Identification: "\$label"
|
||||
echo Target directory: "\$targetdir"
|
||||
@@ -372,14 +402,6 @@
|
||||
echo SKIP=\"\$skip\"
|
||||
exit 0
|
||||
;;
|
||||
- --lsm)
|
||||
-cat << EOLSM
|
||||
-EOF
|
||||
-eval "$LSM_CMD"
|
||||
-cat << EOF >> "$archname"
|
||||
-EOLSM
|
||||
- exit 0
|
||||
- ;;
|
||||
--list)
|
||||
echo Target directory: \$targetdir
|
||||
offset=\`head -n "\$skip" "\$0" | wc -c | tr -d " "\`
|
||||
@@ -422,10 +444,10 @@
|
||||
keep=y
|
||||
shift
|
||||
;;
|
||||
- --target)
|
||||
+ --extract=*)
|
||||
keep=y
|
||||
- targetdir="\${2:-.}"
|
||||
- if ! shift 2; then MS_Help; exit 1; fi
|
||||
+ targetdir=\`echo \$1 | cut -d"=" -f2 \`
|
||||
+ if ! shift; then MS_Help; exit 1; fi
|
||||
;;
|
||||
--noprogress)
|
||||
noprogress=y
|
||||
@@ -470,19 +492,34 @@
|
||||
cleanupargs="\$2"
|
||||
if ! shift 2; then MS_help; exit 1; fi
|
||||
;;
|
||||
- --)
|
||||
- shift
|
||||
- break ;;
|
||||
- -*)
|
||||
- echo Unrecognized flag : "\$1" >&2
|
||||
- MS_Help
|
||||
- exit 1
|
||||
- ;;
|
||||
*)
|
||||
- break ;;
|
||||
+ Script_Args_Check \$1
|
||||
+ scriptargs="\$scriptargs \$1"
|
||||
+ shift
|
||||
+ ;;
|
||||
esac
|
||||
done
|
||||
|
||||
+quiet_para=""
|
||||
+
|
||||
+if test x"\$quiet" = xy; then
|
||||
+ quiet_para="--quiet "
|
||||
+fi
|
||||
+
|
||||
+keep_para=""
|
||||
+
|
||||
+if test x"\$keep" = xy; then
|
||||
+ keep_para="--keep "
|
||||
+fi
|
||||
+
|
||||
+confirm_para=""
|
||||
+
|
||||
+if test x"\$verbose" = xy; then
|
||||
+ confirm_para="--confirm "
|
||||
+fi
|
||||
+
|
||||
+
|
||||
+scriptargs="--\$name_of_file""--\$pwd_of_file""\$quiet_para""\$keep_para""\$confirm_para""\$scriptargs"
|
||||
if test x"\$quiet" = xy -a x"\$verbose" = xy; then
|
||||
echo Cannot be verbose and quiet at the same time. >&2
|
||||
exit 1
|
||||
@@ -559,7 +596,7 @@
|
||||
fi
|
||||
mkdir \$dashp "\$tmpdir" || {
|
||||
echo 'Cannot create target directory' \$tmpdir >&2
|
||||
- echo 'You should try option --target dir' >&2
|
||||
+ echo 'You should try option --extract=<path>' >&2
|
||||
eval \$finish
|
||||
exit 1
|
||||
}
|
||||
@@ -643,11 +680,19 @@
|
||||
fi
|
||||
|
||||
if test x"\$verbose" = x"y"; then
|
||||
- MS_Printf "OK to execute: \$script \$scriptargs \$* ? [Y/n] "
|
||||
- read yn
|
||||
- if test x"\$yn" = x -o x"\$yn" = xy -o x"\$yn" = xY; then
|
||||
- eval "\"\$script\" \$scriptargs \"\\\$@\""; res=\$?;
|
||||
- fi
|
||||
+ yn="x"
|
||||
+ while test x"\$yn" != x -a x"\$yn" != xy -a x"\$yn" != xY -a x"\$yn" != xn -a x"\$yn" != xN
|
||||
+ do
|
||||
+ MS_Printf "OK to execute: \$script \$scriptargs \$* ? [Y/n] "
|
||||
+ read yn
|
||||
+ if test x"\$yn" = x -o x"\$yn" = xy -o x"\$yn" = xY; then
|
||||
+ eval "\"\$script\" \$scriptargs \"\\\$@\""; res=\$?;
|
||||
+ elif test x"\$yn" = xn -o x"\$yn" = xN; then
|
||||
+ echo "Unable to decompress \$script ,because of aborting! ";res=\$?
|
||||
+ else
|
||||
+ echo "Input value is unacceptable,please try again."
|
||||
+ fi
|
||||
+ done
|
||||
else
|
||||
eval "\"\$script\" \$scriptargs \"\\\$@\""; res=\$?
|
||||
fi
|
158
build/scripts/run_main.sh
Normal file
158
build/scripts/run_main.sh
Normal 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
|
@@ -32,6 +32,20 @@
|
||||
</copy>
|
||||
</copies>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<versionType>3rd-party</versionType>
|
||||
<repoType>Generic</repoType>
|
||||
<id>
|
||||
<artifactName>makeself-release-2.4.2.zip</artifactName>
|
||||
<pdmCode>05836ECT</pdmCode>
|
||||
</id>
|
||||
<copies>
|
||||
<copy>
|
||||
<source>/*</source>
|
||||
<dest>opensource</dest>
|
||||
</copy>
|
||||
</copies>
|
||||
</dependency>
|
||||
<!-- Platform -->
|
||||
<dependency>
|
||||
<versionType>BVersion</versionType>
|
||||
|
13
hook/main.go
13
hook/main.go
@@ -10,7 +10,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -25,7 +24,7 @@ const (
|
||||
ascendVisibleDevices = "ASCEND_VISIBLE_DEVICES"
|
||||
ascendRuntimeOptions = "ASCEND_RUNTIME_OPTIONS"
|
||||
ascendDockerCli = "ascend-docker-cli"
|
||||
defaultAscendDockerCli = "/usr/bin/ascend-docker-cli"
|
||||
defaultAscendDockerCli = "/usr/local/bin/ascend-docker-cli"
|
||||
|
||||
borderNum = 2
|
||||
kvPairSize = 2
|
||||
@@ -221,14 +220,14 @@ func doPrestartHook() error {
|
||||
return fmt.Errorf("failed to parse runtime options: %w", err)
|
||||
}
|
||||
|
||||
cliPath, err := exec.LookPath(ascendDockerCliName)
|
||||
currentExecPath, err := os.Executable()
|
||||
if err != nil {
|
||||
_, err = os.Stat(defaultAscendDockerCliName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not found ascend docker cli")
|
||||
return fmt.Errorf("cannot get the path of ascend-docker-hook: %w", err)
|
||||
}
|
||||
|
||||
cliPath = defaultAscendDockerCliName
|
||||
cliPath := path.Join(path.Dir(currentExecPath), ascendDockerCliName)
|
||||
if _, err = os.Stat(cliPath); err != nil {
|
||||
return fmt.Errorf("cannot find ascend-docker-cli executable file at %s: %w", cliPath, err)
|
||||
}
|
||||
|
||||
args := append([]string{cliPath},
|
||||
|
@@ -9,13 +9,14 @@
|
||||
#include "cJSON.h"
|
||||
|
||||
#define MAX_JSON_FILE_SIZE 65535
|
||||
#define NUM_ARGS 4
|
||||
#define MIN_ARGS_NUM 4
|
||||
#define ADD_CMD_ARGS_NUM 5
|
||||
#define ADD_CMD "add"
|
||||
#define RM_CMD "rm"
|
||||
#define CMD_INDEX 1
|
||||
#define FINAL_FILE_INDEX 2
|
||||
#define TEMP_FILE_INDEX 3
|
||||
#define ASCEND_RUNTIME_PATH_VALUE "/usr/bin/ascend-docker-runtime"
|
||||
#define RUNTIME_PATH_INDEX 4
|
||||
#define ASCEND_RUNTIME_PATH_KEY "path"
|
||||
#define ASCEND_RUNTIME_ARGS_KEY "runtimeArgs"
|
||||
#define RUNTIME_KEY "runtimes"
|
||||
@@ -38,7 +39,7 @@ void ReadJsonFile(FILE *pf, char *text, int maxBufferSize)
|
||||
text[size] = '\0';
|
||||
}
|
||||
|
||||
cJSON *CreateAscendRuntimeInfo()
|
||||
cJSON *CreateAscendRuntimeInfo(const char *runtimePath)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
root = cJSON_CreateObject();
|
||||
@@ -48,7 +49,7 @@ cJSON *CreateAscendRuntimeInfo()
|
||||
}
|
||||
|
||||
cJSON *newString = NULL;
|
||||
newString = cJSON_CreateString(ASCEND_RUNTIME_PATH_VALUE);
|
||||
newString = cJSON_CreateString(runtimePath);
|
||||
if (newString == NULL) {
|
||||
fprintf(stderr, "create ascend runtime info path value err\n");
|
||||
cJSON_Delete(root);
|
||||
@@ -70,10 +71,10 @@ cJSON *CreateAscendRuntimeInfo()
|
||||
return root;
|
||||
}
|
||||
|
||||
cJSON *CreateRuntimes()
|
||||
cJSON *CreateRuntimes(const char *runtimePath)
|
||||
{
|
||||
cJSON *ascendRuntime = NULL;
|
||||
ascendRuntime = CreateAscendRuntimeInfo();
|
||||
ascendRuntime = CreateAscendRuntimeInfo(runtimePath);
|
||||
if (ascendRuntime == NULL) {
|
||||
fprintf(stderr, "create ascendruntime err\n");
|
||||
return NULL;
|
||||
@@ -111,11 +112,11 @@ int DelJsonContent(cJSON *root, const char *key)
|
||||
return 0;
|
||||
}
|
||||
|
||||
cJSON *CreateContent()
|
||||
cJSON *CreateContent(const char *runtimePath)
|
||||
{
|
||||
/* 插入ascend runtime */
|
||||
cJSON *runtimes = NULL;
|
||||
runtimes = CreateRuntimes();
|
||||
runtimes = CreateRuntimes(runtimePath);
|
||||
if (runtimes == NULL) {
|
||||
fprintf(stderr, "create runtimes err\n");
|
||||
return NULL;
|
||||
@@ -145,7 +146,7 @@ cJSON *CreateContent()
|
||||
return root;
|
||||
}
|
||||
|
||||
cJSON *ModifyContent(FILE *pf)
|
||||
cJSON *ModifyContent(FILE *pf, const char *runtimePath)
|
||||
{
|
||||
char jsonStr[MAX_JSON_FILE_SIZE] = {0x0};
|
||||
ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE);
|
||||
@@ -161,7 +162,7 @@ cJSON *ModifyContent(FILE *pf)
|
||||
cJSON *runtimes = NULL;
|
||||
runtimes = cJSON_GetObjectItem(root, "runtimes");
|
||||
if (runtimes == NULL) {
|
||||
runtimes = CreateRuntimes();
|
||||
runtimes = CreateRuntimes(runtimePath);
|
||||
if (runtimes == NULL) {
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
@@ -174,7 +175,7 @@ cJSON *ModifyContent(FILE *pf)
|
||||
return NULL;
|
||||
}
|
||||
cJSON *ascendRuntime = NULL;
|
||||
ascendRuntime = CreateAscendRuntimeInfo();
|
||||
ascendRuntime = CreateAscendRuntimeInfo(runtimePath);
|
||||
if (ascendRuntime == NULL) {
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
@@ -236,15 +237,15 @@ cJSON *RemoveContent(FILE *pf)
|
||||
}
|
||||
|
||||
|
||||
int DetectAndCreateJsonFile(const char *filePath, const char *tempPath)
|
||||
int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, const char *runtimePath)
|
||||
{
|
||||
cJSON *root = NULL;
|
||||
FILE *pf = NULL;
|
||||
pf = fopen(filePath, "r+");
|
||||
if (pf == NULL) {
|
||||
root = CreateContent();
|
||||
root = CreateContent(runtimePath);
|
||||
} else {
|
||||
root = ModifyContent(pf);
|
||||
root = ModifyContent(pf, runtimePath);
|
||||
fclose(pf);
|
||||
}
|
||||
|
||||
@@ -302,14 +303,21 @@ int CreateRevisedJsonFile(const char *filePath, const char *tempPath)
|
||||
/* 该函数只负责生成json.bak文件,由调用者进行覆盖操作 */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != NUM_ARGS) {
|
||||
if (argc < MIN_ARGS_NUM) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%s\n", argv[FINAL_FILE_INDEX]);
|
||||
printf("%s\n", argv[TEMP_FILE_INDEX]);
|
||||
printf("%s\n", argv[CMD_INDEX]);
|
||||
|
||||
if (strcmp(argv[CMD_INDEX], ADD_CMD) == 0) {
|
||||
return DetectAndCreateJsonFile(argv[FINAL_FILE_INDEX], argv[TEMP_FILE_INDEX]);
|
||||
if (argc != ADD_CMD_ARGS_NUM) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return DetectAndCreateJsonFile(argv[FINAL_FILE_INDEX], argv[TEMP_FILE_INDEX], argv[RUNTIME_PATH_INDEX]);
|
||||
}
|
||||
|
||||
return CreateRevisedJsonFile(argv[FINAL_FILE_INDEX], argv[TEMP_FILE_INDEX]);
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
@@ -20,7 +21,7 @@ import (
|
||||
const (
|
||||
loggingPrefix = "ascend-docker-runtime"
|
||||
hookCli = "ascend-docker-hook"
|
||||
hookDefaultFilePath = "/usr/bin/ascend-docker-hook"
|
||||
hookDefaultFilePath = "/usr/local/bin/ascend-docker-hook"
|
||||
dockerRuncFile = "docker-runc"
|
||||
runcFile = "runc"
|
||||
)
|
||||
@@ -71,12 +72,14 @@ var execRunc = func() error {
|
||||
}
|
||||
|
||||
func addHook(spec *specs.Spec) error {
|
||||
path, err := exec.LookPath(hookCliPath)
|
||||
currentExecPath, err := os.Executable()
|
||||
if err != nil {
|
||||
path = hookDefaultFile
|
||||
if _, err = os.Stat(path); err != nil {
|
||||
return fmt.Errorf("cannot find the hook")
|
||||
return fmt.Errorf("cannot get the path of ascend-docker-runtime: %w", err)
|
||||
}
|
||||
|
||||
hookCliPath = path.Join(path.Dir(currentExecPath), hookCli)
|
||||
if _, err = os.Stat(hookCliPath); err != nil {
|
||||
return fmt.Errorf("cannot find ascend-docker-hook executable file at %s: %w", hookCliPath, err)
|
||||
}
|
||||
|
||||
if spec.Hooks == nil {
|
||||
@@ -91,8 +94,8 @@ func addHook(spec *specs.Spec) error {
|
||||
}
|
||||
|
||||
spec.Hooks.Prestart = append(spec.Hooks.Prestart, specs.Hook{
|
||||
Path: path,
|
||||
Args: []string{path},
|
||||
Path: hookCliPath,
|
||||
Args: []string{hookCliPath},
|
||||
})
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user