Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
Fix installer
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Oct 25, 2021
1 parent 5a216b8 commit db84312
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Description=RancherOS Automatic Installation
Documentation=https://github.com/rancher/os2
Wants=network-online.target
After=network-online.target
Before=getty-pre.target [email protected]

[Install]
WantedBy=multi-user.target
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type Install struct {
ForceEFI bool `json:"forceEfi,omitempty"`
Device string `json:"device,omitempty"`
ConfigURL string `json:"configUrl,omitempty"`
Silent bool `json:"silent,omitempty"`
ISOURL string `json:"isoUrl,omitempty"`
PowerOff bool `json:"powerOff,omitempty"`
NoFormat bool `json:"noFormat,omitempty"`
Expand Down
48 changes: 35 additions & 13 deletions pkg/config/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ func readNested(data map[string]interface{}) (map[string]interface{}, error) {
funcs []reader
)

if len(nestedConfigFiles) == 0 {
return data, nil
}

values.RemoveValue(data, "rancheros", "install", "configUrl")

for _, nestedConfigFile := range nestedConfigFiles {
funcs = append(funcs, readFileFunc(nestedConfigFile))
}
Expand Down Expand Up @@ -123,7 +117,7 @@ func readFile(path string) (result map[string]interface{}, _ error) {
return nil, err
}

return data, nil
return readNested(data)
}

type reader func() (map[string]interface{}, error)
Expand All @@ -138,17 +132,45 @@ func merge(readers ...reader) (map[string]interface{}, error) {
if err := schema.Mapper.ToInternal(newData); err != nil {
return nil, err
}
newData, err = readNested(newData)
if err != nil {
return nil, err
}
d = values.MergeMapsConcatSlice(d, newData)
}
return d, nil
}

func readConfigMap(cfg string) (map[string]interface{}, error) {
return merge(readCmdline, readFileFunc(cfg))
data, err := merge(readCmdline, readFileFunc(cfg))
if err != nil {
return nil, err
}
if cfg != "" {
values.PutValue(data, cfg, "rancheros", "install", "configUrl")
}
return data, nil
}

func ToFile(cfg Config, output string) error {
data, err := ToBytes(cfg)
if err != nil {
return err
}
return ioutil.WriteFile(output, data, 0600)
}

func ToBytes(cfg Config) ([]byte, error) {
data, err := merge(readFileFunc(cfg.RancherOS.Install.ConfigURL), func() (map[string]interface{}, error) {
return convert.EncodeToMap(cfg)
})
if err != nil {
return nil, err
}
values.RemoveValue(data, "install")
values.RemoveValue(data, "rancheros", "install")
bytes, err := yaml.Marshal(data)
if err != nil {
return nil, err
}

return append([]byte("#cloud-config\n"), bytes...), nil
}

func ReadConfig(cfg string) (result Config, err error) {
Expand Down Expand Up @@ -199,5 +221,5 @@ func readCmdline() (map[string]interface{}, error) {
}
}

return data, nil
return readNested(data)
}
8 changes: 4 additions & 4 deletions pkg/install/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func isServer() (bool, bool, error) {
}

func AskServerAgent(cfg *config.Config) error {
if cfg.RancherOS.Install.ServerURL != "" || cfg.RancherOS.Install.Silent {
if cfg.RancherOS.Install.ServerURL != "" || cfg.RancherOS.Install.Automatic {
return nil
}

Expand Down Expand Up @@ -118,7 +118,7 @@ func AskServerAgent(cfg *config.Config) error {
}

func AskPassword(cfg *config.Config) error {
if cfg.RancherOS.Install.Silent || cfg.RancherOS.Install.Password != "" {
if cfg.RancherOS.Install.Automatic || cfg.RancherOS.Install.Password != "" {
return nil
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func AskPassword(cfg *config.Config) error {
}

func AskGithub(cfg *config.Config) error {
if len(cfg.SSHAuthorizedKeys) > 0 || cfg.RancherOS.Install.Password != "" || cfg.RancherOS.Install.Silent {
if len(cfg.SSHAuthorizedKeys) > 0 || cfg.RancherOS.Install.Password != "" || cfg.RancherOS.Install.Automatic {
return nil
}

Expand All @@ -169,7 +169,7 @@ func AskGithub(cfg *config.Config) error {
}

func AskConfigURL(cfg *config.Config) error {
if cfg.RancherOS.Install.ConfigURL != "" || cfg.RancherOS.Install.Silent {
if cfg.RancherOS.Install.ConfigURL != "" || cfg.RancherOS.Install.Automatic {
return nil
}

Expand Down
11 changes: 7 additions & 4 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ func Run(automatic bool, configFile string) error {

if automatic && !cfg.RancherOS.Install.Automatic {
return nil
} else if automatic {
cfg.RancherOS.Install.Silent = true
}

err = Ask(&cfg)
Expand All @@ -45,7 +43,7 @@ func runInstall(cfg config.Config, output string) error {
return err
}

if !cfg.RancherOS.Install.Silent {
if !cfg.RancherOS.Install.Automatic {
val, err := questions.PromptBool("\nConfiguration\n"+"-------------\n\n"+
string(installBytes)+
"\nYour disk will be formatted and installed with the above configuration.\nContinue?", false)
Expand All @@ -54,7 +52,7 @@ func runInstall(cfg config.Config, output string) error {
}
}

if cfg.RancherOS.Install.ConfigURL == "" && !cfg.RancherOS.Install.Silent {
if cfg.RancherOS.Install.ConfigURL == "" && !cfg.RancherOS.Install.Automatic {
yip := config.YipConfig{
Rancherd: config.Rancherd{
Server: cfg.RancherOS.Install.ServerURL,
Expand Down Expand Up @@ -87,6 +85,11 @@ func runInstall(cfg config.Config, output string) error {
cfg.RancherOS.Install.ConfigURL = output + ".yip"
}

if err := config.ToFile(cfg, output); err != nil {
return err
}
cfg.RancherOS.Install.ConfigURL = output

ev, err := config.ToEnv(cfg)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ set url ${RELEASE_URL}/\${version}
set kernel rancheros-${PXE_ASSET_VERSION}-kernel
set initrd rancheros-${PXE_ASSET_VERSION}-initrd
set rootfs rancheros-${PXE_ASSET_VERSION}.squashfs
kernel \${url}/\${kernel} initrd=\${initrd} ip=dhcp rd.cos.disable root=live:\${url}/\${rootfs} rancheros.install.automatic=true rancheros.install.config_url=\${config} console=tty1 console=ttyS0 ${cmdline}
kernel \${url}/\${kernel} initrd=\${initrd} ip=dhcp rd.cos.disable root=live:\${url}/\${rootfs} rancheros.install.automatic=true rancheros.install.config_url=\${config} console=tty1 console=ttyS0 \${cmdline}
initrd \${url}/\${initrd}
boot
EOF
Expand Down
1 change: 1 addition & 0 deletions scripts/run
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if [ "$1" = "pxe" ]; then
BOOT="-boot cn"

if [ ! -e dev ]; then
rm -f dev
ln -s ../dist/artifacts dev
fi
fi
Expand Down

0 comments on commit db84312

Please sign in to comment.