Skip to content

Commit 3633ed4

Browse files
committed
If the robot is on my CFW, don't remount / as rw. It already has a compatible vic-cloud
1 parent 2091dfe commit 3633ed4

File tree

4 files changed

+56
-41
lines changed

4 files changed

+56
-41
lines changed

chipper/pkg/wirepod/setup/ssh.go

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,20 @@ func SetupBotViaSSH(ip string, key []byte) error {
8383
if !strings.Contains(output, "Vector") {
8484
return doErr(fmt.Errorf("the remote device is not a vector"), "checking if vector")
8585
}
86+
SetupSSHStatus = "Checking if Vector is running CFW..."
87+
output, err = runCmd(client, "cat /build.prop")
88+
if err != nil {
89+
return doErr(err, "checking if cfw")
90+
}
91+
var doCloud bool = true
92+
var initCommand string = "mount -o rw,remount / && mount -o rw,remount,exec /data && systemctl stop anki-robot.target"
93+
if strings.Contains(output, "wire_os") {
94+
initCommand = "mount -o rw,remount,exec /data && systemctl stop anki-robot.target"
95+
// my cfw already has a wire-pod compatible vic-cloud
96+
doCloud = false
97+
}
8698
SetupSSHStatus = "Running initial commands before transfers (screen will go blank, this is normal)..."
87-
_, 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")
99+
_, err = runCmd(client, initCommand)
88100
if err != nil {
89101
if !strings.Contains(err.Error(), "Process exited with status 1") {
90102
return doErr(err, "initial commands")
@@ -115,53 +127,55 @@ func SetupBotViaSSH(ip string, key []byte) error {
115127
if err != nil {
116128
return doErr(err, "new scp client 2")
117129
}
118-
err = scpClient.CopyFile(context.Background(), serverConfig, "/anki/data/assets/cozmo_resources/config/server_config.json", "0755")
130+
err = scpClient.CopyFile(context.Background(), serverConfig, "/data/data/server_config.json", "0755")
119131
if err != nil {
120132
return doErr(err, "copying server-config.json")
121133
}
122134
scpClient.Session.Close()
123-
if runtime.GOOS != "android" && !vars.Packaged {
124-
cloud, err := os.Open("../vector-cloud/build/vic-cloud")
125-
if err != nil {
126-
return doErr(err, "transferring new vic-cloud")
127-
}
128-
SetupSSHStatus = "Transferring new vic-cloud..."
129-
scpClient, err = scp.NewClientBySSH(client)
130-
if err != nil {
131-
return doErr(err, "new scp client 3")
132-
}
133-
err = scpClient.CopyFile(context.Background(), cloud, "/anki/bin/vic-cloud", "0755")
134-
if err != nil {
135-
time.Sleep(time.Second * 1)
135+
if doCloud {
136+
if runtime.GOOS != "android" && !vars.Packaged {
137+
cloud, err := os.Open("../vector-cloud/build/vic-cloud")
138+
if err != nil {
139+
return doErr(err, "transferring new vic-cloud")
140+
}
141+
SetupSSHStatus = "Transferring new vic-cloud..."
136142
scpClient, err = scp.NewClientBySSH(client)
137143
if err != nil {
138-
return doErr(err, "copying vic-cloud")
144+
return doErr(err, "new scp client 3")
139145
}
140146
err = scpClient.CopyFile(context.Background(), cloud, "/anki/bin/vic-cloud", "0755")
141147
if err != nil {
142-
return doErr(err, "copying vic-cloud")
148+
time.Sleep(time.Second * 1)
149+
scpClient, err = scp.NewClientBySSH(client)
150+
if err != nil {
151+
return doErr(err, "copying vic-cloud")
152+
}
153+
err = scpClient.CopyFile(context.Background(), cloud, "/anki/bin/vic-cloud", "0755")
154+
if err != nil {
155+
return doErr(err, "copying vic-cloud")
156+
}
143157
}
144-
}
145-
} else {
146-
resp, _ := http.Get("https://github.com/kercre123/wire-pod/raw/main/vector-cloud/build/vic-cloud")
147-
if err != nil {
148-
return doErr(err, "transferring new vic-cloud")
149-
}
150-
SetupSSHStatus = "Transferring new vic-cloud..."
151-
scpClient, err = scp.NewClientBySSH(client)
152-
if err != nil {
153-
return doErr(err, "new scp client 3")
154-
}
155-
err = scpClient.CopyFile(context.Background(), resp.Body, "/anki/bin/vic-cloud", "0755")
156-
if err != nil {
157-
time.Sleep(time.Second * 1)
158+
} else {
159+
resp, _ := http.Get("https://github.com/kercre123/wire-pod/raw/main/vector-cloud/build/vic-cloud")
160+
if err != nil {
161+
return doErr(err, "transferring new vic-cloud")
162+
}
163+
SetupSSHStatus = "Transferring new vic-cloud..."
158164
scpClient, err = scp.NewClientBySSH(client)
159165
if err != nil {
160-
return doErr(err, "copying vic-cloud")
166+
return doErr(err, "new scp client 3")
161167
}
162168
err = scpClient.CopyFile(context.Background(), resp.Body, "/anki/bin/vic-cloud", "0755")
163169
if err != nil {
164-
return doErr(err, "copying vic-cloud")
170+
time.Sleep(time.Second * 1)
171+
scpClient, err = scp.NewClientBySSH(client)
172+
if err != nil {
173+
return doErr(err, "copying vic-cloud")
174+
}
175+
err = scpClient.CopyFile(context.Background(), resp.Body, "/anki/bin/vic-cloud", "0755")
176+
if err != nil {
177+
return doErr(err, "copying vic-cloud")
178+
}
165179
}
166180
}
167181
}
@@ -182,17 +196,13 @@ func SetupBotViaSSH(ip string, key []byte) error {
182196
if err != nil {
183197
return doErr(err, "new scp client 4")
184198
}
185-
err = scpClient.CopyFile(context.Background(), cert, "/anki/etc/wirepod-cert.crt", "0755")
199+
err = scpClient.CopyFile(context.Background(), cert, "/data/data/wirepod-cert.crt", "0755")
186200
if err != nil {
187201
return doErr(err, "copying wire-pod cert")
188202
}
189203
scpClient.Session.Close()
190-
_, err = runCmd(client, "cp /anki/etc/wirepod-cert.crt /data/data/wirepod-cert.crt")
191-
if err != nil {
192-
return doErr(err, "copying wire-pod cert in robot")
193-
}
194204
SetupSSHStatus = "Generating new robot certificate (this may take a while)..."
195-
_, 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")
205+
_, 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")
196206
if err != nil {
197207
return doErr(err, "generating new robot cert")
198208
}

vector-cloud/build/vic-cloud

-80 Bytes
Binary file not shown.

vector-cloud/internal/config/urls.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"encoding/json"
55
"io/ioutil"
6+
"os"
67
)
78

89
// URLs represents a set of URLs where Anki's cloud services can be reached
@@ -43,12 +44,17 @@ func SetGlobal(filename string) error {
4344
}
4445

4546
var defaultFilename = "/anki/data/assets/cozmo_resources/config/server_config.json"
47+
var wirepodFilename = "/data/data/server_config.json"
4648

4749
// LoadURLs attempts to load a URL config from the given filename. If the given filename
4850
// is blank, a known hardcoded location for server_config.json on the robot is used.
4951
func LoadURLs(filename string) (*URLs, error) {
5052
if filename == "" {
51-
filename = defaultFilename
53+
if _, err := os.Open(wirepodFilename); err != nil {
54+
filename = defaultFilename
55+
} else {
56+
filename = wirepodFilename
57+
}
5258
}
5359
buf, err := ioutil.ReadFile(filename)
5460
if err != nil {

vector-cloud/pod-bot-install.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
systemctl stop anki-robot.target
44
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"
55
sleep 2
6-
chmod +rwx /anki/data/assets/cozmo_resources/config/server_config.json
76
rm -f /data/data/com.anki.victor/persistent/token/token.jwt
87
rm -f /data/data/com.anki.victor/persistent/onboarding/onboardingState.json
98
rm -f /data/etc/robot.pem

0 commit comments

Comments
 (0)