mirror of
https://github.com/rancher/os.git
synced 2025-09-09 10:40:30 +00:00
Fix installer
This commit is contained in:
@@ -3,7 +3,6 @@ Description=RancherOS Automatic Installation
|
|||||||
Documentation=https://github.com/rancher/os2
|
Documentation=https://github.com/rancher/os2
|
||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
Before=getty-pre.target serial-getty@ttyS0.service
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
@@ -9,7 +9,6 @@ type Install struct {
|
|||||||
ForceEFI bool `json:"forceEfi,omitempty"`
|
ForceEFI bool `json:"forceEfi,omitempty"`
|
||||||
Device string `json:"device,omitempty"`
|
Device string `json:"device,omitempty"`
|
||||||
ConfigURL string `json:"configUrl,omitempty"`
|
ConfigURL string `json:"configUrl,omitempty"`
|
||||||
Silent bool `json:"silent,omitempty"`
|
|
||||||
ISOURL string `json:"isoUrl,omitempty"`
|
ISOURL string `json:"isoUrl,omitempty"`
|
||||||
PowerOff bool `json:"powerOff,omitempty"`
|
PowerOff bool `json:"powerOff,omitempty"`
|
||||||
NoFormat bool `json:"noFormat,omitempty"`
|
NoFormat bool `json:"noFormat,omitempty"`
|
||||||
|
@@ -66,12 +66,6 @@ func readNested(data map[string]interface{}) (map[string]interface{}, error) {
|
|||||||
funcs []reader
|
funcs []reader
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(nestedConfigFiles) == 0 {
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
values.RemoveValue(data, "rancheros", "install", "configUrl")
|
|
||||||
|
|
||||||
for _, nestedConfigFile := range nestedConfigFiles {
|
for _, nestedConfigFile := range nestedConfigFiles {
|
||||||
funcs = append(funcs, readFileFunc(nestedConfigFile))
|
funcs = append(funcs, readFileFunc(nestedConfigFile))
|
||||||
}
|
}
|
||||||
@@ -123,7 +117,7 @@ func readFile(path string) (result map[string]interface{}, _ error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, nil
|
return readNested(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
type reader func() (map[string]interface{}, error)
|
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 {
|
if err := schema.Mapper.ToInternal(newData); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
newData, err = readNested(newData)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
d = values.MergeMapsConcatSlice(d, newData)
|
d = values.MergeMapsConcatSlice(d, newData)
|
||||||
}
|
}
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfigMap(cfg string) (map[string]interface{}, error) {
|
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) {
|
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 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ func AskServerAgent(cfg *config.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AskPassword(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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ func AskPassword(cfg *config.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AskGithub(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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ func AskGithub(cfg *config.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AskConfigURL(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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,8 +19,6 @@ func Run(automatic bool, configFile string) error {
|
|||||||
|
|
||||||
if automatic && !cfg.RancherOS.Install.Automatic {
|
if automatic && !cfg.RancherOS.Install.Automatic {
|
||||||
return nil
|
return nil
|
||||||
} else if automatic {
|
|
||||||
cfg.RancherOS.Install.Silent = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = Ask(&cfg)
|
err = Ask(&cfg)
|
||||||
@@ -45,7 +43,7 @@ func runInstall(cfg config.Config, output string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.RancherOS.Install.Silent {
|
if !cfg.RancherOS.Install.Automatic {
|
||||||
val, err := questions.PromptBool("\nConfiguration\n"+"-------------\n\n"+
|
val, err := questions.PromptBool("\nConfiguration\n"+"-------------\n\n"+
|
||||||
string(installBytes)+
|
string(installBytes)+
|
||||||
"\nYour disk will be formatted and installed with the above configuration.\nContinue?", false)
|
"\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{
|
yip := config.YipConfig{
|
||||||
Rancherd: config.Rancherd{
|
Rancherd: config.Rancherd{
|
||||||
Server: cfg.RancherOS.Install.ServerURL,
|
Server: cfg.RancherOS.Install.ServerURL,
|
||||||
@@ -87,6 +85,11 @@ func runInstall(cfg config.Config, output string) error {
|
|||||||
cfg.RancherOS.Install.ConfigURL = output + ".yip"
|
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)
|
ev, err := config.ToEnv(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -53,7 +53,7 @@ set url ${RELEASE_URL}/\${version}
|
|||||||
set kernel rancheros-${PXE_ASSET_VERSION}-kernel
|
set kernel rancheros-${PXE_ASSET_VERSION}-kernel
|
||||||
set initrd rancheros-${PXE_ASSET_VERSION}-initrd
|
set initrd rancheros-${PXE_ASSET_VERSION}-initrd
|
||||||
set rootfs rancheros-${PXE_ASSET_VERSION}.squashfs
|
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}
|
initrd \${url}/\${initrd}
|
||||||
boot
|
boot
|
||||||
EOF
|
EOF
|
||||||
|
@@ -27,6 +27,7 @@ if [ "$1" = "pxe" ]; then
|
|||||||
BOOT="-boot cn"
|
BOOT="-boot cn"
|
||||||
|
|
||||||
if [ ! -e dev ]; then
|
if [ ! -e dev ]; then
|
||||||
|
rm -f dev
|
||||||
ln -s ../dist/artifacts dev
|
ln -s ../dist/artifacts dev
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user