1
0
Fork 0
dotfiles/.local/bin/startgraphical

99 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc" ]; then
server=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc
elif [ -r "$HOME/.xserverrc" ]; then
server=$HOME/.xserverrc
else
server=/etc/X11/xinit/xserverrc
fi
if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession" ]; then
client=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession
elif [ -r "$HOME/.xsession" ]; then
client="$HOME/.xsession"
else
client=/etc/X11/xinit/xinitrc
fi
# Automatically determine an unused $DISPLAY
d=0
while true; do
[ -e "/tmp/.X$d-lock" ] || [ -S "/tmp/.X11-unix/X$d" ] || break
d=$((d + 1))
done
display=":$d"
unset d
if [ -z "${XAUTHORITY+x}" ]; then
XAUTHORITY=$HOME/.Xauthority
export XAUTHORITY
fi
removelist=
# check for GNU hostname
if hostname --version >/dev/null 2>&1; then
if ! hostname --version 2>&1 | grep GNU -q; then
hostname=$(hostname -f)
fi
fi
if [ -z "$hostname" ]; then
hostname=$(hostname)
fi
authdisplay=${display:-:0}
mcookie=$(/usr/bin/mcookie)
if [ -z "${mcookie+x}" ]; then
echo "Couldn't create cookie"
exit 1
fi
dummy=0
# create a file with auth information for the server. ':0' is a dummy.
xserverauthfile=$(mktemp --tmpdir serverauth.XXXXXXXXXX)
trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP BUS TERM
xauth -q -f "$xserverauthfile" <<EOF
add :$dummy . $mcookie
EOF
serverargs=${serverargs}" -auth "${xserverauthfile}
# now add the same credentials to the client authority file
# if '$displayname' already exists do not overwrite it as another
# server may need it. Add them to the '$xserverauthfile' instead.
for displayname in $authdisplay $hostname$authdisplay; do
authcookie=$(xauth list "$displayname" | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p") 2>/dev/null
if [ -n "${authcookie+x}" ]; then
xauth -q <<EOF
add $displayname . $mcookie
EOF
removelist="$displayname $removelist"
else
dummy=$((dummy + 1))
xauth -q -f "$xserverauthfile" <<EOF
add :$dummy . $authcookie
EOF
fi
done
xinit $client -- $server $serverargs $display
retval=$?
if [ -z "${removelist+x}" ]; then
xauth remove $removelist
fi
if [ x"$xserverauthfile" != x ]; then
rm -f "$xserverauthfile"
fi
if command -v deallocvt >/dev/null 2>&1; then
deallocvt
fi
exit $retval