| | |
| | | import ( |
| | | "archive/tar" |
| | | "archive/zip" |
| | | "basic.com/valib/logger.git" |
| | | "bytes" |
| | | "compress/gzip" |
| | | "crypto/md5" |
| | |
| | | func DeCompress(tarFile, dest string) error { |
| | | srcFile, err := os.Open(tarFile) |
| | | if err != nil { |
| | | logger.Debug("open tarFile err:",err) |
| | | return err |
| | | } |
| | | defer srcFile.Close() |
| | | gr, err := gzip.NewReader(srcFile) |
| | | if err != nil { |
| | | logger.Debug("gzip.NewReader err:",err) |
| | | return err |
| | | } |
| | | defer gr.Close() |
| | |
| | | filename := dest + hdr.Name |
| | | file, err := createFile(filename) |
| | | if err != nil { |
| | | logger.Debug("createFile err:",err) |
| | | return err |
| | | } |
| | | io.Copy(file, tr) |
| | |
| | | return false |
| | | } |
| | | |
| | | zipFilePath := configPatchPath+"/"+identifier+ext |
| | | err := util.DeCompress(zipFilePath, unPackPath) |
| | | unPackFilePath := configPatchPath+"/"+identifier+ext |
| | | err := util.DeCompress(unPackFilePath, unPackPath) |
| | | if err !=nil { |
| | | logger.Debug("UnZip err:",err,"zipFile:",zipFilePath) |
| | | logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath) |
| | | return false |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | //判断更新包里是否有补丁脚本,如果有则执行,否则执行updatePatch.sh |
| | | updateCmd := fmt.Sprintf("./updatePatch.sh %s %s %s &",unPackPath,zipFilePath,configPatchPath+"/"+identifier) |
| | | updateCmd := fmt.Sprintf("./updatePatch.sh %s %s %s &",unPackPath,unPackFilePath,configPatchPath+"/"+identifier) |
| | | if util.Exists(unPackPath+"upgrade.sh") { |
| | | updateCmd = fmt.Sprintf("%supgrade.sh %s %s %s &",unPackPath,unPackPath,zipFilePath,configPatchPath+"/"+identifier) |
| | | updateCmd = fmt.Sprintf("%supgrade.sh %s %s %s &",unPackPath,unPackPath,unPackFilePath,configPatchPath+"/"+identifier) |
| | | } |
| | | //2.更新系统 |
| | | b,err := ExecCmd(updateCmd) |