added remote shell detection
This commit is contained in:
		
							parent
							
								
									b21b623273
								
							
						
					
					
						commit
						958985df83
					
				
					 2 changed files with 28 additions and 0 deletions
				
			
		| 
						 | 
					@ -114,3 +114,10 @@ function rv() {
 | 
				
			||||||
	printf ' RV=%d \e[0m\n' $RV >&2
 | 
						printf ' RV=%d \e[0m\n' $RV >&2
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function hexy() {
 | 
				
			||||||
 | 
						python3 -c 'import sys
 | 
				
			||||||
 | 
					for v in sys.argv[1:]:
 | 
				
			||||||
 | 
					  print("{:02x}".format(int(v)), end="")
 | 
				
			||||||
 | 
					print("")
 | 
				
			||||||
 | 
					' $*
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										21
									
								
								is_remote.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								is_remote.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					# Detect if the current session is running on a remote server by listing parent
 | 
				
			||||||
 | 
					# processes of this shell and checking for things like sshd/tailscaled. Runs
 | 
				
			||||||
 | 
					# first because multiple other things rely on this.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function __is_remote() {
 | 
				
			||||||
 | 
						# names of daemon processes a remote shell might be a child process of
 | 
				
			||||||
 | 
						remote_daemons=(
 | 
				
			||||||
 | 
						    sshd
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						is_remote=()
 | 
				
			||||||
 | 
						parent_procs="$(pstree -s $$)"
 | 
				
			||||||
 | 
						for d in ${remote_daemons[@]}; do
 | 
				
			||||||
 | 
							if [[ "$parent_procs" =~ "$d" ]]; then
 | 
				
			||||||
 | 
								return 1
 | 
				
			||||||
 | 
							fi
 | 
				
			||||||
 | 
						done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue