Skip to content

Commit cbf7d32

Browse files
committed
rc1
1 parent 29e9cef commit cbf7d32

File tree

9 files changed

+47
-30
lines changed

9 files changed

+47
-30
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ else
1616
PATH_VERSION = v$(TAG_VERSION)
1717
endif
1818

19-
LDFLAGS = "-s -w -X 'github.com/viamrobotics/agent.Version=${TAG_VERSION}' -X 'github.com/viamrobotics/agent.GitRevision=${GIT_REVISION}'"
19+
LDFLAGS = "-s -w -X 'github.com/viamrobotics/agent/utils.Version=${TAG_VERSION}' -X 'github.com/viamrobotics/agent/utils.GitRevision=${GIT_REVISION}'"
2020
TAGS = osusergo,netgo
2121

2222

agent.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,8 @@ const (
2222
serviceFileName = "viam-agent.service"
2323
)
2424

25-
var (
26-
// versions embedded at build time.
27-
Version = ""
28-
GitRevision = ""
29-
30-
//go:embed viam-agent.service
31-
serviceFileContents []byte
32-
)
25+
//go:embed viam-agent.service
26+
var serviceFileContents []byte
3327

3428
// InstallNewVersion runs the newly downloaded binary's Install() for installation of systemd files and the like.
3529
func InstallNewVersion(ctx context.Context, logger logging.Logger) (bool, error) {

examples/agent-config.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"system_configuration": {
4646
"logging_journald_system_max_use_megabytes": 512, // can be -1 to disable
4747
"logging_journald_runtime_max_use_megabytes": 512, // can be -1 to disable
48-
"os_auto_upgrade_type": "security" // can be "" to disable
48+
"os_auto_upgrade_type": "security" // can be "" to do nothing, or "disable" to remove customization, "all", or "security"
4949
}
5050
}
5151
}

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.23.1
55
require (
66
github.com/Masterminds/semver/v3 v3.3.0
77
github.com/Otterverse/gonetworkmanager/v2 v2.2.1
8+
github.com/gabriel-vasile/mimetype v1.4.8
89
github.com/google/uuid v1.6.0
910
github.com/jessevdk/go-flags v1.6.1
1011
github.com/nightlyone/lockfile v1.0.0
@@ -83,7 +84,7 @@ require (
8384
go.uber.org/multierr v1.11.0 // indirect
8485
golang.org/x/crypto v0.31.0 // indirect
8586
golang.org/x/mod v0.21.0 // indirect
86-
golang.org/x/net v0.30.0 // indirect
87+
golang.org/x/net v0.33.0 // indirect
8788
golang.org/x/oauth2 v0.22.0 // indirect
8889
golang.org/x/sync v0.10.0 // indirect
8990
golang.org/x/text v0.21.0 // indirect

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
143143
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
144144
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
145145
github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASxc7x3E=
146+
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
147+
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
146148
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
147149
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
148150
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
@@ -819,8 +821,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
819821
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
820822
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
821823
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
822-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
823-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
824+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
825+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
824826
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
825827
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
826828
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ func (m *Manager) getVersions() *pb.VersionInfo {
563563
m.cfgMu.RLock()
564564
defer m.cfgMu.RUnlock()
565565
vers := &pb.VersionInfo{
566-
AgentRunning: Version,
566+
AgentRunning: utils.GetVersion(),
567567
AgentInstalled: m.cache.AgentVersion(),
568568
ViamServerRunning: m.cache.ViamServerRunningVersion(),
569569
ViamServerInstalled: m.cache.ViamServerVersion(),

subsystems/syscfg/logging.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var (
2323
func (s *syscfg) EnforceLogging() error {
2424
s.mu.RLock()
2525
defer s.mu.RUnlock()
26-
if s.cfg.LoggingJournaldRuntimeMaxUseMegabytes < 0 || s.cfg.LoggingJournaldSystemMaxUseMegabytes < 0 {
26+
if s.cfg.LoggingJournaldRuntimeMaxUseMegabytes < 0 && s.cfg.LoggingJournaldSystemMaxUseMegabytes < 0 {
2727
if err := os.Remove(journaldConfPath); err != nil {
2828
if errw.Is(err, fs.ErrNotExist) {
2929
return nil
@@ -48,6 +48,10 @@ func (s *syscfg) EnforceLogging() error {
4848
return err
4949
}
5050

51+
journalConf := &conf.JournaldFile{
52+
Journal: conf.JournaldJournalSection{},
53+
}
54+
5155
persistSize := fmt.Sprintf("%dM", s.cfg.LoggingJournaldSystemMaxUseMegabytes)
5256
tempSize := fmt.Sprintf("%dM", s.cfg.LoggingJournaldRuntimeMaxUseMegabytes)
5357

@@ -59,11 +63,12 @@ func (s *syscfg) EnforceLogging() error {
5963
tempSize = defaultLogLimit
6064
}
6165

62-
journalConf := &conf.JournaldFile{
63-
Journal: conf.JournaldJournalSection{
64-
SystemMaxUse: sysd.Value{persistSize},
65-
RuntimeMaxUse: sysd.Value{tempSize},
66-
},
66+
if s.cfg.LoggingJournaldSystemMaxUseMegabytes >= 0 {
67+
journalConf.Journal.SystemMaxUse = sysd.Value{persistSize}
68+
}
69+
70+
if s.cfg.LoggingJournaldRuntimeMaxUseMegabytes >= 0 {
71+
journalConf.Journal.RuntimeMaxUse = sysd.Value{tempSize}
6772
}
6873

6974
newFileBytes, err := sysd.Marshal(journalConf)

utils/utils.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,21 @@ func DownloadFile(ctx context.Context, rawURL string) (outPath string, errRet er
138138

139139
req, err := http.NewRequestWithContext(ctx, http.MethodGet, parsedURL.String(), nil)
140140
if err != nil {
141-
return "", errw.Wrap(err, "checking viam-server status")
141+
return "", errw.Wrap(err, "downloading file")
142142
}
143143

144144
resp, err := http.DefaultClient.Do(req)
145145
if err != nil {
146-
return "", errw.Wrap(err, "checking viam-server status")
146+
return "", errw.Wrap(err, "downloading file")
147147
}
148148
defer func() {
149149
errRet = errors.Join(errRet, resp.Body.Close())
150150
}()
151151

152+
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
153+
return "", errw.Errorf("got response '%s' while downloading %s", resp.Status, parsedURL)
154+
}
155+
152156
//nolint:gosec
153157
if err := os.MkdirAll(ViamDirs["tmp"], 0o755); err != nil {
154158
return "", err

version_control.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"sync"
1616
"time"
1717

18+
"github.com/gabriel-vasile/mimetype"
1819
errw "github.com/pkg/errors"
1920
"github.com/viamrobotics/agent/subsystems/viamserver"
2021
"github.com/viamrobotics/agent/utils"
@@ -52,6 +53,7 @@ type Versions struct {
5253

5354
// temporary, so not exported for json/caching
5455
runningVersion string
56+
brokenTarget bool
5557
}
5658

5759
// VersionInfo records details about each version of a subsystem.
@@ -125,14 +127,6 @@ func (c *VersionCache) save() error {
125127
return err
126128
}
127129

128-
//SMURF uneeded?
129-
// Save saves the cached data to disk.
130-
// func (c *VersionCache) Save() error {
131-
// c.mu.Lock()
132-
// defer c.mu.Unlock()
133-
// return c.save()
134-
// }
135-
136130
// Update processes data for the two binaries: agent itself, and viam-server.
137131
func (c *VersionCache) Update(cfg *pb.UpdateInfo, binary string) error {
138132
c.mu.Lock()
@@ -154,6 +148,7 @@ func (c *VersionCache) Update(cfg *pb.UpdateInfo, binary string) error {
154148
}
155149

156150
data.TargetVersion = newVersion
151+
data.brokenTarget = false
157152
info, ok := data.Versions[newVersion]
158153
if !ok {
159154
info = &VersionInfo{}
@@ -187,6 +182,10 @@ func (c *VersionCache) UpdateBinary(ctx context.Context, binary string) (bool, e
187182

188183
var needRestart bool
189184

185+
if data.brokenTarget {
186+
return needRestart, nil
187+
}
188+
190189
verData, ok := data.Versions[data.TargetVersion]
191190
if !ok {
192191
return needRestart, errw.Errorf("version data not found for %s %s", binary, data.TargetVersion)
@@ -227,6 +226,9 @@ func (c *VersionCache) UpdateBinary(ctx context.Context, binary string) (bool, e
227226
var err error
228227
verData.DlPath, err = utils.DownloadFile(ctx, verData.URL)
229228
if err != nil {
229+
if isCustomURL {
230+
data.brokenTarget = true
231+
}
230232
return needRestart, errw.Wrapf(err, "downloading %s", binary)
231233
}
232234
actualSha, err := utils.GetFileSum(verData.DlPath)
@@ -239,6 +241,15 @@ func (c *VersionCache) UpdateBinary(ctx context.Context, binary string) (bool, e
239241
verData.DlSHA = actualSha
240242

241243
if len(verData.UnpackedSHA) <= 1 && isCustomURL {
244+
// new custom download, so need to check the file is an executable binary and use locally generated sha
245+
mtype, err := mimetype.DetectFile(verData.UnpackedPath)
246+
if err != nil {
247+
return needRestart, errw.Wrapf(err, "determining file type of download")
248+
}
249+
if !mtype.Is("application/x-elf") && !mtype.Is("application/x-executable") {
250+
data.brokenTarget = true
251+
return needRestart, errw.Errorf("downloaded file is %s, not application/x-elf or application/x-executable, skipping", mtype)
252+
}
242253
verData.UnpackedSHA = actualSha
243254
}
244255

0 commit comments

Comments
 (0)