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