zcmd

package module
v0.0.0-...-5935ba0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 23 Imported by: 0

README

zcmd: mitZ's CoMmanD line collections

CircleCI GoDoc Go Report Card

Installation

go get github.com/mitsutaka/zcmd/pkg/z

Usage

z
sync command

rsync wrapper command for servers. It plans replace it with Go native sync library.

  • z sync pull: Pull files from the remote server in parallel.
  • z sync push: Push files to the remote server in parallel.

Command line flag can append additional rsync flags. Default rsync flags are -avzP --stats --delete --delete-excluded.

Configuration example $HOME/.z.yaml:

sync:
  # Config for pulling
  pull:
    # It uses when command runs with particular path
    - name: movie
      # Source URL for pulling
      source: RSYNC_URL
      # Destination directory
      destination: /mnt/nas/movie
    - name: picture
      source: RSYNC_URL
      destination: /mnt/nas/picture
      # Exclude pattern
      excludes:
        - xxxx
        - yyyy
  # Config for pushing
  push:
    - name: music
      source: /mnt/nas/music
      destination: RSYNC_URL
      excludes:
        - zzzz
    - name: fuse
      source: /home/mitz/Documents
      destination: LOCAL_PATH
      # Some cases should disable sudo with fuse mounts
      disable_sudo: true
backup command

rsync wrapper command for backup.

  • z backup: Run backup to the remote server in parallel.

Command line flag can append additional rsync flags. Default rsync flags are -avzP --stats --delete.

Configuration example $HOME/.z.yaml:

backup:
  # Backup URLs
  destinations:
    - rsync://BACKUP_URL
  # Include backup paths
  includes:
    - /
    - /boot
    - /home
 # Exclude paths and pattern
  excludes:
    - .cache/
    - /dev
    - /media
    - /misc
    - /mnt
    - /proc
    - /run
    - /sys
    - /var/cache
repos-update command

Run git clean, git checkout master and git pull for checked out git repositories.

Configuration example $HOME/.z.yaml:

repos:
  # Root directory of the git repositories
  root: /your/root/git/repos
dotfiles command

dotfiles manager inspired by https://github.com/dotphiles/dotphiles

  • z dotfiles init GITURL: Initialize dotfiles in local.
  • z dotfiles pull: Download latest dotfiles and make symbolic links.
dotfiles:
  # default is $HOME/.zdotfiles
  dir: /home/mitz/.zdotfiles
  hosts:
    - YOUR_HOSTNAME
  files:
    - bashrc
    - config/sway/config
    - spacemacs
    - ssh
proxy command

NOT IMPLEMENTED YET

Make multiple ssh port forward at once.

  • z proxy: Setup ssh port forward.
proxy:
  - name: testforward1
    user: ubuntu
    address: remotehost1
    private_key: ~/.ssh/id_rsa
    forward:
      # Local forwarding
      - type: local
        # default bindAddress is *
        bind_pddress: localhost
        bind_port: 13128
        remote_address: localhost
        remote_port: 3128
      # Dynamic forwarding for SOCK4, 5
      - type: dynamic
        bind_address: localhost
        bind_port: 1080
  - name: testforward2
    user: admin
    address: remotehost2
    private_key: ~/.ssh/id_ecdsa
    port: 10000
    forward:
      # Remote forwarding
      - type: remote
        bind_address: localhost
        bind_port: 9000
        remote_address: localhost
        remote_port: 3000
Misc

To load bash completion scripts, run:

. <(z completion)

License

MIT

Documentation

Index

Constants

View Source
const (
	// DefaultProxyPort is default ssh port
	DefaultProxyPort int = 22
	// LocalForward is local forwarding
	LocalForward ProxyForwardType = "local"
	// RemoteForward is remote forwarding
	RemoteForward ProxyForwardType = "remote"
	// DynamicForward is dynamic forwarding
	DynamicForward ProxyForwardType = "dynamic"
)

Variables

This section is empty.

Functions

func Ask

func Ask(param *string, query string, hide bool) error

func SetDefaultConfigValues

func SetDefaultConfigValues(cfg *Config) error

SetDefaultConfigValues set default values if omitted

Types

type Backup

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

Backup is client for backup

func (*Backup) Do

func (b *Backup) Do(ctx context.Context) error

Do is main backup process

type BackupConfig

type BackupConfig struct {
	Destinations []string `yaml:"destinations"`
	Includes     []string `yaml:"includes"`
	Excludes     []string `yaml:"excludes,omitempty"`
	BackupPrefix string   `yaml:"prefix,omitempty"`
}

BackupConfig is backup: config

type Config

type Config struct {
	Sync     SyncConfig     `yaml:"sync,omitempty"`
	Backup   BackupConfig   `yaml:"backup,omitempty"`
	Repos    ReposConfig    `yaml:"repos,omitempty"`
	DotFiles DotFilesConfig `yaml:"dotfiles,omitempty"`
	Proxy    []ProxyConfig  `yaml:"proxy,omitempty"`
}

func NewConfig

func NewConfig(source []byte) (*Config, error)

NewConfig returns new Config

type DotFiler

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

DotFiler is client for dotfiles management

func NewDotFiler

func NewDotFiler(cfg *DotFilesConfig) (*DotFiler, error)

NewDotFiler returns DotFiler with given home directory

func (*DotFiler) Init

func (d *DotFiler) Init(ctx context.Context, gitURL string) error

Init initializes dotfiles directory if not exist

func (d *DotFiler) MakeSymlinks() error

MakeSymlinks makes symlinks to the home directory

func (*DotFiler) Pull

func (d *DotFiler) Pull(ctx context.Context) error

Pull updates dotfiles and make symlinks

type DotFilesConfig

type DotFilesConfig struct {
	Dir   string   `yaml:"dir,omitempty"`
	Hosts []string `yaml:"hosts"`
	Files []string `yaml:"files"`
}

DotFilesConfig is dotfiles: config

type Proxy

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

Proxy is client for proxy

func NewProxy

func NewProxy(cfgs []ProxyConfig) (*Proxy, error)

NewProxy returns Proxy

func (*Proxy) Run

func (p *Proxy) Run(ctx context.Context) error

type ProxyConfig

type ProxyConfig struct {
	Name       string               `yaml:"name"`
	User       string               `yaml:"user,omitempty"`
	Address    string               `yaml:"address"`
	Port       int                  `yaml:"port,omitempty"`
	PrivateKey string               `yaml:"private_key"`
	Forward    []ProxyForwardConfig `yaml:"forward"`
}

ProxyConfig is proxy: config

type ProxyForwardConfig

type ProxyForwardConfig struct {
	Type          ProxyForwardType `yaml:"type"`
	BindAddress   string           `yaml:"bind_address,omitempty"`
	BindPort      int              `yaml:"bind_port"`
	RemoteAddress string           `yaml:"remote_address,omitempty"`
	RemotePort    int              `yaml:"remote_port,omitempty"`
}

ProxyForwardConfig is forward: config in proxy;

type ProxyForwardType

type ProxyForwardType string

ProxyForwardType is ssh forwarding type

type ReposConfig

type ReposConfig struct {
	Root string `yaml:"root"`
}

ReposConfig is repos: config

type Rsync

type Rsync interface {
	// Do runs rsync command
	Do(ctx context.Context) error
	// contains filtered or unexported methods
}

Rsync is rsync interface

func NewBackup

func NewBackup(cfg *BackupConfig, rsyncFlags string) Rsync

NewBackup returns Syncer

func NewSync

func NewSync(sync []SyncInfo, argSyncs []string, rsyncFlags string) Rsync

NewSync returns Syncer

type Sync

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

Sync is client for sync pull

func (*Sync) Do

func (s *Sync) Do(ctx context.Context) error

Do is main pulling process

type SyncConfig

type SyncConfig struct {
	Pull []SyncInfo `yaml:"pull,omitempty"`
	Push []SyncInfo `yaml:"push,omitempty"`
}

SyncConfig is sync: config

type SyncInfo

type SyncInfo struct {
	Name        string   `yaml:"name"`
	Source      string   `yaml:"source"`
	Destination string   `yaml:"destination"`
	Excludes    []string `yaml:"excludes,omitempty"`
	DisableSudo bool     `yaml:"disable_sudo,omitempty"`
}

SyncInfo is path information for synchronize directories

type Updater

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

Updater is client for repos update

func NewUpdater

func NewUpdater(root string) (*Updater, error)

NewUpdater returns Updater with given root directory

func (*Updater) FindRepositories

func (u *Updater) FindRepositories() error

FindRepositories traverses given directory and return git repositories

func (*Updater) Update

func (u *Updater) Update(ctx context.Context, jobs int) error

Update fetches, checkouts and pulls git repositories

Directories

Path Synopsis
pkg
z

Jump to

Keyboard shortcuts

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