diff --git a/chipper/pkg/wirepod/setup/ssh.go b/chipper/pkg/wirepod/setup/ssh.go index 85d58ee4..6c32cf87 100644 --- a/chipper/pkg/wirepod/setup/ssh.go +++ b/chipper/pkg/wirepod/setup/ssh.go @@ -83,8 +83,20 @@ func SetupBotViaSSH(ip string, key []byte) error { if !strings.Contains(output, "Vector") { return doErr(fmt.Errorf("the remote device is not a vector"), "checking if vector") } + SetupSSHStatus = "Checking if Vector is running CFW..." + output, err = runCmd(client, "cat /build.prop") + if err != nil { + return doErr(err, "checking if cfw") + } + var doCloud bool = true + var initCommand string = "mount -o rw,remount / && mount -o rw,remount,exec /data && systemctl stop anki-robot.target" + if strings.Contains(output, "wire_os") { + initCommand = "mount -o rw,remount,exec /data && systemctl stop anki-robot.target" + // my cfw already has a wire-pod compatible vic-cloud + doCloud = false + } SetupSSHStatus = "Running initial commands before transfers (screen will go blank, this is normal)..." - _, err = runCmd(client, "mount -o rw,remount / && mount -o rw,remount,exec /data && systemctl stop anki-robot.target && mv /anki/data/assets/cozmo_resources/config/server_config.json /anki/data/assets/cozmo_resources/config/server_config.json.bak") + _, err = runCmd(client, initCommand) if err != nil { if !strings.Contains(err.Error(), "Process exited with status 1") { return doErr(err, "initial commands") @@ -115,53 +127,55 @@ func SetupBotViaSSH(ip string, key []byte) error { if err != nil { return doErr(err, "new scp client 2") } - err = scpClient.CopyFile(context.Background(), serverConfig, "/anki/data/assets/cozmo_resources/config/server_config.json", "0755") + err = scpClient.CopyFile(context.Background(), serverConfig, "/data/data/server_config.json", "0755") if err != nil { return doErr(err, "copying server-config.json") } scpClient.Session.Close() - if runtime.GOOS != "android" && !vars.Packaged { - cloud, err := os.Open("../vector-cloud/build/vic-cloud") - if err != nil { - return doErr(err, "transferring new vic-cloud") - } - SetupSSHStatus = "Transferring new vic-cloud..." - scpClient, err = scp.NewClientBySSH(client) - if err != nil { - return doErr(err, "new scp client 3") - } - err = scpClient.CopyFile(context.Background(), cloud, "/anki/bin/vic-cloud", "0755") - if err != nil { - time.Sleep(time.Second * 1) + if doCloud { + if runtime.GOOS != "android" && !vars.Packaged { + cloud, err := os.Open("../vector-cloud/build/vic-cloud") + if err != nil { + return doErr(err, "transferring new vic-cloud") + } + SetupSSHStatus = "Transferring new vic-cloud..." scpClient, err = scp.NewClientBySSH(client) if err != nil { - return doErr(err, "copying vic-cloud") + return doErr(err, "new scp client 3") } err = scpClient.CopyFile(context.Background(), cloud, "/anki/bin/vic-cloud", "0755") if err != nil { - return doErr(err, "copying vic-cloud") + time.Sleep(time.Second * 1) + scpClient, err = scp.NewClientBySSH(client) + if err != nil { + return doErr(err, "copying vic-cloud") + } + err = scpClient.CopyFile(context.Background(), cloud, "/anki/bin/vic-cloud", "0755") + if err != nil { + return doErr(err, "copying vic-cloud") + } } - } - } else { - resp, _ := http.Get("https://github.com/kercre123/wire-pod/raw/main/vector-cloud/build/vic-cloud") - if err != nil { - return doErr(err, "transferring new vic-cloud") - } - SetupSSHStatus = "Transferring new vic-cloud..." - scpClient, err = scp.NewClientBySSH(client) - if err != nil { - return doErr(err, "new scp client 3") - } - err = scpClient.CopyFile(context.Background(), resp.Body, "/anki/bin/vic-cloud", "0755") - if err != nil { - time.Sleep(time.Second * 1) + } else { + resp, _ := http.Get("https://github.com/kercre123/wire-pod/raw/main/vector-cloud/build/vic-cloud") + if err != nil { + return doErr(err, "transferring new vic-cloud") + } + SetupSSHStatus = "Transferring new vic-cloud..." scpClient, err = scp.NewClientBySSH(client) if err != nil { - return doErr(err, "copying vic-cloud") + return doErr(err, "new scp client 3") } err = scpClient.CopyFile(context.Background(), resp.Body, "/anki/bin/vic-cloud", "0755") if err != nil { - return doErr(err, "copying vic-cloud") + time.Sleep(time.Second * 1) + scpClient, err = scp.NewClientBySSH(client) + if err != nil { + return doErr(err, "copying vic-cloud") + } + err = scpClient.CopyFile(context.Background(), resp.Body, "/anki/bin/vic-cloud", "0755") + if err != nil { + return doErr(err, "copying vic-cloud") + } } } } @@ -182,17 +196,13 @@ func SetupBotViaSSH(ip string, key []byte) error { if err != nil { return doErr(err, "new scp client 4") } - err = scpClient.CopyFile(context.Background(), cert, "/anki/etc/wirepod-cert.crt", "0755") + err = scpClient.CopyFile(context.Background(), cert, "/data/data/wirepod-cert.crt", "0755") if err != nil { return doErr(err, "copying wire-pod cert") } scpClient.Session.Close() - _, err = runCmd(client, "cp /anki/etc/wirepod-cert.crt /data/data/wirepod-cert.crt") - if err != nil { - return doErr(err, "copying wire-pod cert in robot") - } SetupSSHStatus = "Generating new robot certificate (this may take a while)..." - _, err = runCmd(client, "chmod +rwx /anki/data/assets/cozmo_resources/config/server_config.json /anki/bin/vic-cloud /data/data/wirepod-cert.crt /anki/etc/wirepod-cert.crt /data/pod-bot-install.sh && /data/pod-bot-install.sh") + _, err = runCmd(client, "chmod +rwx /data/data/server_config.json /data/data/wirepod-cert.crt /data/pod-bot-install.sh && /data/pod-bot-install.sh") if err != nil { return doErr(err, "generating new robot cert") } diff --git a/vector-cloud/build/vic-cloud b/vector-cloud/build/vic-cloud index 2859de5f..cecbca1d 100755 Binary files a/vector-cloud/build/vic-cloud and b/vector-cloud/build/vic-cloud differ diff --git a/vector-cloud/internal/config/urls.go b/vector-cloud/internal/config/urls.go index 30dd7634..c6399549 100644 --- a/vector-cloud/internal/config/urls.go +++ b/vector-cloud/internal/config/urls.go @@ -3,6 +3,7 @@ package config import ( "encoding/json" "io/ioutil" + "os" ) // URLs represents a set of URLs where Anki's cloud services can be reached @@ -43,12 +44,17 @@ func SetGlobal(filename string) error { } var defaultFilename = "/anki/data/assets/cozmo_resources/config/server_config.json" +var wirepodFilename = "/data/data/server_config.json" // LoadURLs attempts to load a URL config from the given filename. If the given filename // is blank, a known hardcoded location for server_config.json on the robot is used. func LoadURLs(filename string) (*URLs, error) { if filename == "" { - filename = defaultFilename + if _, err := os.Open(wirepodFilename); err != nil { + filename = defaultFilename + } else { + filename = wirepodFilename + } } buf, err := ioutil.ReadFile(filename) if err != nil { diff --git a/vector-cloud/pod-bot-install.sh b/vector-cloud/pod-bot-install.sh index 4eb8645c..f66f9e6a 100755 --- a/vector-cloud/pod-bot-install.sh +++ b/vector-cloud/pod-bot-install.sh @@ -3,7 +3,6 @@ systemctl stop anki-robot.target echo "Resetting Vector to Onboarding mode (user data is NOT being reset, all faces and photos and stuff will persist), screen will be blank for a minute" sleep 2 -chmod +rwx /anki/data/assets/cozmo_resources/config/server_config.json rm -f /data/data/com.anki.victor/persistent/token/token.jwt rm -f /data/data/com.anki.victor/persistent/onboarding/onboardingState.json rm -f /data/etc/robot.pem