func makePartFromSystemImageConfigFile(p partition.Interface, channelIniPath string, isActive bool) (part Part, err error) { cfg := goconfigparser.New() f, err := os.Open(channelIniPath) if err != nil { return nil, err } defer f.Close() err = cfg.Read(f) if err != nil { logger.Noticef("Can not parse config %q: %v", channelIniPath, err) return nil, err } st, err := os.Stat(channelIniPath) if err != nil { logger.Noticef("Can not stat %q: %v", channelIniPath, err) return nil, err } currentBuildNumber, err := cfg.Get("service", "build_number") versionDetails, err := cfg.Get("service", "version_detail") channelName, err := cfg.Get("service", "channel") return &SystemImagePart{ isActive: isActive, isInstalled: true, version: currentBuildNumber, versionDetails: versionDetails, channelName: channelName, lastUpdate: st.ModTime(), partition: p}, err }
func (g *grub) GetBootVars(names ...string) (map[string]string, error) { out := map[string]string{} // Grub doesn't provide a get verb, so retrieve all values and // search for the required variable ourselves. output, err := runCommand(grubEnvCmd, g.envFile(), "list") if err != nil { return nil, err } cfg := goconfigparser.New() cfg.AllowNoSectionHeader = true if err := cfg.ReadString(output); err != nil { return nil, err } for _, name := range names { v, err := cfg.Get("", name) if err != nil { return nil, err } out[name] = v } return out, nil }
// Setup is used to initialiaze the release information for the system func Setup(rootDir string) error { channelsIniPath := filepath.Join(rootDir, channelsIni) cfg := goconfigparser.New() if err := cfg.ReadFile(channelsIniPath); err != nil { return err } channel, err := cfg.Get("service", "channel") if err != nil { return err } // I'm not so sure about this check if !strings.HasPrefix(channel, "ubuntu-") { return errors.New("release does not correspond to an ubuntu channel") } channelParts := strings.Split(channel, "/") if len(channelParts) != 3 { // deprecated channel usage setLegacy() return nil } rel = Release{ Flavor: strings.Trim(channelParts[0], "ubuntu-"), Series: channelParts[1], Channel: channelParts[2], } return nil }
func getBootVarLegacy(name string) (value string, err error) { cfg := goconfigparser.New() cfg.AllowNoSectionHeader = true if err := cfg.ReadFile(bootloaderUbootEnvFile); err != nil { return "", nil } return cfg.Get("", name) }
func getVersionFromConfig(c *check.C) string { cfg := goconfigparser.New() f, err := os.Open("/etc/system-image/channel.ini") c.Assert(err, check.IsNil, check.Commentf("Error opening the config file: %v:", err)) defer f.Close() err = cfg.Read(f) c.Assert(err, check.IsNil, check.Commentf("Error parsing the config file: %v", err)) version, err := cfg.Get("service", "build_number") c.Assert(err, check.IsNil, check.Commentf("Error getting the build number: %v", err)) return version }
func (g *grub) GetBootVar(name string) (string, error) { // Grub doesn't provide a get verb, so retrieve all values and // search for the required variable ourselves. output, err := runCommand(grubEnvCmd, g.envFile(), "list") if err != nil { return "", err } cfg := goconfigparser.New() cfg.AllowNoSectionHeader = true if err := cfg.ReadString(output); err != nil { return "", err } return cfg.Get("", name) }
func systemImageClientCheckForUpdates(configFile string) (us updateStatus, err error) { cfg := goconfigparser.New() if err := cfg.ReadFile(configFile); err != nil { return us, err } channel, _ := cfg.Get("service", "channel") device, _ := cfg.Get("service", "device") indexURL := systemImageServer + "/" + path.Join(channel, device, "index.json") resp, err := http.Get(indexURL) if err != nil { return us, err } defer resp.Body.Close() if resp.StatusCode != 200 { return us, fmt.Errorf("systemImageDbusProxy: unexpected http statusCode %v for %s", resp.StatusCode, indexURL) } // and decode json var channelData channelJSON dec := json.NewDecoder(resp.Body) if err := dec.Decode(&channelData); err != nil { return us, err } // global property us.lastUpdate, _ = time.Parse("Mon Jan 2 15:04:05 MST 2006", channelData.Global.GeneratedAt) // FIXME: find latest image of type "full" here latestImage := channelData.Images[len(channelData.Images)-1] us.targetVersion = fmt.Sprintf("%d", latestImage.Version) us.targetVersionDetails = latestImage.VersionDetails // FIXME: this is not accurate right now as it does not take // the deltas into account for _, f := range latestImage.Files { us.updateSize += f.Size } return us, nil }