diff --git a/README.md b/README.md index e4d69a4..aab12dc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Have you ever wanted to back up all your .env files in case your hard drive gets nuked? `envr` makes it easier. -`envr` is a binary applicate that tracks your `.env` files +`envr` is a binary application that tracks your `.env` files in an encyrpted sqlite database. Changes can be effortlessly synced with `envr sync`, and restored with `envr restore`. @@ -18,59 +18,57 @@ the tool [of your choosing](#backup-options). be run on a cron. - 🔍 **Smart Scanning**: Automatically discover and import `.env` files in your home directory. -- 📝 **Multiple Config Formats**: Support for many configuration formats, -including: JSON, TOML, YAML, INI, XML, and NUON. -- [ ] TODO: 🗂️ **Rename Detection**: Automatically handle renamed repositories. -- ✨ **Interactive CLI**: User-friendly prompts for file selection and management -thanks to [nushell](https://www.nushell.sh/) +- ✨ **Interactive CLI**: User-friendly prompts for file selection and management. ## TODOS -- [ ] Allow configuration of ssh key. -- [ ] Allow multiple ssh keys. +- [ ] 🗂️ **Rename Detection**: Automatically handle renamed repositories. +- [ ] Allow use of keys from `ssh-agent` +- [x] Allow configuration of ssh key. +- [x] Allow multiple ssh keys. ## Prerequisites - An SSH key pair (for encryption/decryption) - The following binaries: - - [nushell](https://www.nushell.sh/) - - [age](https://github.com/FiloSottile/age) - [fd](https://github.com/sharkdp/fd) - - [sqlite3](https://github.com/sqlite/sqlite) + - [git](https://git-scm.com) ## Installation -1. Clone the repository: - ```bash - git clone https://github.com/username/envr.git - cd envr - ``` -2. Install [dependencies](#prerequisites). -3. Configure nushell. +### With Go + +If you already have `go` installed: + +```bash +go install github.com/sbrow/envr +envr init +``` + +### With Nix + +If you are a [nix](https://nixos.org/) user + +#### Try it out + +```bash +nix run github.com:sbrow/envr -- +``` + +#### Install it + +```nix +# /etc/nixos/configuration.nix +{ config, envr, system, ... }: { + environment.systemPackages = [ + envr.packages.${system}.default + ]; +} +``` ## Quick Start -1. **Initialize envr**: - ```bash - envr init - ``` - This will create your configuration file and set up encrypted storage. - -2. **Scan for existing .env files**: - ```bash - envr scan - ``` - Select files you want to back up from the interactive list. - -3. **List tracked files**: - ```bash - envr list - ``` - -4. **Sync your environment files**: - ```bash - envr sync - ``` +Check out the [man page](./docs/cli/envr.md) for the quick setup guide. ## Disclaimers @@ -79,44 +77,52 @@ thanks to [nushell](https://www.nushell.sh/) ## Commands -| Command | Description | -|---------|-------------| -| `envr init [format]` | Initialize envr with configuration file | -| `envr backup ` | Back up a specific .env file | -| `envr restore [path]` | Restore a backed-up .env file | -| `envr list` | View all tracked environment files | -| `envr scan` | Search for and selectively back up .env files | -| `envr sync` | Synchronize all tracked files (backup changes, restore missing) | -| `envr remove [...paths]` | Remove files from backup storage | -| `envr edit config` | Edit your configuration file | -| `envr config show` | Display current configuration | +See [the docs](./docs/cli) for the current list of available commands. ## Configuration -The configuration file is created during initialization and supports multiple formats: +The configuration file is created during initialization: -```toml -# Example ~/.envr/config.toml -source = "~/.envr/config.toml" -priv_key = "~/.ssh/id_ed25519" -pub_key = "~/.ssh/id_ed25519.pub" - -[scan] -matcher = "\.env" -exclude = "*.envrc" -include = "~" +```jsonc +# Example ~/.envr/config.json +{ + "keys": [ + { + "private": "/home/spencer/.ssh/id_ed25519", + "public": "/home/spencer/.ssh/id_ed25519.pub" + } + ], + "scan": { + "matcher": "\\.env", + "exclude": "*.envrc", + "include": "~" + } +} ``` ## Backup Options `envr` merely gathers your `.env` files in one local place. It is up to you to -back up the database (found at ~/.envr/data.age) to a *secure* and *remote* +back up the database (found at `~/.envr/data.age`) to a *secure* and *remote* location. ### Git +`envr` preserves inodes when updating the database, so you can safely hardlink +`~/.envr/data.age` into your [GNU Stow](https://www.gnu.org/software/stow/), +[Home Manager](https://github.com/nix-community/home-manager), or +[NixOS](https://nixos.wiki/wiki/flakes) repository. + +> [!CAUTION] +> For **maximum security**, only save your `data.age` file to a local +(i.e. non-cloud) git server that **you personally control**. +> +> I take no responsibility if you push all your secrets to a public GitHub repo. + ### restic +[restic](https://restic.readthedocs.io/en/latest/010_introduction.html). + ## License This project is licensed under the [MIT License](./LICENSE). diff --git a/docs/cli/envr.md b/docs/cli/envr.md new file mode 100644 index 0000000..e0fc30d --- /dev/null +++ b/docs/cli/envr.md @@ -0,0 +1,57 @@ +## envr + +Manage your .env files. + +### Synopsis + +envr keeps your .env synced to a local, age encrypted database. +Is a safe and eay way to gather all your .env files in one place where they can +easily be backed by another tool such as restic or git. + +All your data is stored in ~/data.age + +Getting started is easy: + +1. Create your configuration file and set up encrypted storage: + +> envr init + +2. Scan for existing .env files: + +> envr scan + +Select the files you want to back up from the interactive list. + +3. Verify that it worked: + +> envr list + +4. After changing any of your .env files, update the backup with: + +> envr sync + +5. If you lose a repository, after re-cloning the repo into the same path it was +at before, restore your backup with: + +> envr restore ~/<path to repository>/.env + +### Options + +``` + -h, --help help for envr +``` + +### SEE ALSO + +* [envr backup](envr_backup.md) - Import a .env file into envr +* [envr check](envr_check.md) - Check for missing binaries +* [envr edit-config](envr_edit-config.md) - Edit your config with your default editor +* [envr init](envr_init.md) - Set up envr +* [envr list](envr_list.md) - View your tracked files +* [envr nushell-completion](envr_nushell-completion.md) - Generate custom completions for nushell +* [envr remove](envr_remove.md) - Remove a .env file from your database +* [envr restore](envr_restore.md) - Install a .env file from the database into your file system +* [envr scan](envr_scan.md) - Find and select .env files for backup +* [envr sync](envr_sync.md) - Update or restore your env backups +* [envr version](envr_version.md) - Show envr's version + diff --git a/docs/cli/envr_backup.md b/docs/cli/envr_backup.md new file mode 100644 index 0000000..2ebbb7c --- /dev/null +++ b/docs/cli/envr_backup.md @@ -0,0 +1,18 @@ +## envr backup + +Import a .env file into envr + +``` +envr backup [flags] +``` + +### Options + +``` + -h, --help help for backup +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_check.md b/docs/cli/envr_check.md new file mode 100644 index 0000000..d06c504 --- /dev/null +++ b/docs/cli/envr_check.md @@ -0,0 +1,24 @@ +## envr check + +Check for missing binaries + +### Synopsis + +envr relies on external binaries for certain functionality. + +The check command reports on which binaries are available and which are not. + +``` +envr check [flags] +``` + +### Options + +``` + -h, --help help for check +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_edit-config.md b/docs/cli/envr_edit-config.md new file mode 100644 index 0000000..8e70d90 --- /dev/null +++ b/docs/cli/envr_edit-config.md @@ -0,0 +1,18 @@ +## envr edit-config + +Edit your config with your default editor + +``` +envr edit-config [flags] +``` + +### Options + +``` + -h, --help help for edit-config +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_init.md b/docs/cli/envr_init.md new file mode 100644 index 0000000..7535a4c --- /dev/null +++ b/docs/cli/envr_init.md @@ -0,0 +1,27 @@ +## envr init + +Set up envr + +### Synopsis + +The init command generates your initial config and saves it to +~/.envr/config in JSON format. + +During setup, you will be prompted to select one or more ssh keys with which to +encrypt your databse. **Make 100% sure** that you have **a remote copy** of this +key somewhere, otherwise your data could be lost forever. + +``` +envr init +``` + +### Options + +``` + -h, --help help for init +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_list.md b/docs/cli/envr_list.md new file mode 100644 index 0000000..7b667e9 --- /dev/null +++ b/docs/cli/envr_list.md @@ -0,0 +1,18 @@ +## envr list + +View your tracked files + +``` +envr list [flags] +``` + +### Options + +``` + -h, --help help for list +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_nushell-completion.md b/docs/cli/envr_nushell-completion.md new file mode 100644 index 0000000..7dd6cd0 --- /dev/null +++ b/docs/cli/envr_nushell-completion.md @@ -0,0 +1,23 @@ +## envr nushell-completion + +Generate custom completions for nushell + +### Synopsis + +At time of writing, cobra does not natively support nushell, +so a custom command had to be written + +``` +envr nushell-completion [flags] +``` + +### Options + +``` + -h, --help help for nushell-completion +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_remove.md b/docs/cli/envr_remove.md new file mode 100644 index 0000000..fb26a60 --- /dev/null +++ b/docs/cli/envr_remove.md @@ -0,0 +1,18 @@ +## envr remove + +Remove a .env file from your database + +``` +envr remove [flags] +``` + +### Options + +``` + -h, --help help for remove +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_restore.md b/docs/cli/envr_restore.md new file mode 100644 index 0000000..3fa947f --- /dev/null +++ b/docs/cli/envr_restore.md @@ -0,0 +1,18 @@ +## envr restore + +Install a .env file from the database into your file system + +``` +envr restore [flags] +``` + +### Options + +``` + -h, --help help for restore +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_scan.md b/docs/cli/envr_scan.md new file mode 100644 index 0000000..73c699c --- /dev/null +++ b/docs/cli/envr_scan.md @@ -0,0 +1,18 @@ +## envr scan + +Find and select .env files for backup + +``` +envr scan [flags] +``` + +### Options + +``` + -h, --help help for scan +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_sync.md b/docs/cli/envr_sync.md new file mode 100644 index 0000000..cc11cba --- /dev/null +++ b/docs/cli/envr_sync.md @@ -0,0 +1,18 @@ +## envr sync + +Update or restore your env backups + +``` +envr sync [flags] +``` + +### Options + +``` + -h, --help help for sync +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. + diff --git a/docs/cli/envr_version.md b/docs/cli/envr_version.md new file mode 100644 index 0000000..123968f --- /dev/null +++ b/docs/cli/envr_version.md @@ -0,0 +1,19 @@ +## envr version + +Show envr's version + +``` +envr version [flags] +``` + +### Options + +``` + -h, --help help for version + -l, --long Show all version information +``` + +### SEE ALSO + +* [envr](envr.md) - Manage your .env files. +