mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-15 22:58:49 +00:00
feat: improve configuration generation in setup process
- Added checks to prevent overwriting existing node.yaml and gateway.yaml files during configuration generation. - Enhanced error handling for bootstrap.yaml creation, providing informative messages based on the existence of files. - Implemented conditional renaming of bootstrap.yaml to node.yaml, ensuring it only occurs if node.yaml does not already exist. - Updated output messages for clarity on configuration readiness and existing file usage.
This commit is contained in:
parent
351ce086bf
commit
061b17de4f
@ -665,6 +665,17 @@ func generateConfigsInteractive(force bool) {
|
|||||||
fmt.Printf(" • No external peers required\n")
|
fmt.Printf(" • No external peers required\n")
|
||||||
fmt.Printf(" • Gateway connected to local node\n\n")
|
fmt.Printf(" • Gateway connected to local node\n\n")
|
||||||
|
|
||||||
|
bootstrapPath := "/home/debros/.debros/bootstrap.yaml"
|
||||||
|
nodeConfigPath := "/home/debros/.debros/node.yaml"
|
||||||
|
gatewayPath := "/home/debros/.debros/gateway.yaml"
|
||||||
|
|
||||||
|
// Check if node.yaml already exists
|
||||||
|
nodeExists := false
|
||||||
|
if _, err := os.Stat(nodeConfigPath); err == nil {
|
||||||
|
nodeExists = true
|
||||||
|
fmt.Printf(" ℹ️ node.yaml already exists, will not overwrite\n")
|
||||||
|
}
|
||||||
|
|
||||||
// Generate bootstrap node config with explicit parameters
|
// Generate bootstrap node config with explicit parameters
|
||||||
// Pass empty bootstrap-peers and no join address for bootstrap node
|
// Pass empty bootstrap-peers and no join address for bootstrap node
|
||||||
bootstrapArgs := []string{
|
bootstrapArgs := []string{
|
||||||
@ -680,22 +691,56 @@ func generateConfigsInteractive(force bool) {
|
|||||||
cmd := exec.Command("sudo", bootstrapArgs...)
|
cmd := exec.Command("sudo", bootstrapArgs...)
|
||||||
cmd.Stdin = nil // Explicitly close stdin to prevent interactive prompts
|
cmd.Stdin = nil // Explicitly close stdin to prevent interactive prompts
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
|
bootstrapCreated := (err == nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Check if bootstrap.yaml already exists (config init failed because it exists)
|
||||||
|
if _, statErr := os.Stat(bootstrapPath); statErr == nil {
|
||||||
|
fmt.Printf(" ℹ️ bootstrap.yaml already exists, skipping creation\n")
|
||||||
|
bootstrapCreated = true
|
||||||
|
} else {
|
||||||
fmt.Fprintf(os.Stderr, "⚠️ Failed to generate bootstrap config: %v\n", err)
|
fmt.Fprintf(os.Stderr, "⚠️ Failed to generate bootstrap config: %v\n", err)
|
||||||
if len(output) > 0 {
|
if len(output) > 0 {
|
||||||
fmt.Fprintf(os.Stderr, " Output: %s\n", string(output))
|
fmt.Fprintf(os.Stderr, " Output: %s\n", string(output))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" ✓ Bootstrap node config created\n")
|
fmt.Printf(" ✓ Bootstrap node config created\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename bootstrap.yaml to node.yaml so the service can find it
|
// Rename bootstrap.yaml to node.yaml only if node.yaml doesn't exist
|
||||||
renameCmd := exec.Command("sudo", "-u", "debros", "mv", "/home/debros/.debros/bootstrap.yaml", "/home/debros/.debros/node.yaml")
|
if !nodeExists && bootstrapCreated {
|
||||||
|
// Check if bootstrap.yaml exists before renaming
|
||||||
|
if _, err := os.Stat(bootstrapPath); err == nil {
|
||||||
|
renameCmd := exec.Command("sudo", "-u", "debros", "mv", bootstrapPath, nodeConfigPath)
|
||||||
if err := renameCmd.Run(); err != nil {
|
if err := renameCmd.Run(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "⚠️ Failed to rename config: %v\n", err)
|
fmt.Fprintf(os.Stderr, "⚠️ Failed to rename config: %v\n", err)
|
||||||
|
} else {
|
||||||
|
fmt.Printf(" ✓ Renamed bootstrap.yaml to node.yaml\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if nodeExists {
|
||||||
|
// If node.yaml exists, we can optionally remove bootstrap.yaml if it was just created
|
||||||
|
if bootstrapCreated && !force {
|
||||||
|
// Clean up bootstrap.yaml if it was just created but node.yaml already exists
|
||||||
|
if _, err := os.Stat(bootstrapPath); err == nil {
|
||||||
|
exec.Command("sudo", "-u", "debros", "rm", "-f", bootstrapPath).Run()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf(" ℹ️ Using existing node.yaml\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate gateway config with explicit empty bootstrap peers
|
// Generate gateway config with explicit empty bootstrap peers
|
||||||
|
// Check if gateway.yaml already exists
|
||||||
|
gatewayExists := false
|
||||||
|
if _, err := os.Stat(gatewayPath); err == nil {
|
||||||
|
gatewayExists = true
|
||||||
|
if !force {
|
||||||
|
fmt.Printf(" ℹ️ gateway.yaml already exists, skipping creation\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !gatewayExists || force {
|
||||||
gatewayArgs := []string{
|
gatewayArgs := []string{
|
||||||
"-u", "debros",
|
"-u", "debros",
|
||||||
"/home/debros/bin/network-cli", "config", "init",
|
"/home/debros/bin/network-cli", "config", "init",
|
||||||
@ -710,15 +755,21 @@ func generateConfigsInteractive(force bool) {
|
|||||||
cmd.Stdin = nil // Explicitly close stdin to prevent interactive prompts
|
cmd.Stdin = nil // Explicitly close stdin to prevent interactive prompts
|
||||||
output, err = cmd.CombinedOutput()
|
output, err = cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Check if gateway.yaml already exists (config init failed because it exists)
|
||||||
|
if _, statErr := os.Stat(gatewayPath); statErr == nil {
|
||||||
|
fmt.Printf(" ℹ️ gateway.yaml already exists, skipping creation\n")
|
||||||
|
} else {
|
||||||
fmt.Fprintf(os.Stderr, "⚠️ Failed to generate gateway config: %v\n", err)
|
fmt.Fprintf(os.Stderr, "⚠️ Failed to generate gateway config: %v\n", err)
|
||||||
if len(output) > 0 {
|
if len(output) > 0 {
|
||||||
fmt.Fprintf(os.Stderr, " Output: %s\n", string(output))
|
fmt.Fprintf(os.Stderr, " Output: %s\n", string(output))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" ✓ Gateway config created\n")
|
fmt.Printf(" ✓ Gateway config created\n")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf(" ✓ Configurations generated\n")
|
fmt.Printf(" ✓ Configurations ready\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSystemdServices() {
|
func createSystemdServices() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user