Switch to chroot-based usage (run from installer ISO)

This commit is contained in:
2025-09-29 23:51:15 -04:00
parent 85b345d54c
commit 9cbabb58c9
12 changed files with 128 additions and 139 deletions
+8 -81
View File
@@ -3,7 +3,6 @@ package main
import (
"bufio"
"os"
"os/exec"
"strings"
"github.com/rwinkhart/go-boilerplate/front"
@@ -13,7 +12,7 @@ import (
func system() {
for {
var doAll bool
choice := front.InputMenuGen("Tweak:", []string{"BACK", "ALL", "replace sudo with doas", "enable ipv6 privacy extensions", "enable ext4 fast_commit", "enable SysRq reboots", "disable kernel security mitigations", "unlock amdgpu tuning", "enable amd_pstate in passive mode (recommended for zenver2)"})
choice := front.InputMenuGen("Tweak:", []string{"BACK", "ALL", "replace sudo with doas", "enable ipv6 privacy extensions", "enable SysRq reboots", "disable kernel security mitigations", "unlock amdgpu tuning", "enable amd_pstate in passive mode (recommended for zenver2)"})
switch choice {
case 1:
return
@@ -22,69 +21,9 @@ func system() {
fallthrough
case 3:
// TODO fix!
err := os.RemoveAll("/tmp/custom-base-devel/")
if err != nil {
other.PrintError("Failed to remove /tmp/custom-base-devel", 1)
}
writeFile("/etc/doas.conf", "permit persist keepenv :wheel as root\n", "root", 0644)
err = os.MkdirAll("/tmp/custom-base-devel", 0777)
if err != nil {
other.PrintError("Failed to create /tmp/custom-base-devel/", 1)
}
uid := getUID()
err = os.Chown("/tmp/custom-base-devel", uid, uid)
writeFile("/tmp/custom-base-devel/PKGBUILD", `pkgname=base-devel
pkgver=1
pkgrel=2
pkgdesc='Basic tools to build Arch Linux packages'
url='https://www.archlinux.org'
arch=('any')
license=('GPL')
options=('!debug')
depends=(
archlinux-keyring
autoconf
automake
binutils
bison
debugedit
fakeroot
file
findutils
flex
gawk
gcc
gettext
grep
groff
gzip
libtool
m4
make
pacman
pacman-contrib
patch
pkgconf
sed
opendoas
texinfo
which
)
# vim: ts=2 sw=2 et:
`, getUsername(), 0777)
cmd := exec.Command("sudo", "-u", getUsername(), "makepkg", "--dir", "/tmp/custom-base-devel")
err = cmd.Run()
if err != nil {
other.PrintError("Failed to build+install custom base-devel: "+err.Error(), 1)
}
managePackage("-U", "/tmp/custom-base-devel/base-devel-1-2-any.pkg.tar.xz")
writeFile(mountPoint+"/etc/doas.conf", "permit persist keepenv :wheel as root\n", "root", 0644)
managePackage("-S", "opendoas")
cmd = exec.Command("pacman", "-R", "sudo", "qt-sudo", "octopi", "--noconfirm")
err = cmd.Run()
if err != nil {
other.PrintError("Failed to remove sudo", 1)
}
//chrootCommandRun([]string{"pacman", "-R", "sudo", "qt-sudo", "--noconfirm"})
if !doAll {
break
@@ -100,39 +39,27 @@ depends=(
for _, nic := range nics {
sysctlConf.WriteString("\nnet.ipv6.conf." + nic.Name() + ".use_tempaddr = 2")
}
writeFile("/etc/sysctl.d/40-ipv6-priv-ext.conf", sysctlConf.String()+"\n", "root", 0644)
writeFile(mountPoint+"/etc/sysctl.d/40-ipv6-priv-ext.conf", sysctlConf.String()+"\n", "root", 0644)
if !doAll {
break
}
fallthrough
case 5:
// TODO move to chroot!
cmd := exec.Command("tune2fs", "-O", "fast_commit", front.Input("/dev/driveparition:"))
err := cmd.Run()
if err != nil {
other.PrintError("Failed to enable fast_commit", 1)
}
writeFile(mountPoint+"/etc/sysctl.d/35-sysrq.conf", "kernel.sysrq = 244\n", "root", 0644)
if !doAll {
break
}
fallthrough
case 6:
writeFile("/etc/sysctl.d/35-sysrq.conf", "kernel.sysrq = 244\n", "root", 0644)
if !doAll {
break
}
fallthrough
case 7:
addKernelParams([]string{"mitigations=off"})
if !doAll {
break
}
fallthrough
case 8:
case 7:
addKernelParams([]string{"amdgpu.ppfeaturemask=0xffffffff"})
if !doAll {
@@ -146,7 +73,7 @@ depends=(
}
func addKernelParams(newParameters []string) {
f, err := os.Open("/boot/loader/entries/linux-cachyos.conf")
f, err := os.Open(mountPoint + "/boot/loader/entries/linux-cachyos.conf")
if err != nil {
other.PrintError("Failed to open systemd-boot entry", 1)
}
@@ -160,5 +87,5 @@ func addKernelParams(newParameters []string) {
}
}
parameters = append(parameters, newParameters...)
writeFile("/boot/loader/entries/linux-cachyos.conf", "title Linux Cachyos\noptions root=UUID=e2ff600b-0202-4620-bed3-54d7a58414f8 "+strings.Join(parameters, " ")+"\nlinux /vmlinuz-linux-cachyos\ninitrd /initramfs-linux-cachyos.img\n", "root", 0700)
writeFile(mountPoint+"/boot/loader/entries/linux-cachyos.conf", "title Linux Cachyos\noptions root=UUID=e2ff600b-0202-4620-bed3-54d7a58414f8 "+strings.Join(parameters, " ")+"\nlinux /vmlinuz-linux-cachyos\ninitrd /initramfs-linux-cachyos.img\n", "root", 0700)
}