Compare commits

...

3 Commits
master ... pkg

Author SHA1 Message Date
17cfd72173
Stub out fetching secret key entity 2018-02-26 20:07:47 -08:00
85e33bbe90
Simple pre-flight checks
More of this to come ...
2018-02-26 20:02:23 -08:00
2ec42dd61c
Stub out pm package create 2018-02-26 19:58:28 -08:00
3 changed files with 60 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"mcquay.me/pm/keyring" "mcquay.me/pm/keyring"
"mcquay.me/pm/pkg"
) )
const usage = `pm: simple, cross-platform system package manager const usage = `pm: simple, cross-platform system package manager
@ -13,6 +14,7 @@ const usage = `pm: simple, cross-platform system package manager
subcommands: subcommands:
environ (env) -- print environment information environ (env) -- print environment information
keyring (key) -- interact with pm's OpenPGP keyring keyring (key) -- interact with pm's OpenPGP keyring
package (pkg) -- create packages
` `
const keyUsage = `pm keyring: interact with pm's OpenPGP keyring const keyUsage = `pm keyring: interact with pm's OpenPGP keyring
@ -27,6 +29,12 @@ subcommands:
verify (v) -- verify a detached signature verify (v) -- verify a detached signature
` `
const pkgUsage = `pm package: generate pm-compatible packages
subcommands:
create (c) -- create a fresh keypair
`
func main() { func main() {
if len(os.Args) < 2 { if len(os.Args) < 2 {
fatalf("pm: missing subcommand\n\n%v", usage) fatalf("pm: missing subcommand\n\n%v", usage)
@ -126,6 +134,27 @@ func main() {
default: default:
fatalf("unknown keyring subcommand: %q\n\nusage: %v", sub, keyUsage) fatalf("unknown keyring subcommand: %q\n\nusage: %v", sub, keyUsage)
} }
case "package", "pkg":
if len(os.Args[1:]) < 2 {
fatalf("pm package: insufficient args\n\nusage: %v", pkgUsage)
}
sub := os.Args[2]
switch sub {
case "create", "creat", "c":
if signID == "" {
fatalf("must set PM_PGP_ID\n")
}
args := os.Args[3:]
if len(args) != 1 {
fatalf("usage: pm package create <directory>\n")
}
dir := args[0]
if err := pkg.Create(root, signID, dir); err != nil {
fatalf("creating package: %v\n", err)
}
default:
fatalf("unknown package subcommand: %q\n\nusage: %v", sub, pkgUsage)
}
default: default:
fatalf("uknown subcommand %q\n\nusage: %v", cmd, usage) fatalf("uknown subcommand %q\n\nusage: %v", cmd, usage)
} }

View File

@ -340,3 +340,8 @@ func findKey(el openpgp.EntityList, id string) (*openpgp.Entity, error) {
} }
return e, fmt.Errorf("key %q not found", id) return e, fmt.Errorf("key %q not found", id)
} }
// FindSecretEntity searches for id in the secret keyring.
func FindSecretEntity(root, id string) (*openpgp.Entity, error) {
return nil, errors.New("NYI")
}

26
pkg/pkg.go Normal file
View File

@ -0,0 +1,26 @@
package pkg
import (
"fmt"
"log"
"github.com/pkg/errors"
"mcquay.me/fs"
"mcquay.me/pm/keyring"
)
// Create traverses the contents of dir and emits a valid pkg, signed by id
func Create(root, id, dir string) error {
if !fs.Exists(dir) {
return fmt.Errorf("%q: doesn't exist", dir)
}
if !fs.IsDir(dir) {
return fmt.Errorf("%q: is not a directory", dir)
}
e, err := keyring.FindSecretEntity(dir, id)
if err != nil {
return errors.Wrap(err, "find secret key")
}
log.Printf("found key: %v", e.PrimaryKey.KeyIdShortString())
return fmt.Errorf("creating package from %q for %q: NYI", dir, id)
}