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

99 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-02-07 14:24:06 +01:00
#!/bin/sh
if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc" ]; then
2023-02-07 17:19:53 +01:00
server=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc
2023-02-07 14:24:06 +01:00
elif [ -r "$HOME/.xserverrc" ]; then
2023-02-07 17:19:53 +01:00
server=$HOME/.xserverrc
2023-02-07 14:24:06 +01:00
else
2023-02-07 17:19:53 +01:00
server=/etc/X11/xinit/xserverrc
2023-02-07 14:24:06 +01:00
fi
if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession" ]; then
2023-02-07 17:19:53 +01:00
client=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession
2023-02-07 14:24:06 +01:00
elif [ -r "$HOME/.xsession" ]; then
2023-02-07 17:19:53 +01:00
client="$HOME/.xsession"
2023-02-07 14:24:06 +01:00
else
2023-02-07 17:19:53 +01:00
client=/etc/X11/xinit/xinitrc
2023-02-07 14:24:06 +01:00
fi
# Automatically determine an unused $DISPLAY
d=0
2023-02-07 17:19:53 +01:00
while true; do
[ -e "/tmp/.X$d-lock" ] || [ -S "/tmp/.X11-unix/X$d" ] || break
d=$((d + 1))
2023-02-07 14:24:06 +01:00
done
display=":$d"
unset d
2023-02-09 14:51:03 +01:00
if [ -z "${XAUTHORITY+x}" ]; then
2023-02-07 17:19:53 +01:00
XAUTHORITY=$HOME/.Xauthority
export XAUTHORITY
2023-02-07 14:24:06 +01:00
fi
removelist=
# check for GNU hostname
2023-02-07 17:19:53 +01:00
if hostname --version >/dev/null 2>&1; then
if ! hostname --version 2>&1 | grep GNU -q; then
hostname=$(hostname -f)
fi
2023-02-07 14:24:06 +01:00
fi
if [ -z "$hostname" ]; then
2023-02-07 17:19:53 +01:00
hostname=$(hostname)
2023-02-07 14:24:06 +01:00
fi
authdisplay=${display:-:0}
mcookie=$(/usr/bin/mcookie)
2023-02-07 16:00:19 +01:00
if [ -z "${mcookie+x}" ]; then
2023-02-07 17:19:53 +01:00
echo "Couldn't create cookie"
exit 1
2023-02-07 14:24:06 +01:00
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
2023-02-07 17:19:53 +01:00
xauth -q -f "$xserverauthfile" <<EOF
2023-02-07 14:24:06 +01:00
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
2023-02-07 17:19:53 +01:00
authcookie=$(xauth list "$displayname" | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p") 2>/dev/null
if [ -n "${authcookie+x}" ]; then
xauth -q <<EOF
2023-02-07 14:24:06 +01:00
add $displayname . $mcookie
EOF
2023-02-07 17:19:53 +01:00
removelist="$displayname $removelist"
else
dummy=$((dummy + 1))
xauth -q -f "$xserverauthfile" <<EOF
2023-02-07 14:24:06 +01:00
add :$dummy . $authcookie
EOF
2023-02-07 17:19:53 +01:00
fi
2023-02-07 14:24:06 +01:00
done
xinit $client -- $server $serverargs $display
retval=$?
if [ -z "${removelist+x}" ]; then
2023-02-07 17:19:53 +01:00
xauth remove $removelist
2023-02-07 14:24:06 +01:00
fi
if [ x"$xserverauthfile" != x ]; then
2023-02-07 17:19:53 +01:00
rm -f "$xserverauthfile"
2023-02-07 14:24:06 +01:00
fi
2023-02-07 17:19:53 +01:00
if command -v deallocvt >/dev/null 2>&1; then
deallocvt
2023-02-07 14:24:06 +01:00
fi
exit $retval