Verbose logging
This commit is contained in:
parent
732e88a263
commit
1ab24d86e2
30
cmd/init.go
30
cmd/init.go
@ -26,6 +26,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"boxen/config"
|
"boxen/config"
|
||||||
@ -73,11 +74,18 @@ func initProcess(_ *cobra.Command, _ []string) {
|
|||||||
}
|
}
|
||||||
defer logFile.Close()
|
defer logFile.Close()
|
||||||
|
|
||||||
log.SetOutput(logFile)
|
//if verbose {
|
||||||
|
logWriter := io.MultiWriter(os.Stdout, logFile)
|
||||||
|
log.SetOutput(logWriter)
|
||||||
|
//} else {
|
||||||
|
// log.SetOutput(logFile)
|
||||||
|
//}
|
||||||
|
|
||||||
// Generate SSH keys if they don't already exist
|
// Generate SSH keys if they don't already exist
|
||||||
if _, err := os.Stat(config.SshPrivKeyFile); os.IsNotExist(err) {
|
if _, err := os.Stat(config.SshPrivKeyFile); os.IsNotExist(err) {
|
||||||
|
log.Printf("Generating ssh private key '%s'...", config.SshPrivKeyFile)
|
||||||
utils.GenerateSSHKeys(config.SshPrivKeyFile, config.SshPubKeyFile)
|
utils.GenerateSSHKeys(config.SshPrivKeyFile, config.SshPubKeyFile)
|
||||||
|
log.Print("Done")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a password that is 50 characters long with 10 digits, 0 symbols,
|
// Generate a password that is 50 characters long with 10 digits, 0 symbols,
|
||||||
@ -87,7 +95,7 @@ func initProcess(_ *cobra.Command, _ []string) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Connecting to %s ...\n", host)
|
log.Printf("Connecting to %s ...\n", host)
|
||||||
|
|
||||||
setupRemoteService(adminServiceSecret)
|
setupRemoteService(adminServiceSecret)
|
||||||
|
|
||||||
@ -155,43 +163,51 @@ func addZoneToLocalConfig(deviceEgo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupRemoteService(serviceSecret string) {
|
func setupRemoteService(serviceSecret string) {
|
||||||
|
|
||||||
|
log.Printf("Setting up remote service...")
|
||||||
|
|
||||||
// Copy over the gnunet.conf from the remote device.
|
// Copy over the gnunet.conf from the remote device.
|
||||||
// TODO: Verify config path
|
// TODO: Verify config path
|
||||||
|
|
||||||
|
log.Printf("... SSH setup")
|
||||||
sshApi, err := sshwrapper.DefaultSshApiSetup(host, port, user, privkey)
|
sshApi, err := sshwrapper.DefaultSshApiSetup(host, port, user, privkey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("... copy .config/gnunet.conf")
|
||||||
err = sshApi.CopyFromRemote(".config/gnunet.conf", "/tmp/gnunet.conf")
|
err = sshApi.CopyFromRemote(".config/gnunet.conf", "/tmp/gnunet.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the admin service to the Exit section of config
|
// Add the admin service to the Exit section of config
|
||||||
|
log.Printf("... load /tmp/gnunet.conf")
|
||||||
cfg, err := ini.LoadSources(ini.LoadOptions{
|
cfg, err := ini.LoadSources(ini.LoadOptions{
|
||||||
IgnoreInlineComment: true,
|
IgnoreInlineComment: true,
|
||||||
}, "/tmp/gnunet.conf")
|
}, "/tmp/gnunet.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Fail to read file: %v", err)
|
log.Panicf("Fail to read file: %v", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("... update /tmp/gnunet.conf")
|
||||||
serviceName := fmt.Sprintf("%s.gnunet.", serviceSecret)
|
serviceName := fmt.Sprintf("%s.gnunet.", serviceSecret)
|
||||||
cfg.Section(serviceName).Key("TCP_REDIRECTS").SetValue("22:169.254.86.1:22")
|
cfg.Section(serviceName).Key("TCP_REDIRECTS").SetValue("22:169.254.86.1:22")
|
||||||
cfg.SaveTo("/tmp/gnunet.conf")
|
cfg.SaveTo("/tmp/gnunet.conf")
|
||||||
|
|
||||||
|
log.Printf("... upload .config/gnunet.conf")
|
||||||
err = sshApi.CopyToRemote("/tmp/gnunet.conf", ".config/gnunet.conf")
|
err = sshApi.CopyToRemote("/tmp/gnunet.conf", ".config/gnunet.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart GNUnet
|
// Restart GNUnet
|
||||||
stdout, stderr, err := sshApi.Run("gnunet-arm -s; gnunet-arm -r; sleep 20")
|
log.Printf("... restart gnunet")
|
||||||
|
stdout, stderr, err := sshApi.Run("gnunet-arm -s ; gnunet-arm -r && sleep 20")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(stdout)
|
log.Print(stdout)
|
||||||
log.Print(stderr)
|
log.Print(stderr)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
log.Printf("...Done!")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user