diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index cb02a84d..949ee428 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -236,6 +236,7 @@ type RuntimeOptions struct { resetDeltaIdxs bool showVersion bool showPaths bool + showDeviceId bool doUpgrade bool doUpgradeCheck bool upgradeTo string @@ -301,6 +302,7 @@ func parseCommandLineOptions() RuntimeOptions { flag.BoolVar(&options.doUpgradeCheck, "upgrade-check", false, "Check for available upgrade") flag.BoolVar(&options.showVersion, "version", false, "Show version") flag.BoolVar(&options.showPaths, "paths", false, "Show configuration paths") + flag.BoolVar(&options.showDeviceId, "device-id", false, "Show the device ID") flag.StringVar(&options.upgradeTo, "upgrade-to", options.upgradeTo, "Force upgrade directly from specified URL") flag.BoolVar(&options.auditEnabled, "audit", false, "Write events to audit file") flag.BoolVar(&options.verbose, "verbose", false, "Print verbose log output") @@ -390,6 +392,17 @@ func main() { return } + if options.showDeviceId { + cert, err := tls.LoadX509KeyPair(locations[locCertFile], locations[locKeyFile]) + if err != nil { + l.Fatalln("Error reading device ID:", err) + } + + myID = protocol.NewDeviceID(cert.Certificate[0]) + fmt.Println(myID) + return + } + if options.browserOnly { openGUI() return