etcaid

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

etcaid

etcaid manages your Linux application config backups with ease. It copies your application configuration to a centralized backup folder which can then be synced to multiple devices using third party tools (such as git).

Quickstart

You must have Go installed on your system before continuing.

  • Clone this repository.
  • Run make install to install etcaid on your system.
$ etcaid init # initializes the etcaid config & directories

$ etcaid new zsh # creates a new application config with the name zsh and opens in your editor (default=`vim`) for you
  • zsh.toml opened in editor:
title = "zsh"
home_paths = [] # home_paths contains paths to files relative to the user's home path (eg: /home/currentuser)
xdg_config_paths = [] # xdg_config_path contains paths to files relative to the xdg application configuration directory for the user (eg: /home/currentuser/.config)
  • You can edit this config to add all configuration file/directory paths for zsh.
title = "zsh"
home_paths = [
	".zshrc"
]
xdg_config_paths = []
  • Once you've saved this and closed the editor:
Application config for zsh edited at /home/currentuser/etcaid/applications/zsh.toml

$ etcaid backup # backups all application config files

copied /home/currentuser/.zshrc to /home/currentuser/etcaid/backup/zsh/home/.zshrc
  • To restore:
$ etcaid restore # restores all application config files

copied /home/currentuser/etcaid/backup/zsh/home/.zshrc to /home/currentuser/.zshrc
  • Use git on the ~/etcaid directory to save your backups and sync it across devices.

Help

Use etcaid help to get a detailed list of commands supported by etcaid.

Available commands:
  • backup: Backups all applications
  • edit: Opens an editor to edit an existing application configuration
  • help: Help about any command
  • init: Initializes etcaid
  • list: Lists all applications available
  • new: Generates a new application configuration and opens it for editing
  • restore: Restores all applications
  • view: Views an application config

Why etcaid?

While there are mature & amazing projects out there that would solve most problems of syncing application configurations across devices, I needed a tool that would be simple enough to just let me define what files needed to be backed up for an application. And I'd just go ahead and use git for versioning and syncing. No magic, no surprises. And thus, etcaid was born.

Todo

  1. Finish with tests
  2. Take a backup of destination before replacing it while running etcaid restore.

Documentation

Overview

Package etcaid implements a framework for configuration backup & restore of apps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteApplicationConfig

func WriteApplicationConfig(config ApplicationConfig, w io.Writer) error

WriteApplicationConfig accepts a writer and writes the ApplicationConfig on it. It returns an error if it fails.

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

Application represents an application instance.

func NewApplication

func NewApplication(
	config ApplicationConfig,
	homePath string,
	xdgConfigPath string,
	targetPath string,
	logger logger,
) *Application

NewApp constructs an instance of Application using ApplicationConfig, paths & a concrete instance of logger.

func (*Application) Backup

func (a *Application) Backup()

Backup backups the application configuration relative to the target path. It assumes that your backup directory has been backed up externally (for example, git) and may overwrite files in case of conflict.

func (*Application) Config

func (a *Application) Config() ApplicationConfig

Config returns the underlying config of an application.

func (*Application) Restore

func (a *Application) Restore()

Restore restores the application configuration relative to the target path. It assumes that your backup directory has been backed up externally (for example, git) and may overwrite files in case of conflict.

type ApplicationConfig

type ApplicationConfig struct {
	Name           string   `toml:"-"`                // Unique name of the application
	Title          string   `toml:"title"`            // Title of the application
	HomePaths      []string `toml:"home_paths"`       // HomePaths is the list of source application file paths that exist relative to the user home directory
	XDGConfigPaths []string `toml:"xdg_config_paths"` // XDGConfigPaths is the list of source application file paths that exist relative to the user XDG Config directory
}

ApplicationConfig is the configuration describing an application.

func ParseApplicationConfig

func ParseApplicationConfig(r io.Reader) (ApplicationConfig, error)

ParseApplicationConfig accepts a reader and parses it into ApplicationConfig. It returns an error if it fails.

type ApplicationError

type ApplicationError struct {
	Op      string
	Message string
	Path    string
	Err     error
}

ApplicationError records an error and the operation and that caused it.

func (*ApplicationError) Error

func (e *ApplicationError) Error() string

func (*ApplicationError) Unwrap

func (e *ApplicationError) Unwrap() error

type Config

type Config struct {
	Dir      string `toml:"etcaid_dir"`       // Name of the etcaid directory in user home, used for syncing backups
	LocalDir string `toml:"etcaid_local_dir"` // Name of the local etcaid directory in user home, for local backups
}

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller represents the etcaid controller. External user interfaces such as CLI will invoke the controller for working with etcaid.

func NewController

func NewController(homePath string, xdgConfigPath string, logger logger) *Controller

NewController constructs an instance of Controller using etcaid config path, user home path, xdg directory path ahd an instance of logger.

func (*Controller) Application

func (c *Controller) Application(name string) (ApplicationConfig, error)

Application accepts an application name and returns the application configuration available.

func (*Controller) ApplicationConfigPath

func (c *Controller) ApplicationConfigPath(name string) (string, error)

ApplicationConfigPath returns the path to application configuration file for an application with the given name. It returns the an error if it fails.

func (*Controller) Applications

func (c *Controller) Applications() []ApplicationConfig

Applications returns the list of all application configurations available.

func (*Controller) BackupAll

func (c *Controller) BackupAll()

BackupAll backs up all applications from their locations as defined by the application configuration. Backed up applications are available in the etcaid dir.

func (*Controller) CheckInit

func (c *Controller) CheckInit() bool

CheckInit checks if etcaid has been initialized. It returns false if the etcaid directories don't exist in home or there's an error accessing the directories. Else, it returns true.

func (*Controller) Create

func (c *Controller) Create(name string) (string, error)

Create creates a new application configuration file to be used for backups. It returns the path to this file, or an error if it fails.

func (*Controller) HomePath

func (c *Controller) HomePath() string

Returns the home path used to initialize the controller.

func (*Controller) Init

func (c *Controller) Init() error

Init initializes etcaid directories & configuration. It returns an error if it fails.

func (*Controller) LoadApplications

func (c *Controller) LoadApplications() error

LoadApplications loads the application configurations from the application config files and makes the applications ready for further use.

func (*Controller) RestoreAll

func (c *Controller) RestoreAll()

RestoreAll restores all applications from the etcaid dir to their locations as defined by the application configuration.

func (*Controller) XDGConfigPath

func (c *Controller) XDGConfigPath() string

Returns the xdg config path used to initialize the controller.

Directories

Path Synopsis
cmd
etcaid command
Package simplelogger implements a simplelogger.
Package simplelogger implements a simplelogger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL