Config struct

Fields:

  • MaxParallelDownloads (uint) - json:"maxParallelDownloads"
  • Registry (string) - json:"registry"
  • RegistryAPIVersion (string) - json:"registryAPIVersion"
  • RegistryService (string) - json:"registryService"
  • Name (string) - json:"name"
  • Tag (string) - json:"tag"
  • IPkgMngPre (string) - json:"iPkgMngPre"
  • IPkgMngPost (string) - json:"iPkgMngPost"
  • IPkgMngAdd (string) - json:"iPkgMngAdd"
  • IPkgMngRm (string) - json:"iPkgMngRm"
  • IPkgMngApi (string) - json:"iPkgMngApi"
  • IPkgMngStatus (int) - json:"iPkgMngStatus"
  • UpdateInitramfsCmd (string) - json:"updateInitramfsCmd"
  • UpdateGrubCmd (string) - json:"updateGrubCmd"
  • DifferURL (string) - json:"differURL"
  • PartLabelVar (string) - json:"partLabelVar"
  • PartLabelA (string) - json:"partLabelA"
  • PartLabelB (string) - json:"partLabelB"
  • PartLabelBoot (string) - json:"partLabelBoot"
  • PartLabelEfi (string) - json:"partLabelEfivar"
  • PartCryptVar (string) - json:"PartCryptVar"
  • ThinProvisioning (bool) - json:"thinProvisioning"
  • ThinInitVolume (string) - json:"thinInitVolume"
  • FullImageName (string)

init function

Show/Hide Function Body
{
	// user paths
	homedir, _ := os.UserHomeDir()
	viper.AddConfigPath(homedir + "/.config/abroot/")

	// dev paths
	viper.AddConfigPath("config/")
	viper.AddConfigPath("../config/")

	// prod paths
	viper.AddConfigPath("/etc/abroot/")
	viper.AddConfigPath("/usr/share/abroot/")

	viper.SetConfigName("abroot")
	viper.SetConfigType("json")

	// VanillaOS specific defaults for backwards compatibility
	viper.SetDefault("updateInitramfsCmd", "lpkg --unlock && /usr/sbin/update-initramfs -u && lpkg --lock")
	viper.SetDefault("updateGrubCmd", "/usr/sbin/grub-mkconfig -o '%s'")

	err := viper.ReadInConfig()
	if err != nil {
		return
	}

	CnfFileUsed = viper.ConfigFileUsed()

	Cnf = &Config{
		// Common
		MaxParallelDownloads: viper.GetUint("maxParallelDownloads"),

		// Registry
		Registry:           viper.GetString("registry"),
		RegistryAPIVersion: viper.GetString("registryAPIVersion"),
		RegistryService:    viper.GetString("registryService"),
		Name:               viper.GetString("name"),
		Tag:                viper.GetString("tag"),

		// Package manager
		IPkgMngPre:    viper.GetString("iPkgMngPre"),
		IPkgMngPost:   viper.GetString("iPkgMngPost"),
		IPkgMngAdd:    viper.GetString("iPkgMngAdd"),
		IPkgMngRm:     viper.GetString("iPkgMngRm"),
		IPkgMngApi:    viper.GetString("iPkgMngApi"),
		IPkgMngStatus: viper.GetInt("iPkgMngStatus"),

		// Boot configuration commands
		UpdateInitramfsCmd: viper.GetString("updateInitramfsCmd"),
		UpdateGrubCmd:      viper.GetString("updateGrubCmd"),

		// Package diff API (Differ)
		DifferURL: viper.GetString("differURL"),

		// Partitions
		PartLabelVar:  viper.GetString("partLabelVar"),
		PartLabelA:    viper.GetString("partLabelA"),
		PartLabelB:    viper.GetString("partLabelB"),
		PartLabelBoot: viper.GetString("partLabelBoot"),
		PartLabelEfi:  viper.GetString("partLabelEfi"),
		PartCryptVar:  viper.GetString("PartCryptVar"),

		// Structure
		ThinProvisioning: viper.GetBool("thinProvisioning"),
		ThinInitVolume:   viper.GetString("thinInitVolume"),

		// Virtual
		FullImageName: "",
	}

	Cnf.FullImageName = fmt.Sprintf("%s/%s:%s", Cnf.Registry, Cnf.Name, Cnf.Tag)
}

WriteConfigToFile function

WriteConfigToFile writes the current configuration to a file

Parameters:

  • file string

Returns:

  • error
Show/Hide Function Body
{
	jsonOutput, err := json.MarshalIndent(Cnf, "", "    ")
	if err != nil {
		return err
	}

	outputFile, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC, 0o644)
	if err != nil {
		return err
	}

	_, err = outputFile.Write(jsonOutput)

	return err
}

encoding/json import

Import example:

import "encoding/json"

fmt import

Import example:

import "fmt"

os import

Import example:

import "os"

github.com/spf13/viper import

Import example:

import "github.com/spf13/viper"