summaryrefslogtreecommitdiff
path: root/system/xrdp/xrdp-xwmconfig
blob: b614ba60204a05552cddbb948bb851de139efbee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh
# Copyright 1999, 2002  Patrick Volkerding, Moorhead, Minnesota USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Modified by Phillip Warner <pc_warner@yahoo.com>
# for editing xrdp-xinitrc for use with xrdp

# $DWM is the file under /usr/lib/xrdp that points to /etc/xrdp/xrdp-xinitrc.
# /etc/xrdp/xrdp-xinitrc will be modified by this script if run by root.
# $UWM is the file under $HOME that will be modified by this script.
# The values for DefaultWindowManager and UserWindowManager, respectively, 
# in sesman.ini should match these.
DWM=startwm.sh
UWM=.xrdp-xinitrc

# First, let's bail if our being here doesn't make sense:
if [ ! -d /etc/X11/xinit ]; then
  exit
fi
if [ "`cd /etc/X11/xinit ; echo *.*`" = '*.*' ]; then
  exit
fi
if [ ! -d /etc/xrdp ]; then
  exit
fi
if [ $(grep -w DefaultWindowManager /etc/xrdp/sesman.ini | cut -f2 -d"=") != $DWM ]
then
  echo "DefaultWindowManager in sesman.ini MUST be $DWM to use this tool.  Aborting..."
  exit
fi
if [ $(grep -w UserWindowManager /etc/xrdp/sesman.ini | cut -f2 -d"=") != $UWM ]
then
  echo "UserWindowManager in sesman.ini MUST be $UWM to use this tool.  Aborting..."
  exit
fi

if [ "$USER" = "root" ]; then
  TMP=/var/log/setup/tmp
else
  TMP=$HOME/.xrdp-xwmconfig
fi

if [ ! -d $TMP ]; then
 mkdir -p $TMP
 chmod 700 $TMP
fi

# Do we already have an existing default?
unset PRESELECT
if [ -L /etc/xrdp/xrdp-xinitrc ]; then
  CURRENT="$(basename $(/bin/ls -l /etc/xrdp/xrdp-xinitrc | cut -f 2 -d '>'))"
  PRESELECT=" --default-item $CURRENT "
fi

# Figure out who we are and set up some background information:
if [ "$USER" = "root" ]; then
  BACKTITLE="--backtitle \"Setting system-wide default xrdp window manager at /etc/xrdp/xrdp-xinitrc\""
else
  BACKTITLE="--backtitle \"Setting user default xrdp window manager in $HOME/$UWM\""
fi

# This stops --backtitle from cluttering the initial install:
if [ ! -r /proc/kcore ]; then
  BACKTITLE=""
fi

# Remove any previous script:
rm -f $TMP/tmpscript.sh

# Add the top of the script:
cat << EOF > $TMP/tmpscript.sh
dialog $BACKTITLE --title "SELECT DEFAULT WINDOW MANAGER FOR XRDP" $PRESELECT --menu \\
"Please select the default window manager to use with XRDP. \\
This will define the style of graphical user interface the \\
client computer uses in remote X11rdp sessions." 0 0 0 \\
EOF

# Add KDE as the first and default entry:
if [ -r /etc/X11/xinit/xinitrc.kde ]; then
  echo "\"xinitrc.kde\" \"KDE: K Desktop Environment\" \\" >> $TMP/tmpscript.sh
fi

# Then, we add GNOME:
if [ -r /etc/X11/xinit/xinitrc.gnome ]; then
  echo "\"xinitrc.gnome\" \"GNU Network Object Model Environment\" \\" >> $TMP/tmpscript.sh
fi

# Add XFce:
if [ -r /etc/X11/xinit/xinitrc.xfce ]; then
  echo "\"xinitrc.xfce\" \"The Cholesterol Free Desktop Environment\" \\" >> $TMP/tmpscript.sh
fi

# Add Enlightenment:
if [ -r /etc/X11/xinit/xinitrc.e ]; then
  echo "\"xinitrc.e\" \"Enlightenment\" \\" >> $TMP/tmpscript.sh
fi

# Add Fluxbox:
if [ -r /etc/X11/xinit/xinitrc.fluxbox ]; then
  echo "\"xinitrc.fluxbox\" \"The fluxbox window manager\" \\" >> $TMP/tmpscript.sh
fi

# Add Blackbox:
if [ -r /etc/X11/xinit/xinitrc.blackbox ]; then
  echo "\"xinitrc.blackbox\" \"The blackbox window manager\" \\" >> $TMP/tmpscript.sh
fi

# Add WindowMaker:
if [ -r /etc/X11/xinit/xinitrc.wmaker ]; then
  echo "\"xinitrc.wmaker\" \"WindowMaker\" \\" >> $TMP/tmpscript.sh
fi

# Add FVWM2:
if [ -r /etc/X11/xinit/xinitrc.fvwm2 ]; then
  echo "\"xinitrc.fvwm2\" \"F(?) Virtual Window Manager (version 2.xx)\" \\" >> $TMP/tmpscript.sh
fi

# Add FVWM95:
if [ -r /etc/X11/xinit/xinitrc.fvwm95 ]; then
  echo "\"xinitrc.fvwm95\" \"FVWM2 with a Windows look and feel\" \\" >> $TMP/tmpscript.sh
fi

# Add icewm:
if [ -r /etc/X11/xinit/xinitrc.icewm ]; then
  echo "\"xinitrc.icewm\" \"ICE Window Manager\" \\" >> $TMP/tmpscript.sh
fi

# Add sawfish:
if [ -r /etc/X11/xinit/xinitrc.sawfish ]; then
  echo "\"xinitrc.sawfish\" \"Sawfish without GNOME\" \\" >> $TMP/tmpscript.sh
fi

# Add twm:
if [ -r /etc/X11/xinit/xinitrc.twm ]; then
  echo "\"xinitrc.twm\" \"Tab Window Manager (very basic)\" \\" >> $TMP/tmpscript.sh
fi

# Add mwm:
if [ -r /etc/X11/xinit/xinitrc.mwm ]; then
  echo "\"xinitrc.mwm\" \"Motif WM\" \\" >> $TMP/tmpscript.sh
fi

# Now, add support for the other window managers:
( cd /etc/X11/xinit
  for file in xinitrc.* ; do
    if [ ! "$file" = "xinitrc.kde" -a ! "$file" = "xinitrc.gnome" \
      -a ! "$file" = "xinitrc.e" -a ! "$file" = "xinitrc.wmaker" \
      -a ! "$file" = "xinitrc.fvwm2" -a ! "$file" = "xinitrc.fvwm95" \
      -a ! "$file" = "xinitrc.icewm" -a ! "$file" = "xinitrc.twm" \
      -a ! "$file" = "xinitrc.mwm" -a ! "$file" = "xinitrc.xfce" \
      -a ! "$file" = "xinitrc.blackbox" -a ! "$file" = "xinitrc.fluxbox" \
      -a ! "$file" = "xinitrc.sawfish" ]; then
      echo "\"$file\" \"$file\" \\" >> $TMP/tmpscript.sh
    fi
  done
)

# Then, the tail end:
cat << EOF >> $TMP/tmpscript.sh
2> $TMP/output
if [ ! \$? = 0 ]; then
  rm -f $TMP/output
  echo "Canceled."
  exit
fi
EOF

sh $TMP/tmpscript.sh

if [ ! -r $TMP/output ]; then
  rm -f $TMP/tmpscript.sh
  exit
fi

OUTPUT=`cat $TMP/output`

# If xrdp-xwmconfig is run by root, it changes the system-wide default for users
# that do not have a $HOME/$UWM:
if [ "$USER" = "root" ]; then
  if [ -r /etc/X11/xinit/$OUTPUT ]; then
    ( cd /etc/xrdp/ ; rm -f xrdp-xinitrc ; ln -sf /etc/X11/xinit/$OUTPUT xrdp-xinitrc )
  fi
fi

# Also set up a new $HOME/$UWM:
if [ -r /etc/X11/xinit/$OUTPUT -a ! "$HOME" = "/" ]; then
  if [ -r $HOME/$UWM ]; then
    rm -f $HOME/${UWM}-backup
    mv $HOME/$UWM $HOME/${UWM}-backup
    chmod -x $HOME/${UWM}-backup
  fi
  cat /etc/X11/xinit/$OUTPUT > $HOME/$UWM
  # Unlike .xinitrc, $UWM *MUST* be executable
  chmod u+x $HOME/$UWM
fi

rm -f $TMP/tmpscript.sh $TMP/output