| | |
| | | |
| | | } |
| | | |
| | | func (sv SdkInstallService) Active(cod string) error { |
| | | func (sv SdkInstallService) Active(cod string, sdkId string) (interface{},error) { |
| | | //使用激活码激活算法 |
| | | url := "http://"+config.ShopConf.Url+"/data/api-s/sdk/activeByAINode" |
| | | machineCode := licence.GetMachineCode() |
| | | if machineCode == "" { |
| | | logger.Debug("获取机器码失败") |
| | | return errors.New("获取机器码失败") |
| | | return nil, errors.New("获取机器码失败") |
| | | } |
| | | paramBody := map[string]interface{}{ |
| | | "code": cod, |
| | | "sdkId": sdkId, |
| | | "machineCode": machineCode, |
| | | } |
| | | header := map[string]string { |
| | |
| | | respBody, err := reqUtil.DoPostRequest(url, reqUtil.CONTENT_TYPE_JSON, paramBody, nil, header) |
| | | if err != nil { |
| | | logger.Debug("DoPostRequest err:", err) |
| | | return err |
| | | return nil, err |
| | | } |
| | | var res dbapi.Result |
| | | if err = json.Unmarshal(respBody, &res); err != nil { |
| | | logger.Debug("unmarshal err:", err) |
| | | return err |
| | | return nil, err |
| | | } |
| | | if !res.Success { |
| | | logger.Debug("res.Data:", res.Data) |
| | | return errors.New("请求商城失败") |
| | | return nil, errors.New("请求商城失败") |
| | | } |
| | | |
| | | return nil |
| | | return res.Data, nil |
| | | } |
| | | |
| | | //算法安装包安装 |
| | |
| | | } |
| | | } |
| | | |
| | | //解压上传的算法安装包 |
| | | func unPackPatchPackage(identifier string, ext string) (bool,error) { |
| | | configPatchPath := "" |
| | | if config.Server.PatchPath != "" { |
| | | configPatchPath = config.Server.PatchPath |
| | | } else { |
| | | configPatchPath = "../patch" |
| | | } |
| | | //1.解压缩更新包 |
| | | unPackTargetPath := configPatchPath+"/"+identifier+"_basic/" |
| | | unPackFilePath := configPatchPath+"/"+identifier+ext |
| | | |
| | | if util.Exists(unPackTargetPath) { |
| | | //此版本已经更新过 |
| | | rmErr := os.RemoveAll(unPackTargetPath) |
| | | if rmErr !=nil { |
| | | return false,rmErr |
| | | } |
| | | } |
| | | if !util.CreateDirectory(unPackTargetPath) { |
| | | return false, errors.New("创建压缩文件夹失败") |
| | | } |
| | | logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackTargetPath) |
| | | _,err := util.UnTarGzByCmd(unPackFilePath, unPackTargetPath) |
| | | if err !=nil { |
| | | logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath) |
| | | return false, err |
| | | } |
| | | return true, nil |
| | | } |
| | | |
| | | func (sv SdkInstallService) ShowInstallInfo(identifier string, filename string) (bool, map[string]interface{}, error) { |
| | | configPatchPath := "" |
| | | if config.Server.PatchPath != "" { |
| | | configPatchPath = config.Server.PatchPath |
| | | } else { |
| | | configPatchPath = "../patch" |
| | | } |
| | | unPackTargetPath := configPatchPath+"/"+identifier+"_basic/" |
| | | isValid := false |
| | | defer func() { |
| | | if !isValid { |
| | | filenameWithSuffix := path.Base(filename) |
| | | ext := path.Ext(filenameWithSuffix) |
| | | unPackFilePath := configPatchPath+"/"+identifier+ext |
| | | md5DirPath := configPatchPath+"/"+identifier |
| | | |
| | | if util.Exists(unPackTargetPath) { |
| | | os.RemoveAll(unPackTargetPath) |
| | | } |
| | | if util.Exists(unPackFilePath) { |
| | | os.RemoveAll(unPackFilePath) |
| | | } |
| | | if util.DirExists(md5DirPath) { |
| | | go os.RemoveAll(md5DirPath) |
| | | } |
| | | |
| | | } |
| | | }() |
| | | if util.Exists(unPackTargetPath) { |
| | | targetFileName := "" |
| | | err := filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error { |
| | | if f == nil { |
| | | return err |
| | | } |
| | | if f.IsDir() { |
| | | targetFileName = f.Name() |
| | | } |
| | | return nil |
| | | }) |
| | | if err != nil { |
| | | return isValid, nil, errors.New("非法的安装包") |
| | | } else { |
| | | unPackPath := unPackTargetPath + targetFileName +"/" |
| | | //解压完成,获取安装包中的文件,开始安装 |
| | | //1.解析安装说明ins.inc |
| | | incPath := unPackPath+"ins.inc" |
| | | if util.Exists(incPath) { |
| | | if incB, err := ioutil.ReadFile(incPath); err == nil { |
| | | var ins InsInc |
| | | if err = json.Unmarshal(incB, &ins); err == nil { |
| | | return true, map[string]interface{} { |
| | | "sdkName": ins.ProductName, |
| | | "installVersion": ins.InstallVersion, |
| | | "installContent": ins.InstallContent, |
| | | }, nil |
| | | } else { |
| | | return false, nil, errors.New("非法的安装包") |
| | | } |
| | | } else { |
| | | return false, nil, errors.New("非法的安装包") |
| | | } |
| | | } else { |
| | | return false, nil, errors.New("非法的安装包") |
| | | } |
| | | } |
| | | } else { |
| | | return isValid, nil, errors.New("安装包已不存在") |
| | | } |
| | | } |
| | | |
| | | //安装sdk |
| | | func installSdk(identifier string, ext string) (bool, error) { |
| | | configPatchPath := "" |
| | |
| | | } |
| | | }() |
| | | |
| | | if util.Exists(unPackTargetPath) { |
| | | //此版本已经更新过 |
| | | rmErr := os.RemoveAll(unPackTargetPath) |
| | | if rmErr !=nil { |
| | | return false,rmErr |
| | | } |
| | | } |
| | | if !util.CreateDirectory(unPackTargetPath) { |
| | | return false, errors.New("创建压缩文件夹失败") |
| | | if !util.Exists(unPackTargetPath) {//安装包不存在 |
| | | return false, errors.New("安装文件已不存在") |
| | | } |
| | | |
| | | logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackTargetPath) |
| | | _,err := util.UnTarGzByCmd(unPackFilePath, unPackTargetPath) |
| | | if err !=nil { |
| | | logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath) |
| | | return false, err |
| | | } |
| | | targetFileName := "" |
| | | err = filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error { |
| | | err := filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error { |
| | | if f == nil { |
| | | return err |
| | | } |
| | |
| | | return false, err |
| | | } |
| | | unPackPath := unPackTargetPath + targetFileName +"/" |
| | | if !util.Exists(unPackPath) { |
| | | return false, errors.New("安装文件已不存在") |
| | | } |
| | | //解压完成,获取安装包中的文件,开始安装 |
| | | //1.解析安装说明ins.inc |
| | | incPath := unPackPath+"ins.inc" |
| | |
| | | sdkVersion, ok := sm["version"] |
| | | if ok { //有版本号 |
| | | vStr := sdkVersion.(string) |
| | | if shouldVersionBeUpgrade(vStr, skd.Def.Version) { |
| | | if shouldVersionBeUpgrade(vStr, skd.Def.Version) { //比对版本号确定是否需要安装 |
| | | nInsM[skd.Def.SdkType] = skd.Def.SdkType |
| | | aInsM[skd.Def.Id] = skd.Def.Id |
| | | } |
| | |
| | | logger.Debug("upper version has been installed") |
| | | } |
| | | } |
| | | |
| | | } else { |
| | | return false, errors.New("反序列化算法定义信息失败") |
| | | logger.Debug("反序列化算法定义信息失败") |
| | | return false, errors.New("错误的安装包") |
| | | } |
| | | } else { |
| | | return false, errors.New("读取算法定义信息失败") |
| | | logger.Debug("读取算法定义信息失败") |
| | | return false, errors.New("错误的安装包") |
| | | } |
| | | } else { |
| | | return false, errors.New("算法定义信息丢失") |
| | | logger.Debug("算法定义信息丢失") |
| | | return false, errors.New("错误的安装包") |
| | | } |
| | | } else { |
| | | return false, errors.New("反序列化授权信息失败") |
| | | logger.Debug("反序列化授权信息失败") |
| | | return false, errors.New("错误的安装包") |
| | | } |
| | | } else { |
| | | return false, errors.New("读取授权文件失败") |
| | | logger.Debug("读取授权文件失败") |
| | | return false, errors.New("错误的安装包") |
| | | } |
| | | } else { |
| | | return false, errors.New("授权文件不存在") |
| | | return false, errors.New("错误的安装包") |
| | | } |
| | | |
| | | return true, nil |
| | |
| | | ChCount int `json:"chCount"` |
| | | AuthCount int `json:"authCount"` |
| | | ServeYear int `json:"serveYear"` |
| | | |
| | | ProductName string `json:"productName"` |
| | | InstallVersion string `json:"installVersion"` |
| | | InstallContent string `json:"installContent"` |
| | | } |
| | | |
| | | //算法和参数定义 |