Skip to content

Commit

Permalink
If the robot is on my CFW, don't remount / as rw. It already has a co…
Browse files Browse the repository at this point in the history
…mpatible vic-cloud
  • Loading branch information
kercre123 committed Oct 1, 2024
1 parent 2091dfe commit 3633ed4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 41 deletions.
88 changes: 49 additions & 39 deletions chipper/pkg/wirepod/setup/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}
}
}
}
Expand All @@ -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")
}
Expand Down
Binary file modified vector-cloud/build/vic-cloud
Binary file not shown.
8 changes: 7 additions & 1 deletion vector-cloud/internal/config/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion vector-cloud/pod-bot-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3633ed4

Please sign in to comment.