| | |
| | | logger.Debug("write chunkData err:",err2,"nn:",nn) |
| | | return false |
| | | } |
| | | if err = writer.Flush(); err != nil { |
| | | logger.Debug("write flush err:",err) |
| | | } |
| | | isComplete := false |
| | | dirFiles, _ := ioutil.ReadDir(fileTmpPath) |
| | | if dirFiles != nil && len(dirFiles) == arg.TotalChunks { |
| | |
| | | return false,errors.New("获取升级压缩包md5失败") |
| | | } |
| | | if strMd5 == identifier { |
| | | if util.ZipCheck(zipFilePath) { |
| | | if util.TarGzCheck(zipFilePath) { |
| | | if !updatePatch(identifier, ext) { |
| | | return false,errors.New("执行升级过程异常") |
| | | } |
| | |
| | | if !util.CreateDirectory(configBakPath) { |
| | | return false |
| | | } |
| | | b, err := ExecCmd("cp /opt/vasystem/bin /opt/vasystem/bak") |
| | | logger.Debug("bakBeforeUpgrade result:",string(b)) |
| | | b, err := ExecCmd("cp -r /opt/vasystem/bin /opt/vasystem/bak") |
| | | if err != nil { |
| | | logger.Debug("bakBeforeUpgrade result:",string(b),"err:",err) |
| | | return false |
| | | } |
| | | return true |
| | |
| | | configPatchPath = "/opt/vasystem/patch" |
| | | } |
| | | //1.解压缩更新包 |
| | | unZipPath := configPatchPath+"/"+identifier+"_basic/" |
| | | if util.Exists(unZipPath) { |
| | | unPackPath := configPatchPath+"/"+identifier+"_basic/" |
| | | if util.Exists(unPackPath) { |
| | | //此版本已经更新过 |
| | | rmErr := os.RemoveAll(unZipPath) |
| | | rmErr := os.RemoveAll(unPackPath) |
| | | if rmErr !=nil { |
| | | return false |
| | | } |
| | | } |
| | | if !util.CreateDirectory(unZipPath) { |
| | | if !util.CreateDirectory(unPackPath) { |
| | | return false |
| | | } |
| | | |
| | | zipFilePath := configPatchPath+"/"+identifier+ext |
| | | err := util.UnZip(zipFilePath, unZipPath) |
| | | err := util.DeCompress(zipFilePath, unPackPath) |
| | | if err !=nil { |
| | | logger.Debug("UnZip err:",err,"zipFile:",zipFilePath) |
| | | return false |
| | | } |
| | | |
| | | //如果通用脚本有更新,则更新通用脚本 |
| | | if util.Exists(unPackPath+"updatePatch.sh") { |
| | | cpStr := fmt.Sprintf("cp %s /opt/vasystem/bin",unPackPath+"updatePatch.sh") |
| | | b, err := ExecCmd(cpStr) |
| | | if err != nil { |
| | | logger.Debug("cp updatePatch.sh to bin err:",err,"result:",string(b)) |
| | | return false |
| | | } |
| | | } |
| | | |
| | | //判断更新包里是否有补丁脚本,如果有则执行,否则执行updatePatch.sh |
| | | updateCmd := fmt.Sprintf("./updatePatch.sh %s %s %s &",unZipPath,zipFilePath,configPatchPath+"/"+identifier) |
| | | if util.Exists(unZipPath+"upgrade.sh") { |
| | | updateCmd = fmt.Sprintf("%supgrade.sh %s %s %s &",unZipPath,unZipPath,zipFilePath,configPatchPath+"/"+identifier) |
| | | logger.Debug("upgrade use ",unZipPath,"upgrade.sh") |
| | | updateCmd := fmt.Sprintf("./updatePatch.sh %s %s %s &",unPackPath,zipFilePath,configPatchPath+"/"+identifier) |
| | | if util.Exists(unPackPath+"upgrade.sh") { |
| | | updateCmd = fmt.Sprintf("%supgrade.sh %s %s %s",unPackPath,unPackPath,zipFilePath,configPatchPath+"/"+identifier) |
| | | } |
| | | //2.更新系统 |
| | | var cmd *exec.Cmd |
| | | cmd = exec.Command("/bin/sh","-c", updateCmd) |
| | | if b, err := cmd.Output(); err != nil { |
| | | logger.Debug("updatePatch err:",err,"result:",string(b)) |
| | | b,err := ExecCmd(updateCmd) |
| | | if err != nil { |
| | | logger.Debug("upgrade err:",err,"result:",string(b),"cmd:",updateCmd) |
| | | return false |
| | | } else { |
| | | logger.Debug("updatePatch result:",string(b),"cmd:",updateCmd) |
| | | logger.Debug("upgrade result:",string(b),"cmd:",updateCmd) |
| | | } |
| | | return true |
| | | } |