69 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #! /usr/bin/env bash
 | |
| #
 | |
| # xephwrap.sh
 | |
| # Copyright (C) 2018 salt <salt@lap-th-e560-0>
 | |
| #
 | |
| # Distributed under terms of the MIT license.
 | |
| #
 | |
| 
 | |
| name="$(basename -- "$0" .sh)"
 | |
| 
 | |
| log() {
 | |
| 	[ -z ${1+x} ] && return 1
 | |
| 	printf "\\e[94m%s\\e[0m: %s\\n" \
 | |
| 		"$name" \
 | |
| 		"$1"
 | |
| }
 | |
| 
 | |
| xprompt() {
 | |
| 	[ -z ${1+x} ] && return 2
 | |
| 	[ -z ${2+x} ] || default="$2"; suffix=" [$default]"
 | |
| 	read -rp "$1$suffix: "
 | |
| 	if [ "$REPLY" == "" ]; then
 | |
| 		export REPLY="$2"
 | |
| 	fi
 | |
| }
 | |
| 
 | |
| validatedep() {
 | |
| 	[ -z ${1+x} ] && return 2
 | |
| 	if ! command -v "$1" > /dev/null 2>&1; then
 | |
| 		return 1
 | |
| 	fi
 | |
| 	return 0
 | |
| }
 | |
| 
 | |
| # Validate dependencies
 | |
| for dep in Xephyr; do
 | |
| 	if ! validatedep "$dep"; then
 | |
| 		log "Failed to validate dependency: \"$dep\""
 | |
| 		exit 1
 | |
| 	fi
 | |
| done
 | |
| 
 | |
| # Prompt for user interaction
 | |
| xprompt "Size" "1280x720"
 | |
| size="$REPLY"
 | |
| 
 | |
| xprompt "Display" "10"
 | |
| display="$REPLY"
 | |
| 
 | |
| if ! [ "$display" -ge "-1" ]; then
 | |
| 	log "Invalid response for display: \"$display\""
 | |
| 	exit 4
 | |
| fi
 | |
| if [ "$display" == "$DISPLAY" ]; then
 | |
| 	log "Response matches host display: \"$display\""
 | |
| 	exit 5
 | |
| fi
 | |
| 
 | |
| # Start the server up
 | |
| Xephyr \
 | |
| 	-ac \
 | |
| 	-screen "$size" \
 | |
| 	:"$display" \
 | |
| 	&
 | |
| disown
 | |
| log "Started Xephyr server"
 | |
| exit 0
 | |
| 
 |