Andrey Smirnov d3d011c8d2 chore: replace /* */ comments with // comments in license header
This fixes issues with `// +build` directives not being recognized in
source files.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-10-25 14:15:17 -07:00

82 lines
2.2 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package interactive
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"golang.org/x/sys/unix"
"github.com/talos-systems/talos/internal/pkg/installer"
"github.com/talos-systems/talos/internal/pkg/kernel"
"github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/blockdevice/probe"
"github.com/talos-systems/talos/pkg/config/machine"
"github.com/talos-systems/talos/pkg/constants"
)
// Interactive is an initializer that performs an installation by prompting the
// user.
type Interactive struct{}
// Initialize implements the Initializer interface.
func (i *Interactive) Initialize(platform runtime.Platform, install machine.Install) (err error) {
var dev *probe.ProbedBlockDevice
dev, err = probe.GetDevWithFileSystemLabel(constants.ISOFilesystemLabel)
if err != nil {
return fmt.Errorf("failed to find %s iso: %w", constants.ISOFilesystemLabel, err)
}
if err = unix.Mount(dev.Path, "/tmp", dev.SuperBlock.Type(), unix.MS_RDONLY, ""); err != nil {
return err
}
for _, f := range []string{"/tmp/usr/install/vmlinuz", "/tmp/usr/install/initramfs.xz"} {
var source []byte
source, err = ioutil.ReadFile(f)
if err != nil {
return err
}
if err = ioutil.WriteFile("/"+filepath.Base(f), source, 0644); err != nil {
return err
}
}
reader := bufio.NewReader(os.Stdin)
fmt.Print("Talos configuration URL: ")
endpoint, err := reader.ReadString('\n')
if err != nil {
return err
}
cmdline := kernel.NewDefaultCmdline()
cmdline.Append("initrd", filepath.Join("/", "default", constants.InitramfsAsset))
cmdline.Append(constants.KernelParamPlatform, strings.ToLower(platform.Name()))
cmdline.Append(constants.KernelParamConfig, endpoint)
var inst *installer.Installer
inst, err = installer.NewInstaller(cmdline, install)
if err != nil {
return err
}
if err = inst.Install(); err != nil {
return fmt.Errorf("failed to install: %w", err)
}
return unix.Reboot(int(unix.LINUX_REBOOT_CMD_RESTART))
}