package update import ( "crypto/sha256" "encoding/hex" "path" ) const ( RestartRequestFileName = "update-restart-request.json" ResultFileName = "update-result.json" HelperStatusFileName = "update-helper.json" RunningInfoFileName = "update-running.json" UpdatesDirName = "updates" HelperStatusVersion = 1 PathUnitName = "renewcms-update.path" ServiceUnitName = "renewcms-update.service" DefaultService = "renewcms" DefaultPort = "8080" PreviousSuffix = ".previous" PreviousTempSuffix = ".previous.tmp" InstallTempSuffix = ".new" RestoreTempSuffix = ".restore" ResultTempSuffix = ".tmp" ExecutableMode = 0o755 PrivateFileMode = 0o600 ) type HelperLayout struct { DataDir string BinaryPath string } func (l HelperLayout) UpdatesDir() string { return path.Join(l.DataDir, UpdatesDirName) } func (l HelperLayout) StagedDir(tag string) string { return path.Join(l.UpdatesDir(), tag) } func (l HelperLayout) ResultPath() string { return path.Join(l.DataDir, ResultFileName) } func (l HelperLayout) ResultTempPath() string { return l.ResultPath() + ResultTempSuffix } func (l HelperLayout) RestartRequestPath() string { return path.Join(l.DataDir, RestartRequestFileName) } func (l HelperLayout) PreviousPath() string { return l.BinaryPath + PreviousSuffix } func SHA256Hex(content []byte) string { sum := sha256.Sum256(content) return hex.EncodeToString(sum[:]) }