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 <supakeen@redhat.com>
This commit is contained in:
Simon de Vlieger 2024-10-28 11:08:27 +01:00
parent 943e6d3f7a
commit bea17a4077
No known key found for this signature in database
3 changed files with 87 additions and 0 deletions

12
cmd/posadka/main.go Normal file
View file

@ -0,0 +1,12 @@
package main
import (
"flag"
)
func init() {
}
func main() {
flag.Parse()
}

44
modify.go Normal file
View file

@ -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
}

31
primitive.go Normal file
View file

@ -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
}