Borg/cmd/compile.go
google-labs-jules[bot] 3398fabb14 feat: Add trix encryption and format
This commit introduces the `Enchantrix` library to add support for the `.trix` encrypted file format.

The main changes are:

- The `matrix` format has been renamed to `tim` (Terminal Isolation Matrix).
- The `.tim` format is now a specialized `.trix` file.
- A new `decode` command has been added to decode `.trix` and `.tim` files.
- The `collect` commands now support the `trix` and `tim` formats.
- A `--password` flag has been added to the `collect` commands for encryption.
- A `--i-am-in-isolation` flag has been added to the `decode` command for safely decoding `.tim` files.
- The decryption functionality is currently disabled due to a bug in the `Enchantrix` library. A follow-up PR will be created to re-enable it.
2025-11-14 13:47:27 +00:00

74 lines
1.5 KiB
Go

package cmd
import (
"fmt"
"os"
"strings"
"github.com/Snider/Borg/pkg/tim"
"github.com/spf13/cobra"
)
var borgfile string
var output string
var compileCmd = NewCompileCmd()
func NewCompileCmd() *cobra.Command {
compileCmd := &cobra.Command{
Use: "compile",
Short: "Compile a Borgfile into a Terminal Isolation Matrix.",
RunE: func(cmd *cobra.Command, args []string) error {
content, err := os.ReadFile(borgfile)
if err != nil {
return err
}
m, err := tim.New()
if err != nil {
return err
}
lines := strings.Split(string(content), "\n")
for _, line := range lines {
parts := strings.Fields(line)
if len(parts) == 0 {
continue
}
switch parts[0] {
case "ADD":
if len(parts) != 3 {
return fmt.Errorf("invalid ADD instruction: %s", line)
}
src := parts[1]
dest := parts[2]
data, err := os.ReadFile(src)
if err != nil {
return err
}
m.RootFS.AddData(strings.TrimPrefix(dest, "/"), data)
default:
return fmt.Errorf("unknown instruction: %s", parts[0])
}
}
tarball, err := m.ToTar()
if err != nil {
return err
}
return os.WriteFile(output, tarball, 0644)
},
}
compileCmd.Flags().StringVarP(&borgfile, "file", "f", "Borgfile", "Path to the Borgfile.")
compileCmd.Flags().StringVarP(&output, "output", "o", "a.tim", "Path to the output tim file.")
return compileCmd
}
func GetCompileCmd() *cobra.Command {
return compileCmd
}
func init() {
RootCmd.AddCommand(GetCompileCmd())
}