mirror of
https://github.com/rancher/os.git
synced 2025-09-08 10:11:46 +00:00
Fix installer
This commit is contained in:
@@ -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
|
||||
|
@@ -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"`
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user