Skip to content

Commit

Permalink
fix(cmd.Setup): added back env var to supply IPFS config on setup
Browse files Browse the repository at this point in the history
A little while back we lost the capacity to supply IPFS config files,
this adds it back, using the "@" file pattern from other setup options.
  • Loading branch information
b5 committed Mar 5, 2018
1 parent 51d36d2 commit fb19615
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
setupOverwrite bool
setupIPFS bool
setupPeername string
setupIPFSConfigFile string
setupIPFSConfigData string
setupConfigData string
setupProfileData string
)
Expand Down Expand Up @@ -54,8 +54,9 @@ overwrite this info.`,
fmt.Printf("setting up qri repo at: %s\n", QriRepoPath)

envVars := map[string]*string{
"QRI_SETUP_CONFIG_DATA": &setupConfigData,
"QRI_SETUP_PROFILE_DATA": &setupProfileData,
"QRI_SETUP_CONFIG_DATA": &setupConfigData,
"QRI_SETUP_PROFILE_DATA": &setupProfileData,
"QRI_SETUP_IPFS_CONFIG_DATA": &setupIPFSConfigData,
}
mapEnvVars(envVars)

Expand Down Expand Up @@ -93,7 +94,24 @@ overwrite this info.`,
ExitIfErr(err)

if setupIPFS {
err = ipfs.InitRepo(IpfsFsPath, setupIPFSConfigFile)

tmpIPFSConfigPath := ""
if setupIPFSConfigData != "" {
err = readAtFile(&setupIPFSConfigData)
ExitIfErr(err)

// TODO - remove this temp file & instead adjust ipfs.InitRepo to accept an io.Reader
tmpIPFSConfigPath = filepath.Join(os.TempDir(), "ipfs_init_config")

err = ioutil.WriteFile(tmpIPFSConfigPath, []byte(setupIPFSConfigData), os.ModePerm)
ExitIfErr(err)

defer func() {
os.Remove(tmpIPFSConfigPath)
}()
}

err = ipfs.InitRepo(IpfsFsPath, tmpIPFSConfigPath)
if err != nil && strings.Contains(err.Error(), "already") {
err = nil
}
Expand Down Expand Up @@ -133,7 +151,7 @@ func init() {
setupCmd.Flags().BoolVarP(&setupOverwrite, "overwrite", "", false, "overwrite repo if one exists")
setupCmd.Flags().BoolVarP(&setupIPFS, "init-ipfs", "", true, "initialize an IPFS repo if one isn't present")
setupCmd.Flags().StringVarP(&setupPeername, "peername", "", "", "choose your desired peername")
setupCmd.Flags().StringVarP(&setupIPFSConfigFile, "ipfs-config", "", "", "config file for initialization")
setupCmd.Flags().StringVarP(&setupIPFSConfigData, "ipfs-config", "", "", "json-encoded configuration data, specify a filepath with '@' prefix")
setupCmd.Flags().StringVarP(&setupConfigData, "id", "", "", "json-encoded configuration data, specify a filepath with '@' prefix")
setupCmd.Flags().StringVarP(&setupProfileData, "profile", "", "", "json-encoded user profile data, specify a filepath with '@' prefix")
}
Expand Down

0 comments on commit fb19615

Please sign in to comment.