commands

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add [<pack> | -f <packs list>]",
	Short: "Add Open-CMSIS-Pack packages",
	Long: `
Add a pack using the following "<pack>" specification or using packs provided by "-f <packs list>":

  $ cpackget add Vendor.Pack.1.2.3
  $ cpackget add Vendor::Pack@1.2.3

  Use the syntax above to let cpackget determine
  the location of pack files prior to installing it locally.

  $ cpackget add Vendor.Pack.1.2.3.pack

  Use this syntax if you already have a pack at hand and simply
  want to install it under pack-root folder.

  $ cpackget add path/to/Vendor.Pack.pdsc

  Use this syntax if you are installing a pack that has not
  been released yet. This will install it as a local pack and
  keep a reference in ".Local/local_repository.pidx".

The file can be a local file or a file hosted somewhere else on the Internet.
If it's hosted somewhere, cpackget will first download it then extract all pack files into "CMSIS_PACK_ROOT/<vendor>/<packName>/<x.y.z>/"
If "-f" is used, cpackget will call "cpackget pack add" on each URL specified in the <packs list> file.`,
	Args:              cobra.MinimumNArgs(0),
	PersistentPreRunE: configureInstaller,
	RunE: func(cmd *cobra.Command, args []string) error {

		utils.SetEncodedProgress(addCmdFlags.encodedProgress)
		utils.SetSkipTouch(addCmdFlags.skipTouch)

		if addCmdFlags.packsListFileName != "" {
			log.Infof("Parsing packs urls via file %v", addCmdFlags.packsListFileName)

			file, err := os.Open(addCmdFlags.packsListFileName)
			if err != nil {
				return err
			}
			defer file.Close()

			scanner := bufio.NewScanner(file)
			for scanner.Scan() {
				tmpEntry := strings.TrimSpace(scanner.Text())
				if len(tmpEntry) == 0 {
					continue
				}
				args = append(args, tmpEntry)
			}

			if err := scanner.Err(); err != nil {
				return err
			}
		}

		if len(args) == 0 {
			log.Warn("Missing a pack-path or list with pack urls specified via -f/--packs-list-filename")

			if addCmdFlags.packsListFileName != "" {
				return nil
			}

			return errs.ErrIncorrectCmdArgs
		}

		log.Debugf("Specified packs %v", args)
		var lastErr error
		installer.UnlockPackRoot()
		for _, packPath := range args {
			var err error
			if filepath.Ext(packPath) == ".pdsc" {
				err = installer.AddPdsc(packPath)
			} else {
				err = installer.AddPack(packPath, !addCmdFlags.skipEula, addCmdFlags.extractEula, addCmdFlags.forceReinstall, addCmdFlags.noRequirements, viper.GetInt("timeout"))
			}
			if err != nil {
				lastErr = err
				if !errs.AlreadyLogged(err) {
					log.Error(err)
				}
			}
		}
		installer.LockPackRoot()
		return lastErr
	},
}

AllCommands contains all available commands for cpackget

