github.com/ethereum/go-ethereum@v1.16.1/cmd/geth/misccmd.go (about)

     1  // Copyright 2016 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-ethereum is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package main
    18  
    19  import (
    20  	"fmt"
    21  	"os"
    22  	"runtime"
    23  	"strings"
    24  
    25  	"github.com/ethereum/go-ethereum/internal/version"
    26  	"github.com/urfave/cli/v2"
    27  )
    28  
    29  var (
    30  	VersionCheckUrlFlag = &cli.StringFlag{
    31  		Name:  "check.url",
    32  		Usage: "URL to use when checking vulnerabilities",
    33  		Value: "https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json",
    34  	}
    35  	VersionCheckVersionFlag = &cli.StringFlag{
    36  		Name:  "check.version",
    37  		Usage: "Version to check",
    38  		Value: version.ClientName(clientIdentifier),
    39  	}
    40  	versionCommand = &cli.Command{
    41  		Action:    printVersion,
    42  		Name:      "version",
    43  		Usage:     "Print version numbers",
    44  		ArgsUsage: " ",
    45  		Description: `
    46  The output of this command is supposed to be machine-readable.
    47  `,
    48  	}
    49  	versionCheckCommand = &cli.Command{
    50  		Action: versionCheck,
    51  		Flags: []cli.Flag{
    52  			VersionCheckUrlFlag,
    53  			VersionCheckVersionFlag,
    54  		},
    55  		Name:      "version-check",
    56  		Usage:     "Checks (online) for known Geth security vulnerabilities",
    57  		ArgsUsage: "<versionstring (optional)>",
    58  		Description: `
    59  The version-check command fetches vulnerability-information from https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json, 
    60  and displays information about any security vulnerabilities that affect the currently executing version.
    61  `,
    62  	}
    63  	licenseCommand = &cli.Command{
    64  		Action:    license,
    65  		Name:      "license",
    66  		Usage:     "Display license information",
    67  		ArgsUsage: " ",
    68  	}
    69  )
    70  
    71  func printVersion(ctx *cli.Context) error {
    72  	git, _ := version.VCS()
    73  
    74  	fmt.Println(strings.Title(clientIdentifier))
    75  	fmt.Println("Version:", version.WithMeta)
    76  	if git.Commit != "" {
    77  		fmt.Println("Git Commit:", git.Commit)
    78  	}
    79  	if git.Date != "" {
    80  		fmt.Println("Git Commit Date:", git.Date)
    81  	}
    82  	fmt.Println("Architecture:", runtime.GOARCH)
    83  	fmt.Println("Go Version:", runtime.Version())
    84  	fmt.Println("Operating System:", runtime.GOOS)
    85  	fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
    86  	fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
    87  	return nil
    88  }
    89  
    90  func license(_ *cli.Context) error {
    91  	fmt.Println(`Geth is free software: you can redistribute it and/or modify
    92  it under the terms of the GNU General Public License as published by
    93  the Free Software Foundation, either version 3 of the License, or
    94  (at your option) any later version.
    95  
    96  Geth is distributed in the hope that it will be useful,
    97  but WITHOUT ANY WARRANTY; without even the implied warranty of
    98  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    99  GNU General Public License for more details.
   100  
   101  You should have received a copy of the GNU General Public License
   102  along with geth. If not, see <http://www.gnu.org/licenses/>.`)
   103  	return nil
   104  }