minor fixups
This commit is contained in:
parent
1f0a18a0a8
commit
6f6f28a22a
6
apt.go
6
apt.go
|
@ -15,6 +15,10 @@ func (me *Machine) initPackages() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if me.Packages == nil {
|
||||||
|
me.Packages = new(Packages)
|
||||||
|
}
|
||||||
|
|
||||||
// Print the installed packages and their versions
|
// Print the installed packages and their versions
|
||||||
for pkg, version := range newP {
|
for pkg, version := range newP {
|
||||||
new1 := new(Package)
|
new1 := new(Package)
|
||||||
|
@ -37,7 +41,7 @@ func (me *Machine) addNew(name string, version string) bool {
|
||||||
return me.Packages.Append(new1)
|
return me.Packages.Append(new1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *Machine) updatePackages() string {
|
func (me *Machine) UpdatePackages() string {
|
||||||
// Get the list of installed packages for the detected distro
|
// Get the list of installed packages for the detected distro
|
||||||
newP, err := getPackageList(me.Distro)
|
newP, err := getPackageList(me.Distro)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
22
config.go
22
config.go
|
@ -81,14 +81,24 @@ func (m *Machine) ConfigLoad() error {
|
||||||
hostname, _ := os.Hostname()
|
hostname, _ := os.Hostname()
|
||||||
fname := hostname + ".pb"
|
fname := hostname + ".pb"
|
||||||
|
|
||||||
if data, err := m.loadFile(fname); err == nil {
|
var data []byte
|
||||||
|
var err error
|
||||||
|
if data, err = loadFile(fname); err != nil {
|
||||||
|
// something went wrong loading the file
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if data != nil {
|
||||||
if err = proto.Unmarshal(data, m); err != nil {
|
if err = proto.Unmarshal(data, m); err != nil {
|
||||||
log.Warn("broken zookeeper.pb config file", fname)
|
log.Warn("broken zookeeper.pb config file", fname)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
return nil
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Hostname = hostname
|
||||||
|
m.Distro = detectDistro()
|
||||||
|
m.initPackages()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +107,12 @@ func loadFile(filename string) ([]byte, error) {
|
||||||
p := filepath.Join(homeDir, ".config/zookeeper")
|
p := filepath.Join(homeDir, ".config/zookeeper")
|
||||||
fullname := filepath.Join(p, filename)
|
fullname := filepath.Join(p, filename)
|
||||||
data, err := os.ReadFile(fullname)
|
data, err := os.ReadFile(fullname)
|
||||||
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
|
// if file does not exist, just return nil. this
|
||||||
|
// will cause ConfigLoad() to try the next config file like "forge.text"
|
||||||
|
// because the user might want to edit the .config by hand
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// log.Info("open config file :", err)
|
// log.Info("open config file :", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue