mirror of
https://github.com/rancher/os.git
synced 2025-07-04 10:36:14 +00:00
Merge pull request #1157 from joshwget/autologin-key
Add rancher.autologin key
This commit is contained in:
commit
26a9331e41
@ -1,6 +1,7 @@
|
|||||||
package console
|
package console
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -18,6 +19,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
consoleDone = "/run/console-done"
|
consoleDone = "/run/console-done"
|
||||||
dockerHome = "/home/docker"
|
dockerHome = "/home/docker"
|
||||||
|
gettyCmd = "/sbin/agetty"
|
||||||
rancherHome = "/home/rancher"
|
rancherHome = "/home/rancher"
|
||||||
startScript = "/opt/rancher/bin/start.sh"
|
startScript = "/opt/rancher/bin/start.sh"
|
||||||
)
|
)
|
||||||
@ -63,28 +65,14 @@ func Main() {
|
|||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
respawn := `
|
|
||||||
/sbin/getty 115200 tty6
|
|
||||||
/sbin/getty 115200 tty5
|
|
||||||
/sbin/getty 115200 tty4
|
|
||||||
/sbin/getty 115200 tty3
|
|
||||||
/sbin/getty 115200 tty2
|
|
||||||
/sbin/getty 115200 tty1
|
|
||||||
/usr/sbin/sshd -D`
|
|
||||||
|
|
||||||
cmdline, err := ioutil.ReadFile("/proc/cmdline")
|
cmdline, err := ioutil.ReadFile("/proc/cmdline")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
cmdlineString := string(cmdline)
|
|
||||||
|
|
||||||
for _, tty := range []string{"ttyS0", "ttyS1", "ttyS2", "ttyS3", "ttyAMA0"} {
|
respawnConf := generateRespawnConf(string(cmdline))
|
||||||
if strings.Contains(cmdlineString, "console="+tty) {
|
|
||||||
respawn += "\n/sbin/getty 115200 " + tty
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = ioutil.WriteFile("/etc/respawn.conf", []byte(respawn), 0644); err != nil {
|
if err = ioutil.WriteFile("/etc/respawn.conf", respawnConf, 0644); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +145,36 @@ func Main() {
|
|||||||
log.Fatal(syscall.Exec(respawnBinPath, []string{"respawn", "-f", "/etc/respawn.conf"}, os.Environ()))
|
log.Fatal(syscall.Exec(respawnBinPath, []string{"respawn", "-f", "/etc/respawn.conf"}, os.Environ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateRespawnConf(cmdline string) []byte {
|
||||||
|
autologin := strings.Contains(cmdline, "rancher.autologin")
|
||||||
|
|
||||||
|
var respawnConf bytes.Buffer
|
||||||
|
|
||||||
|
for i := 1; i < 7; i++ {
|
||||||
|
respawnConf.WriteString(gettyCmd)
|
||||||
|
if autologin {
|
||||||
|
respawnConf.WriteString(" --autologin rancher")
|
||||||
|
}
|
||||||
|
respawnConf.WriteString(fmt.Sprintf(" 115200 tty%d\n", i))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tty := range []string{"ttyS0", "ttyS1", "ttyS2", "ttyS3", "ttyAMA0"} {
|
||||||
|
if !strings.Contains(cmdline, fmt.Sprintf("console=%s", tty)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
respawnConf.WriteString(gettyCmd)
|
||||||
|
if autologin {
|
||||||
|
respawnConf.WriteString(" --autologin rancher")
|
||||||
|
}
|
||||||
|
respawnConf.WriteString(fmt.Sprintf(" 115200 %s\n", tty))
|
||||||
|
}
|
||||||
|
|
||||||
|
respawnConf.WriteString("/usr/sbin/sshd -D")
|
||||||
|
|
||||||
|
return respawnConf.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
func modifySshdConfig() error {
|
func modifySshdConfig() error {
|
||||||
sshdConfig, err := ioutil.ReadFile("/etc/ssh/sshd_config")
|
sshdConfig, err := ioutil.ReadFile("/etc/ssh/sshd_config")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,4 +2,4 @@ default rancheros
|
|||||||
label rancheros
|
label rancheros
|
||||||
kernel /boot/vmlinuz
|
kernel /boot/vmlinuz
|
||||||
initrd /boot/initrd
|
initrd /boot/initrd
|
||||||
append quiet rancher.password=rancher
|
append quiet rancher.autologin
|
||||||
|
Loading…
Reference in New Issue
Block a user