diff --git a/setup/setup.go b/setup/setup.go index f7617d87..24706394 100644 --- a/setup/setup.go +++ b/setup/setup.go @@ -80,6 +80,9 @@ var configDir = "/etc" // unitComment is comment for service unit var unitComment = "# Unit generated by ek.go/setup" +// checksum is current binary checksum +var checksum string + // ////////////////////////////////////////////////////////////////////////////////// // // Install installs or reinstalls application on the system @@ -142,7 +145,7 @@ func (b *binaryInfo) ServiceUnitPath() string { // IsBinInstalled returns true if current binary already installed func (b *binaryInfo) IsBinInstalled() bool { return fsutil.IsExist(b.BinInstallPath()) && - hash.FileHash(b.File) == hash.FileHash(b.BinInstallPath()) + b.Checksum() == hash.FileHash(b.BinInstallPath()) } // IsServiceInstalled returns true if service unit already installed @@ -150,6 +153,17 @@ func (b *binaryInfo) IsServiceInstalled() bool { return fsutil.IsExist(b.ServiceUnitPath()) } +// Checksum returns checksum of current binary +func (b *binaryInfo) Checksum() string { + if checksum != "" { + return checksum + } + + checksum = hash.FileHash(b.File) + + return checksum +} + // ////////////////////////////////////////////////////////////////////////////////// // // getBinary returns basic info about current binary @@ -367,7 +381,12 @@ func createServiceFile(app App, bin binaryInfo) error { func generateServiceUnit(app App, bin binaryInfo) []byte { var buf bytes.Buffer - buf.WriteString(unitComment + "\n\n") + buf.WriteString(fmt.Sprintf( + "%s (%s)\n\n", + unitComment, + strutil.Head(bin.Checksum(), 7), + )) + buf.WriteString("[Unit]\n") buf.WriteString(fmt.Sprintf("Description=%s\n", strutil.Q(app.Name, bin.Name)))