From f84f304466c663adfbe4d1b64dc3fc5cdf4fd078 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 28 Sep 2025 02:17:31 -0400 Subject: [PATCH] Add utility function for simple package management --- applications.go | 66 ++++++++++------------------------------------- configurations.go | 13 ++-------- cosmic.go | 12 +-------- removals.go | 6 +---- system.go | 12 ++------- utilities.go | 8 ++++++ 6 files changed, 27 insertions(+), 90 deletions(-) diff --git a/applications.go b/applications.go index 7a4dc36..daa5561 100644 --- a/applications.go +++ b/applications.go @@ -18,63 +18,35 @@ func applications() { doAll = true fallthrough case 3: - cmd := exec.Command("pacman", "-S", "pamac-aur", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to perform application installation", 1) - } - cmd = exec.Command("pacman", "-Rcns", "octopi", "--noconfirm") - err = cmd.Run() - if err != nil { - other.PrintError("Failed to perform application removal", 1) - } + managePackage("-S", "pamac-aur") + managePackage("-Rcns", "octopi") if !doAll { break } fallthrough case 4: - cmd := exec.Command("pacman", "-S", "yay-bin", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to perform application installation", 1) - } - cmd = exec.Command("pacman", "-Rcns", "paru", "--noconfirm") - err = cmd.Run() - if err != nil { - other.PrintError("Failed to perform application removal", 1) - } + managePackage("-S", "yay-bin") + managePackage("-Rcns", "paru") if !doAll { break } fallthrough case 5: - cmd := exec.Command("pacman", "-S", "htop", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to perform application installation", 1) - } - cmd = exec.Command("pacman", "-Rcns", "btop", "--noconfirm") - err = cmd.Run() - if err != nil { - other.PrintError("Failed to perform application removal", 1) - } + managePackage("-S", "htop") + managePackage("-Rcns", "btop") if !doAll { break } fallthrough case 6: - cmd := exec.Command("pacman", "-S", "neovim", "--noconfirm") + managePackage("-S", "neovim") + cmd := exec.Command("pacman", "-Rcns", "vi", "vim", "nano", "micro", "--noconfirm") err := cmd.Run() if err != nil { - other.PrintError("Failed to perform application installation", 1) - } - cmd = exec.Command("pacman", "-Rcns", "vi", "vim", "nano", "micro", "--noconfirm") - err = cmd.Run() - if err != nil { - other.PrintError("Failed to perform application removals", 1) + other.PrintError("Failed to perform application removals for neovim installation", 1) } if !doAll { @@ -85,7 +57,7 @@ func applications() { cmd := exec.Command("pacman", "-S", "virt-manager", "qemu-desktop", "libvirt", "--noconfirm") err := cmd.Run() if err != nil { - other.PrintError("Failed to perform application installations", 1) + other.PrintError("Failed to perform application installations for virt-manager", 1) } manageService("enable", "libvirtd.service") manageService("start", "libvirtd.service") @@ -95,33 +67,21 @@ func applications() { } fallthrough case 8: - cmd := exec.Command("pacman", "-S", "librewolf-bin", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to perform application installation", 1) - } + managePackage("-S", "librewolf-bin") if !doAll { break } fallthrough case 9: - cmd := exec.Command("pacman", "-S", "zed", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to perform application installation", 1) - } + managePackage("-S", "zed") if !doAll { break } fallthrough case 10: - cmd := exec.Command("pacman", "-S", "steam", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to perform application installation", 1) - } + managePackage("-S", "steam") } } } diff --git a/configurations.go b/configurations.go index 5315da9..daae7bf 100644 --- a/configurations.go +++ b/configurations.go @@ -2,7 +2,6 @@ package main import ( "os" - "os/exec" "github.com/rwinkhart/go-boilerplate/front" "github.com/rwinkhart/go-boilerplate/other" @@ -19,11 +18,7 @@ func configurations() { doAll = true fallthrough case 3: - cmd := exec.Command("pacman", "-S", "wayland-protocols", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to install wayland-protocols", 1) - } + managePackage("-S", "wayland-protocols") writeFile("/home/"+getUsername()+"/.profile", shellProfile, getUsername(), 0644) if !doAll { @@ -63,11 +58,7 @@ func configurations() { } fallthrough case 8: - cmd := exec.Command("pacman", "-S", "pacman-contrib", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to install pacman-contrib", 1) - } + managePackage("-S", "pacman-contrib") writeFile("/etc/pacman.conf", pacman, "root", 0644) writeFile("/etc/pacman.d/hooks/paccache-clean.hook", pacmanHookClean, "root", 0644) writeFile("/etc/pacman.d/hooks/nvidia.hook", pacmanHookNvidia, "root", 0644) diff --git a/cosmic.go b/cosmic.go index 2e1b973..5e2495f 100644 --- a/cosmic.go +++ b/cosmic.go @@ -1,11 +1,5 @@ package main -import ( - "os/exec" - - "github.com/rwinkhart/go-boilerplate/other" -) - func cosmic() { version := "/v1/" filenamesToValues := map[string]string{ @@ -37,9 +31,5 @@ func cosmic() { manageService("stop", "sddm.service") manageService("disable", "sddm.service") manageService("enable", "greetd.service") - cmd := exec.Command("pacman", "-Rcns", "sddm", "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to remove SDDM", 1) - } + managePackage("-Rcns", "sddm") } diff --git a/removals.go b/removals.go index 7f9fa4d..d83af5d 100644 --- a/removals.go +++ b/removals.go @@ -38,11 +38,7 @@ func removals() { target = "modemmanager" } if !doAll { - cmd := exec.Command("pacman", "-Rcns", target, "--noconfirm") - err := cmd.Run() - if err != nil { - other.PrintError("Failed to remove "+target, 1) - } + managePackage("-Rcns", target) } } } diff --git a/system.go b/system.go index 6f2cb99..633e29a 100644 --- a/system.go +++ b/system.go @@ -67,16 +67,8 @@ depends=( if err != nil { other.PrintError("Failed to build+install custom base-devel", 1) } - cmd = exec.Command("pacman", "-S", "opendoas", "--noconfirm") - err = cmd.Run() - if err != nil { - other.PrintError("Failed to install opendoas", 1) - } - cmd = exec.Command("pacman", "-R", "sudo", "--noconfirm") - err = cmd.Run() - if err != nil { - other.PrintError("Failed to remove sudo", 1) - } + managePackage("-S", "opendoas") + managePackage("-R", "sudo") if !doAll { break diff --git a/utilities.go b/utilities.go index 059a098..9122009 100644 --- a/utilities.go +++ b/utilities.go @@ -23,6 +23,14 @@ func manageService(action, service string) { } } +func managePackage(action, targetPackage string) { + cmd := exec.Command("pacman", action, targetPackage, "--noconfirm") + err := cmd.Run() + if err != nil { + other.PrintError("Failed to "+action+" "+targetPackage, 1) + } +} + func writeFile(path, data, owner string, perms os.FileMode) { err := os.WriteFile(path, []byte(data), perms) if err != nil {