diff --git a/README.md b/README.md index 90e67cf..d85e733 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # zerkalo +A tool to efficiently mirror Linux distribution repositories (and perhaps some other forms of repositories). Uses a [git](https://git-scm.com/)-alike blob storage for data allowing for cheap snapshotting of repositories. + ## Name The name zerkalo comes from the Russian [зеркало](https://en.wiktionary.org/wiki/%D0%B7%D0%B5%D1%80%D0%BA%D0%B0%D0%BB%D0%BE) which is a mirror. diff --git a/cmd/root.go b/cmd/root.go index bc639f5..da9a041 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,14 +6,14 @@ import ( var ( // Used for flags. - userLicense string + storagePath string rootCmd = &cobra.Command{ Use: "zerkalo", - Short: "", - //Long: `Cobra is a CLI library for Go that empowers applications. - //This application is a tool to generate the needed files - //to quickly create a Cobra application.`, + Short: "Efficiently mirror Linux distribution repositories", + Long: `zerkalo is a CLI program that allows its users to mirror. +Linux distribution repositories such as apt, or yum. It lets users easily +snapshot repositories per day and deduplicates as much content as it can.`, } ) @@ -23,5 +23,5 @@ func Execute() error { } func init() { - // rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project") + rootCmd.PersistentFlags().StringVarP(&storagePath, "storage-path", "p", "", "zerkalo storage path") } diff --git a/cmd/storage.go b/cmd/storage.go new file mode 100644 index 0000000..de6ca22 --- /dev/null +++ b/cmd/storage.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(storageCmd) +} + +var storageCmd = &cobra.Command{ + Use: "storage", + Short: "Interact with the storage used by zerkalo", + //Long: `All software has versions. This is Hugo's`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("Hugo Static Site Generator v0.9 -- HEAD") + }, +} diff --git a/internal/format/yum/yum.go b/internal/format/yum/yum.go new file mode 100644 index 0000000..bfe7b1a --- /dev/null +++ b/internal/format/yum/yum.go @@ -0,0 +1 @@ +package yum diff --git a/internal/modify.go b/internal/modify.go deleted file mode 100644 index e69de29..0000000 diff --git a/internal/primitive.go b/internal/primitive.go deleted file mode 100644 index e69de29..0000000 diff --git a/internal/storage/storage.go b/internal/storage/storage.go new file mode 100644 index 0000000..59495d9 --- /dev/null +++ b/internal/storage/storage.go @@ -0,0 +1,61 @@ +package storage + +import ( + "crypto/sha256" +) + +type Storage struct { + Path string +} + +func NewStorage(path string) (*Storage, error) { + s := Storage{ + Path: path, + } + + return &s, nil +} + +type Object interface { + GetHash() [32]byte +} + +type Blob struct { + Data []byte +} + +// The `GetHash()` for a `Blob` is a straightforward SHA256 hash of the +// contents of that blob. +func (b *Blob) GetHash() [32]byte { + return sha256.Sum256(b.Data) +} + +func NewBlob(data []byte) (*Blob, error) { + b := Blob{ + Data: data, + } + + return &b, nil +} + +type Tree struct { + Items map[string]Object +} + +func NewTree() (*Tree, error) { + return nil, nil +} + +// For a `Tree` the `GetHash()` is a bit more intertwined. It's basically the +// hash of all its items. Yes, this recurses trees which is bad but the naive +// approach suffices for now. I also don't like the `[32]` vs `[]` dance here. +func (t *Tree) GetHash() [32]byte { + h := sha256.New() + + for _, v := range t.Items { + s := v.GetHash() + h.Write(s[:]) + } + + return [32]byte(h.Sum(nil)) +}