#!/bin/bash

# Copyright (C) 2010-2019 by X2Go project, https://wiki.x2go.org
#       Oleksandr Shneyder <o.shneyder@phoca-gmbh.de>
#       Moritz 'Morty' Struebe <Moritz.Struebe@informatik.uni-erlangen.de>
#       Mike Gabriel <mike.gabriel@das-netzwerkteam.de>

# X2Go is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# X2Go is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

if [ -z "$X2GO_HANDLE_DAEMON" ]; then
	mkdir -p ~x2gothinclient
	mkdir -p ~x2gothinclient/.x2goclient
	if [ -e /etc/x2go/x2gothinclient_sessions ]; then
		 cp /etc/x2go/x2gothinclient_sessions ~x2gothinclient/.x2goclient/sessions
	fi
	if [ -e /etc/x2go/freerdp/known_hosts ]; then
		mkdir -p ~x2gothinclient/.freerdp
		cp /etc/x2go/freerdp/known_hosts ~x2gothinclient/.freerdp/known_hosts
	fi
	if [ -e /etc/x2go/freerdp/known_hosts2 ]; then
		mkdir -p ~x2gothinclient/.config/freerdp
		cp /etc/x2go/freerdp/known_hosts2 ~x2gothinclient/.config/freerdp/known_hosts2
	fi
	if [ -e /etc/xdg/autostart/x2gothinclient-minidesktop.desktop ]; then
		mkdir -p ~x2gothinclient/Desktop
		cp /etc/xdg/autostart/x2gothinclient-minidesktop.desktop ~x2gothinclient/Desktop/
		chmod 0700 ~x2gothinclient/Desktop/x2gothinclient-minidesktop.desktop
	fi
	mkdir -p ~x2gothinclient/.kde
	mkdir -p ~x2gothinclient/.kde/socket-`hostname`
	mkdir -p ~x2gothinclient/mounts
	mkdir -p ~x2gothinclient/.gnupg
	echo -e "pinentry-program /usr/bin/pinentry-x2go\nenable-ssh-support">~x2gothinclient/.gnupg/gpg-agent.conf
	mkdir -p ~x2gothinclient/export
	mkdir -p ~x2gothinclient/logins
	mkdir -p ~x2gothinclient/.ssh
	mkdir -p ~x2gothinclient/.x2go
	chown x2gothinclient:x2gothinclient ~x2gothinclient -Rf
	chmod go-rwx ~x2gothinclient -Rf
fi
