Add utility function for simple package management

This commit is contained in:
2025-09-28 02:17:31 -04:00
parent 8b265cd3d9
commit f84f304466
6 changed files with 27 additions and 90 deletions
+13 -53
View File
@@ -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")
}
}
}
+2 -11
View File
@@ -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)
+1 -11
View File
@@ -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")
}
+1 -5
View File
@@ -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)
}
}
}
+2 -10
View File
@@ -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
+8
View File
@@ -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 {