github.com/core-coin/go-core/v2@v2.1.9/cmd/gocore/misccmd.go (about)

     1  // Copyright 2023 by the Authors
     2  // This file is part of go-core.
     3  //
     4  // go-core 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-core 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-core. 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  	"gopkg.in/urfave/cli.v1"
    26  
    27  	"github.com/core-coin/go-core/v2/cmd/utils"
    28  	"github.com/core-coin/go-core/v2/params"
    29  	"github.com/core-coin/go-core/v2/xcb"
    30  )
    31  
    32  var (
    33  	VersionCheckUrlFlag = cli.StringFlag{
    34  		Name:  "check.url",
    35  		Usage: "URL to use when checking vulnerabilities",
    36  		Value: "https://gocore.coreblockchain.cc/docs/vulnerabilities/vulnerabilities.json",
    37  	}
    38  	VersionCheckVersionFlag = cli.StringFlag{
    39  		Name:  "check.version",
    40  		Usage: "Version to check",
    41  		Value: fmt.Sprintf("Gocore/%v/%v-%v/%v",
    42  			params.VersionWithTag(gitTag, gitCommit, gitDate),
    43  			runtime.GOOS, runtime.GOARCH, runtime.Version()),
    44  	}
    45  	versionCommand = cli.Command{
    46  		Action:    utils.MigrateFlags(version),
    47  		Name:      "version",
    48  		Usage:     "Print version numbers",
    49  		ArgsUsage: " ",
    50  		Category:  "MISCELLANEOUS COMMANDS",
    51  		Description: `
    52  The output of this command is supposed to be machine-readable.
    53  `,
    54  	}
    55  	versionCheckCommand = cli.Command{
    56  		Action: utils.MigrateFlags(versionCheck),
    57  		Flags: []cli.Flag{
    58  			VersionCheckUrlFlag,
    59  			VersionCheckVersionFlag,
    60  		},
    61  		Name:      "version-check",
    62  		Usage:     "Checks (online) whether the current version suffers from any known security vulnerabilities",
    63  		ArgsUsage: "<versionstring (optional)>",
    64  		Category:  "MISCELLANEOUS COMMANDS",
    65  		Description: `
    66  The version-check command fetches vulnerability-information from https://gocore.coreblockchain.cc/docs/vulnerabilities/vulnerabilities.json, 
    67  and displays information about any security vulnerabilities that affect the currently executing version.
    68  `,
    69  	}
    70  	licenseCommand = cli.Command{
    71  		Action:    utils.MigrateFlags(license),
    72  		Name:      "license",
    73  		Usage:     "Display license information",
    74  		ArgsUsage: " ",
    75  		Category:  "MISCELLANEOUS COMMANDS",
    76  	}
    77  )
    78  
    79  func version(ctx *cli.Context) error {
    80  	fmt.Println(strings.Title(clientIdentifier))
    81  	if gitCommit != "" {
    82  		fmt.Println("Git Commit:", gitCommit)
    83  	}
    84  	if gitDate != "" {
    85  		fmt.Println("Git Commit Date:", gitDate)
    86  	}
    87  	fmt.Println("Architecture:", runtime.GOARCH)
    88  	fmt.Println("Protocol Versions:", xcb.ProtocolVersions)
    89  	fmt.Println("Go Version:", runtime.Version())
    90  	fmt.Println("Operating System:", runtime.GOOS)
    91  	fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
    92  	fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
    93  	return nil
    94  }
    95  
    96  func license(_ *cli.Context) error {
    97  	fmt.Println(`Gocore is free software: you can redistribute it and/or modify
    98  it under the terms of the GNU General Public License as published by
    99  the Free Software Foundation, either version 3 of the License, or
   100  (at your option) any later version.
   101  
   102  Gocore is distributed in the hope that it will be useful,
   103  but WITHOUT ANY WARRANTY; without even the implied warranty of
   104  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   105  GNU General Public License for more details.
   106  
   107  You should have received a copy of the GNU General Public License
   108  along with gocore. If not, see <http://www.gnu.org/licenses/>.`)
   109  	return nil
   110  }