Files
clr-installer/conf/conf.go
T
Mark D Horn 786a1f27b5 Download User Messages
New functionality to download Pre and Post Installer messages
TODO: Display the messages as pop-ups
- Need to use system curl command to handle proxies for now

Refactoring for enabling:
- Moved FetchRemoteConfigFile from conf to network
- Move code for Clear Linux Version parsing until a utility function
  which is called early in the flow for reuse

Now that use external curl FILE protocol passes.

Signed-off-by: Mark D Horn <mark.d.horn@intel.com>
2019-03-11 17:11:55 -07:00

104 lines
3.0 KiB
Go

// Copyright © 2018 Intel Corporation
//
// SPDX-License-Identifier: GPL-3.0-only
package conf
import (
"os"
"path/filepath"
"strings"
"github.com/clearlinux/clr-installer/utils"
)
const (
// BundleListFile the file file for the containing the bundle list definition
BundleListFile = "bundles.json"
// LogFile is the installation log file name
LogFile = "clr-installer.log"
// ConfigFile is the install descriptor
ConfigFile = "clr-installer.yaml"
// ChpasswdPAMFile is the chpasswd pam configuration file
ChpasswdPAMFile = "chpasswd"
// DefaultConfigDir is the system wide default configuration directory
DefaultConfigDir = "/usr/share/defaults/clr-installer"
// CustomConfigDir directory contains custom configuration files
// i.e per image configuration files
CustomConfigDir = "/var/lib/clr-installer"
// KernelListFile is the file describing the available kernel bundles
KernelListFile = "kernels.json"
// SourcePath is the source path (within the .gopath)
SourcePath = "src/github.com/clearlinux/clr-installer"
)
func isRunningFromSourceTree() (bool, string, error) {
src, err := os.Executable()
if err != nil {
return false, src, err
}
src, err = filepath.Abs(filepath.Dir(src))
if err != nil {
return false, src, err
}
return !strings.HasPrefix(src, "/usr/bin"), src, nil
}
func lookupDefaultFile(file string) (string, error) {
isSourceTree, sourcePath, err := isRunningFromSourceTree()
if err != nil {
return "", err
}
// use the config from source code's etc dir if not installed binary
if isSourceTree {
sourceRoot := strings.Replace(sourcePath, "bin", filepath.Join(SourcePath, "etc"), 1)
return filepath.Join(sourceRoot, file), nil
}
custom := filepath.Join(CustomConfigDir, file)
if ok, _ := utils.FileExists(custom); ok {
return custom, nil
}
return filepath.Join(DefaultConfigDir, file), nil
}
// LookupBundleListFile looks up the bundle list definition
// Guesses if we're running from source code or from system, if we're running from
// source code directory then we load the source default file, otherwise tried to load
// the system installed file
func LookupBundleListFile() (string, error) {
return lookupDefaultFile(BundleListFile)
}
// LookupKernelListFile looks up the kernel list definition
// Guesses if we're running from source code or from system, if we're running from
// source code directory then we load the source default file, otherwise load the system
// installed file
func LookupKernelListFile() (string, error) {
return lookupDefaultFile(KernelListFile)
}
// LookupDefaultConfig looks up the install descriptor
// Guesses if we're running from source code our from system, if we're running from
// source code directory then we loads the source default file, otherwise tried to load
// the system installed file
func LookupDefaultConfig() (string, error) {
return lookupDefaultFile(ConfigFile)
}
// LookupChpasswdConfig looks up the chpasswd pam file used in the post install
func LookupChpasswdConfig() (string, error) {
return lookupDefaultFile(ChpasswdPAMFile)
}