#!/bin/bash
#
-# This must be sourced
+
+# to make audio work will need to do this:
+# > sudo dnf install pulseaudio-utils
+# > pactl load-module module-native-protocol-tcp
+
+#set -x
subu=$1
+
+if [ ! -x "/usr/local/bin/user-stem" ]; then
+ echo "no /usr/local/bin/user-stem program found (it is in the system repo)"
+ exit 1
+fi
+
if [ -z "$subu" ]; then
echo "no subuser name supplied"
exit 1
fi
machine="$(hostname)"
-xkey=$(xauth list | grep Turbine | awk '{print $3}')
+xkey=$(xauth list | grep "$machine" | head -1 | awk '{print $3}')
-if [ -z "$key" ]; then
+if [ -z "$xkey" ]; then
echo "xauth key not found"
exit 1
fi
-sudo su "$subu"
+stem=$(/usr/local/bin/user-stem)
+user_subu="$stem-$subu"
+home_subu="/home/$stem/$subu"
+bashrc="$home_subu/.bashrc"
+xauthority="$home_subu/.Xauthority"
+
+read -r -d '' script0 <<-EOF
+ cd "$home_subu" \
+ ;export DISPLAY=$DISPLAY \
+ ;export NO_AT_BRIDGE=1 \
+ ;export PULSE_SERVER=localhost \
+ ;touch "$xauthority" \
+ ;xauth add "$DISPLAY" . "$xkey" \
+ ;gnome-terminal
+EOF
+
+sudo su "$user_subu" -c "$script0"
-xauth
\ No newline at end of file
+#set +x