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