mirror of
https://github.com/rancher/os.git
synced 2025-09-04 00:04:25 +00:00
Add an autologin that allows us to fix the stty
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
72
cmd/control/autologin.go
Normal file
72
cmd/control/autologin.go
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package control
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/rancher/os/config"
|
||||||
|
"github.com/rancher/os/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AutologinMain() {
|
||||||
|
log.InitLogger()
|
||||||
|
app := cli.NewApp()
|
||||||
|
|
||||||
|
app.Name = os.Args[0]
|
||||||
|
app.Usage = "autologin console"
|
||||||
|
app.Version = config.Version
|
||||||
|
app.Author = "Rancher Labs, Inc."
|
||||||
|
app.Email = "sven@rancher.com"
|
||||||
|
app.EnableBashCompletion = true
|
||||||
|
app.Action = autologinAction
|
||||||
|
app.HideHelp = true
|
||||||
|
app.Run(os.Args)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func autologinAction(c *cli.Context) error {
|
||||||
|
cmd := exec.Command("/bin/stty", "sane")
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
usertty := ""
|
||||||
|
user := "root"
|
||||||
|
tty := ""
|
||||||
|
if c.NArg() > 0 {
|
||||||
|
usertty = c.Args().Get(0)
|
||||||
|
s := strings.SplitN(usertty, ":", 2)
|
||||||
|
user = s[0]
|
||||||
|
if len(s) > 1 {
|
||||||
|
tty = s[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfg := config.LoadConfig()
|
||||||
|
// replace \n and \l
|
||||||
|
banner := config.Banner
|
||||||
|
banner = strings.Replace(banner, "\\v", config.Version, -1)
|
||||||
|
banner = strings.Replace(banner, "\\s", "RancherOS " + runtime.GOARCH, -1)
|
||||||
|
banner = strings.Replace(banner, "\\r", "4.9....", -1)
|
||||||
|
banner = strings.Replace(banner, "\\n", cfg.Hostname, -1)
|
||||||
|
banner = strings.Replace(banner, "\\l", tty, -1)
|
||||||
|
banner = strings.Replace(banner, "\\\\", "\\", -1)
|
||||||
|
banner = banner + "\n"
|
||||||
|
fmt.Printf(banner)
|
||||||
|
|
||||||
|
cmd = exec.Command("/usr/bin/login", "-f", user)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@@ -109,17 +109,7 @@ func consoleInitFunc() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// font backslashes need to be escaped for when issue is output! (but not the others..)
|
// font backslashes need to be escaped for when issue is output! (but not the others..)
|
||||||
if err := ioutil.WriteFile("/etc/issue", []byte(`
|
if err := ioutil.WriteFile("/etc/issue", []byte(config.Banner), 0644); err != nil {
|
||||||
, , ______ _ _____ _____TM
|
|
||||||
,------------|'------'| | ___ \\ | | / _ / ___|
|
|
||||||
/ . '-' |- | |_/ /__ _ _ __ ___| |__ ___ _ __ | | | \\ '--.
|
|
||||||
\\/| | | | // _' | '_ \\ / __| '_ \\ / _ \\ '__' | | | |'--. \\
|
|
||||||
| .________.'----' | |\\ \\ (_| | | | | (__| | | | __/ | | \\_/ /\\__/ /
|
|
||||||
| | | | \\_| \\_\\__,_|_| |_|\\___|_| |_|\\___|_| \\___/\\____/
|
|
||||||
\\___/ \\___/ \s \r
|
|
||||||
|
|
||||||
RancherOS `+config.Version+` \n \l `+cpuid.CPU.HypervisorName+`
|
|
||||||
`), 0644); err != nil {
|
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +153,8 @@ func generateRespawnConf(cmdline, user string, sshd bool) string {
|
|||||||
|
|
||||||
respawnConf.WriteString(gettyCmd)
|
respawnConf.WriteString(gettyCmd)
|
||||||
if strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
|
if strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
|
||||||
respawnConf.WriteString(fmt.Sprintf(" --autologin %s", user))
|
respawnConf.WriteString(fmt.Sprintf(" -n -l /usr/bin/autologin -o %s:tty%d", user, i))
|
||||||
|
//respawnConf.WriteString(fmt.Sprintf(" --autologin %s", user))
|
||||||
}
|
}
|
||||||
respawnConf.WriteString(fmt.Sprintf(" --noclear %s linux\n", tty))
|
respawnConf.WriteString(fmt.Sprintf(" --noclear %s linux\n", tty))
|
||||||
}
|
}
|
||||||
@@ -175,7 +166,9 @@ func generateRespawnConf(cmdline, user string, sshd bool) string {
|
|||||||
|
|
||||||
respawnConf.WriteString(gettyCmd)
|
respawnConf.WriteString(gettyCmd)
|
||||||
if strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
|
if strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
|
||||||
respawnConf.WriteString(fmt.Sprintf(" --autologin %s", user))
|
//respawnConf.WriteString(fmt.Sprintf(" -n -l /usr/bin/autologin -o rancher"))
|
||||||
|
respawnConf.WriteString(fmt.Sprintf(" -n -l /usr/bin/autologin -o %s:%s", user, tty))
|
||||||
|
//respawnConf.WriteString(fmt.Sprintf(" --autologin %s", user))
|
||||||
}
|
}
|
||||||
respawnConf.WriteString(fmt.Sprintf(" %s\n", tty))
|
respawnConf.WriteString(fmt.Sprintf(" %s\n", tty))
|
||||||
}
|
}
|
||||||
|
@@ -79,6 +79,7 @@ func writeFiles(cfg *config.CloudConfig) error {
|
|||||||
|
|
||||||
func setupCommandSymlinks() {
|
func setupCommandSymlinks() {
|
||||||
for _, link := range []symlink{
|
for _, link := range []symlink{
|
||||||
|
{config.RosBin, "/usr/bin/autologin"},
|
||||||
{config.RosBin, "/usr/bin/cloud-init-execute"},
|
{config.RosBin, "/usr/bin/cloud-init-execute"},
|
||||||
{config.RosBin, "/usr/bin/cloud-init-save"},
|
{config.RosBin, "/usr/bin/cloud-init-save"},
|
||||||
{config.RosBin, "/usr/bin/dockerlaunch"},
|
{config.RosBin, "/usr/bin/dockerlaunch"},
|
||||||
|
@@ -5,6 +5,18 @@ import (
|
|||||||
"github.com/rancher/os/util"
|
"github.com/rancher/os/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const Banner = `
|
||||||
|
, , ______ _ _____ _____TM
|
||||||
|
,------------|'------'| | ___ \\ | | / _ / ___|
|
||||||
|
/ . '-' |- | |_/ /__ _ _ __ ___| |__ ___ _ __ | | | \\ '--.
|
||||||
|
\\/| | | | // _' | '_ \\ / __| '_ \\ / _ \\ '__' | | | |'--. \\
|
||||||
|
| .________.'----' | |\\ \\ (_| | | | | (__| | | | __/ | | \\_/ /\\__/ /
|
||||||
|
| | | | \\_| \\_\\__,_|_| |_|\\___|_| |_|\\___|_| \\___/\\____/
|
||||||
|
\\___/ \\___/ \s \r
|
||||||
|
|
||||||
|
RancherOS \v \n \l
|
||||||
|
`
|
||||||
|
|
||||||
func Merge(bytes []byte) error {
|
func Merge(bytes []byte) error {
|
||||||
data, err := readConfigs(bytes, false, true)
|
data, err := readConfigs(bytes, false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -263,12 +263,12 @@ func RunInit() error {
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}},
|
}},
|
||||||
config.CfgFuncData{"load modules", loadModules},
|
config.CfgFuncData{"load modules", loadModules},
|
||||||
config.CfgFuncData("recovery console", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
config.CfgFuncData{"recovery console", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
if cfg.Rancher.Recovery {
|
if cfg.Rancher.Recovery {
|
||||||
recovery(nil)
|
recovery(nil)
|
||||||
}
|
}
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
},
|
}},
|
||||||
config.CfgFuncData{"b2d env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
config.CfgFuncData{"b2d env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
if dev := util.ResolveDevice("LABEL=B2D_STATE"); dev != "" {
|
if dev := util.ResolveDevice("LABEL=B2D_STATE"); dev != "" {
|
||||||
boot2DockerEnvironment = true
|
boot2DockerEnvironment = true
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/docker/libcompose/yaml"
|
"github.com/docker/libcompose/yaml"
|
||||||
"github.com/rancher/os/compose"
|
"github.com/rancher/os/compose"
|
||||||
"github.com/rancher/os/config"
|
"github.com/rancher/os/config"
|
||||||
|
"github.com/rancher/os/netconf"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -55,8 +56,8 @@ func recovery(initFailure error) {
|
|||||||
|
|
||||||
var recoveryConfig config.CloudConfig
|
var recoveryConfig config.CloudConfig
|
||||||
recoveryConfig.Rancher.Defaults = config.Defaults{
|
recoveryConfig.Rancher.Defaults = config.Defaults{
|
||||||
Network: config.NetworkConfig{
|
Network: netconf.NetworkConfig{
|
||||||
DNS: config.DNSConfig{
|
DNS: netconf.DNSConfig{
|
||||||
Nameservers: []string{
|
Nameservers: []string{
|
||||||
"8.8.8.8",
|
"8.8.8.8",
|
||||||
"8.8.4.4",
|
"8.8.4.4",
|
||||||
@@ -82,8 +83,10 @@ func recovery(initFailure error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = config.ChainCfgFuncs(&recoveryConfig,
|
_, err = config.ChainCfgFuncs(&recoveryConfig,
|
||||||
loadImages,
|
[]config.CfgFuncData{
|
||||||
recoveryServices)
|
config.CfgFuncData{"loadImages", loadImages},
|
||||||
|
config.CfgFuncData{"recovery console", recoveryServices},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
1
main.go
1
main.go
@@ -23,6 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var entrypoints = map[string]func(){
|
var entrypoints = map[string]func(){
|
||||||
|
"autologin": control.AutologinMain,
|
||||||
"cloud-init-execute": cloudinitexecute.Main,
|
"cloud-init-execute": cloudinitexecute.Main,
|
||||||
"cloud-init-save": cloudinitsave.Main,
|
"cloud-init-save": cloudinitsave.Main,
|
||||||
"console": control.ConsoleInitMain,
|
"console": control.ConsoleInitMain,
|
||||||
|
Reference in New Issue
Block a user