mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-25 02:40:21 +08:00
Match-id-166316a638ef119d6bcf9222fc5d52f1b73f6ada
This commit is contained in:
@@ -74,29 +74,35 @@ mkdir -pv {${DEBDIR},${BINDIR}}
|
||||
/bin/cp -f {${RUNTIMESRCDIR},${HOOKSRCDIR},${INSTALLHELPERSRCDIR},${CLISRCDIR}}/build/ascend-docker* ${BINDIR}
|
||||
CONPATH=`find ${INSTALLHELPERDIR} -name "control"`
|
||||
INSTPATH=`find ${INSTALLHELPERDIR} -name "postinst"`
|
||||
/bin/cp -f ${CONPATH} ${INSTPATH} ${DEBDIR}
|
||||
RMPATH=`find ${INSTALLHELPERDIR} -name "prerm"`
|
||||
/bin/cp -f ${CONPATH} ${INSTPATH} ${RMPATH} ${DEBDIR}
|
||||
echo ${INSTPATH}
|
||||
chmod 555 ${DEBDIR}/postinst
|
||||
chmod 555 ${DEBDIR}/prerm
|
||||
dpkg-deb -b ${DEBPACK} ascenddockertool_1.0.0_i386.deb
|
||||
DEBS=`find ${BUILD} -name "*.deb"`
|
||||
/bin/cp ${DEBS} ${OUTPUT}
|
||||
}
|
||||
|
||||
funcfillarch(){
|
||||
CPUARCH=`uname -m`
|
||||
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}
|
||||
SPECPATH=`find ${INSTALLHELPERDIR} -name "*.spec"`
|
||||
dos2unix ${SPECPATH}
|
||||
/bin/cp -f ${SPECPATH} ${RPMSPECDIR}
|
||||
funcfillarch
|
||||
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"`
|
||||
ARCH=`uname -m`
|
||||
RPMSNAME=${RPMS##*/}
|
||||
/bin/cp ${RPMS} ${OUTPUT}/${RPMSNAME}.${ARCH}
|
||||
/bin/cp ${RPMS} ${OUTPUT}
|
||||
}
|
||||
|
||||
funcmakeclean(){
|
||||
|
||||
@@ -6,7 +6,7 @@ fi
|
||||
SRC="${DIR}/daemon.json.${PPID}"
|
||||
DST="${DIR}/daemon.json"
|
||||
BINDIR=/usr/local/bin
|
||||
${BINDIR}/ascend-docker-plugin-install-helper ${DST} ${SRC}
|
||||
${BINDIR}/ascend-docker-plugin-install-helper add ${DST} ${SRC}
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "create damon.json failed\n"
|
||||
exit 1
|
||||
|
||||
15
install/deb/scripts/prerm
Normal file
15
install/deb/scripts/prerm
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
DIR=/etc/docker
|
||||
if [ ! -d "${DIR}" ]; then
|
||||
mkdir ${DIR}
|
||||
fi
|
||||
SRC="${DIR}/daemon.json.${PPID}"
|
||||
DST="${DIR}/daemon.json"
|
||||
BINDIR=/usr/local/bin
|
||||
${BINDIR}/ascend-docker-plugin-install-helper rm ${DST} ${SRC}
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "del damon.json failed\n"
|
||||
exit 1
|
||||
fi
|
||||
\mv ${SRC} ${DST}
|
||||
echo "del damom.json success\n"
|
||||
@@ -8,9 +8,12 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAX_JSON_FILE_SIZE 65535
|
||||
#define NUM_ARGS 3
|
||||
#define FINAL_FILE_INDEX 1
|
||||
#define TEMP_FILE_INDEX 2
|
||||
#define NUM_ARGS 4
|
||||
#define ADD_CMD "add"
|
||||
#define RM_CMD "rm"
|
||||
#define CMD_INDEX 1
|
||||
#define FINAL_FILE_INDEX 2
|
||||
#define TEMP_FILE_INDEX 3
|
||||
#define PATH_VALUE "/usr/local/bin/ascend-docker-runtime"
|
||||
|
||||
void ReadJsonFile(const FILE *pf, char *text, int maxBufferSize)
|
||||
@@ -137,11 +140,90 @@ int DetectAndCreateJsonFile(const char *filePath, const char *tempPath)
|
||||
return 0;
|
||||
}
|
||||
|
||||
cJSON *GetNewContent(const FILE *pf)
|
||||
{
|
||||
char jsonStr[MAX_JSON_FILE_SIZE] = {0x0};
|
||||
ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE);
|
||||
|
||||
cJSON *root = NULL;
|
||||
root = cJSON_Parse(jsonStr);
|
||||
if (!root) {
|
||||
fprintf(stderr, "Error before: [%s]\n", cJSON_GetErrorPtr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cJSON *runtimes = NULL;
|
||||
runtimes = cJSON_GetObjectItem(root, "runtimes");
|
||||
if (runtimes == NULL) {
|
||||
fprintf(stderr, "no runtime key found\n");
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cJSON *ascend = NULL;
|
||||
ascend = cJSON_GetObjectItem(runtimes, "ascend");
|
||||
if (ascend == NULL) {
|
||||
fprintf(stderr, "no ascend key found\n");
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cJSON *removedItem = NULL;
|
||||
removedItem = cJSON_DetachItemViaPointer(runtimes, ascend);
|
||||
if (removedItem == NULL) {
|
||||
fprintf(stderr, "remove runtime failed\n");
|
||||
cJSON_Delete(root);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cJSON_Delete(removedItem);
|
||||
return root;
|
||||
}
|
||||
|
||||
int CreateRevisedJsonFile(const char *filePath, const char *tempPath)
|
||||
{
|
||||
FILE *pf = NULL;
|
||||
pf = fopen(filePath, "r+");
|
||||
if (pf == NULL) {
|
||||
fprintf(stderr, "error: no json files found\n");
|
||||
return -1;
|
||||
}
|
||||
cJSON *newContent = NULL;
|
||||
newContent = GetNewContent(pf);
|
||||
fclose(pf);
|
||||
|
||||
if (newContent == NULL) {
|
||||
fprintf(stderr, "error: failed to create json\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pf = fopen(tempPath, "w");
|
||||
if (pf == NULL) {
|
||||
fprintf(stderr, "error: failed to create file\n");
|
||||
cJSON_Delete(newContent);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(pf, "%s", cJSON_Print(newContent));
|
||||
fclose(pf);
|
||||
|
||||
cJSON_Delete(newContent);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 该函数只负责生成json.bak文件,由调用者进行覆盖操作 */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != NUM_ARGS) {
|
||||
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]);
|
||||
}
|
||||
return CreateRevisedJsonFile(argv[FINAL_FILE_INDEX], argv[TEMP_FILE_INDEX]);
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
Name: ascenddockerplugin
|
||||
Version: 1.0.0
|
||||
Release: 1
|
||||
BuildArch: noarch
|
||||
Summary: simple RPM package
|
||||
License: FIXME
|
||||
|
||||
@@ -29,7 +28,7 @@ BINDIR=/usr/local/bin
|
||||
if [ ! -d "${DIR}" ]; then
|
||||
mkdir ${DIR}
|
||||
fi
|
||||
${BINDIR}/ascend-docker-plugin-install-helper ${DST} ${SRC}
|
||||
${BINDIR}/ascend-docker-plugin-install-helper add ${DST} ${SRC}
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "create damon.json failed\n"
|
||||
exit 1
|
||||
@@ -38,6 +37,18 @@ fi
|
||||
echo "create damom.json success\n"
|
||||
|
||||
%preun
|
||||
#!/bin/bash
|
||||
DIR=/etc/docker
|
||||
BINDIR=/usr/local/bin
|
||||
SRC="${DIR}/daemon.json.${PPID}"
|
||||
DST="${DIR}/daemon.json"
|
||||
${BINDIR}/ascend-docker-plugin-install-helper rm ${DST} ${SRC}
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "del damon.json failed\n"
|
||||
exit 1
|
||||
fi
|
||||
\mv ${SRC} ${DST}
|
||||
echo "del damom.json success\n"
|
||||
|
||||
%postun
|
||||
|
||||
|
||||
Reference in New Issue
Block a user