Compare commits
65 Commits
Author | SHA1 | Date |
---|---|---|
DataHearth | 06d09e1be6 | |
DataHearth | 9ab934eb4d | |
DataHearth | c61a8e4a4d | |
DataHearth | f8ef48e57a | |
DataHearth | 4f66244e9a | |
DataHearth | fac6dd5b69 | |
DataHearth | ef93dd8db7 | |
DataHearth | 35c3c41ec7 | |
Antoine Langlois | d0b19e61f6 | |
DataHearth | d444de44f1 | |
DataHearth | 8a4932aa72 | |
DataHearth | a568ca9bb8 | |
DataHearth | f627f8e199 | |
DataHearth | bcc4faae27 | |
DataHearth | 7c1c71ad55 | |
DataHearth | 5682db8ac9 | |
DataHearth | 29e0be566c | |
DataHearth | b27c1f9e89 | |
DataHearth | dd6eeb3041 | |
DataHearth | 68f263e245 | |
DataHearth | fe4ff05d5d | |
DataHearth | 8efdca8fe4 | |
DataHearth | f85fc9d39c | |
DataHearth | 8051912b35 | |
DataHearth | 224754870d | |
DataHearth | 0f1019774d | |
DataHearth | 42d2152f8e | |
DataHearth | 66f0fe3042 | |
DataHearth | 21c031d8fc | |
DataHearth | 6e5ede992a | |
DataHearth | 48fef365e8 | |
DataHearth | f576eec3c3 | |
DataHearth | f00d7c0288 | |
DataHearth | 7aa343fc2a | |
DataHearth | 0c8d52f32d | |
DataHearth | 6f24de2bd0 | |
DataHearth | 5f52ce6658 | |
DataHearth | e92265791e | |
DataHearth | ea25075c82 | |
DataHearth | 56da676e15 | |
DataHearth | a0662e9066 | |
DataHearth | d3bab447e0 | |
DataHearth | 588e3c1e66 | |
DataHearth | 555d05d640 | |
DataHearth | 46249857f3 | |
DataHearth | f4bf8070ac | |
DataHearth | 3a7210bc69 | |
Antoine Langlois | 07e187e528 | |
Antoine Langlois | 02c82bc9d1 | |
DataHearth | ec82828509 | |
DataHearth | 29d91e0e73 | |
DataHearth | 3b3a4d59e0 | |
DataHearth | 81713eb583 | |
DataHearth | 1241858027 | |
DataHearth | fab9533da1 | |
DataHearth | 1cfd84b8cf | |
DataHearth | f526bf1f5d | |
DataHearth | 3af07f159e | |
DataHearth | 638e0ff3a2 | |
DataHearth | 35d8210ca9 | |
DataHearth | 584fe09fe2 | |
DataHearth | a85165e8fe | |
DataHearth | 94b2838f7e | |
DataHearth | 71526ec28d | |
DataHearth | 759604ebda |
|
@ -0,0 +1,31 @@
|
|||
<a name="{{ (index .Versions 0).Tag.Name }}"></a>
|
||||
## {{ if (index .Versions 0).Tag.Previous }}[{{ (index .Versions 0).Tag.Name }}]{{ else }}{{ (index .Versions 0).Tag.Name }}{{ end }} - {{ datetime "2006-01-02" (index .Versions 0).Tag.Date }}
|
||||
{{ range (index .Versions 0).CommitGroups -}}
|
||||
### {{ .Title }}
|
||||
{{ range .Commits -}}
|
||||
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
|
||||
{{- if (index .Versions 0).RevertCommits -}}
|
||||
### Reverts
|
||||
{{ range (index .Versions 0).RevertCommits -}}
|
||||
- {{ .Revert.Header }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
|
||||
{{- if (index .Versions 0).MergeCommits -}}
|
||||
### Pull Requests
|
||||
{{ range (index .Versions 0).MergeCommits -}}
|
||||
- {{ .Header }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
|
||||
{{- if (index .Versions 0).NoteGroups -}}
|
||||
{{ range (index .Versions 0).NoteGroups -}}
|
||||
### {{ .Title }}
|
||||
{{ range .Notes }}
|
||||
{{ .Body }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
|
@ -2,7 +2,7 @@ style: github
|
|||
template: CHANGELOG.tpl.md
|
||||
info:
|
||||
title: CHANGELOG
|
||||
repository_url: https://github.com/DataHearth/config-mapper
|
||||
repository_url: https://gitea.antoine-langlois.net/DataHearth/config-mapper
|
||||
options:
|
||||
commits:
|
||||
filters:
|
||||
|
|
|
@ -2,20 +2,24 @@ storage:
|
|||
# Where will be the repository folder located ? [DEFAULT: MacOS($TMPDIR/config-mapper) | Linux(/tmp/config-mapper)]
|
||||
location: /path/to/folder
|
||||
git:
|
||||
# * by default, if ssh dict is set with its keys filled, I'll try to clone with SSH
|
||||
# username used for commit author
|
||||
name: USERNAME
|
||||
# email used for commit author
|
||||
email: EMAIL
|
||||
repository: git@github.com:DataHearth/my-config.git
|
||||
basic-auth:
|
||||
username: USERNAME
|
||||
# * NOTE: if you're having trouble with error "authentication required", you should maybe use a token access
|
||||
# * In some cases, it's due to 2FA authentication enabled on the git hosting provided
|
||||
# * In some cases, it's due to 2FA authentication enabled on the git hosting provider
|
||||
password: TOKEN
|
||||
# * by default, if ssh dict is set with its keys filled, I'll try to clone with SSH
|
||||
ssh:
|
||||
# path can be relative and can contain environment variables
|
||||
private-key: /path/to/private/key
|
||||
passphrase: PASSPHRASE
|
||||
|
||||
# NOTE: the $LOCATION if refering to the "storage.location" path. It'll be replaced automatically
|
||||
# The left part of ":" is your repository location and right part when it should be on your system
|
||||
# The left part of ":" is your repository location and right part where it should be located on your system
|
||||
files:
|
||||
- darwin: "$LOCATION/macos/.zshrc:~/.zshrc"
|
||||
linux: "$LOCATION/linux/.zshrc:~/.zshrc"
|
||||
|
@ -25,8 +29,10 @@ folders:
|
|||
linux: "$LOCATION/macos/.config:~/.config"
|
||||
|
||||
package-managers:
|
||||
installation-order: ["homebrew"]
|
||||
homebrew:
|
||||
# available: brew, pip (pip check also for pip3), cargo, apt, npm, go
|
||||
installation-order:
|
||||
- brew
|
||||
brew:
|
||||
- bat
|
||||
- hexyl
|
||||
- fd
|
||||
|
@ -42,5 +48,3 @@ package-managers:
|
|||
- nmap
|
||||
- pinentry
|
||||
- zsh
|
||||
|
||||
apt-get: []
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
.config-mapper.yml
|
||||
.config-mapper.yml.template
|
||||
.gitignore
|
||||
LICENSE
|
||||
README.md
|
||||
demo
|
|
@ -0,0 +1,21 @@
|
|||
name: build
|
||||
|
||||
run-name: Build and test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and test
|
||||
|
||||
runs-on: debian-go
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
|
@ -0,0 +1,45 @@
|
|||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and test
|
||||
|
||||
runs-on: debian-go
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
release:
|
||||
name: Release
|
||||
|
||||
needs: build
|
||||
runs-on: debian-go
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Fetch tags
|
||||
run: git fetch --force --tags
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Release
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
go install github.com/goreleaser/goreleaser@latest
|
||||
go install github.com/git-chglog/git-chglog/cmd/git-chglog@latest
|
||||
goreleaser release --clean --release-notes <(git-chglog -t .chglog/RELEASE_CHANGELOG.tpl.md)
|
|
@ -1,3 +1,5 @@
|
|||
.config-mapper.yml
|
||||
demo
|
||||
build
|
||||
.env
|
||||
.DS_STORE
|
||||
build
|
||||
dist/
|
||||
.config-mapper.yml
|
|
@ -0,0 +1,47 @@
|
|||
before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
goarch:
|
||||
- "386"
|
||||
- amd64
|
||||
- arm
|
||||
- arm64
|
||||
archives:
|
||||
- format: tar.gz
|
||||
files:
|
||||
- LICENSE
|
||||
- README.md
|
||||
- .config-mapper.yml.template
|
||||
- CHANGELOG.md
|
||||
name_template: >-
|
||||
{{ .ProjectName }}_
|
||||
{{ .Version }}_
|
||||
{{- title .Os }}_
|
||||
{{- if eq .Arch "amd64" }}x86_64
|
||||
{{- else if eq .Arch "386" }}i386
|
||||
{{- else }}{{ .Arch }}{{ end }}
|
||||
|
||||
gitea_urls:
|
||||
api: https://gitea.antoine-langlois.net/api/v1
|
||||
download: https://gitea.antoine-langlois.net
|
||||
|
||||
release:
|
||||
gitea:
|
||||
owner: DataHearth
|
||||
name: config-mapper
|
||||
mode: append
|
||||
|
||||
checksum:
|
||||
name_template: "checksums.txt"
|
||||
|
||||
snapshot:
|
||||
name_template: "{{ incpatch .Version }}-next"
|
||||
|
||||
force_token: gitea
|
84
CHANGELOG.md
84
CHANGELOG.md
|
@ -3,8 +3,75 @@
|
|||
## [Unreleased]
|
||||
|
||||
|
||||
<a name="0.1.0"></a>
|
||||
## 0.1.0 - 2022-02-27
|
||||
<a name="v0.6.2"></a>
|
||||
## [v0.6.2] - 2023-07-15
|
||||
|
||||
<a name="v0.6.1"></a>
|
||||
## [v0.6.1] - 2022-10-04
|
||||
### Features
|
||||
- **ssh:** add possibilty to use multiple SSH configurations
|
||||
|
||||
|
||||
<a name="v0.6.0"></a>
|
||||
## [v0.6.0] - 2022-08-21
|
||||
### Bug Fixes
|
||||
- **configuration:** remove installation-order default value
|
||||
- **items:** fix stdout when no path is available
|
||||
- **pkgs:** update command building
|
||||
- **pkgs:** add pkg manager validation check and parsing cli arguments
|
||||
|
||||
### Features
|
||||
- **packages:** add nala package manager
|
||||
|
||||
|
||||
<a name="v0.5.0"></a>
|
||||
## [v0.5.0] - 2022-08-01
|
||||
### Bug Fixes
|
||||
- **git:** use go-git for adding removed file (workaround)
|
||||
|
||||
### Features
|
||||
- **pkgs:** add more package manager
|
||||
|
||||
|
||||
<a name="v0.4.0"></a>
|
||||
## [v0.4.0] - 2022-08-01
|
||||
### Bug Fixes
|
||||
- **config:** don't throw error when file not available on OS
|
||||
- **save:** remove folder before copy (avoid unwanted files)
|
||||
|
||||
### Features
|
||||
- **cli:** add verbose flag and a spinner for pkgs
|
||||
- **config:** add SSH capability with user/pass or key/pass
|
||||
|
||||
|
||||
<a name="v0.3.0"></a>
|
||||
## [v0.3.0] - 2022-08-01
|
||||
### Features
|
||||
- **cli:** packages are disabled by default
|
||||
- **sync:** add .ignore file to filter folder's content
|
||||
|
||||
|
||||
<a name="v0.2.0"></a>
|
||||
## [v0.2.0] - 2022-08-01
|
||||
### Bug Fixes
|
||||
- **git:** use git binary for "git add"
|
||||
- **git:** deleted files are not pushed
|
||||
- **git:** add error handling and repo URL from config
|
||||
- **rm:** remove dir even if not empty
|
||||
- **stderr:** add stderr to brew command output
|
||||
|
||||
### Code Refactoring
|
||||
- **archi:** reduce base code to one struct
|
||||
- **cli:** separate functions from CLI for lisibility
|
||||
- **logging:** drop pterm
|
||||
|
||||
### Features
|
||||
- **cli:** add git push option with message
|
||||
- **index:** add indexing system
|
||||
|
||||
|
||||
<a name="v0.1.0"></a>
|
||||
## v0.1.0 - 2022-07-31
|
||||
### Bug Fixes
|
||||
- **config:** fix config path check
|
||||
- **copy:** use io.Copy instead of custom copy
|
||||
|
@ -14,13 +81,20 @@
|
|||
|
||||
### Features
|
||||
- **cli:** add save and load features
|
||||
- **cli:** add init sub-command
|
||||
- **cli:** add copy folder
|
||||
- **cli:** add save command
|
||||
- **cli:** add configuration-file persistant flag
|
||||
- **cli:** implement pkgs installation
|
||||
- **config:** update git configuration
|
||||
- **cli:** add init sub-command
|
||||
- **config:** add yaml tags for yaml.v3
|
||||
- **config:** update git configuration
|
||||
|
||||
|
||||
[Unreleased]: https://github.com/DataHearth/config-mapper/compare/0.1.0...HEAD
|
||||
[Unreleased]: https://gitea.antoine-langlois.net/DataHearth/config-mapper/compare/v0.6.2...HEAD
|
||||
[v0.6.2]: https://gitea.antoine-langlois.net/DataHearth/config-mapper/compare/v0.6.1...v0.6.2
|
||||
[v0.6.1]: https://gitea.antoine-langlois.net/DataHearth/config-mapper/compare/v0.6.0...v0.6.1
|
||||
[v0.6.0]: https://gitea.antoine-langlois.net/DataHearth/config-mapper/compare/v0.5.0...v0.6.0
|
||||
[v0.5.0]: https://gitea.antoine-langlois.net/DataHearth/config-mapper/compare/v0.4.0...v0.5.0
|
||||
[v0.4.0]: https://gitea.antoine-langlois.net/DataHearth/config-mapper/compare/v0.3.0...v0.4.0
|
||||
[v0.3.0]: https://gitea.antoine-langlois.net/DataHearth/config-mapper/compare/v0.2.0...v0.3.0
|
||||
[v0.2.0]: https://gitea.antoine-langlois.net/DataHearth/config-mapper/compare/v0.1.0...v0.2.0
|
||||
|
|
14
Earthfile
14
Earthfile
|
@ -1,14 +0,0 @@
|
|||
VERSION 0.6
|
||||
|
||||
FROM golang:1.17-alpine3.15
|
||||
WORKDIR /config-mapper
|
||||
|
||||
build-macos:
|
||||
COPY . .
|
||||
RUN GOOS=darwin go build -o build/config-mapper main.go
|
||||
SAVE ARTIFACT build/config-mapper /config-mapper AS LOCAL build/x86-x64_darwin_config-mapper
|
||||
|
||||
build-linux:
|
||||
COPY . .
|
||||
RUN GOOS=linux go build -o build/config-mapper main.go
|
||||
SAVE ARTIFACT build/config-mapper /config-mapper AS LOCAL build/x86-x64_linux_config-mapper
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2022 Antoine Langlois
|
||||
Copyright (c) 2022 Antoine Langlois "antoine.l@antoine-langlois.net"
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
85
README.md
85
README.md
|
@ -1,7 +1,10 @@
|
|||
# config-mapper
|
||||
|
||||
`config-mapper` is CLI utility tool to help you manage your configuration between systems.
|
||||
It provides a set of tools to load your configuration from a system, save it on a git repository and then save it to a new system. This configuration can be a set of files, folders or even dependencies.
|
||||
[![License](https://img.shields.io/badge/license-MIT-blue)](https://gitea.antoine-langlois.net/DataHearth/config-mapper/src/branch/main/LICENSE)
|
||||
[![Version](https://img.shields.io/badge/version-v0.6.2-blue)](https://gitea.antoine-langlois.net/DataHearth/config-mapper/tags)
|
||||
|
||||
`config-mapper` is CLI utility tool to help you manage your configuration between UNIX systems.
|
||||
It provides a set of tools to load your configuration from a system, save it into a git repository and then save it to a new system. This configuration can be a set of files, folders or even dependencies.
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -11,14 +14,34 @@ When copying a file from your configuration repository to your system, it's perf
|
|||
|
||||
The system is detected automatically. You just need to specify whether the related field in case of `files` or folders `sections` (fields: `darwin` | `linux`).
|
||||
|
||||
You can get a configuration template [here](https://raw.githubusercontent.com/DataHearth/config-mapper/main/.config-mapper.yml.template).
|
||||
You can get a configuration template [here](https://gitea.antoine-langlois.net/DataHearth/config-mapper/raw/branch/main/.config-mapper.yml.template).
|
||||
|
||||
### Installation
|
||||
|
||||
- Using a pre-build binary
|
||||
|
||||
Binaries are available in the `release` section at [https://gitea.antoine-langlois.net/DataHearth/config-mapper/releases](https://gitea.antoine-langlois.net/DataHearth/config-mapper/releases).
|
||||
|
||||
- Building from source:
|
||||
|
||||
```bash
|
||||
git clone https://gitea.antoine-langlois.net/DataHearth/config-mapper.git
|
||||
cd config-mapper
|
||||
go build -o $HOME/.local/bin/config-mapper
|
||||
```
|
||||
|
||||
- With Golang cli
|
||||
|
||||
```bash
|
||||
go install gitea.antoine-langlois.net/datahearth/config-mapper@latest
|
||||
```
|
||||
|
||||
### Setup
|
||||
|
||||
Create a file called `.config-mapper.yml` in your `home` directory (it is the default search path for config-mapper).
|
||||
If you wish to move it to another directory, you can have to choice to inform the tool. By either set an environment like this one: `CONFIG_MAPPER_CFG=/path/to/config/.config-mapper.yml`. Or by providing the `-c /path/to/config/.config-mapper.yml` flag to the tool.
|
||||
If you wish to move it to another directory, you can choose by either setting an environment: `CONFIG_MAPPER_CFG=/path/to/config/.config-mapper.yml` or by using the `-c /path/to/config/.config-mapper.yml` flag.
|
||||
|
||||
Once the configuratio file created, run this command to initialize the repository localy:
|
||||
Once the configuration file created, run this command to initialize the repository locally:
|
||||
|
||||
```bash
|
||||
config-mapper init
|
||||
|
@ -56,15 +79,37 @@ config-mapper save
|
|||
|
||||
All defined files and folders will be copied inside your repository.
|
||||
|
||||
If you want to exclude one part of your configuration file (files, folders, package-managers), you can use these flags to ignore them `--disable-files` `--disable-folders` `--disable-pkgs`
|
||||
If you want to exclude one part of your configuration file (files, folders), you can use these flags to ignore them `--disable-files` `--disable-folders`.
|
||||
|
||||
If `homebrew` is provided in the `installation-order` (default: `["apt", "homebrew"]`), it will override the `homebrew` field with all user installed packages (`brew leaves --installed-on-request`). The same principle will be implemented with `aptitude`.
|
||||
You can also exclude files and folders from a given directory with a `.gitignore` like file named `.ignore`. Put it in the root directory of an included folder and add relative path to exclude (does not support glob for now). E.g:
|
||||
|
||||
```bash
|
||||
Permissions Size User Date Modified Name
|
||||
drwxr-xr-x - antoine 1 Jun 20:28 ../demo
|
||||
.rw-r--r-- 12 antoine 1 Jun 20:28 ├── .ignore
|
||||
drwxr-xr-x - antoine 1 Jun 20:28 ├── egg
|
||||
.rw-r--r-- 0 antoine 1 Jun 20:28 │ └── bar.py
|
||||
.rw-r--r-- 0 antoine 1 Jun 20:26 ├── example.py
|
||||
drwxr-xr-x - antoine 1 Jun 20:27 └── foo
|
||||
.rw-r--r-- 0 antoine 1 Jun 20:24 ├── bar
|
||||
.rw-r--r-- 0 antoine 1 Jun 20:27 └── demo.py
|
||||
```
|
||||
|
||||
`.ignore` content:
|
||||
|
||||
```text
|
||||
# bar file will be ignored
|
||||
foo/bar
|
||||
|
||||
# egg folder will be ignore
|
||||
egg
|
||||
```
|
||||
|
||||
template for your configuration:
|
||||
|
||||
```yaml
|
||||
# NOTE: the $LOCATION if refering to the "storage.location" path. It'll be replaced automatically
|
||||
# The left part of ":" is your repository location and right part when it should be on your system
|
||||
# The left part of ":" is your repository location and right part is on your system
|
||||
files:
|
||||
- darwin: "$LOCATION/macos/.zshrc:~/.zshrc"
|
||||
linux: "$LOCATION/linux/.zshrc:~/.zshrc"
|
||||
|
@ -74,8 +119,9 @@ folders:
|
|||
linux: "$LOCATION/macos/.config:~/.config"
|
||||
|
||||
package-managers:
|
||||
installation-order: ["homebrew"]
|
||||
homebrew:
|
||||
installation-order:
|
||||
- brew
|
||||
brew:
|
||||
- bat
|
||||
- hexyl
|
||||
- fd
|
||||
|
@ -93,6 +139,10 @@ package-managers:
|
|||
- zsh
|
||||
|
||||
apt-get: []
|
||||
pip: []
|
||||
cargo: []
|
||||
pip: []
|
||||
go: []
|
||||
```
|
||||
|
||||
### Load your configuration onto the system
|
||||
|
@ -107,12 +157,13 @@ The same ignore flags are used in the `save` command.
|
|||
|
||||
## TO-DO
|
||||
|
||||
- [] load configuration though SSH
|
||||
- [] save configuration though SSH
|
||||
- [x] add `.ignore` file to ignore content inside directory
|
||||
- [x] use remote configuration: SSH
|
||||
- [ ] optimisation over speed and memory
|
||||
- add more storage options
|
||||
- [] smb storage
|
||||
- [] nfs storage
|
||||
- [] zip
|
||||
- [ ] smb storage
|
||||
- [ ] nfs storage
|
||||
- [ ] zip
|
||||
|
||||
## Known issues
|
||||
|
||||
|
@ -120,3 +171,7 @@ The same ignore flags are used in the `save` command.
|
|||
Resolved by create a new primary key based on GitHub new GIT SSH standards ([issue](https://github.com/go-git/go-git/issues/411))
|
||||
- Cloning from GitHub with `https BasicAuth` and 2FA activated: `authentication required`
|
||||
Resolved by creating an access token and set it as password in configuration
|
||||
- WSL might have a rough time with opened files by `homebrew` and throwing `Error: too many open files`.
|
||||
[This thread](https://github.com/Homebrew/linuxbrew-core/issues/21139) discuss about this issue.
|
||||
The workaround seems to be increase the filesystem limit (`ulimit -Hn && ulimit -Sn`). Another way is to launch again your command as homebrew already installed
|
||||
some the packages.
|
||||
|
|
230
cmd/cli.go
230
cmd/cli.go
|
@ -1,145 +1,185 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
mapper "github.com/datahearth/config-mapper/internal"
|
||||
"github.com/pterm/pterm"
|
||||
mapper "gitea.antoine-langlois.net/datahearth/config-mapper/internal"
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/configuration"
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/git"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
errLogger = log.New(os.Stderr, "", 0)
|
||||
logger = log.New(os.Stderr, "", 0)
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "config-mapper",
|
||||
Short: "Manage your systems configuration",
|
||||
Long: `config-mapper aims to help you manage your configurations between systems
|
||||
with a single configuration file.`,
|
||||
Version: "v0.1.0.beta0",
|
||||
Version: "v0.6.2",
|
||||
}
|
||||
var initCmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialize your configuration folder",
|
||||
Long: `Initialize will retrieve your configuration folder from the source location and
|
||||
copy it into the destination field`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var config mapper.Configuration
|
||||
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
errLogger.Printf(pterm.Red(fmt.Sprintf("failed to decode configuration: %v\n", err)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.Println("initializing config-mapper folder from configuration...")
|
||||
|
||||
if _, err := mapper.OpenGitRepo(config.Storage.Git, config.Storage.Location); err != nil {
|
||||
errLogger.Printf(pterm.Red(fmt.Sprintf("failed to initialize folder: %v\n", err)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.Printf("repository initialized at \"%v\"\n", viper.GetString("storage.location"))
|
||||
},
|
||||
Run: initCommand,
|
||||
}
|
||||
var loadCmd = &cobra.Command{
|
||||
Use: "load",
|
||||
Short: "Load your configurations onto your system",
|
||||
Long: `Load your files, folders and package managers deps configurations onto your new
|
||||
onto your new system based on your configuration file`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var config mapper.Configuration
|
||||
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
errLogger.Printf(pterm.Red(fmt.Sprintf("failed to decode configuration: %v\n", err)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !viper.GetBool("load-disable-files") {
|
||||
if err := mapper.LoadFiles(config.Files, config.Storage.Location); err != nil {
|
||||
errLogger.Printf(pterm.Red(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if !viper.GetBool("load-disable-folders") {
|
||||
if err := mapper.LoadFolders(config.Folders, config.Storage.Location); err != nil {
|
||||
errLogger.Printf(pterm.Red(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if !viper.GetBool("load-disable-pkgs") {
|
||||
if err := mapper.LoadPkgs(config.PackageManagers); err != nil {
|
||||
errLogger.Printf(pterm.Red(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
},
|
||||
Run: load,
|
||||
}
|
||||
var saveCmd = &cobra.Command{
|
||||
Use: "save",
|
||||
Short: "save your configurations onto your saved location",
|
||||
Long: `Save your files, folders and package managers deps configurations onto your
|
||||
saved location based on your configuration file`,
|
||||
Run: save,
|
||||
}
|
||||
var installCmd = &cobra.Command{
|
||||
Use: "install",
|
||||
Short: "install additional tools",
|
||||
Long: `install additional tools like package managers, programming languages, etc.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var config mapper.Configuration
|
||||
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
errLogger.Printf(pterm.Red(fmt.Sprintf("failed to decode configuration: %v\n", err)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !viper.GetBool("save-disable-files") {
|
||||
if err := mapper.SaveFiles(config.Files, config.Storage.Location); err != nil {
|
||||
errLogger.Printf(pterm.Red(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if !viper.GetBool("save-disable-folders") {
|
||||
if err := mapper.SaveFolders(config.Folders, config.Storage.Location); err != nil {
|
||||
errLogger.Printf(pterm.Red(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if !viper.GetBool("save-disable-pkgs") {
|
||||
if err := mapper.SavePkgs(config); err != nil {
|
||||
errLogger.Printf(pterm.Red(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
log.Fatal("install command not implemented yet")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(mapper.InitConfig)
|
||||
cobra.OnInitialize(configuration.InitConfig)
|
||||
|
||||
rootCmd.AddCommand(initCmd)
|
||||
rootCmd.AddCommand(loadCmd)
|
||||
rootCmd.AddCommand(saveCmd)
|
||||
rootCmd.AddCommand(installCmd)
|
||||
|
||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "STDOUT will be more verbose")
|
||||
rootCmd.PersistentFlags().StringP("configuration-file", "c", "", "location of configuration file")
|
||||
rootCmd.PersistentFlags().String("ssh-user", "", "SSH username to retrieve configuration file")
|
||||
rootCmd.PersistentFlags().String("ssh-password", "", "SSH password to retrieve configuration file")
|
||||
rootCmd.PersistentFlags().String("ssh-key", "", "SSH key to retrieve configuration file (if a passphrase is needed, use the \"CONFIG_MAPPER_PASS\" env variable")
|
||||
viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))
|
||||
viper.BindPFlag("configuration-file", rootCmd.PersistentFlags().Lookup("configuration-file"))
|
||||
viper.BindPFlag("ssh-user", rootCmd.PersistentFlags().Lookup("ssh-user"))
|
||||
viper.BindPFlag("ssh-password", rootCmd.PersistentFlags().Lookup("ssh-password"))
|
||||
viper.BindPFlag("ssh-key", rootCmd.PersistentFlags().Lookup("ssh-key"))
|
||||
|
||||
loadCmd.PersistentFlags().Bool("disable-files", false, "files will be ignored")
|
||||
loadCmd.PersistentFlags().Bool("disable-folders", false, "folders will be ignored")
|
||||
loadCmd.PersistentFlags().Bool("disable-pkgs", false, "package managers will be ignored")
|
||||
viper.BindPFlag("load-disable-files", loadCmd.PersistentFlags().Lookup("disable-files"))
|
||||
viper.BindPFlag("load-disable-folders", loadCmd.PersistentFlags().Lookup("disable-folders"))
|
||||
viper.BindPFlag("load-disable-pkgs", loadCmd.PersistentFlags().Lookup("disable-pkgs"))
|
||||
loadCmd.Flags().Bool("disable-files", false, "files will be ignored")
|
||||
loadCmd.Flags().Bool("disable-folders", false, "folders will be ignored")
|
||||
loadCmd.Flags().Bool("pkgs", false, "packages will be installed")
|
||||
loadCmd.Flags().StringSlice("exclude-pkg-managers", []string{}, "package managers to exclude (comma separated)")
|
||||
viper.BindPFlag("load-disable-files", loadCmd.Flags().Lookup("disable-files"))
|
||||
viper.BindPFlag("load-disable-folders", loadCmd.Flags().Lookup("disable-folders"))
|
||||
viper.BindPFlag("load-enable-pkgs", loadCmd.Flags().Lookup("pkgs"))
|
||||
viper.BindPFlag("exclude-pkg-managers", loadCmd.Flags().Lookup("exclude-pkg-managers"))
|
||||
|
||||
saveCmd.PersistentFlags().Bool("disable-files", false, "files will be ignored")
|
||||
saveCmd.PersistentFlags().Bool("disable-folders", false, "folders will be ignored")
|
||||
saveCmd.PersistentFlags().Bool("disable-pkgs", false, "package managers will be ignored")
|
||||
viper.BindPFlag("save-disable-files", saveCmd.PersistentFlags().Lookup("disable-files"))
|
||||
viper.BindPFlag("save-disable-folders", saveCmd.PersistentFlags().Lookup("disable-folders"))
|
||||
viper.BindPFlag("save-disable-pkgs", saveCmd.PersistentFlags().Lookup("disable-pkgs"))
|
||||
saveCmd.Flags().Bool("disable-files", false, "files will be ignored")
|
||||
saveCmd.Flags().Bool("disable-folders", false, "folders will be ignored")
|
||||
saveCmd.Flags().BoolP("push", "p", false, "new configurations will be committed and pushed")
|
||||
saveCmd.Flags().StringP("message", "m", strconv.FormatInt(time.Now().Unix(), 10), "combined with --push to set a commit message")
|
||||
saveCmd.Flags().Bool("disable-index", false, "configuration index will not be updated")
|
||||
viper.BindPFlag("save-disable-files", saveCmd.Flags().Lookup("disable-files"))
|
||||
viper.BindPFlag("save-disable-folders", saveCmd.Flags().Lookup("disable-folders"))
|
||||
viper.BindPFlag("push", saveCmd.Flags().Lookup("push"))
|
||||
viper.BindPFlag("disable-index-update", saveCmd.Flags().Lookup("disable-index"))
|
||||
viper.BindPFlag("message", saveCmd.Flags().Lookup("message"))
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
errLogger.Printf("an error occured while running command: %v\n", err)
|
||||
os.Exit(1)
|
||||
log.Fatal("an error occured while running command", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
func save(cmd *cobra.Command, args []string) {
|
||||
var c configuration.Configuration
|
||||
if err := viper.Unmarshal(&c); err != nil {
|
||||
log.Fatal("failed to decode configuration", "err", err)
|
||||
}
|
||||
|
||||
indexer, err := mapper.NewIndexer(c.Storage.Path)
|
||||
if err != nil {
|
||||
log.Fatal("failed to open the indexer", "err", err)
|
||||
}
|
||||
|
||||
r, err := git.NewRepository(c.Storage.Git, c.Storage.Path)
|
||||
if err != nil {
|
||||
log.Fatal("failed to open repository", "path", c.Storage.Path, "err", err)
|
||||
}
|
||||
|
||||
el := mapper.NewItemsActions(nil, c.Storage.Path, r, indexer)
|
||||
|
||||
if !viper.GetBool("save-disable-files") {
|
||||
el.AddItems(c.Files)
|
||||
}
|
||||
if !viper.GetBool("save-disable-folders") {
|
||||
el.AddItems(c.Folders)
|
||||
}
|
||||
|
||||
el.Action("save")
|
||||
|
||||
if err := el.CleanUp(indexer.RemovedLines()); err != nil {
|
||||
log.Fatal("failed to clean repository", "err", err)
|
||||
}
|
||||
|
||||
if viper.GetBool("push") {
|
||||
log.Info("pushing changes...")
|
||||
|
||||
if err := r.PushChanges(viper.GetString("message"), indexer.Lines(), indexer.RemovedLines()); err != nil {
|
||||
log.Fatal("failed to push changes to repository", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func load(cmd *cobra.Command, args []string) {
|
||||
var c configuration.Configuration
|
||||
if err := viper.Unmarshal(&c); err != nil {
|
||||
log.Fatal("failed to decode configuration", "err", err)
|
||||
}
|
||||
|
||||
i, err := mapper.NewIndexer(c.Storage.Path)
|
||||
if err != nil {
|
||||
log.Fatal("failed to open the indexer", "err", err)
|
||||
}
|
||||
|
||||
r, err := git.NewRepository(c.Storage.Git, c.Storage.Path)
|
||||
if err != nil {
|
||||
log.Fatal("failed to open repository", "path", c.Storage.Path, "err", err)
|
||||
}
|
||||
|
||||
el := mapper.NewItemsActions(nil, c.Storage.Path, r, i)
|
||||
|
||||
if !viper.GetBool("load-disable-files") {
|
||||
el.AddItems(c.Files)
|
||||
}
|
||||
if !viper.GetBool("load-disable-folders") {
|
||||
el.AddItems(c.Folders)
|
||||
}
|
||||
|
||||
el.Action("load")
|
||||
|
||||
if viper.GetBool("load-enable-pkgs") {
|
||||
if err := mapper.InstallPackages(c.PackageManagers); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func initCommand(cmd *cobra.Command, args []string) {
|
||||
var c configuration.Configuration
|
||||
if err := viper.Unmarshal(&c); err != nil {
|
||||
log.Fatal("failed to decode configuration", "err", err)
|
||||
}
|
||||
|
||||
log.Info("initializing config-mapper folder from configuration...")
|
||||
|
||||
if _, err := git.NewRepository(c.Storage.Git, c.Storage.Path); err != nil {
|
||||
log.Fatal("failed to initialize folder", "err", err)
|
||||
}
|
||||
|
||||
log.Info("repository initialized", "path", viper.GetString("storage.location"))
|
||||
}
|
||||
|
|
21
go.mod
21
go.mod
|
@ -1,34 +1,39 @@
|
|||
module github.com/datahearth/config-mapper
|
||||
module gitea.antoine-langlois.net/datahearth/config-mapper
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/gernest/wow v0.1.0
|
||||
github.com/go-git/go-git/v5 v5.4.2
|
||||
github.com/pterm/pterm v0.12.37
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
github.com/spf13/cobra v1.3.0
|
||||
github.com/spf13/viper v1.10.1
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
|
||||
github.com/charmbracelet/log v0.1.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.4.16 // indirect
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
|
||||
github.com/acomagu/bufpipe v1.0.3 // indirect
|
||||
github.com/atomicgo/cursor v0.0.1 // indirect
|
||||
github.com/charmbracelet/lipgloss v0.6.0 // indirect
|
||||
github.com/emirpasic/gods v1.12.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||
github.com/go-git/gcfg v1.5.0 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.3.1 // indirect
|
||||
github.com/gookit/color v1.4.2 // indirect
|
||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/magiconair/properties v1.8.5 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
||||
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 // indirect
|
||||
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 // indirect
|
||||
github.com/pelletier/go-toml v1.9.4 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/sergi/go-diff v1.1.0 // indirect
|
||||
|
@ -38,10 +43,8 @@ require (
|
|||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.2.0 // indirect
|
||||
github.com/xanzy/ssh-agent v0.3.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
|
||||
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
|
||||
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
|
|
60
go.sum
60
go.sum
|
@ -49,12 +49,6 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
|
|||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs=
|
||||
github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8=
|
||||
github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII=
|
||||
github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k=
|
||||
github.com/MarvinJWendt/testza v0.2.12 h1:/PRp/BF+27t2ZxynTiqj0nyND5PbOtfJS0SuTuxmgeg=
|
||||
github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI=
|
||||
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
|
||||
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
|
||||
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
|
||||
|
@ -77,8 +71,6 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
|
|||
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/atomicgo/cursor v0.0.1 h1:xdogsqa6YYlLfM+GyClC/Lchf7aiMerFiZQn7soTOoU=
|
||||
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
|
@ -88,6 +80,10 @@ github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA
|
|||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/charmbracelet/lipgloss v0.6.0 h1:1StyZB9vBSOyuZxQUcUwGr17JmojPNm87inij9N3wJY=
|
||||
github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk=
|
||||
github.com/charmbracelet/log v0.1.2 h1:xmKMxo0T/lcftgggQOhUkS32exku2/ID55FGYbr4nKQ=
|
||||
github.com/charmbracelet/log v0.1.2/go.mod h1:86XdIdmrubqtL/6u0z+jGFol1bQejBGG/qPSTwGZuQQ=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
|
@ -130,6 +126,8 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF
|
|||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
|
||||
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
|
||||
github.com/gernest/wow v0.1.0 h1:g9xdwCwP0+xgVYlA2sopI0gZHqXe7HjI/7/LykG4fks=
|
||||
github.com/gernest/wow v0.1.0/go.mod h1:dEPabJRi5BneI1Nev1VWo0ZlcTWibHWp43qxKms4elY=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
|
||||
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
|
@ -149,6 +147,8 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
|
|||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
||||
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
|
@ -225,8 +225,6 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
|
|||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0=
|
||||
github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0eJc8R6ouapiM=
|
||||
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
|
||||
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||
github.com/hashicorp/consul/api v1.11.0/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M=
|
||||
github.com/hashicorp/consul/api v1.12.0/go.mod h1:6pVBMo0ebnYdt2S3H87XhekM/HHrUoTD2XXb/VrZVy0=
|
||||
|
@ -281,8 +279,6 @@ github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgy
|
|||
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
|
@ -294,6 +290,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
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/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
|
||||
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
|
||||
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
|
@ -310,6 +308,9 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
|
|||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
|
@ -322,13 +323,18 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
|
|||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
|
||||
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=
|
||||
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
|
||||
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 h1:STjmj0uFfRryL9fzRA/OupNppeAID6QJYPMavTL7jtY=
|
||||
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
|
@ -356,13 +362,7 @@ github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8b
|
|||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI=
|
||||
github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg=
|
||||
github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE=
|
||||
github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU=
|
||||
github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE=
|
||||
github.com/pterm/pterm v0.12.37 h1:QGOyuaDUmY3yTbP0k6i0uPNqNHA9YofEBQDy0tIyKTA=
|
||||
github.com/pterm/pterm v0.12.37/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
|
@ -394,20 +394,23 @@ github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
|
|||
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
||||
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
|
||||
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
@ -429,6 +432,7 @@ go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9i
|
|||
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
|
@ -553,6 +557,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
|
|||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190116161447-11f53e031339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
@ -614,14 +619,12 @@ golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 h1:5hpz5aRr+W1erYCL5JRhSUBJRph7l9XkNveoExlrKYk=
|
||||
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
@ -862,8 +865,9 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
Storage Storage `mapstructure:"storage" yaml:"storage"`
|
||||
Files []ItemLocation `mapstructure:"files" yaml:"files"`
|
||||
Folders []ItemLocation `mapstructure:"folders" yaml:"folders"`
|
||||
PackageManagers PkgManagers `mapstructure:"package-managers" yaml:"package-managers"`
|
||||
}
|
||||
|
||||
type ItemLocation struct {
|
||||
Darwin string `mapstructure:"darwin" yaml:"darwin"`
|
||||
Linux string `mapstructure:"linux" yaml:"linux"`
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
Location string `mapstructure:"location" yaml:"location"`
|
||||
Git Git `mapstructure:"git" yaml:"git"`
|
||||
}
|
||||
|
||||
type Git struct {
|
||||
Repository string `mapstructure:"repository" yaml:"repository"`
|
||||
BasicAuth BasicAuth `mapstructure:"basic-auth" yaml:"basic-auth"`
|
||||
SSH Ssh `mapstructure:"ssh" yaml:"ssh"`
|
||||
}
|
||||
|
||||
type BasicAuth struct {
|
||||
Username string `mapstructure:"username" yaml:"username"`
|
||||
Password string `mapstructure:"password" yaml:"password"`
|
||||
}
|
||||
|
||||
type Ssh struct {
|
||||
PrivateKey string `mapstructure:"private-key" yaml:"private-key"`
|
||||
Passphrase string `mapstructure:"passphrase" yaml:"passphrase"`
|
||||
}
|
||||
|
||||
type PkgManagers struct {
|
||||
InstallationOrder []string `mapstructure:"installation-order" yaml:"installation-order"`
|
||||
Homebrew []string `mapstructure:"homebrew" yaml:"homebrew"`
|
||||
Aptitude []string `mapstructure:"apt-get" yaml:"apt-get"`
|
||||
}
|
||||
|
||||
func InitConfig() {
|
||||
h, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
errLogger.Printf("can't get home directory through $HOME variable: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if c := viper.GetString("configuration-file"); c != "" {
|
||||
if strings.Contains(c, ".yml") {
|
||||
viper.AddConfigPath(path.Dir(c))
|
||||
} else {
|
||||
viper.AddConfigPath(c)
|
||||
}
|
||||
}
|
||||
if c := os.Getenv("CONFIG_MAPPER_CFG"); c != "" {
|
||||
if strings.Contains(c, ".yml") {
|
||||
viper.AddConfigPath(path.Dir(c))
|
||||
} else {
|
||||
viper.AddConfigPath(c)
|
||||
}
|
||||
}
|
||||
viper.AddConfigPath(h)
|
||||
|
||||
viper.SetConfigType("yml")
|
||||
viper.SetConfigName(".config-mapper")
|
||||
|
||||
viper.SetDefault("storage.location", fmt.Sprintf("%s/config-mapper", os.TempDir()))
|
||||
viper.SetDefault("package-managers.installation-order", []string{"apt", "homebrew"})
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
errLogger.Println(pterm.Red(err))
|
||||
} else {
|
||||
errLogger.Printf(pterm.Red(fmt.Sprintf("failed to read config: %v\n", err)))
|
||||
}
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
viper.Set("configuration-file", viper.ConfigFileUsed())
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package configuration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func InitConfig() {
|
||||
h, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if c := viper.GetString("configuration-file"); c != "" {
|
||||
if strings.Contains(c, "ssh://") {
|
||||
viper.AddConfigPath(h)
|
||||
|
||||
viper.SetConfigType("yml")
|
||||
viper.SetConfigName(".config-mapper")
|
||||
|
||||
if err := loadConfigSSH(c); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if strings.Contains(c, ".yml") {
|
||||
viper.AddConfigPath(path.Dir(c))
|
||||
} else {
|
||||
viper.AddConfigPath(c)
|
||||
}
|
||||
}
|
||||
if c := os.Getenv("CONFIG_MAPPER_CFG"); c != "" {
|
||||
if strings.Contains(c, ".yml") {
|
||||
viper.AddConfigPath(path.Dir(c))
|
||||
} else {
|
||||
viper.AddConfigPath(c)
|
||||
}
|
||||
}
|
||||
viper.AddConfigPath(h)
|
||||
|
||||
viper.SetConfigType("yml")
|
||||
viper.SetConfigName(".config-mapper")
|
||||
|
||||
viper.SetDefault("storage.location", fmt.Sprintf("%s/config-mapper", os.TempDir()))
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
var errMsg string
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
errMsg = "no configuration file found"
|
||||
} else {
|
||||
errMsg = "failed to read config"
|
||||
}
|
||||
|
||||
log.Fatal(errMsg, "err", err)
|
||||
}
|
||||
|
||||
viper.Set("configuration-file", viper.ConfigFileUsed())
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package configuration
|
||||
|
||||
type Configuration struct {
|
||||
Storage Storage `mapstructure:"storage" yaml:"storage"`
|
||||
Files []OSLocation `mapstructure:"files" yaml:"files"`
|
||||
Folders []OSLocation `mapstructure:"folders" yaml:"folders"`
|
||||
PackageManagers PkgManagers `mapstructure:"package-managers" yaml:"package-managers"`
|
||||
}
|
||||
|
||||
type OSLocation struct {
|
||||
Darwin string `mapstructure:"darwin" yaml:"darwin"`
|
||||
Linux string `mapstructure:"linux" yaml:"linux"`
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
Path string `mapstructure:"location" yaml:"location"`
|
||||
Git Git `mapstructure:"git" yaml:"git"`
|
||||
}
|
||||
|
||||
type Git struct {
|
||||
URL string `mapstructure:"repository" yaml:"repository"`
|
||||
Name string `mapstructure:"name" yaml:"name"`
|
||||
Email string `mapstructure:"email" yaml:"email"`
|
||||
BasicAuth BasicAuth `mapstructure:"basic-auth" yaml:"basic-auth"`
|
||||
SSH interface{} `mapstructure:"ssh" yaml:"ssh"`
|
||||
}
|
||||
|
||||
type BasicAuth struct {
|
||||
Username string `mapstructure:"username" yaml:"username"`
|
||||
Password string `mapstructure:"password" yaml:"password"`
|
||||
}
|
||||
|
||||
type Ssh struct {
|
||||
PrivateKey string `mapstructure:"private-key" yaml:"private-key"`
|
||||
Passphrase string `mapstructure:"passphrase" yaml:"passphrase"`
|
||||
}
|
||||
|
||||
type PkgManagers struct {
|
||||
InstallationOrder []string `mapstructure:"installation-order" yaml:"installation-order"`
|
||||
Brew []string `mapstructure:"brew" yaml:"brew"`
|
||||
Apt []string `mapstructure:"apt" yaml:"apt"`
|
||||
Cargo []string `mapstructure:"cargo" yaml:"cargo"`
|
||||
Pip []string `mapstructure:"pip" yaml:"pip"`
|
||||
Npm []string `mapstructure:"npm" yaml:"npm"`
|
||||
Go []string `mapstructure:"go" yaml:"go"`
|
||||
Nala []string `mapstructure:"nala" yaml:"nala"`
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
package configuration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
osUser "os/user"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/knownhosts"
|
||||
)
|
||||
|
||||
func loadConfigSSH(uri string) error {
|
||||
config, host, path, err := getSSHConfig(uri)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := ssh.Dial("tcp", host, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
s, err := c.NewSession()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
buff := new(bytes.Buffer)
|
||||
s.Stdout = buff
|
||||
if err := s.Run(fmt.Sprintf("cat %s", path)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := viper.ReadConfig(buff); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSSHConfig(uriFlag string) (*ssh.ClientConfig, string, string, error) {
|
||||
var err error
|
||||
var user, passwd, host, configPath, key string
|
||||
uri := strings.Split(uriFlag, "ssh://")[1]
|
||||
|
||||
if key = viper.GetString("ssh-key"); key != "" {
|
||||
uri, user, passwd, err = getCredentials(uri)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
|
||||
host, configPath, err = getUriContent(uri)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
} else if user = viper.GetString("ssh-user"); user != "" {
|
||||
host, configPath, err = getUriContent(uri)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
|
||||
passwd = viper.GetString("ssh-password")
|
||||
} else {
|
||||
uri, user, passwd, err = getCredentials(uri)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
if passwd == "" {
|
||||
passwd = viper.GetString("ssh-password")
|
||||
}
|
||||
|
||||
host, configPath, err = getUriContent(uri)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
}
|
||||
|
||||
if user == "" {
|
||||
log.Warn("no user was found in either the URI and flags. Current user will be used")
|
||||
|
||||
var currentUser *osUser.User
|
||||
currentUser, err = osUser.Current()
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
|
||||
user = currentUser.Username
|
||||
}
|
||||
|
||||
var auth ssh.AuthMethod
|
||||
if key != "" {
|
||||
auth, err = createPubKeyAuth(key)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
} else {
|
||||
auth = ssh.Password(passwd)
|
||||
}
|
||||
|
||||
h, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
|
||||
hostKeyCallback, err := knownhosts.New(fmt.Sprintf("%s/.ssh/known_hosts", h))
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
|
||||
if len(strings.SplitN(host, ":", 1)) == 1 {
|
||||
host = fmt.Sprintf("%s:22", host)
|
||||
}
|
||||
|
||||
return &ssh.ClientConfig{
|
||||
User: user,
|
||||
Auth: []ssh.AuthMethod{auth},
|
||||
HostKeyCallback: hostKeyCallback,
|
||||
}, host, configPath, nil
|
||||
}
|
||||
|
||||
// getCredentials takes an SSH URI and returns (splitted URI, user, passwd, error)
|
||||
//
|
||||
// "passwd" can be empty in case of a single credential in URI
|
||||
func getCredentials(uri string) (string, string, string, error) {
|
||||
uriContent := strings.SplitN(uri, "@", 2)
|
||||
if len(uriContent) == 1 {
|
||||
fmt.Printf("uriContent: %v\n", uriContent)
|
||||
return "", "", "", errors.New("no credentials in URI")
|
||||
}
|
||||
|
||||
credentials := strings.SplitN(uriContent[0], ":", 2)
|
||||
if len(credentials) == 1 {
|
||||
return uriContent[1], credentials[0], "", nil
|
||||
}
|
||||
|
||||
return uriContent[1], credentials[0], credentials[1], nil
|
||||
}
|
||||
|
||||
// getUriContent takes an SSH URI and returns (host, path, error)
|
||||
func getUriContent(uri string) (string, string, error) {
|
||||
uriContent := strings.Split(uri, ":")
|
||||
if len(uriContent) < 2 {
|
||||
return "", "", errors.New("ssh URI is malformed. It's missing either a host or path. E.g: \"ssh://localhost:/my/config/file.yml\"")
|
||||
}
|
||||
|
||||
return uriContent[0], uriContent[1], nil
|
||||
}
|
||||
|
||||
func createPubKeyAuth(key string) (ssh.AuthMethod, error) {
|
||||
var signer ssh.Signer
|
||||
privateKey, err := os.ReadFile(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if passphrase := os.Getenv("CONFIG_MAPPER_SSH_PASSPHRASE"); passphrase != "" {
|
||||
signer, err = ssh.ParsePrivateKeyWithPassphrase(privateKey, []byte(passphrase))
|
||||
} else {
|
||||
signer, err = ssh.ParsePrivateKey(privateKey)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ssh.PublicKeys(signer), nil
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCopy = errors.New("failed to copy some files")
|
||||
ErrUnsupportedOS = errors.New("unsupported OS. Please, contact the maintainer")
|
||||
)
|
||||
|
||||
func LoadFiles(files []ItemLocation, location string) error {
|
||||
pterm.DefaultSection.Println("Save files into saved location")
|
||||
haveErr := false
|
||||
p, _ := pterm.DefaultProgressbar.WithTotal(len(files)).Start()
|
||||
|
||||
for _, f := range files {
|
||||
src, dst, err := configPaths(f, location)
|
||||
if err != nil {
|
||||
if err == ErrUnsupportedOS {
|
||||
return err
|
||||
}
|
||||
pterm.Error.Println(fmt.Sprintf("failed to destination resolve path \"%s\": %v", f.Linux, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(path.Dir(dst), 0755); err != nil {
|
||||
pterm.Error.Printfln(fmt.Sprintf("failed to create directory architecture for destination path \"%s\": %v", dst, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
p.UpdateTitle(fmt.Sprintf("copying %s", src))
|
||||
|
||||
if err := copyFile(src, dst); err != nil {
|
||||
pterm.Error.Println(fmt.Sprintf("failed to load file from \"%s\" to \"%s\": %v", src, dst, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
pterm.Success.Println(fmt.Sprintf("%s copied", src))
|
||||
p.Increment()
|
||||
}
|
||||
|
||||
p.Stop()
|
||||
if haveErr {
|
||||
return ErrCopy
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SaveFiles(files []ItemLocation, location string) error {
|
||||
haveErr := false
|
||||
pterm.DefaultSection.Println("Save files into saved location")
|
||||
p, _ := pterm.DefaultProgressbar.WithTotal(len(files)).Start()
|
||||
|
||||
for _, f := range files {
|
||||
dst, src, err := configPaths(f, location)
|
||||
if err != nil {
|
||||
if err == ErrUnsupportedOS {
|
||||
return err
|
||||
}
|
||||
pterm.Error.Println(fmt.Sprintf("failed to destination resolve path \"%s\": %v", f.Linux, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
p.UpdateTitle(fmt.Sprintf("copying \"%s\"", src))
|
||||
|
||||
if err := os.MkdirAll(path.Dir(dst), 0755); err != nil {
|
||||
pterm.Error.Printfln(fmt.Sprintf("failed to create directory architecture for destination path \"%s\": %v", dst, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
if err := copyFile(src, dst); err != nil {
|
||||
pterm.Error.Println(fmt.Sprintf("failed to load file from \"%s\" to \"%s\": %v", src, dst, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
pterm.Success.Println(fmt.Sprintf("\"%s\" copied", src))
|
||||
p.Increment()
|
||||
}
|
||||
|
||||
p.Stop()
|
||||
if haveErr {
|
||||
return ErrCopy
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
)
|
||||
|
||||
var ErrFolderCopy = errors.New("failed to copy some folders")
|
||||
|
||||
func LoadFolders(folders []ItemLocation, location string) error {
|
||||
haveErr := false
|
||||
pterm.DefaultSection.Println("Load folders into saved location")
|
||||
p, _ := pterm.DefaultProgressbar.WithTotal(len(folders)).Start()
|
||||
|
||||
for _, f := range folders {
|
||||
src, dst, err := configPaths(f, location)
|
||||
if err != nil {
|
||||
if err == ErrUnsupportedOS {
|
||||
return err
|
||||
}
|
||||
pterm.Error.Println(fmt.Sprintf("failed to destination resolve path \"%s\": %v", f.Linux, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
s, err := os.Stat(src)
|
||||
if err != nil {
|
||||
pterm.Error.Println(fmt.Sprintf("failed to check if source path is a folder \"%s\": %v", src, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
if !s.IsDir() {
|
||||
pterm.Error.Println(fmt.Sprintf("source path is a file \"%s\"", src))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
p.UpdateTitle(fmt.Sprintf("copying folder \"%s\"", src))
|
||||
|
||||
if err := os.MkdirAll(dst, 0755); err != nil {
|
||||
pterm.Error.Printfln(fmt.Sprintf("failed to create directory architecture for destination path \"%s\": %v", dst, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
if err := copyFolder(src, dst); err != nil {
|
||||
pterm.Error.Println(fmt.Sprintf("failed to load folder from \"%s\" to \"%s\": %v", src, dst, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
pterm.Success.Println(fmt.Sprintf("\"%s\" copied", src))
|
||||
p.Increment()
|
||||
}
|
||||
|
||||
p.Stop()
|
||||
if haveErr {
|
||||
return ErrCopy
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SaveFolders(folders []ItemLocation, location string) error {
|
||||
haveErr := false
|
||||
pterm.DefaultSection.Println("Save folders into saved location")
|
||||
p, _ := pterm.DefaultProgressbar.WithTotal(len(folders)).Start()
|
||||
|
||||
for _, f := range folders {
|
||||
dst, src, err := configPaths(f, location)
|
||||
if err != nil {
|
||||
if err == ErrUnsupportedOS {
|
||||
return err
|
||||
}
|
||||
pterm.Error.Println(fmt.Sprintf("failed to destination resolve path \"%s\": %v", f.Linux, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
s, err := os.Stat(src)
|
||||
if err != nil {
|
||||
pterm.Error.Println(fmt.Sprintf("failed to check if source path is a folder \"%s\": %v", src, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
if !s.IsDir() {
|
||||
pterm.Error.Println(fmt.Sprintf("source path is a file \"%s\"", src))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
p.UpdateTitle(fmt.Sprintf("copying folder \"%s\"", src))
|
||||
|
||||
if err := os.MkdirAll(dst, 0755); err != nil {
|
||||
pterm.Error.Printfln(fmt.Sprintf("failed to create directory architecture for destination path \"%s\": %v", dst, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
if err := copyFolder(src, dst); err != nil {
|
||||
pterm.Error.Println(fmt.Sprintf("failed to save folder from \"%s\" to \"%s\": %v", src, dst, err))
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
|
||||
pterm.Success.Println(fmt.Sprintf("\"%s\" copied", src))
|
||||
p.Increment()
|
||||
}
|
||||
|
||||
p.Stop()
|
||||
if haveErr {
|
||||
return ErrCopy
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyFolder(src, dst string) error {
|
||||
var haveErr bool
|
||||
|
||||
items, err := os.ReadDir(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, i := range items {
|
||||
itemName := i.Name()
|
||||
srcItem := fmt.Sprintf("%s/%s", src, itemName)
|
||||
dstItem := fmt.Sprintf("%s/%s", dst, itemName)
|
||||
|
||||
if i.IsDir() {
|
||||
os.Mkdir(dstItem, i.Type().Perm())
|
||||
copyFolder(srcItem, dstItem)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := copyFile(srcItem, dstItem); err != nil {
|
||||
haveErr = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if haveErr {
|
||||
return ErrFolderCopy
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDirIsFile = errors.New("path is a file")
|
||||
ErrInvalidEnv = errors.New("found invalid environment variable in path")
|
||||
)
|
||||
|
||||
func OpenGitRepo(c Git, l string) (*git.Repository, error) {
|
||||
s, err := os.Stat(l)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
var auth transport.AuthMethod
|
||||
|
||||
if c.SSH.Passphrase != "" && c.SSH.PrivateKey != "" {
|
||||
privateKey, err := absolutePath(c.SSH.PrivateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(privateKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auth, err = ssh.NewPublicKeysFromFile("git", privateKey, c.SSH.Passphrase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
auth = &http.BasicAuth{
|
||||
Username: c.BasicAuth.Username,
|
||||
Password: c.BasicAuth.Password,
|
||||
}
|
||||
}
|
||||
|
||||
repo, err := git.PlainClone(l, false, &git.CloneOptions{
|
||||
URL: c.Repository,
|
||||
Progress: os.Stdout,
|
||||
Auth: auth,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !s.IsDir() {
|
||||
return nil, ErrDirIsFile
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(l)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return repo, nil
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/configuration"
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/misc"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDirIsFile = errors.New("path is a file")
|
||||
)
|
||||
|
||||
type RepositoryActions interface {
|
||||
PushChanges(msg string, newLines, removedLines []string) error
|
||||
GetWorktree() (*git.Worktree, error)
|
||||
GetAuthor() *object.Signature
|
||||
openRepository() error
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
auth transport.AuthMethod
|
||||
repository *git.Repository
|
||||
repoPath string
|
||||
author author
|
||||
url string
|
||||
}
|
||||
|
||||
type author struct {
|
||||
name string
|
||||
email string
|
||||
}
|
||||
|
||||
func NewRepository(config configuration.Git, repoPath string) (RepositoryActions, error) {
|
||||
var auth transport.AuthMethod
|
||||
if config.URL == "" {
|
||||
return nil, errors.New("a repository URI is needed (either using GIT protocol or HTTPS)")
|
||||
}
|
||||
repoPath, err := misc.AbsolutePath(repoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch sshConfig := config.SSH.(type) {
|
||||
case map[string]interface{}:
|
||||
var outConfig configuration.Ssh
|
||||
if err := mapstructure.Decode(sshConfig, &outConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auth, err = getSSHAuthMethod(outConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case []interface{}:
|
||||
for i, c := range sshConfig {
|
||||
if _, ok := c.(map[interface{}]interface{}); !ok {
|
||||
fmt.Printf("invalid format for configuration n°%d", i)
|
||||
continue
|
||||
}
|
||||
|
||||
var outConfig configuration.Ssh
|
||||
if err := mapstructure.Decode(c, &outConfig); err != nil {
|
||||
fmt.Printf("failed to decode ssh configuration n°%d: %v\n", i, err)
|
||||
continue
|
||||
}
|
||||
|
||||
auth, err = getSSHAuthMethod(outConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to create SSH authentication method for configuration n°%d: %v\n", i, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if auth == nil {
|
||||
auth = &http.BasicAuth{
|
||||
Username: config.BasicAuth.Username,
|
||||
Password: config.BasicAuth.Password,
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nil, errors.New("git ssh configuration canno't be unmarshaled. Please, pass a valid configuration")
|
||||
}
|
||||
|
||||
repo := &Repository{
|
||||
auth: auth,
|
||||
repository: nil,
|
||||
repoPath: repoPath,
|
||||
url: config.URL,
|
||||
author: author{
|
||||
name: config.Name,
|
||||
email: config.Email,
|
||||
},
|
||||
}
|
||||
|
||||
if err := repo.openRepository(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
func (r *Repository) openRepository() error {
|
||||
s, err := os.Stat(r.repoPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
repo, err := git.PlainClone(r.repoPath, false, &git.CloneOptions{
|
||||
URL: r.url,
|
||||
Progress: os.Stdout,
|
||||
Auth: r.auth,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r.repository = repo
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
if !s.IsDir() {
|
||||
return ErrDirIsFile
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(r.repoPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := repo.Worktree()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = w.Pull(&git.PullOptions{
|
||||
Auth: r.auth,
|
||||
})
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
return err
|
||||
}
|
||||
|
||||
r.repository = repo
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) PushChanges(msg string, newLines, removedLines []string) error {
|
||||
w, err := r.repository.Worktree()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
status, err := w.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for file := range status {
|
||||
_, err = w.Add(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := w.Commit(msg, &git.CommitOptions{
|
||||
Author: r.GetAuthor(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return r.repository.Push(&git.PushOptions{})
|
||||
}
|
||||
|
||||
func (r *Repository) GetWorktree() (*git.Worktree, error) {
|
||||
return r.repository.Worktree()
|
||||
}
|
||||
|
||||
func (r *Repository) GetAuthor() *object.Signature {
|
||||
return &object.Signature{
|
||||
Name: r.author.name,
|
||||
Email: r.author.email,
|
||||
When: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
func getSSHAuthMethod(config configuration.Ssh) (transport.AuthMethod, error) {
|
||||
if config.Passphrase == "" && config.PrivateKey == "" {
|
||||
return nil, errors.New("passphrase and private are empty")
|
||||
}
|
||||
|
||||
privateKey, err := misc.AbsolutePath(config.PrivateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(privateKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auth, err := ssh.NewPublicKeysFromFile("git", privateKey, config.Passphrase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return auth, nil
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/misc"
|
||||
)
|
||||
|
||||
type Index struct {
|
||||
lines []string
|
||||
path string
|
||||
perms fs.FileMode
|
||||
repoPath string
|
||||
removedLines []string
|
||||
}
|
||||
|
||||
type Indexer interface {
|
||||
Write(newLines []string) error
|
||||
filter(configLines []string) map[string]bool
|
||||
RemovedLines() []string
|
||||
Lines() []string
|
||||
}
|
||||
|
||||
func NewIndexer(repoPath string) (Indexer, error) {
|
||||
perms := fs.FileMode(0755)
|
||||
indexPath, err := misc.AbsolutePath(fmt.Sprintf("%s/.index", repoPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var l []string
|
||||
s, err := os.Stat(indexPath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l = []string{}
|
||||
} else {
|
||||
perms = s.Mode()
|
||||
|
||||
b, err := os.ReadFile(indexPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l = strings.Split(string(b), "\n")
|
||||
}
|
||||
|
||||
return &Index{
|
||||
lines: l,
|
||||
path: indexPath,
|
||||
perms: perms,
|
||||
repoPath: repoPath,
|
||||
removedLines: []string{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (i *Index) RemovedLines() []string {
|
||||
return i.removedLines
|
||||
}
|
||||
|
||||
func (i *Index) Lines() []string {
|
||||
return i.lines
|
||||
}
|
||||
|
||||
// filter removes lines that are no more used in configuration from the index
|
||||
func (i *Index) filter(newLines []string) map[string]bool {
|
||||
removedLines := []string{}
|
||||
foundLines := map[string]bool{}
|
||||
for _, nl := range newLines {
|
||||
foundLines[nl] = true
|
||||
}
|
||||
for _, ml := range i.lines {
|
||||
if _, ok := foundLines[ml]; !ok {
|
||||
removedLines = append(removedLines, ml)
|
||||
}
|
||||
}
|
||||
|
||||
i.removedLines = removedLines
|
||||
return foundLines
|
||||
}
|
||||
|
||||
// Write add lines stored in memory the .index file
|
||||
func (i *Index) Write(newLines []string) error {
|
||||
lines := i.filter(newLines)
|
||||
|
||||
linesNumber := len(lines)
|
||||
var data []byte
|
||||
index := 0
|
||||
i.lines = []string{}
|
||||
for path := range lines {
|
||||
if index+1 == linesNumber {
|
||||
data = append(data, []byte(fmt.Sprint(path))...)
|
||||
} else {
|
||||
data = append(data, []byte(fmt.Sprintln(path))...)
|
||||
}
|
||||
|
||||
index += 1
|
||||
i.lines = append(i.lines, path)
|
||||
}
|
||||
|
||||
os.WriteFile(i.path, data, i.perms)
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/configuration"
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/git"
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/misc"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Items struct {
|
||||
locations []configuration.OSLocation
|
||||
storage string
|
||||
repository git.RepositoryActions
|
||||
indexer Indexer
|
||||
}
|
||||
|
||||
type ItemsActions interface {
|
||||
Action(action string)
|
||||
AddItems(items []configuration.OSLocation)
|
||||
CleanUp(removedLines []string) error
|
||||
}
|
||||
|
||||
func NewItemsActions(items []configuration.OSLocation, storage string, repository git.RepositoryActions, indexer Indexer) ItemsActions {
|
||||
if items == nil {
|
||||
items = []configuration.OSLocation{}
|
||||
}
|
||||
|
||||
return &Items{
|
||||
locations: items,
|
||||
storage: storage,
|
||||
repository: repository,
|
||||
indexer: indexer,
|
||||
}
|
||||
}
|
||||
|
||||
// Action performs a "save" or "load" action on all given items.
|
||||
//
|
||||
// Any error is printed to STDERR and item is skipped.
|
||||
//
|
||||
// If the performed action is "save", it'll also write the `.index` file with all new items.
|
||||
func (e *Items) Action(action string) {
|
||||
log.Info("performing action", "action", action)
|
||||
newLines := []string{}
|
||||
|
||||
for i, l := range e.locations {
|
||||
storagePath, systemPath, err := misc.ConfigPaths(l, e.storage)
|
||||
if err != nil {
|
||||
log.Error("failed to resolve item paths", "item", i, "location", l, "err", err)
|
||||
continue
|
||||
}
|
||||
if storagePath == "" && systemPath == "" {
|
||||
log.Info("item is empty", "item", i, "location", l)
|
||||
continue
|
||||
}
|
||||
|
||||
if action == "save" {
|
||||
if newItem := e.saveItem(systemPath, storagePath, i); newItem != "" {
|
||||
newLines = append(newLines, newItem)
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
e.loadItem(storagePath, systemPath, i)
|
||||
}
|
||||
|
||||
log.Info("item processed", "action", action, "item", i, "location", l)
|
||||
}
|
||||
|
||||
if action == "save" && !viper.GetBool("disable-index-update") {
|
||||
if err := e.indexer.Write(newLines); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// saveItem saves a given item inside the configured saved location.
|
||||
//
|
||||
// If an error is given during the process, the function returns an empty string
|
||||
// (meaning the item hasn't been saved) and prints the error in STDERR.
|
||||
//
|
||||
// Else, returns the relative item location from the saved location to write the index
|
||||
// (E.g: /home/user/.config => .config)
|
||||
func (e *Items) saveItem(src, dst string, index int) string {
|
||||
if err := os.MkdirAll(path.Dir(dst), 0755); err != nil {
|
||||
log.Error("failed to create directory architecture for destination path", "path", path.Dir(dst), "err", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
s, err := os.Stat(src)
|
||||
if err != nil {
|
||||
log.Error("failed to check if source path is a folder", "path", src, "err", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if s.IsDir() {
|
||||
dstPerms := fs.FileMode(0755)
|
||||
s, err := os.Stat(dst)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
log.Error("failed to check if destination folder exists", "path", dst, "err", err)
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
dstPerms = s.Mode()
|
||||
}
|
||||
|
||||
// remove the destination if it exists. It cleans up the saved location from unused files
|
||||
if err := os.RemoveAll(dst); err != nil {
|
||||
log.Error("failed to truncate destination folder", "path", dst, "err", err)
|
||||
}
|
||||
|
||||
if err := os.Mkdir(dst, dstPerms); err != nil {
|
||||
if !os.IsExist(err) {
|
||||
log.Error("failed to create destination folder", "path", dst, "err", err)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
if err := misc.CopyFolder(src, dst, true); err != nil {
|
||||
log.Error("failed to save folder from source to destination", "source", src, "destination", dst, "err", err)
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
if err := misc.CopyFile(src, dst); err != nil {
|
||||
log.Error("failed to save file from source to destination", "source", src, "destination", dst, "err", err)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
p, err := misc.AbsolutePath(e.storage)
|
||||
if err != nil {
|
||||
log.Error("failed resolve absolute path from configuration storage", "err", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(dst, p+"/", "")
|
||||
}
|
||||
|
||||
// loadItem loads a given item onto the system.
|
||||
//
|
||||
// If an error is given during the process, the function returns an empty string
|
||||
// (meaning the item hasn't been saved) and prints the error in STDERR.
|
||||
func (e *Items) loadItem(src, dst string, index int) {
|
||||
if err := os.MkdirAll(path.Dir(dst), 0755); err != nil {
|
||||
log.Error("failed to create directory architecture for destination path", "path", path.Dir(dst), "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
s, err := os.Stat(src)
|
||||
if err != nil {
|
||||
log.Error("failed to check if source path is a folder", "path", src, "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
if s.IsDir() {
|
||||
dstPerms := fs.FileMode(0755)
|
||||
s, err := os.Stat(dst)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
log.Error("failed to check if destination folder exists", "path", dst, "err", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
dstPerms = s.Mode()
|
||||
}
|
||||
|
||||
if err := os.Mkdir(dst, dstPerms); err != nil {
|
||||
if !os.IsExist(err) {
|
||||
log.Error("failed to create destination folder", "path", dst, "err", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := misc.CopyFolder(src, dst, false); err != nil {
|
||||
log.Error("failed to load folder from source to destination", "source", src, "destination", dst, "err", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err := misc.CopyFile(src, dst); err != nil {
|
||||
log.Error("failed to load file from source to destination", "source", src, "destination", dst, "err", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Items) AddItems(items []configuration.OSLocation) {
|
||||
e.locations = append(e.locations, items...)
|
||||
}
|
||||
|
||||
func (e *Items) CleanUp(removedLines []string) error {
|
||||
for _, l := range removedLines {
|
||||
path, err := misc.AbsolutePath(fmt.Sprintf("%s/%s", e.storage, l))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
return fmt.Errorf("failed to remove item %s: %v", l, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
package misc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/configuration"
|
||||
)
|
||||
|
||||
func AbsolutePath(p string) (string, error) {
|
||||
finalPath := p
|
||||
if strings.Contains(finalPath, "~") {
|
||||
h, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
finalPath = strings.Replace(p, "~", h, 1)
|
||||
}
|
||||
|
||||
splitted := strings.Split(finalPath, "/")
|
||||
finalPath = ""
|
||||
for _, s := range splitted {
|
||||
pathPart := s
|
||||
if strings.Contains(s, "$") {
|
||||
env := os.Getenv(s)
|
||||
if env == "" {
|
||||
return "", errors.New("found invalid environment variable in path")
|
||||
|
||||
}
|
||||
pathPart = env
|
||||
}
|
||||
|
||||
finalPath += fmt.Sprintf("/%s", pathPart)
|
||||
}
|
||||
|
||||
return path.Clean(finalPath), nil
|
||||
}
|
||||
|
||||
func getPaths(p string, l string) (string, string, error) {
|
||||
paths := strings.Split(p, ":")
|
||||
|
||||
if len(paths) < 2 {
|
||||
return "", "", errors.New("path incorrectly formatted. It requires \"source:destination\"")
|
||||
}
|
||||
|
||||
src, err := AbsolutePath(strings.Replace(paths[0], "$LOCATION", l, 1))
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
dst, err := AbsolutePath(paths[1])
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return src, dst, nil
|
||||
}
|
||||
|
||||
func CopyFile(src, dst string) error {
|
||||
s, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
if _, err := io.Copy(out, in); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Chmod(dst, s.Mode()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ConfigPaths(os configuration.OSLocation, location string) (string, string, error) {
|
||||
var src, dst string
|
||||
var err error
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
if os.Linux == "" {
|
||||
return "", "", nil
|
||||
}
|
||||
src, dst, err = getPaths(os.Linux, location)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
case "darwin":
|
||||
if os.Darwin == "" {
|
||||
return "", "", nil
|
||||
}
|
||||
src, dst, err = getPaths(os.Darwin, location)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
default:
|
||||
return "", "", errors.New("unsupported OS. Please, contact the maintainer")
|
||||
}
|
||||
|
||||
return src, dst, nil
|
||||
}
|
||||
|
||||
var ignored map[string]bool
|
||||
|
||||
func CopyFolder(src, dst string, checkIgnore bool) error {
|
||||
items, err := os.ReadDir(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if checkIgnore {
|
||||
f, err := os.ReadFile(fmt.Sprintf("%s/.ignore", src))
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
ignored = map[string]bool{}
|
||||
for _, l := range strings.Split(string(f), "\n") {
|
||||
if l != "" && !strings.Contains(l, "#") {
|
||||
ignored[fmt.Sprintf("%s/%s", src, l)] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, i := range items {
|
||||
itemName := i.Name()
|
||||
srcItem := fmt.Sprintf("%s/%s", src, itemName)
|
||||
// do not copy item if it's present in .ignore file
|
||||
if ignored != nil {
|
||||
if _, ok := ignored[srcItem]; ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
dstItem := fmt.Sprintf("%s/%s", dst, itemName)
|
||||
|
||||
if i.IsDir() {
|
||||
info, err := i.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(dstItem, info.Mode()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := CopyFolder(srcItem, dstItem, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if err := CopyFile(srcItem, dstItem); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
250
internal/pkgs.go
250
internal/pkgs.go
|
@ -1,40 +1,114 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"gitea.antoine-langlois.net/datahearth/config-mapper/internal/configuration"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gernest/wow"
|
||||
"github.com/gernest/wow/spin"
|
||||
"github.com/spf13/viper"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var (
|
||||
errLogger = log.New(os.Stderr, "", 0)
|
||||
ErrFailedInstallation = errors.New("failed to install some packages. Please, checkout STDERR for more information")
|
||||
ErrFailedSaving = errors.New("failed to save some packages. Please, checkout STDERR for more information")
|
||||
ErrBrewNotAvailable = errors.New("homebrew is not available on your system")
|
||||
ErrAptNotAvailable = errors.New("aptitude is not available on your system")
|
||||
)
|
||||
// InstallPackages install all packages from the configuration file by installation order
|
||||
func InstallPackages(c configuration.PkgManagers) error {
|
||||
pkgManagers := map[string]bool{}
|
||||
for _, pkgManager := range viper.GetStringSlice("exclude-pkg-managers") {
|
||||
pkgManagers[pkgManager] = true
|
||||
}
|
||||
|
||||
func LoadPkgs(c PkgManagers) error {
|
||||
pterm.DefaultSection.Println("Load folders into saved location")
|
||||
for _, pkgManager := range c.InstallationOrder {
|
||||
log.Info("installing packages", "package-manager", pkgManager)
|
||||
if _, ok := pkgManagers[pkgManager]; ok {
|
||||
log.Info("skipping package manager", "package-manager", pkgManager)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, pkg := range c.InstallationOrder {
|
||||
switch pkg {
|
||||
case "homebrew":
|
||||
if err := installBrewPkgs(c.Homebrew); err != nil {
|
||||
errLogger.Println(pterm.Red(err))
|
||||
return ErrFailedInstallation
|
||||
}
|
||||
var pkgs []string
|
||||
switch pkgManager {
|
||||
case "brew":
|
||||
pkgs = c.Brew
|
||||
case "apt":
|
||||
if err := installAptPkgs(c.Aptitude); err != nil {
|
||||
errLogger.Println(pterm.Red(err))
|
||||
return ErrFailedInstallation
|
||||
pkgs = c.Apt
|
||||
case "cargo":
|
||||
pkgs = c.Cargo
|
||||
case "npm":
|
||||
pkgs = c.Npm
|
||||
case "pip":
|
||||
pkgs = c.Pip
|
||||
case "go":
|
||||
pkgs = c.Go
|
||||
case "nala":
|
||||
pkgs = c.Nala
|
||||
default:
|
||||
log.Error("package manager not supported", "package-manager", pkgManager)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := exec.LookPath(pkgManager); err != nil {
|
||||
// * pip might not be available on the system but pip3 is
|
||||
if pkgManager == "pip" {
|
||||
if _, err := exec.LookPath("pip3"); err != nil {
|
||||
log.Error("pip and pip3 are not available on your system", "package-manager", pkgManager)
|
||||
continue
|
||||
}
|
||||
pkgManager = "pip3"
|
||||
} else {
|
||||
log.Error("package manager not available on your system", "package-manager", pkgManager)
|
||||
continue
|
||||
}
|
||||
}
|
||||
// * for some reason, apt binary is available on darwin. Exclude it to avoid errors
|
||||
if pkgManager == "apt" && runtime.GOOS == "darwin" {
|
||||
log.Error("package manager not available on your system", "package-manager", pkgManager)
|
||||
continue
|
||||
}
|
||||
|
||||
if len(pkgs) == 0 {
|
||||
fmt.Printf("✔️ nothing to do\n\n")
|
||||
continue
|
||||
}
|
||||
|
||||
v := viper.GetBool("verbose")
|
||||
commands := []*exec.Cmd{}
|
||||
// * package managers requiring sudo permission
|
||||
if pkgManager == "apt" || pkgManager == "nala" {
|
||||
commands = append(commands, buildDefaultCommand([]string{"sudo", pkgManager, "install", "-y"}, pkgs, v))
|
||||
} else if pkgManager == "cargo" {
|
||||
commands = buildCargoCommand(pkgs, v)
|
||||
} else {
|
||||
commands = append(commands, buildDefaultCommand([]string{pkgManager, "install"}, pkgs, v))
|
||||
}
|
||||
|
||||
for i, cmd := range commands {
|
||||
spinner := wow.New(os.Stdout, spin.Get(spin.Dots3), " Installing...")
|
||||
if !v {
|
||||
spinner.Start()
|
||||
}
|
||||
if err := cmd.Run(); err != nil {
|
||||
if v {
|
||||
log.Error(err)
|
||||
} else {
|
||||
msg := fmt.Sprintf(" %s", cmd.Args)
|
||||
if i == len(commands)-1 {
|
||||
msg = fmt.Sprintf("%s\n", msg)
|
||||
}
|
||||
spinner.PersistWith(spin.Spinner{Frames: []string{"❌"}}, msg)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if !v {
|
||||
// msg := fmt.Sprintf(" %s %s", color.GreenString("Success\t"), cmd.Args)
|
||||
msg := fmt.Sprintf(" %s", cmd.Args)
|
||||
if i == len(commands)-1 {
|
||||
msg = fmt.Sprintf("%s\n", msg)
|
||||
}
|
||||
spinner.PersistWith(spin.Spinner{Frames: []string{"✔️"}}, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,114 +116,42 @@ func LoadPkgs(c PkgManagers) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func SavePkgs(cfg Configuration) error {
|
||||
pterm.DefaultSection.Println("Save user installed packages")
|
||||
func buildCargoCommand(packages []string, verbose bool) []*exec.Cmd {
|
||||
commands := []*exec.Cmd{}
|
||||
|
||||
for _, pkg := range cfg.PackageManagers.InstallationOrder {
|
||||
switch pkg {
|
||||
case "homebrew":
|
||||
if err := SaveBrewPkgs(cfg); err != nil {
|
||||
errLogger.Println(pterm.Red(err))
|
||||
return ErrFailedSaving
|
||||
cmd := exec.Command("cargo", "install")
|
||||
for _, pkg := range packages {
|
||||
if strings.Contains(pkg, " ") {
|
||||
customCmd := exec.Command("cargo", "install")
|
||||
customCmd.Args = append(cmd.Args, strings.Split(pkg, " ")...)
|
||||
if verbose {
|
||||
customCmd.Stderr = os.Stderr
|
||||
customCmd.Stdout = os.Stdout
|
||||
}
|
||||
case "apt":
|
||||
fmt.Println("implemented soon!")
|
||||
commands = append(commands, customCmd)
|
||||
} else {
|
||||
cmd.Args = append(cmd.Args, pkg)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
if verbose {
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
}
|
||||
if len(cmd.Args) > 2 {
|
||||
commands = append(commands, cmd)
|
||||
}
|
||||
|
||||
return commands
|
||||
}
|
||||
|
||||
func SaveBrewPkgs(cfg Configuration) error {
|
||||
if _, err := exec.LookPath("brew"); err != nil {
|
||||
return err
|
||||
func buildDefaultCommand(command, packages []string, verbose bool) *exec.Cmd {
|
||||
cmd := exec.Command(command[0], command[1:]...)
|
||||
cmd.Args = append(cmd.Args, packages...)
|
||||
if verbose {
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
}
|
||||
|
||||
introSpinner, _ := pterm.DefaultSpinner.WithShowTimer(true).WithRemoveWhenDone(false).Start("Installing homebrew packages")
|
||||
|
||||
o, err := exec.Command("brew", "leaves", "--installed-on-request").Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pkgs := strings.Split(string(o), "\n")
|
||||
cfg.PackageManagers.Homebrew = append([]string{}, pkgs[:len(pkgs)-1]...)
|
||||
|
||||
b, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(viper.GetString("configuration-file"), b, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
introSpinner.Stop()
|
||||
introSpinner.Success("Packages intalled succesfully")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func installBrewPkgs(pkgs []string) error {
|
||||
if _, err := exec.LookPath("brew"); err != nil {
|
||||
return ErrBrewNotAvailable
|
||||
}
|
||||
|
||||
if len(pkgs) == 0 {
|
||||
pterm.Println(pterm.Blue("homebrew: nothing to do"))
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd := exec.Command("brew", "install")
|
||||
cmd.Args = append(cmd.Args, pkgs...)
|
||||
introSpinner, _ := pterm.DefaultSpinner.WithShowTimer(true).WithRemoveWhenDone(false).Start("Installing homebrew packages")
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
introSpinner.Stop()
|
||||
introSpinner.SuccessPrinter.PrintOnErrorf("brew command failed", err)
|
||||
return err
|
||||
}
|
||||
|
||||
introSpinner.Stop()
|
||||
introSpinner.Success("Packages intalled succesfully")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func installAptPkgs(pkgs []string) error {
|
||||
if _, err := exec.LookPath("apt-get"); err != nil {
|
||||
return ErrAptNotAvailable
|
||||
}
|
||||
|
||||
if len(pkgs) == 0 {
|
||||
pterm.Println(pterm.Blue("aptitude: nothing to do"))
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd := exec.Command("sudo", "apt-get", "install")
|
||||
cmd.Args = append(cmd.Args, pkgs...)
|
||||
|
||||
introSpinner, _ := pterm.DefaultSpinner.WithShowTimer(true).WithRemoveWhenDone(false).Start("Installing aptitude packages")
|
||||
|
||||
chErr := make(chan error)
|
||||
defer close(chErr)
|
||||
|
||||
go func(chErr chan error) {
|
||||
if err := cmd.Run(); err != nil {
|
||||
chErr <- err
|
||||
return
|
||||
}
|
||||
|
||||
chErr <- nil
|
||||
}(chErr)
|
||||
|
||||
err := <-chErr
|
||||
introSpinner.Stop()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
introSpinner.Success("Packages intalled succesfully")
|
||||
|
||||
return nil
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func absolutePath(p string) (string, error) {
|
||||
finalPath := p
|
||||
if strings.Contains(finalPath, "~") {
|
||||
h, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
finalPath = strings.Replace(p, "~", h, 1)
|
||||
}
|
||||
|
||||
splitted := strings.Split(finalPath, "/")
|
||||
finalPath = ""
|
||||
for _, s := range splitted {
|
||||
pathPart := s
|
||||
if strings.Contains(s, "$") {
|
||||
env := os.Getenv(s)
|
||||
if env == "" {
|
||||
return "", ErrInvalidEnv
|
||||
}
|
||||
pathPart = env
|
||||
}
|
||||
|
||||
finalPath += fmt.Sprintf("/%s", pathPart)
|
||||
}
|
||||
|
||||
return path.Clean(finalPath), nil
|
||||
}
|
||||
|
||||
func getPaths(p string, l string) (string, string, error) {
|
||||
paths := strings.Split(p, ":")
|
||||
|
||||
src, err := absolutePath(strings.Replace(paths[0], "$LOCATION", l, 1))
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
dst, err := absolutePath(paths[1])
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return src, dst, nil
|
||||
}
|
||||
|
||||
func copyFile(src, dst string) error {
|
||||
s, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
if _, err := io.Copy(out, in); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Chmod(dst, s.Mode()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func configPaths(f ItemLocation, location string) (string, string, error) {
|
||||
var src, dst string
|
||||
var err error
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
src, dst, err = getPaths(f.Linux, location)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
case "darwin":
|
||||
src, dst, err = getPaths(f.Darwin, location)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
default:
|
||||
return "", "", ErrUnsupportedOS
|
||||
}
|
||||
|
||||
return src, dst, nil
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
set dotenv-load
|
||||
set shell := ["zsh", "-uc"]
|
||||
|
||||
latest-tag := `git describe --tags --abbrev=0`
|
||||
|
||||
default:
|
||||
@just --list
|
||||
|
||||
publish version: (bump-files-version version)
|
||||
git-chglog --next-tag {{version}} --output CHANGELOG.md
|
||||
git add CHANGELOG.md cmd/cli.go && git commit -m "chore(changelog): release {{version}}"
|
||||
git tag -a {{version}} -m "{{version}}"
|
||||
git push --follow-tags
|
||||
|
||||
bump-files-version version:
|
||||
sd {{latest-tag}} {{version}} cmd/cli.go
|
||||
sd {{latest-tag}} "version-{{version}}-blue" CHANGELOG.md
|
Reference in New Issue