⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
module github.com/mdgspace/sysreplicate

go 1.24.3

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/bubbletea v1.3.10 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/lipgloss v1.1.0 // indirect
github.com/charmbracelet/x/ansi v0.10.1 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/text v0.3.8 // indirect
)
41 changes: 41 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ=
github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
14 changes: 8 additions & 6 deletions internal/core/backup/dotfiles_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"
"os"
"time"
"github.com/mdgspace/sysreplicate/system/output"

"github.com/mdgspace/sysreplicate/internal/core/generator"
"github.com/mdgspace/sysreplicate/internal/domain"
)

type BackupMetadata struct {
Expand All @@ -28,10 +30,10 @@ func (db *DotfileBackupManager) CreateDotfileBackup(outputTar string) error {

hostname, _ := os.Hostname()

// Convert []Dotfile to []output.Dotfile
outputFiles := make([]output.Dotfile, len(files))
// Convert []Dotfile to []domain.Dotfile
outputFiles := make([]domain.Dotfile, len(files))
for i, file := range files {
outputFiles[i] = output.Dotfile{
outputFiles[i] = domain.Dotfile{
Path: file.Path,
RealPath: file.RealPath,
IsDir: file.IsDir,
Expand All @@ -44,13 +46,13 @@ func (db *DotfileBackupManager) CreateDotfileBackup(outputTar string) error {

// Create backup metadata
// struct from output
meta := &output.BackupMetadata{
meta := &domain.BackupMetadata{
Timestamp: time.Now(),
Hostname: hostname,
Files: outputFiles,
}

if err := output.CreateDotfilesBackupTarball(meta, outputTar); err != nil {
if err := generator.CreateDotfilesBackupTarball(meta, outputTar); err != nil {
return fmt.Errorf("failed to create backup tarball: %w", err)
}

Expand Down
17 changes: 9 additions & 8 deletions internal/core/backup/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"strings"
"time"

"github.com/mdgspace/sysreplicate/system/output"
"github.com/mdgspace/sysreplicate/internal/core/generator"
"github.com/mdgspace/sysreplicate/internal/domain"
)

// backup and restore operations
Expand Down Expand Up @@ -52,10 +53,10 @@ func (bm *BackupManager) CreateBackup(customPaths []string) error {
}

//create backup data
backupData := &output.BackupData{
backupData := &domain.BackupData{
Timestamp: time.Now(),
SystemInfo: bm.getSystemInfo(),
EncryptedKeys: make(map[string]output.EncryptedKey),
EncryptedKeys: make(map[string]domain.EncryptedKey),
EncryptionKey: key, // Store the key in backup data
}

Expand All @@ -73,7 +74,7 @@ func (bm *BackupManager) CreateBackup(customPaths []string) error {
fmt.Println("Creating backup tarball...")
tarballPath := fmt.Sprintf("dist/key-backup-%s.tar.gz",
time.Now().Format("2006-01-02-15-04-05"))
err = output.CreateBackupTarball(backupData, tarballPath)
err = generator.CreateBackupTarball(backupData, tarballPath)
if err != nil {
return fmt.Errorf("failed to create tarball: %w", err)
}
Expand All @@ -84,7 +85,7 @@ func (bm *BackupManager) CreateBackup(customPaths []string) error {
}

// processLocation processes a single key location
func (bm *BackupManager) processLocation(location KeyLocation, backupData *output.BackupData) error {
func (bm *BackupManager) processLocation(location KeyLocation, backupData *domain.BackupData) error {
for _, filePath := range location.Files {
//get file info for permissions
fileInfo, err := os.Stat(filePath)
Expand All @@ -100,7 +101,7 @@ func (bm *BackupManager) processLocation(location KeyLocation, backupData *outpu

// store encrypted key
keyID := filepath.Base(filePath) + "_" + strings.ReplaceAll(filePath, "/", "_")
backupData.EncryptedKeys[keyID] = output.EncryptedKey{
backupData.EncryptedKeys[keyID] = domain.EncryptedKey{
OriginalPath: filePath,
KeyType: location.Type,
EncryptedData: encryptedData,
Expand Down Expand Up @@ -161,13 +162,13 @@ func (bm *BackupManager) processCustomPaths(customPaths []string) []KeyLocation
}

// collect basic system information
func (bm *BackupManager) getSystemInfo() output.SystemInfo {
func (bm *BackupManager) getSystemInfo() domain.SystemInfo {
hostname, _ := os.Hostname()
username := os.Getenv("USER")
if username == "" {
username = os.Getenv("USERNAME")
}
return output.SystemInfo{
return domain.SystemInfo{
Hostname: hostname,
Username: username,
OS: "linux",
Expand Down
4 changes: 2 additions & 2 deletions internal/core/backup/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"path/filepath"
"strings"

"github.com/mdgspace/sysreplicate/internal/core/generator"
"github.com/mdgspace/sysreplicate/internal/domain"
"github.com/mdgspace/sysreplicate/system/output"
)

type RestoreManager struct {
Expand Down Expand Up @@ -261,7 +261,7 @@ func (rm *RestoreManager) generateInstallScript() error {
return fmt.Errorf("failed to create directory: %w", err)
}

return output.GenerateInstallScript(rm.backupData.BaseDistro, rm.backupData.Packages, rm.backupData.Automation, scriptPath)
return generator.GenerateInstallScript(rm.backupData.BaseDistro, rm.backupData.Packages, rm.backupData.Automation, scriptPath)
}

// decryptData decrypts base64 encoded data using AES-GCM
Expand Down
20 changes: 10 additions & 10 deletions internal/core/backup/unified_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import (

"github.com/mdgspace/sysreplicate/internal/domain"
"github.com/mdgspace/sysreplicate/system/automation"
"github.com/mdgspace/sysreplicate/system/output"
// "github.com/mdgspace/sysreplicate/system/output"
"github.com/mdgspace/sysreplicate/internal/platform"
)

// all backup information in one structure
type UnifiedBackupData struct {
Timestamp time.Time `json:"timestamp"`
SystemInfo output.SystemInfo `json:"system_info"`
EncryptedKeys map[string]output.EncryptedKey `json:"encrypted_keys"`
Dotfiles []output.Dotfile `json:"dotfiles"`
SystemInfo domain.SystemInfo `json:"system_info"`
EncryptedKeys map[string]domain.EncryptedKey `json:"encrypted_keys"`
Dotfiles []domain.Dotfile `json:"dotfiles"`
Packages map[string][]string `json:"packages"`
Automation *automation.AutomationData `json:"automation"`
Automation *domain.AutomationData `json:"automation"`
EncryptionKey []byte `json:"encryption_key"`
Distro string `json:"distro"`
BaseDistro string `json:"base_distro"`
Expand Down Expand Up @@ -78,12 +78,12 @@ func (ubm *UnifiedBackupManager) CreateUnifiedBackup(customPaths []string) error
// Create unified backup data
backupData := &UnifiedBackupData{
Timestamp: time.Now(),
SystemInfo: output.SystemInfo{
SystemInfo: domain.SystemInfo{
Hostname: hostname,
Username: username,
OS: "linux",
},
EncryptedKeys: make(map[string]output.EncryptedKey),
EncryptedKeys: make(map[string]domain.EncryptedKey),
EncryptionKey: key,
Packages: packages,
Distro: distro,
Expand Down Expand Up @@ -177,7 +177,7 @@ func (ubm *UnifiedBackupManager) backupKeys(customPaths []string, backupData *Un

fmt.Printf(" - %s\n", filePath)
keyID := filepath.Base(filePath) + "_" + strings.ReplaceAll(filePath, "/", "_")
backupData.EncryptedKeys[keyID] = output.EncryptedKey{
backupData.EncryptedKeys[keyID] = domain.EncryptedKey{
OriginalPath: filePath,
KeyType: location.Type,
EncryptedData: encryptedData,
Expand Down Expand Up @@ -205,7 +205,7 @@ func (ubm *UnifiedBackupManager) backupDotfiles(backupData *UnifiedBackupData) e
}

// Convert to output format and show details
outputFiles := make([]output.Dotfile, len(files))
outputFiles := make([]domain.Dotfile, len(files))
dotfileCount := 0

for i, file := range files {
Expand All @@ -214,7 +214,7 @@ func (ubm *UnifiedBackupManager) backupDotfiles(backupData *UnifiedBackupData) e
dotfileCount++
}

outputFiles[i] = output.Dotfile{
outputFiles[i] = domain.Dotfile{
Path: file.Path,
RealPath: file.RealPath,
IsDir: file.IsDir,
Expand Down
44 changes: 4 additions & 40 deletions system/output/tarball.go → internal/core/generator/archive.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package output
package generator

import (
"archive/tar"
Expand All @@ -7,47 +7,11 @@ import (
"fmt"
"io"
"os"
"time"
"github.com/mdgspace/sysreplicate/internal/domain"
)

// backupData structure for tarball creation
type BackupData struct {
Timestamp time.Time `json:"timestamp"`
SystemInfo SystemInfo `json:"system_info"`
EncryptedKeys map[string]EncryptedKey `json:"encrypted_keys"`
EncryptionKey []byte `json:"encryption_key"`
}

type SystemInfo struct {
Hostname string `json:"hostname"`
Username string `json:"username"`
OS string `json:"os"`
}

type EncryptedKey struct {
OriginalPath string `json:"original_path"`
KeyType string `json:"key_type"`
EncryptedData string `json:"encrypted_data"`
Permissions uint32 `json:"permissions"`
}

type Dotfile struct {
Path string `json:"path"`
RealPath string `json:"real_path"`
IsDir bool `json:"is_dir"`
IsBinary bool `json:"is_binary"`
Mode os.FileMode `json:"mode"`
Content string `json:"content"` // ignore for the binary files
}

type BackupMetadata struct {
Timestamp time.Time `json:"timestamp"`
Hostname string `json:"hostname"`
Files []Dotfile `json:"files"`
}

// create a compressed tarball with the backup data
func CreateBackupTarball(backupData *BackupData, tarballPath string) error {
func CreateBackupTarball(backupData *domain.BackupData, tarballPath string) error {
//create tarball file
file, err := os.Create(tarballPath)
if err != nil {
Expand Down Expand Up @@ -87,7 +51,7 @@ func CreateBackupTarball(backupData *BackupData, tarballPath string) error {
return nil
}

func CreateDotfilesBackupTarball(meta *BackupMetadata, tarballPath string) error {
func CreateDotfilesBackupTarball(meta *domain.BackupMetadata, tarballPath string) error {
// Create the tarball file
file, err := os.Create(tarballPath)
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions internal/core/generator/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package generator

import (
"encoding/json"
"github.com/mdgspace/sysreplicate/internal/domain"
)

// BuildSystemJSON creates a well-structured JSON object for the system info and packages.
func GenerateMetadata(osType, distro, baseDistro string, packages map[string][]string) ([]byte, error) {

// type SystemInfo struct {
// OS string `json:"os"`
// Distro string `json:"distro"`
// BaseDistro string `json:"base_distro"`
// Packages map[string][]string `json:"packages"`
// }

info := domain.SystemInfoOutput{
OS: osType,
Distro: distro,
BaseDistro: baseDistro,
Packages: packages,
}
return json.MarshalIndent(info, "", " ")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package output
package generator

import (
"fmt"
Expand All @@ -10,7 +10,7 @@ import (

// generateInstallScript creates a shell script to install all packages for the given distro.
// Returns an error if the script cannot be created or written.
func GenerateInstallScript(baseDistro string, packages map[string][]string, automationData *automation.AutomationData, scriptPath string) error {
func GenerateInstallScript(baseDistro string, packages map[string][]string, automationData *domain.AutomationData, scriptPath string) error {
f, err := os.Create(scriptPath)
if err != nil {
return err
Expand Down
21 changes: 21 additions & 0 deletions internal/domain/automation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package domain

type AutomationData struct {
SystemDServices []SystemDUnit `json:"systemd_services"`
SystemDTimers []SystemDUnit `json:"systemd_timers"`
UserCronjobs []Cronjob `json:"user_cronjobs"`
SystemCronjobs []Cronjob `json:"system_cronjobs"`
}
type SystemDUnit struct {
Name string `json:"name"`
Path string `json:"path"`
Content string `json:"content"`
UnitType string `json:"unit_type"` ////saare service, timer and target available ere
IsEnabled bool `json:"is_enabled"`
IsActive bool `json:"is_active"`
}
type Cronjob struct {
Path string `json:"path"`
Content string `json:"content"`
Type string `json:"type"` //.//user, system, cron_d
}
Loading