View Source
var ChecksumCreateCmd = &cobra.Command{
	Use:   "checksum-create [<local .path pack>]",
	Short: "Generates a .checksum file containing the digests of a pack",
	Long: `
Creates a .checksum file of a local pack. This file contains the digests
of the contents of the pack. Example <Vendor.Pack.1.2.3.sha256.checksum> file:

  "6f95628e4e0824b0ff4a9f49dad1c3eb073b27c2dd84de3b985f0ef3405ca9ca Vendor.Pack.1.2.3.pdsc
  435fsdf..."

  The referenced pack must be in its original/compressed form (.pack), and be present locally:

  $ cpackget checksum-create Vendor.Pack.1.2.3.pack

The default Cryptographic Hash Function used is "` + cryptography.Hashes[0] + `". In the future other hash functions
might be supported. The used function will be prefixed to the ".checksum" extension.

By default the checksum file will be created in the same directory as the provided pack.`,
	Args:              cobra.ExactArgs(1),
	PersistentPreRunE: configureInstallerGlobalCmd,
	RunE: func(cmd *cobra.Command, args []string) error {
		return cryptography.GenerateChecksum(args[0], checksumCreateCmdFlags.outputDir, checksumCreateCmdFlags.hashAlgorithm)
	},
}
View Source
var ChecksumVerifyCmd = &cobra.Command{
	Use:   "checksum-verify [<local .path pack>]",
	Short: "Verifies the integrity of a pack using its .checksum file",
	Long: `
Verifies the contents of a pack, checking its integrity against its .checksum file (created
with "checksum-create"), present in the same directory:

  $ cpackget checksum-verify Vendor.Pack.1.2.3.pack

The used hash function is inferred from the checksum filename, and if any of the digests
computed doesn't match the one provided in the checksum file an error will be thrown.
If the .checksum file is in another directory, specify it with the -p/--path flag`,
	Args:              cobra.ExactArgs(1),
	PersistentPreRunE: configureInstallerGlobalCmd,
	RunE: func(cmd *cobra.Command, args []string) error {
		return cryptography.VerifyChecksum(args[0], checksumVerifyCmdFlags.checksumPath)
	},
}
View Source
var ConnectionCmd = &cobra.Command{
	Use:   "connection [<url>]",
	Short: "Check online connection to default or given URL",
	Long: `Checks if the given or default url is accessible
The url is optional. Ex "cpackget connection https://www.keil.com/pack"`,
	Args: cobra.MinimumNArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		utils.SetEncodedProgress(connectionCmdFlags.encodedProgress)
		utils.SetSkipTouch(connectionCmdFlags.skipTouch)

		var indexPath string
		if len(args) > 0 {
			indexPath = args[0]
		}
		createPackRoot = false
		var err error

		if indexPath == "" {
			err = configureInstaller(cmd, args)
			if err != nil {
				return err
			}
		}

		indexPath, err = installer.GetIndexPath(indexPath)
		if err != nil {
			return err
		}

		err = utils.CheckConnection(indexPath, viper.GetInt("timeout"))
		return err
	},
}
View Source
var Copyright string
View Source
var InitCmd = &cobra.Command{
	Use:   "init [--pack-root <pack root>] <index-url>",
	Short: "Initializes a pack root folder",
	Long: `Initializes a pack root folder specified by -R/--pack-root command line
or via the CMSIS_PACK_ROOT environment variable with the following contents:
  - .Download/
  - .Local/
  - .Web/
  - .Web/index.pidx (downloaded from <index-url>)
The index-url is mandatory. Ex "cpackget init --pack-root path/to/mypackroot https://www.keil.com/pack/index.pidx"`,
	Args: cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		packRoot := viper.GetString("pack-root")
		utils.SetEncodedProgress(initCmdFlags.encodedProgress)
		utils.SetSkipTouch(initCmdFlags.skipTouch)

		indexPath := args[0]

		log.Debugf("Initializing a new pack root in \"%v\" using index url \"%v\"", packRoot, indexPath)

		createPackRoot = true
		err := configureInstaller(cmd, args)
		if err != nil {
			return err
		}

		installer.UnlockPackRoot()
		err = installer.UpdatePublicIndex(indexPath, true, true, initCmdFlags.downloadPdscFiles, false, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
		installer.LockPackRoot()
		return err
	},
}
View Source
var ListCmd = &cobra.Command{
	Use:               "list [--cached|--public]",
	Short:             "List installed packs",
	Long:              "List all installed packs and optionally cached pack files",
	Args:              cobra.MaximumNArgs(0),
	PersistentPreRunE: configureInstaller,
	RunE: func(cmd *cobra.Command, args []string) error {
		return installer.ListInstalledPacks(listCmdFlags.listCached, listCmdFlags.listPublic, false, listCmdFlags.listFilter)
	},
}
View Source
var RmCmd = &cobra.Command{
	Use:   "rm <pack reference>",
	Short: "Remove Open-CMSIS-Pack packages",
	Long: `
Remove a pack using the reference "Vendor.Pack[.x.y.z]", "Vendor::Pack[@x.y.z]" or "[path/to/]Vendor.Pack.pdsc".

  $ cpackget rm Vendor.Pack.1.2.3
  $ cpackget rm Vendor::Pack@1.2.3

  Use the syntax above to let cpackget determine
  the location of pack files prior to removing them.

  $ cpackget rm Vendor.LocalPackInstalledViaPdsc.pdsc
  $ cpackget rm path/to/Vendor.LocalPackInstalledViaPdsc.pdsc

  cpackget also identifies if the pack was installed via
  PDSC file. In this case, cpackget will remove its reference
  from ".Local/local_repository.pidx".

  In the first example, since just the basename of the PDSC file
  path was specified, cpackget will remove *ALL* references of the
  PDSC file it might find. Since it is possible to have many versions
  of the same pack installed via different PDSC file paths, one may
  wish to remove a specific one by specifying a more complete
  PDSC file path, as shown in the second example.

The version "x.y.z" is optional.
Cache files (i.e. under CMSIS_PACK_ROOT/.Download/)
are *NOT* removed. If cache files need to be actually removed,
please use "--purge".`,
	Args:              cobra.MinimumNArgs(1),
	PersistentPreRunE: configureInstaller,
	RunE: func(cmd *cobra.Command, args []string) error {
		utils.SetSkipTouch(rmCmdFlags.skipTouch)
		log.Infof("Removing %v", args)
		var lastErr error
		installer.UnlockPackRoot()
		for _, packPath := range args {
			var err error
			if filepath.Ext(packPath) == ".pdsc" {
				err = installer.RemovePdsc(packPath)
				if err == errs.ErrPdscEntryNotFound {
					err = errs.ErrPackNotInstalled
				}
			} else {
				err = installer.RemovePack(packPath, rmCmdFlags.purge, viper.GetInt("timeout"))
			}
			if err != nil {
				if err != errs.ErrAlreadyLogged {
					log.Error(err)
					err = errs.ErrAlreadyLogged
				}
				lastErr = err

			}
		}
		installer.LockPackRoot()

		return lastErr
	},
}
View Source
var SignatureCreateCmd = &cobra.Command{
	Use:   "signature-create [<local .path pack>]",
	Short: "Digitally signs a pack with a X.509 certificate or PGP key",
	Long: `
Signs a pack using X.509 Public Key Infrastructure or PGP signatures.

Three modes are available. "full" is the default, and takes a X.509 public key
certificate and its private key (currently only RSA supported), which is used
to sign the hashed (SHA256) contents of a pack.
If "--cert-only" is specified, only a X.509 certificate will be embed in the pack. This
offers a lesser degree of security guarantees.
Both these options perform some basic validations on the X.509 certificate, which can
be skipped.

If "--pgp" is specified, the user must provide a PGP private key (Curve25519 or RSA 2048,
3072 and 4096 bits are supported).

The signature follows a simple scheme which includes the cpackget version used to sign,
the mode, and the outputs, base64 encoded - saved to the pack's Zip comment field.
These can be viewed with any text/hex editor or dedicated zip tools like "zipinfo".

The referenced pack must be in its original/compressed form (.pack), and be present locally:

  $ cpackget signature-create Vendor.Pack.1.2.3.pack -k private.key -c certificate.pem`,
	Args:              cobra.ExactArgs(1),
	PersistentPreRunE: configureInstallerGlobalCmd,
	RunE: func(cmd *cobra.Command, args []string) error {
		if signatureCreateflags.keyPath == "" {
			if !signatureCreateflags.certOnly {
				log.Error("Specify private key file with the -k/--key flag")
				return errs.ErrIncorrectCmdArgs
			}
		} else {
			if signatureCreateflags.certOnly {
				log.Error("-k/--key should not be provided in certificate-only mode")
				return errs.ErrIncorrectCmdArgs
			}
		}
		if signatureCreateflags.certPath == "" {
			if !signatureCreateflags.pgp {
				log.Error("Specify PEM certificate with the -c/--certificate flag")
				return errs.ErrIncorrectCmdArgs
			}
		}
		if signatureCreateflags.pgp {
			if signatureCreateflags.certOnly {
				log.Error("Both PGP and cert-only modes specified")
				return errs.ErrIncorrectCmdArgs
			}
			if signatureCreateflags.certPath != "" {
				log.Error("PGP signature scheme does not need a x509 certificate")
				return errs.ErrIncorrectCmdArgs
			}
			if signatureCreateflags.skipCertValidation {
				log.Error("PGP signature scheme does not validate certificates (--skip-validation)")
				return errs.ErrIncorrectCmdArgs
			}
			if signatureCreateflags.skipInfo {
				log.Error("PGP signature scheme does not display certificate info (--skip-info)")
				return errs.ErrIncorrectCmdArgs
			}
		}
		return cryptography.SignPack(args[0], signatureCreateflags.certPath, signatureCreateflags.keyPath, signatureCreateflags.outputDir, Version, signatureCreateflags.certOnly, signatureCreateflags.skipCertValidation, signatureCreateflags.skipInfo)
	},
}
View Source
var SignatureVerifyCmd = &cobra.Command{
	Use:   "signature-verify [<local .path pack>]",
	Short: "Verifies a signed pack",
	Long: `
Verifies the integrity and authenticity of a pack signed
with the "signature-create" command.

For more information on the signatures, use "cpackget help signature-create".

If attempting to verify a PGP signed pack, use the -k/--pub-key flag to specify
the publisher's public PGP key.

The referenced pack must be in its original/compressed form (.pack), and be present locally:

  $ cpackget signature-verify Vendor.Pack.1.2.3.pack.signed`,
	Args:              cobra.ExactArgs(1),
	PersistentPreRunE: configureInstallerGlobalCmd,
	RunE: func(cmd *cobra.Command, args []string) error {
		if signatureVerifyflags.export && (signatureVerifyflags.skipCertValidation || signatureVerifyflags.skipInfo) {
			log.Error("-e/--export does not need any other flags")
			return errs.ErrIncorrectCmdArgs
		}
		if signatureVerifyflags.pgpKey != "" {
			if signatureVerifyflags.export {
				log.Error("Can't export non X.509 (full, cert-only) signature scheme")
				return errs.ErrIncorrectCmdArgs
			}
			if signatureVerifyflags.skipCertValidation || signatureVerifyflags.skipInfo {
				log.Error("PGP verification does not need any flags other than -k/-pub-key")
				return errs.ErrIncorrectCmdArgs
			}
		}
		return cryptography.VerifyPackSignature(args[0], signatureVerifyflags.pgpKey, Version, signatureVerifyflags.export, signatureVerifyflags.skipCertValidation, signatureVerifyflags.skipInfo)
	},
}
View Source
var UpdateIndexCmd = &cobra.Command{
	Use:               "update-index",
	Short:             "Update the public index",
	Long:              getLongUpdateDescription(),
	PersistentPreRunE: configureInstaller,
	Args:              cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		utils.SetEncodedProgress(updateIndexCmdFlags.encodedProgress)
		utils.SetSkipTouch(updateIndexCmdFlags.skipTouch)
		log.Infof("Updating public index")
		installer.UnlockPackRoot()
		err := installer.UpdatePublicIndex("", true, updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
		installer.LockPackRoot()
		return err
	},
}
View Source
var Version string

Functions

func NewCli added in v0.5.0

func NewCli() *cobra.Command

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL