add prompt
Signed-off-by: Jess Frazelle <jess@mesosphere.com>
This commit is contained in:
parent
f11dd855bc
commit
8f09204450
1 changed files with 42 additions and 1 deletions
|
@ -1,16 +1,30 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/term"
|
||||||
"github.com/jfrazelle/binctr/cryptar"
|
"github.com/jfrazelle/binctr/cryptar"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func unpackRootfs(spec *specs.Spec, keyin string) error {
|
func unpackRootfs(spec *specs.Spec, keyin string) (err error) {
|
||||||
|
fmt.Fprintf(os.Stdout, "Hello.\n")
|
||||||
|
fmt.Fprintf(os.Stdout, "Let's play Global Thermonuclear War.\n")
|
||||||
|
|
||||||
|
if keyin == "" {
|
||||||
|
keyin, err = promptPasskey()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
key, err := base64.StdEncoding.DecodeString(keyin)
|
key, err := base64.StdEncoding.DecodeString(keyin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -32,3 +46,30 @@ func unpackRootfs(spec *specs.Spec, keyin string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prompt for passkey
|
||||||
|
func promptPasskey() (string, error) {
|
||||||
|
inFd, _ := term.GetFdInfo(os.Stdin)
|
||||||
|
oldState, err := term.SaveState(inFd)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stdout, "Key: ")
|
||||||
|
term.DisableEcho(inFd, oldState)
|
||||||
|
|
||||||
|
keyin := readInput(os.Stdin, os.Stdout)
|
||||||
|
fmt.Fprint(os.Stdout, "\n")
|
||||||
|
|
||||||
|
term.RestoreTerminal(inFd, oldState)
|
||||||
|
return keyin, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readInput(in io.Reader, out io.Writer) string {
|
||||||
|
reader := bufio.NewReader(in)
|
||||||
|
line, _, err := reader.ReadLine()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(out, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return string(line)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue