mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-10-31 15:47:46 +00:00 
			
		
		
		
	Warn the user in the MOTD Add "(ns: getty)" or "(ns: sshd)" to the PS1 Use `agetty` and `-a root` to ensure we get a login shell when insecure Signed-off-by: Dave Tucker <dt@docker.com>
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/sh
 | |
| set -x
 | |
| 
 | |
| infinite_loop() {
 | |
| 	while true; do
 | |
| 		$@
 | |
| 	done
 | |
| }
 | |
| 
 | |
| # run getty on all known consoles
 | |
| start_getty() {
 | |
| 	tty=${1%,*}
 | |
| 	speed=${1#*,}
 | |
| 	securetty="$2"
 | |
| 	line=
 | |
| 	term="linux"
 | |
| 	[ "$speed" = "$1" ] && speed=115200
 | |
| 
 | |
| 	case "$tty" in
 | |
| 	ttyS*|ttyAMA*|ttyUSB*|ttyMFD*)
 | |
| 		line="-L"
 | |
| 		term="vt100"
 | |
| 		;;
 | |
| 	tty?)
 | |
| 		line=""
 | |
| 		speed="38400"
 | |
| 		term=""
 | |
| 		;;
 | |
| 	esac
 | |
| 
 | |
| 	# are we secure or insecure?
 | |
| 	loginargs=
 | |
| 	if [ "$INSECURE" == "true" ]; then
 | |
| 		loginargs="-a root"
 | |
| 	fi
 | |
| 
 | |
| 	if ! grep -q -w "$tty" "$securetty"; then
 | |
| 		echo "$tty" >> "$securetty"
 | |
| 	fi
 | |
| 	# respawn forever
 | |
| 	infinite_loop setsid.getty -w /sbin/agetty $loginargs $line $speed $tty $term &
 | |
| }
 | |
| 
 | |
| # check if we have /etc/getty.shadow
 | |
| ROOTSHADOW=/hostroot/etc/getty.shadow
 | |
| if [ -f $ROOTSHADOW ]; then
 | |
| 	cp $ROOTSHADOW /etc/shadow
 | |
| 	# just in case someone forgot a newline
 | |
| 	echo >> /etc/shadow
 | |
| fi
 | |
| 
 | |
| for opt in $(cat /proc/cmdline); do
 | |
| 	case "$opt" in
 | |
| 	console=*)
 | |
| 		start_getty ${opt#console=} /etc/securetty
 | |
| 	esac
 | |
| done
 | |
| 
 | |
| # wait for all our child process to exit; tini will handle subreaping, if necessary
 | |
| wait
 |