diff --git a/framework/files/usr/lib/systemd/system/ros-installer.service b/framework/files/usr/lib/systemd/system/ros-installer.service index c1523803..7a8a1199 100644 --- a/framework/files/usr/lib/systemd/system/ros-installer.service +++ b/framework/files/usr/lib/systemd/system/ros-installer.service @@ -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 serial-getty@ttyS0.service [Install] WantedBy=multi-user.target diff --git a/pkg/config/config.go b/pkg/config/config.go index 84546b78..e6f563b5 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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"` diff --git a/pkg/config/read.go b/pkg/config/read.go index 4d8d84b5..b5a5e2e1 100644 --- a/pkg/config/read.go +++ b/pkg/config/read.go @@ -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)) } @@ -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) @@ -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) { @@ -199,5 +221,5 @@ func readCmdline() (map[string]interface{}, error) { } } - return data, nil + return readNested(data) } diff --git a/pkg/install/ask.go b/pkg/install/ask.go index 65877f7d..d2c83434 100644 --- a/pkg/install/ask.go +++ b/pkg/install/ask.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/pkg/install/install.go b/pkg/install/install.go index b6cc8c92..4eb7f9eb 100644 --- a/pkg/install/install.go +++ b/pkg/install/install.go @@ -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) @@ -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) @@ -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, @@ -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 diff --git a/scripts/package b/scripts/package index 6b540e09..3e43c6ca 100755 --- a/scripts/package +++ b/scripts/package @@ -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 diff --git a/scripts/run b/scripts/run index 6af71837..2a743988 100755 --- a/scripts/run +++ b/scripts/run @@ -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