1
0
mirror of https://github.com/rancher/os.git synced 2025-09-18 08:06:48 +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:
Sven Dowideit
2017-06-20 21:48:14 +10:00
parent fecbb9df2e
commit 45e422d01e
7 changed files with 101 additions and 19 deletions

72
cmd/control/autologin.go Normal file
View 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
}

View File

@@ -109,17 +109,7 @@ func consoleInitFunc() error {
}
// font backslashes need to be escaped for when issue is output! (but not the others..)
if err := ioutil.WriteFile("/etc/issue", []byte(`
, , ______ _ _____ _____TM
,------------|'------'| | ___ \\ | | / _ / ___|
/ . '-' |- | |_/ /__ _ _ __ ___| |__ ___ _ __ | | | \\ '--.
\\/| | | | // _' | '_ \\ / __| '_ \\ / _ \\ '__' | | | |'--. \\
| .________.'----' | |\\ \\ (_| | | | | (__| | | | __/ | | \\_/ /\\__/ /
| | | | \\_| \\_\\__,_|_| |_|\\___|_| |_|\\___|_| \\___/\\____/
\\___/ \\___/ \s \r
RancherOS `+config.Version+` \n \l `+cpuid.CPU.HypervisorName+`
`), 0644); err != nil {
if err := ioutil.WriteFile("/etc/issue", []byte(config.Banner), 0644); err != nil {
log.Error(err)
}
@@ -163,7 +153,8 @@ func generateRespawnConf(cmdline, user string, sshd bool) string {
respawnConf.WriteString(gettyCmd)
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))
}
@@ -175,7 +166,9 @@ func generateRespawnConf(cmdline, user string, sshd bool) string {
respawnConf.WriteString(gettyCmd)
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))
}

View File

@@ -79,6 +79,7 @@ func writeFiles(cfg *config.CloudConfig) error {
func setupCommandSymlinks() {
for _, link := range []symlink{
{config.RosBin, "/usr/bin/autologin"},
{config.RosBin, "/usr/bin/cloud-init-execute"},
{config.RosBin, "/usr/bin/cloud-init-save"},
{config.RosBin, "/usr/bin/dockerlaunch"},