Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit files to git repo #3424

Open
Eugenemdk opened this issue Feb 23, 2025 · 0 comments
Open

Commit files to git repo #3424

Eugenemdk opened this issue Feb 23, 2025 · 0 comments

Comments

@Eugenemdk
Copy link

In my extended LinuxGeneric model i do a backup and save it as a .tar file, but when i check the repo seems like it wasnt added to recent commit, maybe i missing something, can someone point it out what is the cause of the problem.

Thanks in advance.

model:

class LinuxGeneric < Oxidized::Model
  using Refinements

  prompt /^(\w.*|\W.*)(:|#) /
  comment '# '

  # Global command output processing
  cmd :all do |cfg|
    cfg.gsub! /^(default (\S+).* (expires) ).*/, '\\1 <redacted>'
    cfg.gsub! /\r/, ''  # Remove carriage returns
    cfg.cut_both
  end

  # Directories and files to back up
  BACKUP_PATHS = [
    "/etc/network",
    "/etc/fias",
    "/etc/dhcp",
    "/etc/kea",
    "/etc/cfctl",
    "/etc/hosts",
    "/etc/hostname"
  ]


  cmd "hostname" do |host_output|
    device_hostname = host_output.strip

    cmd "echo 'Checking directories...'" do |cfg|
      comment "Starting backup process for #{device_hostname}"
      cfg
    end

    cmd "for dir in #{BACKUP_PATHS.join(' ')}; do [ -e \"$dir\" ] && echo \"$dir\"; done" do |output|
      valid_paths = output.lines.map(&:strip).reject(&:empty?)

      if valid_paths.empty?
        comment "No valid directories found for backup on #{device_hostname}."
        return ""
      end

      backup_file = "backup.tar"
      cmd "tar -cf #{backup_file} #{valid_paths.join(' ')}" do |backup_data|
        comment "Backup of existing system configuration files for #{device_hostname}"
        backup_data
      end

      comment "Backup saved to #{backup_file}"

      backup_file
    end
  end


  cfg :ssh do
    post_login do
      if vars(:enable) == true
        cmd "sudo su -"
      elsif vars(:enable)
        cmd "su -", /^Password:/
        cmd vars(:enable)
      end
    end

    pre_logout 'exit'
    sleep 1
    pre_logout 'exit'
  end
end

config:
...

output:
  default: git
  git:
    user: ansbl
    email: [email protected]
    repo: "/home/oxidized/git/git-repos/default.git"

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant