From cd1ea5495e9c47a98e0f61000129d6b9a5885acb Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sat, 16 Sep 2023 04:54:50 +0300 Subject: [PATCH] apkupdater: Implement Alpine Update() Signed-off-by: HeshamTB --- apkupdater/apkupdater.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apkupdater/apkupdater.go b/apkupdater/apkupdater.go index a100f77..e0ae81d 100644 --- a/apkupdater/apkupdater.go +++ b/apkupdater/apkupdater.go @@ -3,6 +3,7 @@ package apkupdater import ( "fmt" "log" + "os/exec" "sync" "time" ) @@ -24,9 +25,19 @@ type AlpineLinuxPackageUpdate struct { } func (u *AlpineLinuxPackageUpdate) Update() { + u.apkLock.Lock() log.Println("Updating packages...") + cmd := exec.Command("apk", u.Packages...) + stdout, err := cmd.Output() u.apkLock.Unlock() + if err != nil { + log.Println(err.Error()) + } + if cmd.ProcessState.ExitCode() != 1 { + log.Printf("Update command returned exit status %d\n", cmd.ProcessState.ExitCode()) + log.Println(string(stdout)) + } log.Println("Done updating packges") } @@ -45,7 +56,7 @@ func (u *AlpineLinuxPackageUpdate) Run() { } fmt.Println("Updater stopped") }() - log.Println("Started apline linux package updater") + log.Println("Started Alpine linux package updater") } func (u *AlpineLinuxPackageUpdate) ValidPackages() bool {