From 14a203452b1b48837b29dac504deb88e71515fde Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Fri, 8 Jan 2021 09:28:51 +0100 Subject: [PATCH] add -keycard-applet and -cash-applet flags --- VERSION | 2 +- installer.go | 22 +++++++++++++--------- main.go | 13 +++++++------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/VERSION b/VERSION index 1d0ba9e..8f0916f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.0 +0.5.0 diff --git a/installer.go b/installer.go index fef820b..9338243 100644 --- a/installer.go +++ b/installer.go @@ -32,7 +32,7 @@ func NewInstaller(t keycardio.Transmitter) *Installer { } // Install installs the applet from the specified capFile. -func (i *Installer) Install(capFile *os.File, overwriteApplet bool, ndefRecordTemplate string) error { +func (i *Installer) Install(capFile *os.File, overwriteApplet bool, installKeycard bool, installCash bool, ndefRecordTemplate string) error { logger.Info("installation started") startTime := time.Now() cmdSet := globalplatform.NewCommandSet(i.c) @@ -71,16 +71,20 @@ func (i *Installer) Install(capFile *os.File, overwriteApplet bool, ndefRecordTe return err } - logger.Info("installing Keycard applet") - if err = cmdSet.InstallKeycardApplet(); err != nil { - logger.Error("installing Keycard applet failed", "error", err) - return err + if installKeycard { + logger.Info("installing Keycard applet") + if err = cmdSet.InstallKeycardApplet(); err != nil { + logger.Error("installing Keycard applet failed", "error", err) + return err + } } - logger.Info("installing Cash applet") - if err = cmdSet.InstallCashApplet(); err != nil { - logger.Error("installing Cash applet failed", "error", err) - return err + if installCash { + logger.Info("installing Cash applet") + if err = cmdSet.InstallCashApplet(); err != nil { + logger.Error("installing Cash applet failed", "error", err) + return err + } } if ndefRecordTemplate != "" { diff --git a/main.go b/main.go index f1b845a..c9a5226 100644 --- a/main.go +++ b/main.go @@ -26,10 +26,12 @@ var ( commands map[string]commandFunc command string - flagCapFile = flag.String("a", "", "applet cap file path") - flagOverwrite = flag.Bool("f", false, "force applet installation if already installed") - flagLogLevel = flag.String("l", "", `Log level, one of: "error", "warn", "info", "debug", and "trace"`) - flagNdefTemplate = flag.String("ndef", "", "Specify a URL to use in the NDEF record. Use the {{.cashAddress}} variable to get the cash address: http://example.com/{{.cashAddress}}.") + flagCapFile = flag.String("a", "", "applet cap file path") + flagKeycardApplet = flag.Bool("keycard-applet", true, "install keycard applet") + flagCashApplet = flag.Bool("cash-applet", true, "install cash applet") + flagOverwrite = flag.Bool("f", false, "force applet installation if already installed") + flagLogLevel = flag.String("l", "", `Log level, one of: "error", "warn", "info", "debug", and "trace"`) + flagNdefTemplate = flag.String("ndef", "", "Specify a URL to use in the NDEF record. Use the {{.cashAddress}} variable to get the cash address: http://example.com/{{.cashAddress}}.") ) func initLogger() { @@ -236,8 +238,7 @@ func commandInstall(card *scard.Card) error { defer f.Close() i := NewInstaller(card) - - return i.Install(f, *flagOverwrite, *flagNdefTemplate) + return i.Install(f, *flagOverwrite, *flagKeycardApplet, *flagCashApplet, *flagNdefTemplate) } func commandInfo(card *scard.Card) error {