From: Sergey Matveev Date: Fri, 19 Sep 2025 12:44:12 +0000 (+0300) Subject: Combine all excutables X-Git-Tag: v8.12.0^2~2 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=674278b3db2edccf8da53aff4bd6458f146507b9;p=nncp.git Combine all excutables --- diff --git a/bin/build b/build similarity index 68% rename from bin/build rename to build index 340f1fe..bab31e2 100755 --- a/bin/build +++ b/build @@ -1,6 +1,7 @@ #!/bin/sh -e -cd "$(realpath -- $(dirname "$0"))"/../src +cd "$(realpath -- $(dirname "$0"))"/src +mkdir -p ../bin GO=${GO:-go} . ../config [ -d vendor ] && vendor="-mod=vendor" || : @@ -9,7 +10,9 @@ GO_LDFLAGS="$GO_LDFLAGS -X $mod.DefaultCfgPath=$CFGPATH" GO_LDFLAGS="$GO_LDFLAGS -X $mod.DefaultSendmailPath=$SENDMAIL" GO_LDFLAGS="$GO_LDFLAGS -X $mod.DefaultSpoolPath=$SPOOLPATH" GO_LDFLAGS="$GO_LDFLAGS -X $mod.DefaultLogPath=$LOGPATH" -for cmd in `cat ../bin/cmd.list` ; do - $GO build $vendor -o ../bin/$cmd $GO_CFLAGS -ldflags "$GO_LDFLAGS" ./cmd/$cmd -done +$GO build $vendor -o ../bin/nncp $GO_CFLAGS -ldflags "$GO_LDFLAGS" ./cmd/nncp $GO build $vendor -o ../bin/hjson-cli $GO_CFLAGS github.com/hjson/hjson-go/v4/hjson-cli +cd ../bin +for cmd in `cat ../cmd.list` ; do + ln -fs nncp $cmd +done diff --git a/bin/cmd.list b/cmd.list similarity index 100% rename from bin/cmd.list rename to cmd.list diff --git a/doc/building.texi b/doc/building.texi index 4da6a67..78c8945 100644 --- a/doc/building.texi +++ b/doc/building.texi @@ -20,7 +20,7 @@ $ [fetch|wget] http://www.nncpgo.org/download/nncp-@value{VERSION}.tar.xz.@{asc, $ xz -d nncp-"$release".tar.xz diff --git a/src/cmd/nncp-ack/main.go b/src/cmd/nncp/ack.go similarity index 98% rename from src/cmd/nncp-ack/main.go rename to src/cmd/nncp/ack.go index b45a8ab..f97fbaa 100644 --- a/src/cmd/nncp-ack/main.go +++ b/src/cmd/nncp/ack.go @@ -31,7 +31,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageACK() { fmt.Fprint(os.Stderr, "nncp-ack -- send packet receipt acknowledgement\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] -all\n", os.Args[0]) fmt.Fprintf(os.Stderr, "Usage: %s [options] -node NODE[,...]\n", os.Args[0]) @@ -40,7 +40,7 @@ func usage() { flag.PrintDefaults() } -func main() { +func mainACK() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(nncp.DefaultNiceFreq), @@ -60,7 +60,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageACK flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -105,14 +105,14 @@ func main() { } if *doAll { if len(nodes) != 0 { - usage() + usageACK() os.Exit(1) } for _, node := range ctx.Neigh { nodes = append(nodes, node) } } else if len(nodes) == 0 { - usage() + usageACK() os.Exit(1) } @@ -123,7 +123,7 @@ func main() { if *pktRaw != "" { if len(nodes) != 1 { - usage() + usageACK() os.Exit(1) } nncp.ViaOverride(*viaOverride, ctx, nodes[0]) diff --git a/src/cmd/nncp-bundle/main.go b/src/cmd/nncp/bundle.go similarity index 99% rename from src/cmd/nncp-bundle/main.go rename to src/cmd/nncp/bundle.go index d7ec8fc..841a831 100644 --- a/src/cmd/nncp-bundle/main.go +++ b/src/cmd/nncp/bundle.go @@ -35,7 +35,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageBundle() { fmt.Fprint(os.Stderr, "nncp-bundle -- Create/digest stream of NNCP encrypted packets\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] -tx [-delete] NODE [NODE ...] >...\n", os.Args[0]) fmt.Fprintf(os.Stderr, " %s [options] -rx -delete [-dryrun] [NODE ...] <...\n", os.Args[0]) @@ -44,7 +44,7 @@ func usage() { flag.PrintDefaults() } -func main() { +func mainBundle() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(255), "Minimal required niceness") @@ -63,7 +63,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageBundle flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-call/main.go b/src/cmd/nncp/call.go similarity index 98% rename from src/cmd/nncp-call/main.go rename to src/cmd/nncp/call.go index b7e1dad..f2d17f2 100644 --- a/src/cmd/nncp-call/main.go +++ b/src/cmd/nncp/call.go @@ -29,14 +29,14 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageCall() { fmt.Fprint(os.Stderr, "nncp-call -- call TCP daemon\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] NODE[:ADDR] [FORCEADDR]\n", os.Args[0]) fmt.Fprintln(os.Stderr, "Options:") flag.PrintDefaults() } -func main() { +func mainCall() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") ucspi = flag.Bool("ucspi", false, "Is it started as UCSPI-TCP client") @@ -83,7 +83,7 @@ func main() { "Generate ACK packets") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageCall flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -94,7 +94,7 @@ func main() { return } if flag.NArg() < 1 { - usage() + usageCall() os.Exit(1) } nice, err := nncp.NicenessParse(*niceRaw) diff --git a/src/cmd/nncp-caller/main.go b/src/cmd/nncp/caller.go similarity index 99% rename from src/cmd/nncp-caller/main.go rename to src/cmd/nncp/caller.go index 029b676..43027a7 100644 --- a/src/cmd/nncp-caller/main.go +++ b/src/cmd/nncp/caller.go @@ -30,14 +30,14 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageCaller() { fmt.Fprint(os.Stderr, "nncp-caller -- croned NNCP TCP daemon caller\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] [NODE ...]\n", os.Args[0]) fmt.Fprintln(os.Stderr, "Options:") flag.PrintDefaults() } -func main() { +func mainCaller() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") spoolPath = flag.String("spool", "", "Override path to spool") @@ -69,7 +69,7 @@ func main() { "Generate ACK packets") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageCaller flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-cfgdir/main.go b/src/cmd/nncp/cfgdir.go similarity index 96% rename from src/cmd/nncp-cfgdir/main.go rename to src/cmd/nncp/cfgdir.go index 7df3768..8e40d2f 100644 --- a/src/cmd/nncp-cfgdir/main.go +++ b/src/cmd/nncp/cfgdir.go @@ -26,14 +26,14 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageCfgDir() { fmt.Fprint(os.Stderr, "nncp-cfgdir -- Convert configuration file to the directory layout.\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] [-cfg ...] -dump /path/to/dir\n", os.Args[0]) fmt.Fprintf(os.Stderr, " %s [options] -load /path/to/dir >cfg.hjson\nOptions:\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainCfgDir() { var ( doDump = flag.Bool("dump", false, "Dump configuration file to the directory") doLoad = flag.Bool("load", false, "Load directory to create configuration file") @@ -42,7 +42,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageCfgDir flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -54,7 +54,7 @@ func main() { } if (!*doDump && !*doLoad) || flag.NArg() != 1 { - usage() + usageCfgDir() os.Exit(1) } diff --git a/src/cmd/nncp-cfgenc/main.go b/src/cmd/nncp/cfgenc.go similarity index 97% rename from src/cmd/nncp-cfgenc/main.go rename to src/cmd/nncp/cfgenc.go index 122f90d..4fed530 100644 --- a/src/cmd/nncp-cfgenc/main.go +++ b/src/cmd/nncp/cfgenc.go @@ -30,7 +30,7 @@ import ( "golang.org/x/term" ) -func usage() { +func usageCfgEnc() { fmt.Fprint(os.Stderr, "nncp-cfgenc -- encrypt/decrypt configuration file\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] cfg.hjson >cfg.hjson.eblob\n", os.Args[0]) fmt.Fprintf(os.Stderr, " %s [options] -d cfg.hjson.eblob >cfg.hjson\n", os.Args[0]) @@ -39,7 +39,7 @@ func usage() { flag.PrintDefaults() } -func main() { +func mainCfgEnc() { var ( decrypt = flag.Bool("d", false, "Decrypt the file") dump = flag.Bool("dump", false, "Print human-readable eblob information") @@ -50,7 +50,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageCfgEnc flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -62,7 +62,7 @@ func main() { } if flag.NArg() != 1 { - usage() + usageCfgEnc() os.Exit(1) } diff --git a/src/cmd/nncp-cfgmin/main.go b/src/cmd/nncp/cfgmin.go similarity index 97% rename from src/cmd/nncp-cfgmin/main.go rename to src/cmd/nncp/cfgmin.go index 862456e..00bfa33 100644 --- a/src/cmd/nncp-cfgmin/main.go +++ b/src/cmd/nncp/cfgmin.go @@ -26,20 +26,20 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageCfgMin() { fmt.Fprint(os.Stderr, "nncp-cfgmin -- print stripped configuration\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainCfgMin() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageCfgMin flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-cfgnew/main.go b/src/cmd/nncp/cfgnew.go similarity index 99% rename from src/cmd/nncp-cfgnew/main.go rename to src/cmd/nncp/cfgnew.go index 7e4d73a..13cb63f 100644 --- a/src/cmd/nncp-cfgnew/main.go +++ b/src/cmd/nncp/cfgnew.go @@ -33,12 +33,12 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageCfgNew() { fmt.Fprintln(os.Stderr, "nncp-cfgnew -- generate new configuration and keys\nOptions:") flag.PrintDefaults() } -func main() { +func mainCfgNew() { var ( areaName = flag.String("area", "", "Generate area's keypairs") yggdrasil = flag.Bool("yggdrasil", false, "Generate Yggdrasil keypair") @@ -47,7 +47,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageCfgNew flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-check/main.go b/src/cmd/nncp/check.go similarity index 97% rename from src/cmd/nncp-check/main.go rename to src/cmd/nncp/check.go index 0e89135..dcef5c6 100644 --- a/src/cmd/nncp-check/main.go +++ b/src/cmd/nncp/check.go @@ -27,13 +27,13 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageCheck() { fmt.Fprint(os.Stderr, "nncp-check -- verify Rx/Tx packets checksum\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [-nock] [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainCheck() { var ( nock = flag.Bool("nock", false, "Process .nock files") cycle = flag.Uint("cycle", 0, "Repeat check after N seconds in infinite loop") @@ -49,7 +49,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageCheck flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-cronexpr/main.go b/src/cmd/nncp/cronexpr.go similarity index 96% rename from src/cmd/nncp-cronexpr/main.go rename to src/cmd/nncp/cronexpr.go index 00d5661..3942ee6 100644 --- a/src/cmd/nncp-cronexpr/main.go +++ b/src/cmd/nncp/cronexpr.go @@ -28,20 +28,20 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageCronExpr() { fmt.Fprint(os.Stderr, "nncp-cronexpr -- cron expression checker\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [-num XXX] CRON-EXPRESSION\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainCronExpr() { var ( num = flag.Uint("num", 10, "Number of future entries to print") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageCronExpr flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp/daemon.go similarity index 99% rename from src/cmd/nncp-daemon/main.go rename to src/cmd/nncp/daemon.go index ab58bff..39c08b5 100644 --- a/src/cmd/nncp-daemon/main.go +++ b/src/cmd/nncp/daemon.go @@ -33,7 +33,7 @@ import ( "golang.org/x/net/netutil" ) -func usage() { +func usageDaemon() { fmt.Fprint(os.Stderr, "nncp-daemon -- TCP daemon\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() @@ -128,7 +128,7 @@ func startMCDTx(ctx *nncp.Ctx, port int, zeroInterval bool) error { return nil } -func main() { +func mainDaemon() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(255), "Minimal required niceness") @@ -169,7 +169,7 @@ func main() { "Generate ACK packets") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageDaemon flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-exec/main.go b/src/cmd/nncp/exec.go similarity index 98% rename from src/cmd/nncp-exec/main.go rename to src/cmd/nncp/exec.go index 7096337..c264917 100644 --- a/src/cmd/nncp-exec/main.go +++ b/src/cmd/nncp/exec.go @@ -27,7 +27,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageExec() { fmt.Fprint(os.Stderr, "nncp-exec -- send execution command\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] NODE HANDLE [ARG0 ARG1 ...]\n", os.Args[0]) fmt.Fprintf(os.Stderr, " %s [options] %s:AREA HANDLE [ARG0 ARG1 ...]\nOptions:\n", @@ -35,7 +35,7 @@ func usage() { flag.PrintDefaults() } -func main() { +func mainExec() { var ( noCompress = flag.Bool("nocompress", false, "Do not compress input data") cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") @@ -56,7 +56,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageExec flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -67,7 +67,7 @@ func main() { return } if flag.NArg() < 2 { - usage() + usageExec() os.Exit(1) } nice, err := nncp.NicenessParse(*niceRaw) diff --git a/src/cmd/nncp-file/main.go b/src/cmd/nncp/file.go similarity index 97% rename from src/cmd/nncp-file/main.go rename to src/cmd/nncp/file.go index 4b691e9..876e36e 100644 --- a/src/cmd/nncp-file/main.go +++ b/src/cmd/nncp/file.go @@ -26,7 +26,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageFile() { fmt.Fprint(os.Stderr, "nncp-file -- send file\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] SRC NODE:[DST]\n", os.Args[0]) fmt.Fprintf(os.Stderr, " %s [options] SRC %s:AREA:[DST]\nOptions:\n", @@ -41,7 +41,7 @@ options by default. You can forcefully turn them off by specifying 0 value. `) } -func main() { +func mainFile() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(nncp.DefaultNiceFile), @@ -60,7 +60,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageFile flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -71,7 +71,7 @@ func main() { return } if flag.NArg() != 2 { - usage() + usageFile() os.Exit(1) } nice, err := nncp.NicenessParse(*niceRaw) @@ -97,14 +97,14 @@ func main() { splitted := strings.Split(flag.Arg(1), ":") if len(splitted) < 2 { - usage() + usageFile() os.Exit(1) } var areaId *nncp.AreaId var node *nncp.Node if splitted[0] == nncp.AreaDir { if len(splitted) < 3 { - usage() + usageFile() os.Exit(1) } areaId = ctx.AreaName2Id[splitted[1]] diff --git a/src/cmd/nncp-freq/main.go b/src/cmd/nncp/freq.go similarity index 97% rename from src/cmd/nncp-freq/main.go rename to src/cmd/nncp/freq.go index f2ef467..21fcb7c 100644 --- a/src/cmd/nncp-freq/main.go +++ b/src/cmd/nncp/freq.go @@ -27,13 +27,13 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageFreq() { fmt.Fprint(os.Stderr, "nncp-freq -- send file request\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] NODE:SRC [DST]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainFreq() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(nncp.DefaultNiceFreq), @@ -52,7 +52,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageFreq flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -63,7 +63,7 @@ func main() { return } if flag.NArg() == 0 { - usage() + usageFreq() os.Exit(1) } nice, err := nncp.NicenessParse(*niceRaw) @@ -93,7 +93,7 @@ func main() { splitted := strings.SplitN(flag.Arg(0), ":", 2) if len(splitted) != 2 { - usage() + usageFreq() os.Exit(1) } node, err := ctx.FindNode(splitted[0]) diff --git a/src/cmd/nncp-hash/main.go b/src/cmd/nncp/hash.go similarity index 98% rename from src/cmd/nncp-hash/main.go rename to src/cmd/nncp/hash.go index b2c57a5..a166461 100644 --- a/src/cmd/nncp-hash/main.go +++ b/src/cmd/nncp/hash.go @@ -29,13 +29,13 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageHash() { fmt.Fprint(os.Stderr, "nncp-hash -- calculate MTH hash of the file\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [-file ...] [-seek X] [-debug] [-progress] [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainHash() { var ( fn = flag.String("file", "", "Read the file instead of stdin") seek = flag.Uint64("seek", 0, "Seek the file, hash, rewind, hash remaining") @@ -46,7 +46,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageHash flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-log/main.go b/src/cmd/nncp/log.go similarity index 97% rename from src/cmd/nncp-log/main.go rename to src/cmd/nncp/log.go index 3ec6fea..77f1c94 100644 --- a/src/cmd/nncp-log/main.go +++ b/src/cmd/nncp/log.go @@ -27,13 +27,13 @@ import ( "go.cypherpunks.su/recfile/v3" ) -func usage() { +func usageLog() { fmt.Fprint(os.Stderr, "nncp-log -- read logs\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainLog() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") logPath = flag.String("log", "", "Override path to logfile") @@ -42,7 +42,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageLog flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp/main.go b/src/cmd/nncp/main.go new file mode 100644 index 0000000..3970de1 --- /dev/null +++ b/src/cmd/nncp/main.go @@ -0,0 +1,101 @@ +package main + +import ( + "flag" + "fmt" + "os" + "path" + + "go.cypherpunks.su/nncp/v8" +) + +const ( + CmdNameACK = "nncp-ack" + CmdNameBundle = "nncp-bundle" + CmdNameCall = "nncp-call" + CmdNameCaller = "nncp-caller" + CmdNameCfgDir = "nncp-cfgdir" + CmdNameCfgEnc = "nncp-cfgenc" + CmdNameCfgMin = "nncp-cfgmin" + CmdNameCfgNew = "nncp-cfgnew" + CmdNameCheck = "nncp-check" + CmdNameCronExpr = "nncp-cronexpr" + CmdNameDaemon = "nncp-daemon" + CmdNameExec = "nncp-exec" + CmdNameFile = "nncp-file" + CmdNameFreq = "nncp-freq" + CmdNameHash = "nncp-hash" + CmdNameLog = "nncp-log" + CmdNameMain = "nncp-main" + CmdNamePkt = "nncp-pkt" + CmdNameReass = "nncp-reass" + CmdNameRm = "nncp-rm" + CmdNameStat = "nncp-stat" + CmdNameToss = "nncp-toss" + CmdNameTrns = "nncp-trns" + CmdNameXfer = "nncp-xfer" +) + +func main() { + cmdName := path.Base(os.Args[0]) + switch cmdName { + case CmdNameACK: + mainACK() + case CmdNameBundle: + mainBundle() + case CmdNameCall: + mainCall() + case CmdNameCaller: + mainCaller() + case CmdNameCfgDir: + mainCfgDir() + case CmdNameCfgEnc: + mainCfgEnc() + case CmdNameCfgMin: + mainCfgMin() + case CmdNameCfgNew: + mainCfgNew() + case CmdNameCheck: + mainCheck() + case CmdNameCronExpr: + mainCronExpr() + case CmdNameDaemon: + mainDaemon() + case CmdNameExec: + mainExec() + case CmdNameFile: + mainFile() + case CmdNameFreq: + mainFreq() + case CmdNameHash: + mainHash() + case CmdNameLog: + mainLog() + case CmdNamePkt: + mainPkt() + case CmdNameReass: + mainReass() + case CmdNameRm: + mainRm() + case CmdNameStat: + mainStat() + case CmdNameToss: + mainToss() + case CmdNameTrns: + mainTrns() + case CmdNameXfer: + mainXfer() + default: + version := flag.Bool("version", false, "Print version information") + warranty := flag.Bool("warranty", false, "Print warranty information") + flag.Parse() + if *warranty { + fmt.Println(nncp.Warranty) + return + } + if *version { + fmt.Println(nncp.VersionGet()) + return + } + } +} diff --git a/src/cmd/nncp-pkt/main.go b/src/cmd/nncp/pkt.go similarity index 99% rename from src/cmd/nncp-pkt/main.go rename to src/cmd/nncp/pkt.go index 7a51fd1..70ace98 100644 --- a/src/cmd/nncp-pkt/main.go +++ b/src/cmd/nncp/pkt.go @@ -30,7 +30,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usagePkt() { fmt.Fprint(os.Stderr, "nncp-pkt -- parse raw packet\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() @@ -167,7 +167,7 @@ Recipient: %s (%s) } } -func main() { +func mainPkt() { var ( overheads = flag.Bool("overheads", false, "Print packet overheads") dump = flag.Bool("dump", false, "Write decrypted/parsed payload to stdout") @@ -177,7 +177,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usagePkt flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-reass/main.go b/src/cmd/nncp/reass.go similarity index 96% rename from src/cmd/nncp-reass/main.go rename to src/cmd/nncp/reass.go index e1271cb..b61113d 100644 --- a/src/cmd/nncp-reass/main.go +++ b/src/cmd/nncp/reass.go @@ -37,7 +37,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageReass() { fmt.Fprint(os.Stderr, "nncp-reass -- reassemble chunked files\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] [FILE.nncp.meta]\nOptions:\n", os.Args[0]) flag.PrintDefaults() @@ -47,7 +47,7 @@ but at least one of them must be specified. `) } -func process(ctx *nncp.Ctx, path string, keep, dryRun, stdout, dumpMeta bool) bool { +func reassProcess(ctx *nncp.Ctx, path string, keep, dryRun, stdout, dumpMeta bool) bool { fd, err := os.Open(path) if err != nil { log.Fatalln("Can not open file:", err) @@ -313,7 +313,7 @@ func findMetas(ctx *nncp.Ctx, dirPath string) []string { return metaPaths } -func main() { +func mainReass() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") allNodes = flag.Bool("all", false, "Process all found chunked files for all nodes") @@ -332,7 +332,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageReass flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -365,22 +365,22 @@ func main() { } if !(*allNodes || nodeOnly != nil || flag.NArg() > 0) { - usage() + usageReass() os.Exit(1) } if flag.NArg() > 0 && (*allNodes || nodeOnly != nil) { - usage() + usageReass() os.Exit(1) } if *allNodes && nodeOnly != nil { - usage() + usageReass() os.Exit(1) } ctx.Umask() if flag.NArg() > 0 { - if process(ctx, flag.Arg(0), *keep, *dryRun, *stdout, *dumpMeta) { + if reassProcess(ctx, flag.Arg(0), *keep, *dryRun, *stdout, *dumpMeta) { return } os.Exit(1) @@ -397,7 +397,7 @@ func main() { if _, seen := seenMetaPaths[metaPath]; seen { continue } - if !process(ctx, metaPath, *keep, *dryRun, false, false) { + if !reassProcess(ctx, metaPath, *keep, *dryRun, false, false) { hasErrors = true } seenMetaPaths[metaPath] = struct{}{} @@ -408,7 +408,7 @@ func main() { log.Fatalln("Specified -node does not allow incoming") } for _, metaPath := range findMetas(ctx, *nodeOnly.Incoming) { - if !process(ctx, metaPath, *keep, *dryRun, false, false) { + if !reassProcess(ctx, metaPath, *keep, *dryRun, false, false) { hasErrors = true } } diff --git a/src/cmd/nncp-rm/main.go b/src/cmd/nncp/rm.go similarity index 99% rename from src/cmd/nncp-rm/main.go rename to src/cmd/nncp/rm.go index b580236..d087285 100644 --- a/src/cmd/nncp-rm/main.go +++ b/src/cmd/nncp/rm.go @@ -33,7 +33,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageRm() { fmt.Fprint(os.Stderr, "nncp-rm -- remove packet\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] [-older X] -tmp\n", os.Args[0]) fmt.Fprintf(os.Stderr, " %s [options] -lock\n", os.Args[0]) @@ -49,7 +49,7 @@ func usage() { flag.PrintDefaults() } -func main() { +func mainRm() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") doTmp = flag.Bool("tmp", false, "Remove temporary files") @@ -74,7 +74,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageRm flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -189,7 +189,7 @@ func main() { var nodeId *nncp.NodeId if *nodeRaw == "" { if !*doAll { - usage() + usageRm() os.Exit(1) } } else { diff --git a/src/cmd/nncp-stat/main.go b/src/cmd/nncp/stat.go similarity index 98% rename from src/cmd/nncp-stat/main.go rename to src/cmd/nncp/stat.go index c3f4ea1..fc62d7a 100644 --- a/src/cmd/nncp-stat/main.go +++ b/src/cmd/nncp/stat.go @@ -27,7 +27,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageStat() { fmt.Fprint(os.Stderr, "nncp-stat -- show queued Rx/Tx stats\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] [-pkt] [-node NODE]\nOptions:\n", os.Args[0]) flag.PrintDefaults() @@ -43,7 +43,7 @@ func jobPrint(xx nncp.TRxTx, job nncp.Job, suffix string) { ) } -func main() { +func mainStat() { var ( showPkt = flag.Bool("pkt", false, "Show packets listing") cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") @@ -54,7 +54,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageStat flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-toss/main.go b/src/cmd/nncp/toss.go similarity index 98% rename from src/cmd/nncp-toss/main.go rename to src/cmd/nncp/toss.go index b5eb497..d3ec8c0 100644 --- a/src/cmd/nncp-toss/main.go +++ b/src/cmd/nncp/toss.go @@ -27,13 +27,13 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageToss() { fmt.Fprint(os.Stderr, "nncp-toss -- process inbound packets\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainToss() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") nodeRaw = flag.String("node", "", "Process only that node") @@ -58,7 +58,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageToss flag.Parse() if *warranty { fmt.Println(nncp.Warranty) diff --git a/src/cmd/nncp-trns/main.go b/src/cmd/nncp/trns.go similarity index 98% rename from src/cmd/nncp-trns/main.go rename to src/cmd/nncp/trns.go index e879d46..5d11ab8 100644 --- a/src/cmd/nncp-trns/main.go +++ b/src/cmd/nncp/trns.go @@ -28,7 +28,7 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageTrns() { fmt.Fprint(os.Stderr, "nncp-trns -- transit existing encrypted packet\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] -via NODEx[,...] NODE:PKT\n", os.Args[0]) fmt.Fprintf(os.Stderr, " (to transit SPOOL/NODE/tx/PKT)\n") @@ -37,7 +37,7 @@ func usage() { flag.PrintDefaults() } -func main() { +func mainTrns() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(nncp.DefaultNiceFile), @@ -53,7 +53,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageTrns flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -64,7 +64,7 @@ func main() { return } if flag.NArg() != 1 { - usage() + usageTrns() os.Exit(1) } nice, err := nncp.NicenessParse(*niceRaw) diff --git a/src/cmd/nncp-xfer/main.go b/src/cmd/nncp/xfer.go similarity index 99% rename from src/cmd/nncp-xfer/main.go rename to src/cmd/nncp/xfer.go index aed001e..46bb397 100644 --- a/src/cmd/nncp-xfer/main.go +++ b/src/cmd/nncp/xfer.go @@ -31,13 +31,13 @@ import ( "go.cypherpunks.su/nncp/v8" ) -func usage() { +func usageXfer() { fmt.Fprint(os.Stderr, "nncp-xfer -- copy inbound and outbounds packets\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options] DIR\nOptions:\n", os.Args[0]) flag.PrintDefaults() } -func main() { +func mainXfer() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") nodeRaw = flag.String("node", "", "Process only that node") @@ -56,7 +56,7 @@ func main() { warranty = flag.Bool("warranty", false, "Print warranty information") ) log.SetFlags(log.Lshortfile) - flag.Usage = usage + flag.Usage = usageXfer flag.Parse() if *warranty { fmt.Println(nncp.Warranty) @@ -67,7 +67,7 @@ func main() { return } if flag.NArg() != 1 { - usage() + usageXfer() os.Exit(1) } nice, err := nncp.NicenessParse(*niceRaw) diff --git a/src/nncp.go b/src/nncp.go index c29efbb..97ca23b 100644 --- a/src/nncp.go +++ b/src/nncp.go @@ -39,7 +39,7 @@ along with this program. If not, see .` ) var ( - Version string = "8.11.0" + Version string = "8.12.0" Base32Codec *base32.Encoding = base32.StdEncoding.WithPadding(base32.NoPadding) ) diff --git a/uninstall b/uninstall index 6864157..39fed12 100755 --- a/uninstall +++ b/uninstall @@ -3,6 +3,7 @@ root="$(realpath -- $(dirname "$0"))" . "$root"/config cd "$BINDIR" -rm -f `cat "$root"/bin/cmd.list` +xargs rm -f <"$root"/cmd.list +rm -f nncp rm -f "$INFODIR"/nncp.info rm -fr "$DOCDIR"