aboutsummaryrefslogtreecommitdiff
path: root/cmd/fscrypt/fscrypt.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/fscrypt/fscrypt.go')
-rw-r--r--cmd/fscrypt/fscrypt.go51
1 files changed, 22 insertions, 29 deletions
diff --git a/cmd/fscrypt/fscrypt.go b/cmd/fscrypt/fscrypt.go
index d6162f6..93f97de 100644
--- a/cmd/fscrypt/fscrypt.go
+++ b/cmd/fscrypt/fscrypt.go
@@ -22,54 +22,49 @@
fscrypt is a command line tool for managing linux filesystem encryption.
*/
-// +build linux,cgo
-
package main
import (
"fmt"
- "io/ioutil"
+ "io"
"log"
"os"
- "time"
"github.com/urfave/cli"
-)
-var (
- // Current version of the program (set by Makefile)
- version string
- // Formatted build time (set by Makefile)
- buildTime string
- // Authors to display in the info command
- Authors = []cli.Author{{
- Name: "Joe Richey",
- Email: "joerichey@google.com",
- }}
+ "github.com/google/fscrypt/actions"
+ "github.com/google/fscrypt/filesystem"
)
+// Current version of the program (set by Makefile)
+var version string
+
func main() {
cli.AppHelpTemplate = appHelpTemplate
cli.CommandHelpTemplate = commandHelpTemplate
cli.SubcommandHelpTemplate = subcommandHelpTemplate
+ if conffile := os.Getenv("FSCRYPT_CONF"); conffile != "" {
+ actions.ConfigFileLocation = conffile
+ }
+ if rootmnt := os.Getenv("FSCRYPT_ROOT_MNT"); rootmnt != "" {
+ actions.LoginProtectorMountpoint = rootmnt
+ }
+ if consistent := os.Getenv("FSCRYPT_CONSISTENT_OUTPUT"); consistent == "1" {
+ filesystem.SortDescriptorsByLastMtime = true
+ }
+
// Create our command line application
app := cli.NewApp()
app.Usage = shortUsage
- app.Authors = Authors
- app.Copyright = apache2GoogleCopyright
- // Grab the version and compilation time passed in from the Makefile.
+ // Grab the version passed in from the Makefile.
app.Version = version
- app.Compiled, _ = time.Parse(time.UnixDate, buildTime)
app.OnUsageError = onUsageError
// Setup global flags
cli.HelpFlag = helpFlag
cli.VersionFlag = versionFlag
- cli.VersionPrinter = func(c *cli.Context) {
- cli.HelpPrinter(c.App.Writer, versionInfoTemplate, c.App)
- }
app.Flags = universalFlags
// We hide the help subcommand so that "fscrypt <command> --help" works
@@ -78,7 +73,7 @@ func main() {
// Initialize command list and setup all of the commands.
app.Action = defaultAction
- app.Commands = []cli.Command{Setup, Encrypt, Unlock, Purge, Status, Metadata}
+ app.Commands = []cli.Command{Setup, Encrypt, Unlock, Lock, Purge, Status, Metadata}
for i := range app.Commands {
setupCommand(&app.Commands[i])
}
@@ -87,7 +82,7 @@ func main() {
}
// setupCommand performs some common setup for each command. This includes
-// hiding the help, formating the description, adding in the necessary
+// hiding the help, formatting the description, adding in the necessary
// flags, setting up error handlers, etc... Note that the command is modified
// in place and its subcommands are also setup.
func setupCommand(command *cli.Command) {
@@ -104,7 +99,7 @@ func setupCommand(command *cli.Command) {
if len(command.Subcommands) == 0 {
command.Before = setupBefore
} else {
- // Cleanup subcommands (if applicable)
+ // Setup subcommands (if applicable)
for i := range command.Subcommands {
setupCommand(&command.Subcommands[i])
}
@@ -114,11 +109,9 @@ func setupCommand(command *cli.Command) {
// setupBefore makes sure our logs, errors, and output are going to the correct
// io.Writers and that we haven't over-specified our flags. We only print the
// logs when using verbose, and only print normal stuff when not using quiet.
-// When running with sudo, this function also verifies that we have the proper
-// keyring linkage enabled.
func setupBefore(c *cli.Context) error {
- log.SetOutput(ioutil.Discard)
- c.App.Writer = ioutil.Discard
+ log.SetOutput(io.Discard)
+ c.App.Writer = io.Discard
if verboseFlag.Value {
log.SetOutput(os.Stdout)