From 2905fbc275ff396147941ec75b32013329347308 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 30 Sep 2025 00:33:20 -0400 Subject: [PATCH] Fourth round of fixes --- configurations.go | 8 +------- cosmic.go | 9 ++++++++- main.go | 8 ++------ system.go | 4 ++-- universalTweaks.go | 13 +------------ utilities.go | 28 ++++++++++++---------------- 6 files changed, 26 insertions(+), 44 deletions(-) diff --git a/configurations.go b/configurations.go index 327ea11..abe59dc 100644 --- a/configurations.go +++ b/configurations.go @@ -1,10 +1,7 @@ package main import ( - "os" - "github.com/rwinkhart/go-boilerplate/front" - "github.com/rwinkhart/go-boilerplate/other" ) func configurations() { @@ -40,10 +37,7 @@ func configurations() { } fallthrough case 6: - err := os.MkdirAll(mountPoint+"/home/"+getUsername()+"/.config/zed", 0755) - if err != nil { - other.PrintError("Failed to create zed config directory", 1) - } + mkdir(mountPoint + "/home/" + getUsername() + "/.config/zed") writeFile(mountPoint+"/home/"+getUsername()+"/.config/zed/settings.json", zed, getUsername(), 0600) if !doAll { diff --git a/cosmic.go b/cosmic.go index d8927a8..9340a9c 100644 --- a/cosmic.go +++ b/cosmic.go @@ -1,5 +1,9 @@ package main +import ( + "strings" +) + func cosmic() { version := "/v1/" filenamesToValues := map[string]string{ @@ -21,8 +25,11 @@ func cosmic() { "Panel.Panel" + version + "size": "XS", "Tk" + version + "show_maximize": "false"} + mkdir(mountPoint + "/home/" + getUsername() + "/.config/cosmic") for key, value := range filenamesToValues { - writeFile(mountPoint+"/home/"+getUsername()+"/.config/cosmic/com.system76.Cosmic"+key, value+"\n", getUsername(), 0755) + filePath := mountPoint + "/home/" + getUsername() + "/.config/cosmic/com.system76.Cosmic" + key + mkdir(filePath[:strings.LastIndex(filePath, "/")]) + writeFile(filePath, value+"\n", getUsername(), 0755) } // Replace SDDM with cosmic-greeter diff --git a/main.go b/main.go index 179173f..ca41a51 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "os" "os/user" "github.com/rwinkhart/go-boilerplate/front" @@ -26,10 +25,7 @@ func main() { partitionR = front.Input("Target root partition (/dev/driveparition):") partitionB = front.Input("Target boot (efi) partition (/dev/driveparition):") - err = os.MkdirAll("/mnt/cph", 0777) - if err != nil { - other.PrintError("Failed to create mount directory (/mnt/cph)", 1) - } + mkdir("/mnt/cph") for { fmt.Println() @@ -37,7 +33,7 @@ func main() { switch choice { case 1: if partitionIsMounted() { - fmt.Println(partitionR + " is already mounted on " + mountPoint) + fmt.Println("\n" + partitionR + " is already mounted on " + mountPoint) } else { premount() } diff --git a/system.go b/system.go index 959c78b..9626335 100644 --- a/system.go +++ b/system.go @@ -23,7 +23,7 @@ func system() { writeFile(mountPoint+"/etc/doas.conf", "permit persist keepenv :wheel as root\n", "root", 0644) managePackage("-S", "opendoas") chrootCommandRun([]string{"pacman", "-S", "--asexplicit", "--dbonly", "archlinux-keyring", "autoconf", "automake", "binutils", "bison", "debugedit", "fakeroot", "file", "findutils", "flex", "gawk", "gcc", "gettext", "grep", "groff", "gzip", "libtool", "m4", "make", "pacman", "patch", "pkgconf", "sed", "texinfo", "which", "--noconfirm"}) - chrootCommandRun([]string{"pacman", "-R", "sudo", "qt-sudo", "--noconfirm"}) + chrootCommandRun([]string{"pacman", "-R", "base-devel", "sudo", "--noconfirm"}) if !doAll { break @@ -66,7 +66,7 @@ func system() { break } fallthrough - case 9: + case 8: addKernelParams([]string{"amd_pstate=passive"}) } } diff --git a/universalTweaks.go b/universalTweaks.go index 6c0c2c9..ad3cac5 100644 --- a/universalTweaks.go +++ b/universalTweaks.go @@ -1,11 +1,5 @@ package main -import ( - "os" - - "github.com/rwinkhart/go-boilerplate/other" -) - func universalTweaks() { // Lock root account chrootCommandRun([]string{"passwd", "--delete", "root"}) @@ -15,10 +9,5 @@ func universalTweaks() { chrootCommandRun([]string{"usermod", "-aG", "uucp", getUsername()}) // Force disable kernel watchdog (kernel parameters should do this as well) - f, err := os.Create(mountPoint + "/etc/modprobe.d/blacklist.conf") - if err != nil { - other.PrintError("Failed to create "+mountPoint+"/etc/modprobe.d/blacklist.conf", 1) - } - f.WriteString("# Disable kernel watchdog\nblacklist iTCO_wdt") - f.Close() + writeFile(mountPoint+"/etc/modprobe.d/blacklist.conf", "# Disable kernel watchdog\nblacklist iTCO_wdt\n", "root", 0644) } diff --git a/utilities.go b/utilities.go index 9b6b1a6..8985206 100644 --- a/utilities.go +++ b/utilities.go @@ -3,8 +3,6 @@ package main import ( "os" "os/exec" - "os/user" - "strconv" "strings" mnt "github.com/moby/sys/mountinfo" @@ -27,8 +25,7 @@ func writeFile(path, data, owner string, perms os.FileMode) { other.PrintError("Failed to write to "+path+":"+err.Error(), 1) } if owner != "root" { - uid := getUID() - err = os.Chown(path, uid, uid) + err = os.Chown(path, 1000, 1000) if err != nil { other.PrintError("Failed to set ownership of "+path, 1) } @@ -43,18 +40,6 @@ func getUsername() string { return localUsername } -func getUID() int { - userInfo, err := user.Lookup(getUsername()) - if err != nil { - other.PrintError("Failed to lookup UID for "+getUsername(), 1) - } - uid, err := strconv.Atoi(userInfo.Uid) - if err != nil { - other.PrintError("Failed to convert UID to integer", 1) - } - return uid -} - func partitionIsMounted() bool { isMounted, err := mnt.Mounted(mountPoint) if err != nil { @@ -89,3 +74,14 @@ func chrootCommandRun(args []string) { other.PrintError("Failed to run \""+strings.Join(args[1:], " ")+"\" within chroot: "+err.Error(), 1) } } + +func mkdir(path string) { + err := os.MkdirAll(path, 0755) + if err != nil { + other.PrintError("Failed to create \""+path+"/\" directory", 1) + } + err = os.Chown(path, 1000, 1000) + if err != nil { + other.PrintError("Failed to set ownership of \""+path+"\"", 1) + } +}