add overwrite flag for captplanet, hc, and gw setup (#209)
* add overwrite flag for captplanet setup * add overwrite flag for heavy client and gateway
This commit is contained in:
parent
fb77287325
commit
889afd0ae5
@ -23,6 +23,7 @@ type Config struct {
|
||||
BasePath string `help:"base path for captain planet storage" default:"$CONFDIR"`
|
||||
ListenHost string `help:"the host for providers to listen on" default:"127.0.0.1"`
|
||||
StartingPort int `help:"all providers will listen on ports consecutively starting with this one" default:"7777"`
|
||||
Overwrite bool `help:"whether to overwrite pre-existing configuration files" default:"false"`
|
||||
}
|
||||
|
||||
var (
|
||||
@ -42,13 +43,19 @@ func init() {
|
||||
}
|
||||
|
||||
func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
_, err = os.Stat(setupCfg.BasePath)
|
||||
if !setupCfg.Overwrite && err == nil {
|
||||
fmt.Println("A captplanet configuration already exists. Rerun with --overwrite")
|
||||
return nil
|
||||
}
|
||||
|
||||
hcPath := filepath.Join(setupCfg.BasePath, "hc")
|
||||
err = os.MkdirAll(hcPath, 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
identPath := filepath.Join(hcPath, "ident")
|
||||
_, err = peertls.NewTLSFileOptions(identPath, identPath, true, false)
|
||||
_, err = peertls.NewTLSFileOptions(identPath, identPath, true, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -60,7 +67,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
return err
|
||||
}
|
||||
identPath = filepath.Join(farmerPath, "ident")
|
||||
_, err = peertls.NewTLSFileOptions(identPath, identPath, true, false)
|
||||
_, err = peertls.NewTLSFileOptions(identPath, identPath, true, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -72,7 +79,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
return err
|
||||
}
|
||||
identPath = filepath.Join(gwPath, "ident")
|
||||
_, err = peertls.NewTLSFileOptions(identPath, identPath, true, false)
|
||||
_, err = peertls.NewTLSFileOptions(identPath, identPath, true, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -33,7 +34,8 @@ var (
|
||||
|
||||
runCfg miniogw.Config
|
||||
setupCfg struct {
|
||||
BasePath string `default:"$CONFDIR" help:"base path for setup"`
|
||||
BasePath string `default:"$CONFDIR" help:"base path for setup"`
|
||||
Overwrite bool `default:"false" help:"whether to overwrite pre-existing configuration files"`
|
||||
}
|
||||
|
||||
defaultConfDir = "$HOME/.storj/gw"
|
||||
@ -51,13 +53,19 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
_, err = os.Stat(setupCfg.BasePath)
|
||||
if !setupCfg.Overwrite && err == nil {
|
||||
fmt.Println("A gw configuration already exists. Rerun with --overwrite")
|
||||
return nil
|
||||
}
|
||||
|
||||
err = os.MkdirAll(setupCfg.BasePath, 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identityPath := filepath.Join(setupCfg.BasePath, "identity")
|
||||
_, err = peertls.NewTLSFileOptions(identityPath, identityPath, true, false)
|
||||
_, err = peertls.NewTLSFileOptions(identityPath, identityPath, true, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -41,7 +42,8 @@ var (
|
||||
Overlay overlay.Config
|
||||
}
|
||||
setupCfg struct {
|
||||
BasePath string `default:"$CONFDIR" help:"base path for setup"`
|
||||
BasePath string `default:"$CONFDIR" help:"base path for setup"`
|
||||
Overwrite bool `default:"false" help:"whether to overwrite pre-existing configuration files"`
|
||||
}
|
||||
|
||||
defaultConfDir = "$HOME/.storj/hc"
|
||||
@ -60,13 +62,19 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
_, err = os.Stat(setupCfg.BasePath)
|
||||
if !setupCfg.Overwrite && err == nil {
|
||||
fmt.Println("An hc configuration already exists. Rerun with --overwrite")
|
||||
return nil
|
||||
}
|
||||
|
||||
err = os.MkdirAll(setupCfg.BasePath, 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identityPath := filepath.Join(setupCfg.BasePath, "identity")
|
||||
_, err = peertls.NewTLSFileOptions(identityPath, identityPath, true, false)
|
||||
_, err = peertls.NewTLSFileOptions(identityPath, identityPath, true, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user