From 0f9378fda455692ab26960976bc97ce5175dfe5e Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Fri, 2 Sep 2022 08:46:37 +0530 Subject: [PATCH 1/6] added go and bash script to get config out of start.sh and updated flagset.go --- go.mod | 1 + go.sum | 2 + internal/cli/flagset/flagset.go | 9 + scripts/getconfig.go | 676 ++++++++++++++++++++++++++++++++ scripts/getconfig.sh | 107 +++++ 5 files changed, 795 insertions(+) create mode 100644 scripts/getconfig.go create mode 100755 scripts/getconfig.sh diff --git a/go.mod b/go.mod index 2f429ed82d..44b703195d 100644 --- a/go.mod +++ b/go.mod @@ -120,6 +120,7 @@ require ( github.com/mitchellh/pointerstructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.0 // indirect github.com/opentracing/opentracing-go v1.1.0 // indirect + github.com/pelletier/go-toml v1.9.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/posener/complete v1.1.1 // indirect diff --git a/go.sum b/go.sum index a866808996..db397477bb 100644 --- a/go.sum +++ b/go.sum @@ -399,6 +399,8 @@ github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mo github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChlfo5C6hzIHwPqfFE= +github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= +github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= diff --git a/internal/cli/flagset/flagset.go b/internal/cli/flagset/flagset.go index d9e204f0e4..933fe59060 100644 --- a/internal/cli/flagset/flagset.go +++ b/internal/cli/flagset/flagset.go @@ -44,6 +44,15 @@ func (f *Flagset) Help() string { return str + strings.Join(items, "\n\n") } +func (f *Flagset) GetAllFlags() []string { + flags := []string{} + for _, flag := range f.flags { + flags = append(flags, flag.Name) + } + + return flags +} + // MarkDown implements cli.MarkDown interface func (f *Flagset) MarkDown() string { if len(f.flags) == 0 { diff --git a/scripts/getconfig.go b/scripts/getconfig.go new file mode 100644 index 0000000000..db756f7552 --- /dev/null +++ b/scripts/getconfig.go @@ -0,0 +1,676 @@ +package main + +import ( + "encoding/json" + "errors" + "fmt" + "log" + "os" + "strconv" + "strings" + + "github.com/pelletier/go-toml" + + "github.com/ethereum/go-ethereum/internal/cli/server" +) + +// YesFV: Both, Flags and their values has changed +// YesF: Only the Flag has changed, not their value +var flagMap = map[string][]string{ + "networkid": {"notABoolFlag", "YesFV"}, + "miner.gastarget": {"notABoolFlag", "No"}, + "pprof": {"BoolFlag", "No"}, + "pprof.port": {"notABoolFlag", "No"}, + "pprof.addr": {"notABoolFlag", "No"}, + "pprof.memprofilerate": {"notABoolFlag", "No"}, + "pprof.blockprofilerate": {"notABoolFlag", "No"}, + "pprof.cpuprofile": {"notABoolFlag", "No"}, + "jsonrpc.corsdomain": {"notABoolFlag", "YesF"}, + "jsonrpc.vhosts": {"notABoolFlag", "YesF"}, + "http.modules": {"notABoolFlag", "YesF"}, + "ws.modules": {"notABoolFlag", "YesF"}, + "config": {"notABoolFlag", "No"}, + "datadir.ancient": {"notABoolFlag", "No"}, + "datadir.minfreedisk": {"notABoolFlag", "No"}, + "usb": {"BoolFlag", "No"}, + "pcscdpath": {"notABoolFlag", "No"}, + "mainnet": {"BoolFlag", "No"}, + "goerli": {"BoolFlag", "No"}, + "bor-mumbai": {"BoolFlag", "No"}, + "bor-mainnet": {"BoolFlag", "No"}, + "rinkeby": {"BoolFlag", "No"}, + "ropsten": {"BoolFlag", "No"}, + "sepolia": {"BoolFlag", "No"}, + "kiln": {"BoolFlag", "No"}, + "exitwhensynced": {"BoolFlag", "No"}, + "light.serve": {"notABoolFlag", "No"}, + "light.ingress": {"notABoolFlag", "No"}, + "light.egress": {"notABoolFlag", "No"}, + "light.maxpeers": {"notABoolFlag", "No"}, + "ulc.servers": {"notABoolFlag", "No"}, + "ulc.fraction": {"notABoolFlag", "No"}, + "ulc.onlyannounce": {"BoolFlag", "No"}, + "light.nopruning": {"BoolFlag", "No"}, + "light.nosyncserve": {"BoolFlag", "No"}, + "dev.gaslimit": {"notABoolFlag", "No"}, + "ethash.cachedir": {"notABoolFlag", "No"}, + "ethash.cachesinmem": {"notABoolFlag", "No"}, + "ethash.cachesondisk": {"notABoolFlag", "No"}, + "ethash.cacheslockmmap": {"BoolFlag", "No"}, + "ethash.dagdir": {"notABoolFlag", "No"}, + "ethash.dagsinmem": {"notABoolFlag", "No"}, + "ethash.dagsondisk": {"notABoolFlag", "No"}, + "ethash.dagslockmmap": {"BoolFlag", "No"}, + "fdlimit": {"notABoolFlag", "No"}, + "signer": {"notABoolFlag", "No"}, + "authrpc.jwtsecret": {"notABoolFlag", "No"}, + "authrpc.addr": {"notABoolFlag", "No"}, + "authrpc.port": {"notABoolFlag", "No"}, + "authrpc.vhosts": {"notABoolFlag", "No"}, + "graphql.corsdomain": {"notABoolFlag", "No"}, + "graphql.vhosts": {"notABoolFlag", "No"}, + "rpc.evmtimeout": {"notABoolFlag", "No"}, + "rpc.allow-unprotected-txs": {"BoolFlag", "No"}, + "jspath": {"notABoolFlag", "No"}, + "exec": {"notABoolFlag", "No"}, + "preload": {"notABoolFlag", "No"}, + "discovery.dns": {"notABoolFlag", "No"}, + "netrestrict": {"notABoolFlag", "No"}, + "nodekey": {"notABoolFlag", "No"}, + "nodekeyhex": {"notABoolFlag", "No"}, + "miner.threads": {"notABoolFlag", "No"}, + "miner.notify": {"notABoolFlag", "No"}, + "miner.notify.full": {"BoolFlag", "No"}, + "miner.recommit": {"notABoolFlag", "No"}, + "miner.noverify": {"BoolFlag", "No"}, + "vmdebug": {"BoolFlag", "No"}, + "fakepow": {"BoolFlag", "No"}, + "nocompaction": {"BoolFlag", "No"}, + "metrics.addr": {"notABoolFlag", "No"}, + "metrics.port": {"notABoolFlag", "No"}, + "whitelist": {"notABoolFlag", "No"}, + "snapshot": {"BoolFlag", "YesF"}, + "bloomfilter.size": {"notABoolFlag", "No"}, + "bor.logs": {"BoolFlag", "No"}, + "override.arrowglacier": {"notABoolFlag", "No"}, + "override.terminaltotaldifficulty": {"notABoolFlag", "No"}, + "verbosity": {"notABoolFlag", "YesFV"}, + "ws.origins": {"notABoolFlag", "YesF"}, +} + +// map from cli flags to corresponding toml tags +var nameTagMap = map[string]string{ + "chain": "chain", + "identity": "identity", + "log-level": "log-level", + "datadir": "datadir", + "keystore": "keystore", + "syncmode": "syncmode", + "gcmode": "gcmode", + "requiredblocks": "requiredblocks", + "0-snapshot": "snapshot", + "url": "bor.heimdall", + "bor.without": "bor.withoutheimdall", + "grpc-address": "bor.heimdallgRPC", + "locals": "txpool.locals", + "nolocals": "txpool.nolocals", + "journal": "txpool.journal", + "rejournal": "txpool.rejournal", + "pricelimit": "txpool.pricelimit", + "pricebump": "txpool.pricebump", + "accountslots": "txpool.accountslots", + "globalslots": "txpool.globalslots", + "accountqueue": "txpool.accountqueue", + "globalqueue": "txpool.globalqueue", + "lifetime": "txpool.lifetime", + "mine": "mine", + "etherbase": "miner.etherbase", + "extradata": "miner.extradata", + "gaslimit": "miner.gaslimit", + "gasprice": "miner.gasprice", + "ethstats": "ethstats", + "blocks": "gpo.blocks", + "percentile": "gpo.percentile", + "maxprice": "gpo.maxprice", + "ignoreprice": "gpo.ignoreprice", + "cache": "cache", + "1-database": "cache.database", + "trie": "cache.trie", + "trie.journal": "cache.journal", + "trie.rejournal": "cache.rejournal", + "gc": "cache.gc", + "1-snapshot": "cache.snapshot", + "noprefetch": "cache.noprefetch", + "preimages": "cache.preimages", + "txlookuplimit": "txlookuplimit", + "gascap": "rpc.gascap", + "txfeecap": "rpc.txfeecap", + "ipcdisable": "ipcdisable", + "ipcpath": "ipcpath", + "1-corsdomain": "http.corsdomain", + "1-vhosts": "http.vhosts", + "2-corsdomain": "ws.corsdomain", + "2-vhosts": "ws.vhosts", + "3-corsdomain": "graphql.corsdomain", + "3-vhosts": "graphql.vhosts", + "1-enabled": "http", + "1-host": "http.addr", + "1-port": "http.port", + "1-prefix": "http.rpcprefix", + "1-api": "http.api", + "2-enabled": "ws", + "2-host": "ws.addr", + "2-port": "ws.port", + "2-prefix": "ws.rpcprefix", + "2-api": "ws.api", + "3-enabled": "graphql", + "bind": "bind", + "0-port": "port", + "bootnodes": "bootnodes", + "maxpeers": "maxpeers", + "maxpendpeers": "maxpendpeers", + "nat": "nat", + "nodiscover": "nodiscover", + "v5disc": "v5disc", + "metrics": "metrics", + "expensive": "metrics.expensive", + "influxdb": "metrics.influxdb", + "endpoint": "metrics.influxdb.endpoint", + "0-database": "metrics.influxdb.database", + "username": "metrics.influxdb.username", + "0-password": "metrics.influxdb.password", + "tags": "metrics.influxdb.tags", + "prometheus-addr": "metrics.prometheus-addr", + "opencollector-endpoint": "metrics.opencollector-endpoint", + "influxdbv2": "metrics.influxdbv2", + "token": "metrics.influxdb.token", + "bucket": "metrics.influxdb.bucket", + "organization": "metrics.influxdb.organization", + "unlock": "unlock", + "1-password": "password", + "allow-insecure-unlock": "allow-insecure-unlock", + "lightkdf": "lightkdf", + "disable-bor-wallet": "disable-bor-wallet", + "addr": "grpc.addr", + "dev": "dev", + "period": "dev.period", + // "config": , +} + +var removedFlagsAndValues = map[string]string{} + +var replacedFlagsMapFlagAndValue = map[string]map[string]map[string]string{ + "networkid": { + "flag": { + "networkid": "chain", + }, + "value": { + "'137'": "mainnet", + "'80001'": "mumbai", + }, + }, + "verbosity": { + "flag": { + "verbosity": "log-level", + }, + "value": { + "0": "SILENT", + "1": "ERROR", + "2": "WARN", + "3": "INFO", + "4": "DEBUG", + "5": "DETAIL", + }, + }, +} + +var replacedFlagsMapFlag = map[string]string{ + "ws.origins": "ws.corsdomain", + // "jsonrpc.corsdomain": "http.corsdomain", + // "jsonrpc.vhosts": "http.vhosts", + // "http.modules": "http.api", + // "ws.modules": "ws.api", + // "snapshot": "no-snapshot", +} + +var currentBoolFlags = []string{ + "snapshot", + "bor.withoutheimdall", + "txpool.nolocals", + "mine", + "cache.noprefetch", + "cache.preimages", + "ipcdisable", + "http", + "ws", + "graphql", + "nodiscover", + "v5disc", + "metrics", + "metrics.expensive", + "metrics.influxdb", + "metrics.influxdbv2", + "allow-insecure-unlock", + "lightkdf", + "disable-bor-wallet", + "dev", +} + +func contains(s []string, str string) (bool, int) { + for ind, v := range s { + if v == str || v == "-"+str || v == "--"+str { + return true, ind + } + } + + return false, -1 +} + +func indexOf(s []string, str string) int { + for k, v := range s { + if v == str || v == "-"+str || v == "--"+str { + return k + } + } + + return -1 +} + +func remove1(s []string, idx int) []string { + removedFlagsAndValues[s[idx]] = "" + return append(s[:idx], s[idx+1:]...) +} + +func remove2(s []string, idx int) []string { + removedFlagsAndValues[s[idx]] = s[idx+1] + return append(s[:idx], s[idx+2:]...) +} + +func checkFlag(allFlags []string, checkFlags []string) []string { + outOfDateFlags := []string{} + + for _, flag := range checkFlags { + t1, _ := contains(allFlags, flag) + if !t1 { + outOfDateFlags = append(outOfDateFlags, flag) + } + } + + return outOfDateFlags +} + +func checkFileExists(path string) bool { + _, err := os.Stat(path) + if errors.Is(err, os.ErrNotExist) { + fmt.Println("WARN: File does not exist", path) + return false + } else { + return true + } +} + +func writeTempStaticJSON(path string) { + data, err := os.ReadFile(path) + if err != nil { + log.Fatal(err) + } + + var conf interface{} + if err := json.Unmarshal(data, &conf); err != nil { + log.Fatal(err) + } + + temparr := []string{} + for _, item := range conf.([]interface{}) { + temparr = append(temparr, item.(string)) + } + + // write to a temp file + err = os.WriteFile("./tempStaticNodes.json", []byte(strings.Join(temparr, "\", \"")), 0600) + if err != nil { + log.Fatal(err) + } +} + +func writeTempStaticTrustedTOML(path string) { + data, err := toml.LoadFile(path) + if err != nil { + log.Fatal(err) + } + + if data.Has("Node.P2P.StaticNodes") { + temparr := []string{} + for _, item := range data.Get("Node.P2P.StaticNodes").([]interface{}) { + temparr = append(temparr, item.(string)) + } + + err = os.WriteFile("./tempStaticNodes.toml", []byte(strings.Join(temparr, "\", \"")), 0600) + if err != nil { + log.Fatal(err) + } + } + + if data.Has("Node.P2P.TrustedNodes") { + temparr := []string{} + for _, item := range data.Get("Node.P2P.TrustedNodes").([]interface{}) { + temparr = append(temparr, item.(string)) + } + + err = os.WriteFile("./tempTrustedNodes.toml", []byte(strings.Join(temparr, "\", \"")), 0600) + if err != nil { + log.Fatal(err) + } + } +} + +func getStaticTrustedNodes(args []string) { + // if config flag is passed, it should be only a .toml file + t1, t2 := contains(args, "config") + // nolint: nestif + if t1 { + path := args[t2+1] + if !checkFileExists(path) { + return + } + + if path[len(path)-4:] == "toml" { + writeTempStaticTrustedTOML(path) + } else { + fmt.Println("only TOML config file is supported through CLI") + } + } else { + path := "~/.bor/data/bor/static-nodes.json" + if !checkFileExists(path) { + return + } + writeTempStaticJSON(path) + } +} + +func getFlagsToCheck(args []string) []string { + flagsToCheck := []string{} + + for _, item := range args { + if strings.HasPrefix(item, "-") { + if item[1] == '-' { + temp := item[2:] + flagsToCheck = append(flagsToCheck, temp) + } else { + temp := item[1:] + flagsToCheck = append(flagsToCheck, temp) + } + } + } + + return flagsToCheck +} + +func getFlagType(flag string) string { + return flagMap[flag][0] +} + +func updateArgsClean(args []string, outOfDateFlags []string) []string { + updatedArgs := []string{} + updatedArgs = append(updatedArgs, args...) + + // iterate through outOfDateFlags and remove the flags from updatedArgs along with their value (if any) + for _, item := range outOfDateFlags { + idx := indexOf(updatedArgs, item) + + if getFlagType(item) == "BoolFlag" { + // remove the element at index idx + updatedArgs = remove1(updatedArgs, idx) + } else { + // remove the element at index idx and idx + 1 + updatedArgs = remove2(updatedArgs, idx) + } + } + + return updatedArgs +} + +func updateArgsAdd(args []string) []string { + for flag, value := range removedFlagsAndValues { + if strings.HasPrefix(flag, "--") { + flag = flag[2:] + } else { + flag = flag[1:] + } + + if flagMap[flag][1] == "YesFV" { + temp := "--" + replacedFlagsMapFlagAndValue[flag]["flag"][flag] + " " + replacedFlagsMapFlagAndValue[flag]["value"][value] + args = append(args, temp) + } else if flagMap[flag][1] == "YesF" { + temp := "--" + replacedFlagsMapFlag[flag] + " " + value + args = append(args, temp) + } + } + + return args +} + +func handleGRPC(args []string, updatedArgs []string) []string { + var newUpdatedArgs []string + + var addr string + + var port string + + newUpdatedArgs = append(newUpdatedArgs, updatedArgs...) + + for i, val := range args { + if strings.Contains(val, "pprof.addr") && strings.Contains(val, "-") { + addr = args[i+1] + } + + if strings.Contains(val, "pprof.port") && strings.Contains(val, "-") { + port = args[i+1] + } + } + + newUpdatedArgs = append(newUpdatedArgs, "--grpc.addr") + newUpdatedArgs = append(newUpdatedArgs, addr+":"+port) + + return newUpdatedArgs +} + +func dumpFlags(args []string) { + err := os.WriteFile("./temp", []byte(strings.Join(args, " ")), 0600) + if err != nil { + fmt.Println("Error in WriteFile") + } else { + fmt.Println("WriteFile Done") + } +} + +// nolint: gocognit +func commentFlags(path string, updatedArgs []string) { + const cache = "[cache]" + + const telemetry = "[telemetry]" + + // snapshot: "[cache]" + cacheFlag := 0 + + // corsdomain, vhosts, enabled, host, api, port, prefix: "[p2p]", " [jsonrpc.http]", " [jsonrpc.ws]", " [jsonrpc.graphql]" + p2pHttpWsGraphFlag := -1 + + // database: "[telemetry]", "[cache]" + databaseFlag := -1 + + // password: "[telemetry]", "[accounts]" + passwordFlag := -1 + + ignoreLineFlag := false + + input, err := os.ReadFile(path) + if err != nil { + log.Fatalln(err) + } + + lines := strings.Split(string(input), "\n") + + var newLines []string + newLines = append(newLines, lines...) + + for i, line := range lines { + if line == cache { + cacheFlag += 1 + } + + if line == "[p2p]" || line == " [jsonrpc.http]" || line == " [jsonrpc.ws]" || line == " [jsonrpc.graphql]" { + p2pHttpWsGraphFlag += 1 + } + + if line == telemetry || line == cache { + databaseFlag += 1 + } + + if line == telemetry || line == "[accounts]" { + passwordFlag += 1 + } + + if line == "[requiredblocks]" || line == " [telemetry.influx.tags]" { + ignoreLineFlag = true + } else if line != "" { + if strings.HasPrefix(strings.Fields(line)[0], "[") { + ignoreLineFlag = false + } + } + + // nolint: nestif + if !(strings.HasPrefix(line, "[") || strings.HasPrefix(line, " [") || strings.HasPrefix(line, " [") || line == "" || ignoreLineFlag) { + flag := strings.Fields(line)[0] + if flag == "snapshot" { + flag = strconv.Itoa(cacheFlag) + "-" + flag + } else if flag == "corsdomain" { + flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag + } else if flag == "vhosts" { + flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag + } else if flag == "enabled" { + flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag + } else if flag == "host" { + flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag + } else if flag == "api" { + flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag + } else if flag == "port" { + flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag + } else if flag == "prefix" { + flag = strconv.Itoa(p2pHttpWsGraphFlag) + "-" + flag + } else if flag == "database" { + flag = strconv.Itoa(databaseFlag) + "-" + flag + } else if flag == "password" { + flag = strconv.Itoa(passwordFlag) + "-" + flag + } + + if flag != "static-nodes" && flag != "trusted-nodes" { + flag = nameTagMap[flag] + + tempFlag := false + + for _, val := range updatedArgs { + if strings.Contains(val, flag) && (strings.Contains(val, "-") || strings.Contains(val, "--")) { + tempFlag = true + } + } + + if !tempFlag || flag == "" { + newLines[i] = "# " + line + } + } + } + } + + output := strings.Join(newLines, "\n") + + err = os.WriteFile(path, []byte(output), 0600) + if err != nil { + log.Fatalln(err) + } +} + +func checkBoolFlags(val string) bool { + returnFlag := false + + if strings.Contains(val, "=") { + val = strings.Split(val, "=")[0] + } + + for _, flag := range currentBoolFlags { + if val == "-"+flag || val == "--"+flag { + returnFlag = true + } + } + + return returnFlag +} + +func beautifyArgs(args []string) ([]string, []string) { + newArgs := []string{} + + ignoreForNow := []string{} + + temp := []string{} + + for _, val := range args { + // nolint: nestif + if !(checkBoolFlags(val)) { + if strings.HasPrefix(val, "-") { + if strings.Contains(val, "=") { + temparr := strings.Split(val, "=") + newArgs = append(newArgs, temparr...) + } else { + newArgs = append(newArgs, val) + } + } else { + newArgs = append(newArgs, val) + } + } else { + ignoreForNow = append(ignoreForNow, val) + } + } + + for j, val := range newArgs { + if val == "-unlock" || val == "--unlock" { + temp = append(temp, "--miner.etherbase") + temp = append(temp, newArgs[j+1]) + } + } + + newArgs = append(newArgs, temp...) + + return newArgs, ignoreForNow +} + +func main() { + const notYet = "notYet" + + temp := os.Args[1] + args := os.Args[2:] + + args, ignoreForNow := beautifyArgs(args) + + c := server.Command{} + flags := c.Flags() + allFlags := flags.GetAllFlags() + flagsToCheck := getFlagsToCheck(args) + + if temp == notYet { + getStaticTrustedNodes(args) + } + + outOfDateFlags := checkFlag(allFlags, flagsToCheck) + updatedArgs := updateArgsClean(args, outOfDateFlags) + updatedArgs = updateArgsAdd(updatedArgs) + updatedArgs = handleGRPC(args, updatedArgs) + + if temp == notYet { + updatedArgs = append(updatedArgs, ignoreForNow...) + dumpFlags(updatedArgs) + } + + if temp != notYet { + updatedArgs = append(updatedArgs, ignoreForNow...) + commentFlags(temp, updatedArgs) + } +} diff --git a/scripts/getconfig.sh b/scripts/getconfig.sh new file mode 100755 index 0000000000..906a52b5c1 --- /dev/null +++ b/scripts/getconfig.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env sh + +# Instructions: +# Execute `./getconfig.sh`, and follow the instructions displayed on the terminal +# The `config.toml` file will be created in the same directory as start.sh +# It is recommended to check the flags generated in config.toml + + +read -p "* Path to start.sh: " startPath +# check if start.sh is present +if [[ ! -f $startPath ]] +then + echo "Error: start.sh do not exist." + exit 1 +fi +read -p "* Your Address (press Enter, if not required): " ADD +read -p "* Path to bor directory (default is set to '/var/lib/bor') (no forward slash at the end please!): " BORDIR +if [[ "$BORDIR" == "" ]] + then + BORDIR="/var/lib/bor" +fi +DATADIR=$BORDIR/data +echo "\nThank you, your inputs are:" +echo "Path to start.sh: "$startPath +echo "Address: "$ADD +echo "BORDIR: "$BORDIR +echo "DATADIR: "$DATADIR + +confPath=${startPath%start.sh}"config.toml" +echo "Path to the config file: "$confPath +# check if config.toml is present +if [[ -f $confPath ]] +then + echo "WARN: config.toml exists, data will be overwritten." +fi + +count=0 +# -n "$line": just prevents the loop from being skipped if the last line +# ends with end-of-file rather than a newline character +while read line || [ -n "$line" ]; do + # check if the current line is the command used to starting bor + if [[ $line == bor* ]]; then + count=$((count+1)) + # get the flags by removing everything upto the first `-` + # later this `-` can be changed to `server` + flags="-"${line#*-} + fi +done < $startPath + +# check the number of bor commands, exit if not equal to 1 +if [ ! "$count" -eq 1 ]; then + echo "ERROR: More than one bor command" + exit 1 +fi + +# DONOT DELETE THE BELOW 2 LINES (hint: {137 vs '137'}, {* vs '*'}) +# command="go run getconfig.go "$flags +# bash -c "$command" +go run getconfig.go "notYet" $flags + +# read the flags from `./temp` +dumpconfigflags=$(head -1 ./temp) + +# Removing all occurance of `$` +tempflags=${dumpconfigflags//$/} + +# using '@' as the path contains '/' +tempflags=$(echo $tempflags | sed "s@ADDRESS@$ADD@g") +tempflags=$(echo $tempflags | sed "s@BOR_DIR@$BORDIR@g") +tempflags=$(echo $tempflags | sed "s@DATA_DIR@$DATADIR@g") + +# run the dumpconfig command with the flags from `./temp` +command="bor dumpconfig "$tempflags" > "$confPath +bash -c "$command" + +rm ./temp + +if [[ -f ./tempStaticNodes.json ]] +then + echo "JSON StaticNodes found" + staticnodesjson=$(head -1 ./tempStaticNodes.json) + sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodesjson}\"\]%" $confPath + rm ./tempStaticNodes.json +elif [[ -f ./tempStaticNodes.toml ]] +then + echo "TOML StaticNodes found" + staticnodestoml=$(head -1 ./tempStaticNodes.toml) + sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodestoml}\"\]%" $confPath + rm ./tempStaticNodes.toml +else + echo "nither JSON nor TOML StaticNodes found" +fi + +if [[ -f ./tempTrustedNodes.toml ]] +then + echo "TOML TrustedNodes found" + trustednodestoml=$(head -1 ./tempTrustedNodes.toml) + sed -i '' "s%trusted-nodes = \[\]%trusted-nodes = \[\"${trustednodestoml}\"\]%" $confPath + rm ./tempTrustedNodes.toml +else + echo "nither JSON nor TOML TrustedNodes found" +fi + +# comment flags in $configPath that were not passed through $startPath +go run getconfig.go $confPath $flags + +exit 0 \ No newline at end of file From 6baf1845170e31a22a6202c6ab6a8c2b14424fb2 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Wed, 7 Sep 2022 13:35:22 +0400 Subject: [PATCH 2/6] changed 'requiredblocks' flag back to 'eth.requiredblocks' --- builder/files/config.toml | 2 +- docs/config.md | 2 ++ internal/cli/server/command_test.go | 2 +- internal/cli/server/config.go | 2 +- internal/cli/server/config_test.go | 3 --- internal/cli/server/flags.go | 2 +- internal/cli/server/testdata/test.hcl | 4 ---- internal/cli/server/testdata/test.json | 3 --- internal/cli/server/testdata/test.toml | 2 +- scripts/getconfig.go | 4 ++-- scripts/getconfig.sh | 4 +++- 11 files changed, 12 insertions(+), 18 deletions(-) diff --git a/builder/files/config.toml b/builder/files/config.toml index d8503e4351..84c3327bbf 100644 --- a/builder/files/config.toml +++ b/builder/files/config.toml @@ -12,7 +12,7 @@ syncmode = "full" # snapshot = true # ethstats = "" -# [requiredblocks] +# ["eth.requiredblocks"] [p2p] # maxpeers = 1 diff --git a/docs/config.md b/docs/config.md index 196a0bf388..aebd9e12b9 100644 --- a/docs/config.md +++ b/docs/config.md @@ -19,6 +19,8 @@ gcmode = "full" snapshot = true ethstats = "" +["eth.requiredblocks"] + [p2p] maxpeers = 30 maxpendpeers = 50 diff --git a/internal/cli/server/command_test.go b/internal/cli/server/command_test.go index 9006559d0f..ab28de5ee6 100644 --- a/internal/cli/server/command_test.go +++ b/internal/cli/server/command_test.go @@ -24,7 +24,7 @@ func TestFlags(t *testing.T) { "--dev.period", "2", "--datadir", "./data", "--maxpeers", "30", - "--requiredblocks", "a=b", + "--eth.requiredblocks", "a=b", "--http.api", "eth,web3,bor", } err := c.extractFlags(args) diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 7dcc986c01..1e953dbd64 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -45,7 +45,7 @@ type Config struct { Identity string `hcl:"identity,optional" toml:"identity,optional"` // RequiredBlocks is a list of required (block number, hash) pairs to accept - RequiredBlocks map[string]string `hcl:"requiredblocks,optional" toml:"requiredblocks,optional"` + RequiredBlocks map[string]string `hcl:"eth.requiredblocks,optional" toml:"eth.requiredblocks,optional"` // LogLevel is the level of the logs to put out LogLevel string `hcl:"log-level,optional" toml:"log-level,optional"` diff --git a/internal/cli/server/config_test.go b/internal/cli/server/config_test.go index bf7787ac2e..5f3118996b 100644 --- a/internal/cli/server/config_test.go +++ b/internal/cli/server/config_test.go @@ -108,9 +108,6 @@ func TestConfigLoadFile(t *testing.T) { assert.Equal(t, config, &Config{ DataDir: "./data", - RequiredBlocks: map[string]string{ - "a": "b", - }, P2P: &P2PConfig{ MaxPeers: 30, }, diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index 327b0df338..a1c08f4888 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -56,7 +56,7 @@ func (c *Command) Flags() *flagset.Flagset { Default: c.cliConfig.GcMode, }) f.MapStringFlag(&flagset.MapStringFlag{ - Name: "requiredblocks", + Name: "eth.requiredblocks", Usage: "Comma separated block number-to-hash mappings to enforce (=)", Value: &c.cliConfig.RequiredBlocks, }) diff --git a/internal/cli/server/testdata/test.hcl b/internal/cli/server/testdata/test.hcl index 208fdc51c1..44138970fc 100644 --- a/internal/cli/server/testdata/test.hcl +++ b/internal/cli/server/testdata/test.hcl @@ -1,9 +1,5 @@ datadir = "./data" -requiredblocks = { - a = "b" -} - p2p { maxpeers = 30 } diff --git a/internal/cli/server/testdata/test.json b/internal/cli/server/testdata/test.json index 467835e755..a08e5aceb1 100644 --- a/internal/cli/server/testdata/test.json +++ b/internal/cli/server/testdata/test.json @@ -1,8 +1,5 @@ { "datadir": "./data", - "requiredblocks": { - "a": "b" - }, "p2p": { "maxpeers": 30 }, diff --git a/internal/cli/server/testdata/test.toml b/internal/cli/server/testdata/test.toml index ecc313b5b5..24e1dcafcb 100644 --- a/internal/cli/server/testdata/test.toml +++ b/internal/cli/server/testdata/test.toml @@ -1,6 +1,6 @@ datadir = "./data" -[requiredblocks] +["eth.requiredblocks"] a = "b" [p2p] diff --git a/scripts/getconfig.go b/scripts/getconfig.go index db756f7552..f8e9d8566d 100644 --- a/scripts/getconfig.go +++ b/scripts/getconfig.go @@ -107,7 +107,7 @@ var nameTagMap = map[string]string{ "keystore": "keystore", "syncmode": "syncmode", "gcmode": "gcmode", - "requiredblocks": "requiredblocks", + "eth.requiredblocks": "eth.requiredblocks", "0-snapshot": "snapshot", "url": "bor.heimdall", "bor.without": "bor.withoutheimdall", @@ -530,7 +530,7 @@ func commentFlags(path string, updatedArgs []string) { passwordFlag += 1 } - if line == "[requiredblocks]" || line == " [telemetry.influx.tags]" { + if line == "[\"eth.requiredblocks\"]" || line == " [telemetry.influx.tags]" { ignoreLineFlag = true } else if line != "" { if strings.HasPrefix(strings.Fields(line)[0], "[") { diff --git a/scripts/getconfig.sh b/scripts/getconfig.sh index 906a52b5c1..4de91a2ee6 100755 --- a/scripts/getconfig.sh +++ b/scripts/getconfig.sh @@ -2,7 +2,7 @@ # Instructions: # Execute `./getconfig.sh`, and follow the instructions displayed on the terminal -# The `config.toml` file will be created in the same directory as start.sh +# The `*config.toml` file will be created in the same directory as start.sh # It is recommended to check the flags generated in config.toml @@ -67,6 +67,8 @@ tempflags=${dumpconfigflags//$/} # using '@' as the path contains '/' tempflags=$(echo $tempflags | sed "s@ADDRESS@$ADD@g") tempflags=$(echo $tempflags | sed "s@BOR_DIR@$BORDIR@g") +tempflags=$(echo $tempflags | sed "s@BOR_HOME@$BORDIR@g") +tempflags=$(echo $tempflags | sed "s@BOR_DATA_DIR@$DATADIR@g") tempflags=$(echo $tempflags | sed "s@DATA_DIR@$DATADIR@g") # run the dumpconfig command with the flags from `./temp` From 181fc20f077e539a7feb71bd3f7ef6bd38214d56 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Thu, 22 Sep 2022 16:36:31 +0530 Subject: [PATCH 3/6] updated script --- scripts/getconfig.go | 2 + scripts/getconfig.sh | 180 ++++++++++++++++++++++++++++++++----------- 2 files changed, 135 insertions(+), 47 deletions(-) diff --git a/scripts/getconfig.go b/scripts/getconfig.go index f8e9d8566d..03609354cb 100644 --- a/scripts/getconfig.go +++ b/scripts/getconfig.go @@ -206,7 +206,9 @@ var replacedFlagsMapFlagAndValue = map[string]map[string]map[string]string{ }, "value": { "'137'": "mainnet", + "137": "mainnet", "'80001'": "mumbai", + "80001": "mumbai", }, }, "verbosity": { diff --git a/scripts/getconfig.sh b/scripts/getconfig.sh index 4de91a2ee6..c17e04f43b 100755 --- a/scripts/getconfig.sh +++ b/scripts/getconfig.sh @@ -2,7 +2,7 @@ # Instructions: # Execute `./getconfig.sh`, and follow the instructions displayed on the terminal -# The `*config.toml` file will be created in the same directory as start.sh +# The `*-config.toml` file will be created in the same directory as start.sh # It is recommended to check the flags generated in config.toml @@ -14,19 +14,12 @@ then exit 1 fi read -p "* Your Address (press Enter, if not required): " ADD -read -p "* Path to bor directory (default is set to '/var/lib/bor') (no forward slash at the end please!): " BORDIR -if [[ "$BORDIR" == "" ]] - then - BORDIR="/var/lib/bor" -fi -DATADIR=$BORDIR/data + echo "\nThank you, your inputs are:" echo "Path to start.sh: "$startPath echo "Address: "$ADD -echo "BORDIR: "$BORDIR -echo "DATADIR: "$DATADIR -confPath=${startPath%start.sh}"config.toml" +confPath=${startPath%.sh}"-config.toml" echo "Path to the config file: "$confPath # check if config.toml is present if [[ -f $confPath ]] @@ -34,45 +27,20 @@ then echo "WARN: config.toml exists, data will be overwritten." fi -count=0 -# -n "$line": just prevents the loop from being skipped if the last line -# ends with end-of-file rather than a newline character -while read line || [ -n "$line" ]; do - # check if the current line is the command used to starting bor - if [[ $line == bor* ]]; then - count=$((count+1)) - # get the flags by removing everything upto the first `-` - # later this `-` can be changed to `server` - flags="-"${line#*-} - fi -done < $startPath - -# check the number of bor commands, exit if not equal to 1 -if [ ! "$count" -eq 1 ]; then - echo "ERROR: More than one bor command" - exit 1 -fi +# SHA1 hash of `tempStart` -> `3305fe263dd4a999d58f96deb064e21bb70123d9` +sed 's/bor --/go run getconfig.go notYet --/g' $startPath > 3305fe263dd4a999d58f96deb064e21bb70123d9.sh +chmod +x 3305fe263dd4a999d58f96deb064e21bb70123d9.sh +./3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD +rm 3305fe263dd4a999d58f96deb064e21bb70123d9.sh -# DONOT DELETE THE BELOW 2 LINES (hint: {137 vs '137'}, {* vs '*'}) -# command="go run getconfig.go "$flags -# bash -c "$command" -go run getconfig.go "notYet" $flags + +sed -i '' "s%*%'*'%g" ./temp # read the flags from `./temp` dumpconfigflags=$(head -1 ./temp) -# Removing all occurance of `$` -tempflags=${dumpconfigflags//$/} - -# using '@' as the path contains '/' -tempflags=$(echo $tempflags | sed "s@ADDRESS@$ADD@g") -tempflags=$(echo $tempflags | sed "s@BOR_DIR@$BORDIR@g") -tempflags=$(echo $tempflags | sed "s@BOR_HOME@$BORDIR@g") -tempflags=$(echo $tempflags | sed "s@BOR_DATA_DIR@$DATADIR@g") -tempflags=$(echo $tempflags | sed "s@DATA_DIR@$DATADIR@g") - # run the dumpconfig command with the flags from `./temp` -command="bor dumpconfig "$tempflags" > "$confPath +command="bor dumpconfig "$dumpconfigflags" > "$confPath bash -c "$command" rm ./temp @@ -90,7 +58,7 @@ then sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodestoml}\"\]%" $confPath rm ./tempStaticNodes.toml else - echo "nither JSON nor TOML StaticNodes found" + echo "neither JSON nor TOML StaticNodes found" fi if [[ -f ./tempTrustedNodes.toml ]] @@ -100,10 +68,128 @@ then sed -i '' "s%trusted-nodes = \[\]%trusted-nodes = \[\"${trustednodestoml}\"\]%" $confPath rm ./tempTrustedNodes.toml else - echo "nither JSON nor TOML TrustedNodes found" + echo "neither JSON nor TOML TrustedNodes found" fi # comment flags in $configPath that were not passed through $startPath -go run getconfig.go $confPath $flags +# SHA1 hash of `tempStart` -> `3305fe263dd4a999d58f96deb064e21bb70123d9` +sed "s%bor --%go run getconfig.go ${confPath} --%" $startPath > 3305fe263dd4a999d58f96deb064e21bb70123d9.sh +chmod +x 3305fe263dd4a999d58f96deb064e21bb70123d9.sh +./3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD +rm 3305fe263dd4a999d58f96deb064e21bb70123d9.sh + +exit 0 + + +# #################################################### +# +# #################################################### + +# #!/usr/bin/env sh + +# # Instructions: +# # Execute `./getconfig.sh`, and follow the instructions displayed on the terminal +# # The `*-config.toml` file will be created in the same directory as start.sh +# # It is recommended to check the flags generated in config.toml + + +# read -p "* Path to start.sh: " startPath +# # check if start.sh is present +# if [[ ! -f $startPath ]] +# then +# echo "Error: start.sh do not exist." +# exit 1 +# fi +# read -p "* Your Address (press Enter, if not required): " ADD +# read -p "* Path to bor directory (default is set to '/var/lib/bor') (no forward slash at the end please!): " BORDIR +# if [[ "$BORDIR" == "" ]] +# then +# BORDIR="/var/lib/bor" +# fi +# DATADIR=$BORDIR/data +# echo "\nThank you, your inputs are:" +# echo "Path to start.sh: "$startPath +# echo "Address: "$ADD +# echo "BORDIR: "$BORDIR +# echo "DATADIR: "$DATADIR + +# confPath=${startPath%.sh}"-config.toml" +# echo "Path to the config file: "$confPath +# # check if config.toml is present +# if [[ -f $confPath ]] +# then +# echo "WARN: config.toml exists, data will be overwritten." +# fi + +# count=0 +# # -n "$line": just prevents the loop from being skipped if the last line +# # ends with end-of-file rather than a newline character +# while read line || [ -n "$line" ]; do +# # check if the current line is the command used to starting bor +# if [[ $line == bor* ]]; then +# count=$((count+1)) +# # get the flags by removing everything upto the first `-` +# flags="-"${line#*-} +# fi +# done < $startPath + +# # check the number of bor commands, exit if not equal to 1 +# if [ ! "$count" -eq 1 ]; then +# echo "ERROR: More than one bor command" +# exit 1 +# fi + +# # DONOT DELETE THE BELOW 2 LINES (hint: {137 vs '137'}, {* vs '*'}) +# # command="go run getconfig.go "$flags +# # bash -c "$command" +# go run getconfig.go "notYet" $flags + +# # read the flags from `./temp` +# dumpconfigflags=$(head -1 ./temp) + +# # Removing all occurance of `$` +# tempflags=${dumpconfigflags//$/} + +# # using '@' as the path contains '/' +# tempflags=$(echo $tempflags | sed "s@ADDRESS@$ADD@g") +# tempflags=$(echo $tempflags | sed "s@BOR_DIR@$BORDIR@g") +# tempflags=$(echo $tempflags | sed "s@BOR_HOME@$BORDIR@g") +# tempflags=$(echo $tempflags | sed "s@BOR_DATA_DIR@$DATADIR@g") +# tempflags=$(echo $tempflags | sed "s@DATA_DIR@$DATADIR@g") + +# # run the dumpconfig command with the flags from `./temp` +# command="bor dumpconfig "$tempflags" > "$confPath +# bash -c "$command" -exit 0 \ No newline at end of file +# rm ./temp + +# if [[ -f ./tempStaticNodes.json ]] +# then +# echo "JSON StaticNodes found" +# staticnodesjson=$(head -1 ./tempStaticNodes.json) +# sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodesjson}\"\]%" $confPath +# rm ./tempStaticNodes.json +# elif [[ -f ./tempStaticNodes.toml ]] +# then +# echo "TOML StaticNodes found" +# staticnodestoml=$(head -1 ./tempStaticNodes.toml) +# sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodestoml}\"\]%" $confPath +# rm ./tempStaticNodes.toml +# else +# echo "neither JSON nor TOML StaticNodes found" +# fi + +# if [[ -f ./tempTrustedNodes.toml ]] +# then +# echo "TOML TrustedNodes found" +# trustednodestoml=$(head -1 ./tempTrustedNodes.toml) +# sed -i '' "s%trusted-nodes = \[\]%trusted-nodes = \[\"${trustednodestoml}\"\]%" $confPath +# rm ./tempTrustedNodes.toml +# else +# echo "neither JSON nor TOML TrustedNodes found" +# fi + +# # comment flags in $configPath that were not passed through $startPath +# go run getconfig.go $confPath $flags + +# exit 0 \ No newline at end of file From 97ed37c33ff25eff0aa333e3ac5cb822ebdb10df Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Wed, 7 Sep 2022 13:35:22 +0400 Subject: [PATCH 4/6] changed 'requiredblocks' flag back to 'eth.requiredblocks' From 41054a55de45778ca31affbfd370395d34333b84 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Wed, 7 Sep 2022 16:21:55 +0400 Subject: [PATCH 5/6] updated tests, and removed requiredblocks from json and hcl From 4bc8c551462e375d6b063008e5abdaf2bf1887c9 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Thu, 22 Sep 2022 22:27:30 +0530 Subject: [PATCH 6/6] addressed comments --- scripts/getconfig.go | 6 -- scripts/getconfig.sh | 138 +++++-------------------------------------- 2 files changed, 15 insertions(+), 129 deletions(-) diff --git a/scripts/getconfig.go b/scripts/getconfig.go index 03609354cb..9b5e6bf2b3 100644 --- a/scripts/getconfig.go +++ b/scripts/getconfig.go @@ -194,7 +194,6 @@ var nameTagMap = map[string]string{ "addr": "grpc.addr", "dev": "dev", "period": "dev.period", - // "config": , } var removedFlagsAndValues = map[string]string{} @@ -228,11 +227,6 @@ var replacedFlagsMapFlagAndValue = map[string]map[string]map[string]string{ var replacedFlagsMapFlag = map[string]string{ "ws.origins": "ws.corsdomain", - // "jsonrpc.corsdomain": "http.corsdomain", - // "jsonrpc.vhosts": "http.vhosts", - // "http.modules": "http.api", - // "ws.modules": "ws.api", - // "snapshot": "no-snapshot", } var currentBoolFlags = []string{ diff --git a/scripts/getconfig.sh b/scripts/getconfig.sh index c17e04f43b..26d5d0138c 100755 --- a/scripts/getconfig.sh +++ b/scripts/getconfig.sh @@ -13,7 +13,7 @@ then echo "Error: start.sh do not exist." exit 1 fi -read -p "* Your Address (press Enter, if not required): " ADD +read -p "* Your validator address (e.g. 0xca67a8D767e45056DC92384b488E9Af654d78DE2), or press Enter to skip if running a sentry node: " ADD echo "\nThank you, your inputs are:" echo "Path to start.sh: "$startPath @@ -27,11 +27,17 @@ then echo "WARN: config.toml exists, data will be overwritten." fi +tmpDir="$(mktemp -d -t ./temp-dir-XXXXXXXXXXX || oops "Can't create temporary directory")" +cleanup() { + rm -rf "$tmpDir" +} +trap cleanup EXIT INT QUIT TERM + # SHA1 hash of `tempStart` -> `3305fe263dd4a999d58f96deb064e21bb70123d9` -sed 's/bor --/go run getconfig.go notYet --/g' $startPath > 3305fe263dd4a999d58f96deb064e21bb70123d9.sh -chmod +x 3305fe263dd4a999d58f96deb064e21bb70123d9.sh -./3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD -rm 3305fe263dd4a999d58f96deb064e21bb70123d9.sh +sed 's/bor --/go run getconfig.go notYet --/g' $startPath > $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh +chmod +x $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh +$tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD +rm $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh sed -i '' "s%*%'*'%g" ./temp @@ -73,123 +79,9 @@ fi # comment flags in $configPath that were not passed through $startPath # SHA1 hash of `tempStart` -> `3305fe263dd4a999d58f96deb064e21bb70123d9` -sed "s%bor --%go run getconfig.go ${confPath} --%" $startPath > 3305fe263dd4a999d58f96deb064e21bb70123d9.sh -chmod +x 3305fe263dd4a999d58f96deb064e21bb70123d9.sh -./3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD -rm 3305fe263dd4a999d58f96deb064e21bb70123d9.sh +sed "s%bor --%go run getconfig.go ${confPath} --%" $startPath > $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh +chmod +x $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh +$tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh $ADD +rm $tmpDir/3305fe263dd4a999d58f96deb064e21bb70123d9.sh exit 0 - - -# #################################################### -# -# #################################################### - -# #!/usr/bin/env sh - -# # Instructions: -# # Execute `./getconfig.sh`, and follow the instructions displayed on the terminal -# # The `*-config.toml` file will be created in the same directory as start.sh -# # It is recommended to check the flags generated in config.toml - - -# read -p "* Path to start.sh: " startPath -# # check if start.sh is present -# if [[ ! -f $startPath ]] -# then -# echo "Error: start.sh do not exist." -# exit 1 -# fi -# read -p "* Your Address (press Enter, if not required): " ADD -# read -p "* Path to bor directory (default is set to '/var/lib/bor') (no forward slash at the end please!): " BORDIR -# if [[ "$BORDIR" == "" ]] -# then -# BORDIR="/var/lib/bor" -# fi -# DATADIR=$BORDIR/data -# echo "\nThank you, your inputs are:" -# echo "Path to start.sh: "$startPath -# echo "Address: "$ADD -# echo "BORDIR: "$BORDIR -# echo "DATADIR: "$DATADIR - -# confPath=${startPath%.sh}"-config.toml" -# echo "Path to the config file: "$confPath -# # check if config.toml is present -# if [[ -f $confPath ]] -# then -# echo "WARN: config.toml exists, data will be overwritten." -# fi - -# count=0 -# # -n "$line": just prevents the loop from being skipped if the last line -# # ends with end-of-file rather than a newline character -# while read line || [ -n "$line" ]; do -# # check if the current line is the command used to starting bor -# if [[ $line == bor* ]]; then -# count=$((count+1)) -# # get the flags by removing everything upto the first `-` -# flags="-"${line#*-} -# fi -# done < $startPath - -# # check the number of bor commands, exit if not equal to 1 -# if [ ! "$count" -eq 1 ]; then -# echo "ERROR: More than one bor command" -# exit 1 -# fi - -# # DONOT DELETE THE BELOW 2 LINES (hint: {137 vs '137'}, {* vs '*'}) -# # command="go run getconfig.go "$flags -# # bash -c "$command" -# go run getconfig.go "notYet" $flags - -# # read the flags from `./temp` -# dumpconfigflags=$(head -1 ./temp) - -# # Removing all occurance of `$` -# tempflags=${dumpconfigflags//$/} - -# # using '@' as the path contains '/' -# tempflags=$(echo $tempflags | sed "s@ADDRESS@$ADD@g") -# tempflags=$(echo $tempflags | sed "s@BOR_DIR@$BORDIR@g") -# tempflags=$(echo $tempflags | sed "s@BOR_HOME@$BORDIR@g") -# tempflags=$(echo $tempflags | sed "s@BOR_DATA_DIR@$DATADIR@g") -# tempflags=$(echo $tempflags | sed "s@DATA_DIR@$DATADIR@g") - -# # run the dumpconfig command with the flags from `./temp` -# command="bor dumpconfig "$tempflags" > "$confPath -# bash -c "$command" - -# rm ./temp - -# if [[ -f ./tempStaticNodes.json ]] -# then -# echo "JSON StaticNodes found" -# staticnodesjson=$(head -1 ./tempStaticNodes.json) -# sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodesjson}\"\]%" $confPath -# rm ./tempStaticNodes.json -# elif [[ -f ./tempStaticNodes.toml ]] -# then -# echo "TOML StaticNodes found" -# staticnodestoml=$(head -1 ./tempStaticNodes.toml) -# sed -i '' "s%static-nodes = \[\]%static-nodes = \[\"${staticnodestoml}\"\]%" $confPath -# rm ./tempStaticNodes.toml -# else -# echo "neither JSON nor TOML StaticNodes found" -# fi - -# if [[ -f ./tempTrustedNodes.toml ]] -# then -# echo "TOML TrustedNodes found" -# trustednodestoml=$(head -1 ./tempTrustedNodes.toml) -# sed -i '' "s%trusted-nodes = \[\]%trusted-nodes = \[\"${trustednodestoml}\"\]%" $confPath -# rm ./tempTrustedNodes.toml -# else -# echo "neither JSON nor TOML TrustedNodes found" -# fi - -# # comment flags in $configPath that were not passed through $startPath -# go run getconfig.go $confPath $flags - -# exit 0 \ No newline at end of file