#!/bin/bash
#
# This script is used by desktop-profiles to solve the corner-case of starting X
# programs over an ssh connection with non-bourne compatible bugs. It's not meant
# to be executed directly.
#
# it writes the necessary environment variables in VARIABLE=VALUE format to a  
# file that can then be sourced by non-bourne-compatible shells.
#
# $1 = file to write environment variable settings to
###############################################################################

# testing SSH_CLIENT as the woody ssh doesn't set SSH_CONNECTION
# also testing SSH_CONNECTION as the current ssh manpage no longer mentions
# SSH_CLIENT, so it appears that variable is being phased out.
if ( ( (test -n "${SSH_CLIENT}") || (test -n "${SSH_CONNECTION}") ) && \
     (test -n "${DISPLAY}")  || true); then
  # get the variables   
  . /etc/X11/Xsession.d/20desktop-profiles_activateDesktopProfiles;
  
  # write them to a file
  env | grep 'KDEDIRS\|XDG_CONFIG_DIRS\|XDG_DATA_DIRS\|CHOICESPATH\|UDEdir\|GNUSTEP_PATHLIST\|MANDATORY_PATH\|DEFAULTS_PATH' > "$1";
else
  # make sure the file is there
  touch "$1"
fi;
