bin/xephwrap

69 lines
1.1 KiB
Plaintext
Raw Normal View History

2018-10-12 21:34:55 -05:00
#! /usr/bin/env bash
#
# xephwrap.sh
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
2019-01-03 21:43:30 -06:00
name="$(basename -- "$0" .sh)"
2018-10-12 21:34:55 -05:00
2019-01-03 21:43:30 -06:00
log() {
2018-10-12 21:34:55 -05:00
[ -z ${1+x} ] && return 1
2019-01-03 21:43:30 -06:00
printf "\\e[94m%s\\e[0m: %s\\n" \
"$name" \
"$1"
2018-10-12 21:34:55 -05:00
}
2019-01-03 21:43:30 -06:00
xprompt() {
2018-10-12 21:34:55 -05:00
[ -z ${1+x} ] && return 2
[ -z ${2+x} ] || default="$2"; suffix=" [$default]"
2019-01-03 21:43:30 -06:00
read -rp "$1$suffix: "
2018-10-12 21:34:55 -05:00
if [ "$REPLY" == "" ]; then
export REPLY="$2"
fi
}
2019-01-03 21:43:30 -06:00
validatedep() {
2018-10-12 21:34:55 -05:00
[ -z ${1+x} ] && return 2
2019-01-03 21:43:30 -06:00
if ! command -v "$1" > /dev/null 2>&1; then
2018-10-12 21:34:55 -05:00
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