-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common: feat: add versionCheck and implement it on various Health com…
…mands
- Loading branch information
Showing
9 changed files
with
299 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package common | ||
|
||
import ( | ||
"os" | ||
"fmt" | ||
"time" | ||
"io/ioutil" | ||
"github.com/spf13/cobra" | ||
"github.com/monobilisim/monokit/common" | ||
news "github.com/monobilisim/monokit/common/redmine/news" | ||
) | ||
|
||
func StoreVersion(service string, version string) { | ||
common.WriteToFile(common.TmpDir + "/" + service + ".version", version) | ||
} | ||
|
||
func GatherVersion(service string) string { | ||
// Check if the service has a file | ||
if _, err := os.Stat(common.TmpDir + "/" + service + ".version"); os.IsNotExist(err) { | ||
return "" | ||
} | ||
|
||
// Read the file | ||
content, err := ioutil.ReadFile(common.TmpDir + "/" + service + ".version") | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
return string(content) | ||
} | ||
|
||
func CreateNews(service string, oldVersion string, newVersion string) { | ||
news.Create(common.Config.Identifier + " sunucusunun " + service + " sürümü güncellendi", common.Config.Identifier + " sunucusunda " + service + ", " + oldVersion + " sürümünden " + newVersion + " sürümüne yükseltildi.", true) | ||
} | ||
|
||
|
||
func VersionCheck(cmd *cobra.Command, args []string) { | ||
version := "0.1.0" | ||
common.ScriptName = "versionCheck" | ||
common.TmpDir = "/var/cache/mono/" + common.ScriptName | ||
common.Init() | ||
|
||
fmt.Println("versionCheck - v" + version + " - " + time.Now().Format("2006-01-02 15:04:05")) | ||
|
||
// Proxmox | ||
ProxmoxVECheck() | ||
ProxmoxMGCheck() | ||
ProxmoxBSCheck() | ||
|
||
// Zimbra | ||
ZimbraCheck() | ||
|
||
// OPNsense | ||
OPNsenseCheck() | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func OPNsenseCheck() { | ||
// Check if OPNsense is installed by checking the existence of command "opnsense-version" | ||
_, err := exec.LookPath("opnsense-version") | ||
if err != nil { | ||
fmt.Println("OPNsense is not installed on this system.") | ||
return | ||
} | ||
|
||
// Get the version of OPNsense | ||
out, err := exec.Command("opnsense-version").Output() | ||
if err != nil { | ||
fmt.Println("Error getting OPNsense version.") | ||
return | ||
} | ||
|
||
// Parse the version | ||
// Eg. output | ||
// OPNsense 21.1.8_1 (amd64) | ||
version := strings.Split(string(out), " ")[1] | ||
fmt.Println("OPNsense version:", version) | ||
|
||
oldVersion := GatherVersion("opnsense") | ||
|
||
if oldVersion != "" && oldVersion == version { | ||
fmt.Println("OPNsense is up to date.") | ||
return | ||
} else if oldVersion != "" && oldVersion != version { | ||
fmt.Println("OPNsense got updated.") | ||
fmt.Println("Old version:", oldVersion) | ||
fmt.Println("New version:", version) | ||
CreateNews("OPNsense", oldVersion, version) | ||
} | ||
|
||
|
||
StoreVersion("opnsense", version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func ProxmoxVECheck() { | ||
// Check if Proxmox VE is installed by checking the existence of command "pveversion" | ||
_, err := exec.LookPath("pveversion") | ||
if err != nil { | ||
fmt.Println("Proxmox VE is not installed on this system.") | ||
return | ||
} | ||
|
||
// Get the version of Proxmox VE | ||
out, err := exec.Command("pveversion").Output() | ||
if err != nil { | ||
fmt.Println("Error getting Proxmox VE version.") | ||
return | ||
} | ||
|
||
// Parse the version | ||
// Eg. output | ||
// pve-manager/6.4-13/1c2b3f0e (running kernel: 5.4.78-2-pve) | ||
version := strings.Split(string(out), "/")[1] | ||
fmt.Println("Proxmox VE version:", version) | ||
|
||
oldVersion := GatherVersion("pve") | ||
|
||
if oldVersion != "" && oldVersion == version { | ||
fmt.Println("Proxmox VE is up to date.") | ||
return | ||
} else if oldVersion != "" && oldVersion != version { | ||
fmt.Println("Proxmox VE has been updated.") | ||
fmt.Println("Old version:", oldVersion) | ||
fmt.Println("New version:", version) | ||
CreateNews("Proxmox VE", oldVersion, version) | ||
} | ||
|
||
StoreVersion("pve", version) | ||
} | ||
|
||
func ProxmoxMGCheck() { | ||
// Check if Proxmox Mail Gateway is installed by checking the existence of command "pmgversion" | ||
_, err := exec.LookPath("pmgversion") | ||
if err != nil { | ||
fmt.Println("Proxmox Mail Gateway is not installed on this system.") | ||
return | ||
} | ||
|
||
// Get the version of Proxmox Mail Gateway | ||
out, err := exec.Command("pmgversion").Output() | ||
if err != nil { | ||
fmt.Println("Error getting Proxmox Mail Gateway version.") | ||
return | ||
} | ||
|
||
// Parse the version | ||
// Eg. output | ||
// pmg/6.4-13/1c2b3f0e (running kernel: 5.4.78-2-pve) | ||
version := strings.Split(string(out), "/")[1] | ||
fmt.Println("Proxmox Mail Gateway version:", version) | ||
|
||
oldVersion := GatherVersion("pmg") | ||
|
||
if oldVersion != "" && oldVersion == version { | ||
fmt.Println("Proxmox Mail Gateway is up to date.") | ||
return | ||
} else if oldVersion != "" && oldVersion != version { | ||
fmt.Println("Proxmox Mail Gateway has been updated.") | ||
fmt.Println("Old version:", oldVersion) | ||
fmt.Println("New version:", version) | ||
CreateNews("Proxmox Mail Gateway", oldVersion, version) | ||
} | ||
|
||
StoreVersion("pmg", version) | ||
} | ||
|
||
func ProxmoxBSCheck() { | ||
// Check if Proxmox Backup Server is installed by checking the existence of command "proxmox-backup-manager" | ||
_, err := exec.LookPath("proxmox-backup-manager") | ||
if err != nil { | ||
fmt.Println("Proxmox Backup Server is not installed on this system.") | ||
return | ||
} | ||
|
||
// Get the version of Proxmox Backup Server | ||
out, err := exec.Command("proxmox-backup-manager", "version").Output() | ||
if err != nil { | ||
fmt.Println("Error getting Proxmox Backup Server version.") | ||
return | ||
} | ||
|
||
// Parse the version | ||
// Eg. output | ||
// proxmox-backup-server 3.3.2-1 running version: 3.3.2 | ||
version := strings.Split(string(out), " ")[1] | ||
fmt.Println("Proxmox Backup Server version:", version) | ||
|
||
oldVersion := GatherVersion("pbs") | ||
|
||
if oldVersion != "" && oldVersion == version { | ||
fmt.Println("Proxmox Backup Server is up to date.") | ||
return | ||
} else if oldVersion != "" && oldVersion != version { | ||
fmt.Println("Proxmox Backup Server has been updated.") | ||
fmt.Println("Old version:", oldVersion) | ||
fmt.Println("New version:", version) | ||
CreateNews("Proxmox Backup Server", oldVersion, version) | ||
} | ||
|
||
StoreVersion("pbs", version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build !linux | ||
package common | ||
|
||
func ZimbraCheck() { | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//go:build linux | ||
package common | ||
|
||
import ( | ||
"os" | ||
"fmt" | ||
"strings" | ||
"os/exec" | ||
) | ||
|
||
func ZimbraCheck() { | ||
var zimbraPath string | ||
var zimbraUser string | ||
|
||
if _, err := os.Stat("/opt/zimbra"); !os.IsNotExist(err) { | ||
zimbraPath = "/opt/zimbra" | ||
zimbraUser = "zimbra" | ||
} | ||
|
||
if _, err := os.Stat("/opt/zextras"); !os.IsNotExist(err) { | ||
zimbraPath = "/opt/zextras" | ||
zimbraUser = "zextras" | ||
} | ||
|
||
// Get the version of Zimbra | ||
cmd := exec.Command("/bin/su", zimbraUser, "-c", zimbraPath + "/bin/zmcontrol -v") | ||
out, err := cmd.Output() | ||
if err != nil { | ||
fmt.Println("Error getting Zimbra version.") | ||
return | ||
} | ||
|
||
// Parse the version | ||
// Eg. output | ||
// Release 8.8.15_GA_3869.UBUNTU18.64 UBUNTU18_64 FOSS edition. | ||
version := strings.Split(string(out), " ")[1] | ||
version = strings.Split(version, "_GA_")[0] | ||
|
||
fmt.Println("Zimbra version:", version) | ||
|
||
oldVersion := GatherVersion("zimbra") | ||
|
||
if oldVersion != "" && oldVersion == version { | ||
fmt.Println("Zimbra is up to date.") | ||
return | ||
} else if oldVersion != "" && oldVersion != version { | ||
fmt.Println("Zimbra has been updated.") | ||
fmt.Println("Old version:", oldVersion) | ||
fmt.Println("New version:", version) | ||
CreateNews("Zimbra", oldVersion, version) | ||
} | ||
|
||
StoreVersion("zimbra", version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters