Skip to content

Instantly share code, notes, and snippets.

@paigeruten
Created July 13, 2017 22:05
Show Gist options
  • Save paigeruten/b1ab26a55d7ae7be8491eee002651651 to your computer and use it in GitHub Desktop.
Save paigeruten/b1ab26a55d7ae7be8491eee002651651 to your computer and use it in GitHub Desktop.

gzg

gzg helps you use git, tar, and gpg to keep a folder of text files synced across your devices using a server you have SSH access to. Each client has a git repo containing the unencrypted text files. All the server has is the encrypted, gzipped, tar'd, bare git repo in a single file called gzg.git.tar.gz.gpg. There is also a gzg.git.tar.gz.gpg.sha1 file used for the clients to check whether their version of the git repo is outdated.

Here's how you would set up a notes directory:

$ mkdir notes
$ cd notes
$ vim TODO.txt
$ gzg init jeremy@mydomain:git/notes.gzg

This would:

  • Make a .gzg folder in notes/
  • Init a bare git repo at .gzg/gzg.git
  • Store the string jeremy@mydomain:git/notes.gzg into a .gzg/remote file
  • Run git init in the notes/ directory
  • Add /.gzg to .gitignore
  • Add path to .gzg/gzg.git as a git remote
  • Add all untracked files and make a commit
  • Push to the .gzg/gzg.git remote
  • Run tar on the .gzg/gzg.git folder, producing .gzg/gzg.git.tar.gz
  • Run gpg on that, producing .gzg/gzg.git.tar.gz.gpg
  • Run shasum on that, producing .gzg/gzg.git.tar.gz.gpg.sha1
  • scp the last two files to the git/notes.gzg folder on the server

Then, you'd want to run clone on your other devices:

$ gzg clone jeremy@mydomain:git/notes.gzg notes
$ cd notes
$ vim TODO.txt

This would:

  • Make a notes/ directory
  • Make a .gzg folder in notes/
  • Store the string jeremy@mydomain:git/notes.gzg into a .gzg/remote file
  • scp the git/notes.gzg/gzg.git.tar.gz.gpg file from the server into .gzg
  • Decrypt and untar the file, so you have a git repo at .gzg/gzg.git
  • Run git init in the notes/ directory
  • Add path to .gzg/gzg.git as a git remote
  • Run git pull

Then, whenever you make changes or want to update a device with the latest changes, run the sync command:

$ cd notes
$ vim TODO.txt
$ gzg sync

This would:

  • scp the git/notes.gzg/gzg.git.tar.gz.sha1 file from the server
  • Run shasum on the local .gzg/gzg.git.tar.gz file to see if it changed
  • If so, scp the gzg.git.tar.gz.gpg file from the server and decrypt it
  • tar xf the gzg.git.tar.gz file to get a gzg.git bare repo
  • Add all files to the git index
  • Make a commit
  • Run git pull
  • Handle any merge conflicts somehow
  • Run git push
  • tar czvf the gzg.git folder to get gzg.git.tar.gz
  • Encrypt that to get gzg.git.tar.gz.gpg
  • Run shasum on that to get gzg.git.tar.gz.gpg.sha1
  • scp both those files to the server

Notes

  • Maybe the .gzg folder could be contained within the .git folder, so we wouldn't have to worry about having a .gitignore? Or just make .gzg an exception when adding all untracked files, somehow.
  • The user has to specify the GPG key they want to use, and it should be remembered.
  • Only one device should sync at the same time. Access to the server's file should be locked somehow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment