From bea17a40778f46cdb11ae30f5c2ce0c3e8315a8c Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Mon, 28 Oct 2024 11:08:27 +0100 Subject: [PATCH] setup: start sketching out some bits Tiny sketch of what we'd like to do. We'll be having an entrypoint, modifications we can apply to directory structures and some primitives to support those modifications. Signed-off-by: Simon de Vlieger --- cmd/posadka/main.go | 12 ++++++++++++ modify.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ primitive.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 cmd/posadka/main.go create mode 100644 modify.go create mode 100644 primitive.go diff --git a/cmd/posadka/main.go b/cmd/posadka/main.go new file mode 100644 index 0000000..80c4cee --- /dev/null +++ b/cmd/posadka/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "flag" +) + +func init() { +} + +func main() { + flag.Parse() +} diff --git a/modify.go b/modify.go new file mode 100644 index 0000000..a08dc08 --- /dev/null +++ b/modify.go @@ -0,0 +1,44 @@ +package posadka + +import ( + "path/filepath" +) + +func EmptyRootPassword(prefix string) error { + path := filepath.Join(prefix, "etc/passwd") + + return ReplaceInFile( + path, + []byte("root:x:"), + []byte("root::"), + ) +} + +func EnableSystemRequest(prefix string) error { + //579 # Enable System Request debugging of the kernel + //580 if [ "$SYSRQ" != "" ]; then + //581 echo "= Enabling System Request debugging of the kernel." + //582 cat >> ${PREFIX}/etc/sysctl.d/arm-image-installer-sysrq.conf <<-EOH + //583 # Controls the System Request debugging functionality of the kernel + //584 kernel.sysrq = 1 + //585 EOH + //586 fi + return nil +} + +func ShowBoot(prefix string) error { + path := filepath.Join(prefix, "etc/passwd") + + //# remove quiet from kargs + //if [ "$SHOWBOOT" != "" ]; then + // sed -i 's|rhgb quiet ||g' /tmp/boot/loader/entries/*.conf + //fi + + return ReplaceInFile( + path, + []byte("rhgb quiet "), + []byte(""), + ) + + return nil +} diff --git a/primitive.go b/primitive.go new file mode 100644 index 0000000..5797c91 --- /dev/null +++ b/primitive.go @@ -0,0 +1,31 @@ +package posadka + +import ( + "bytes" + "os" +) + +// Replace `a` with `b` in a given file at `path`. This function is non-atomic +// so be careful with crashing. +func ReplaceInFile(path string, a, b []byte) error { + data, err := os.ReadFile(path) + + if err != nil { + return err + } + + data = bytes.Replace( + data, + a, + b, + 1, + ) + + err = os.WriteFile(path, data, 0644) + + if err != nil { + return err + } + + return nil +}