summaryrefslogtreecommitdiff
path: root/send.go
blob: d9534acd3508328702d5a9b1a717c47ca4d97582 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0

package main

import (
	"strings"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

var urlbase string = "http://zookeeper.wit.com:8080"

func send() {
}

func pingStatus() error {
	var url string
	url = urlbase + "/status?hostname=" + me.hostname
	msg, err := me.machine.Packages.Marshal()
	if err != nil {
		log.Info("proto.Marshal() failed:", err)
		return err
	}
	log.Info("proto Marshal len =", len(msg))
	body, err := httpPost(url, msg)
	if err != nil {
		log.Info("httpPost() failed:", err)
		return err
	}

	test := strings.TrimSpace(string(body))
	// log.Info("virtigo returned body:", test)
	for _, line := range strings.Split(test, "\n") {
		switch line {
		case "upgrade":
			log.Info("should upgrade now")
		default:
			log.Info("GOT:", line)
		}
	}
	return nil
}

func sendMachine() error {
	var url string
	url = urlbase + "/machine"
	msg, err := me.machine.Marshal()
	if err != nil {
		log.Info("proto.Marshal() failed:", err)
		return err
	}
	log.Info("proto Marshal len =", len(msg))
	body, err := httpPost(url, msg)
	if err != nil {
		log.Info("httpPost() failed:", err)
		return err
	}

	test := strings.TrimSpace(string(body))
	// log.Info("virtigo returned body:", test)
	for _, line := range strings.Split(test, "\n") {
		switch line {
		case "upgrade":
			log.Info("machine upgrade now")
			shell.Run([]string{"apt", "update"})
		default:
			log.Info("GOT:", line)
		}
	}
	return nil
}