Remove Unixware and openserver support
[oweals/cde.git] / cde / programs / dtlogin / config / Xsession.src
1 XCOMM! KORNSHELL
2 XCOMM ##########################################################################
3 XCOMM
4 XCOMM   Xsession
5 XCOMM
6 XCOMM   Common Desktop Environment (CDE)
7 XCOMM
8 XCOMM   Configuration script for the Login Manager
9 XCOMM
10 XCOMM   (c) Copyright 1996 Digital Equipment Corporation.
11 XCOMM   (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
12 XCOMM   (c) Copyright 1993,1994,1996 International Business Machines Corp.
13 XCOMM   (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
14 XCOMM   (c) Copyright 1993,1994,1996 Novell, Inc. 
15 XCOMM   (c) Copyright 1996 FUJITSU LIMITED.
16 XCOMM   (c) Copyright 1996 Hitachi.
17 XCOMM
18 XCOMM       ************** DO NOT EDIT THIS FILE **************
19 XCOMM
20 XCOMM   CDE_INSTALLATION_TOP/bin/Xsession is a factory-default file and will
21 XCOMM   be unconditionally overwritten upon subsequent installation.
22 XCOMM   Modification is discouraged.
23 XCOMM
24 XCOMM   $TOG: Xsession.src /main/19 1999/03/30 09:38:50 mgreess $
25 XCOMM
26 XCOMM   Usage: $0 [-session session_name]
27 XCOMM
28 XCOMM ##########################################################################
29
30 #define HASH #
31
32 #ifdef sun 
33   HASH 
34   HASH Set OPENWINHOME 
35   HASH 
36   if [ -z "$OPENWINHOME" ]
37   then
38       export OPENWINHOME="/usr/openwin"
39   fi
40 #endif
41
42
43 #if 0
44 /*
45  * Platform specific definitions
46  *
47  * cpp_XINITUSER - user's xinit startup file
48  * cpp_MAIL - system mail file
49  * cpp_HELLO - dthello command line
50  * cpp_XDMSYS - xdm system session file
51  */
52 #endif
53
54 #if defined (_AIX)
55 #  define cpp_XINITUSER "$HOME/.xinitrc"
56 #  define cpp_MAIL "/var/spool/mail/$USER"
57 #elif defined (__hpux)
58 #  define cpp_XDMSYS "/usr/lib/X11/xdm/sys.xsession"
59 #elif defined (sun)
60 #  define cpp_XINITUSER "$HOME/.xinitrc"
61 #  define cpp_MAIL "/var/mail/$USER"
62 #  undef cpp_HELLO
63 #  define cpp_HELLO "$DT_BINPATH/dthello -file $DT_INSTALL/copyright &"
64 #endif
65
66 #ifdef __osf__
67 #  undef cpp_MAIL
68 #  define cpp_MAIL "/usr/spool/mail/$USER"
69 #endif
70
71 #if defined (__hpux) && defined (BLS)
72 #  undef cpp_HELLO
73 #  define cpp_HELLO "$DT_BINPATH/dthello -file /etc/copyright -file $HOME/.dtlogininfo &"
74 #endif
75
76 #ifdef linux
77 #  define cpp_MAIL "/var/spool/mail/$USER"
78 #  define cpp_XDIR "/usr/bin"
79 #  define cpp_XINITUSER "$HOME/.xinitrc"
80 #  define cpp_XDMSYS "/etc/X11/Xsession"
81 #  undef cpp_HELLO
82 #  define cpp_HELLO "$DT_BINPATH/dthello -file $DT_INSTALL/copyright &"
83 #endif
84
85 #ifdef __FreeBSD__
86 #  define cpp_MAIL "/var/mail/$USER"
87 #  define cpp_XINITUSER "$HOME/.xinitrc"
88 #  define cpp_XDMSYS "/usr/local/lib/X11/xdm/Xsession"
89 #  undef cpp_HELLO
90 #  define cpp_HELLO "$DT_BINPATH/dthello -file $DT_INSTALL/copyright &"
91 #endif
92
93 #ifdef __OpenBSD__
94 #  define cpp_MAIL "/var/mail/$USER"
95 #  define cpp_XINITUSER "$HOME/.xinitrc"
96 #  define cpp_XDMSYS "/etc/X11/xdm/Xsession"
97 #  undef cpp_HELLO
98 #  define cpp_HELLO "$DT_BINPATH/dthello -file $DT_INSTALL/copyright &"
99 #endif
100
101 #ifdef __NetBSD__
102 #  define cpp_MAIL "/var/mail/$USER"
103 #  define cpp_XINITUSER "$HOME/.xinitrc"
104 #  define cpp_XDMSYS "/etc/X11/xdm/Xsession"
105 #  undef cpp_HELLO
106 #  define cpp_HELLO "$DT_BINPATH/dthello -file $DT_INSTALL/copyright &"
107 #endif
108
109
110 #if 0
111 /*
112  * Fallback definitions
113  */
114 #endif
115
116 #if !defined (cpp_XINITUSER)
117 #  define cpp_XINITUSER "$HOME/.x11start"
118 #endif
119
120 #if !defined (cpp_MAIL)
121 #  define cpp_MAIL "/usr/mail/$USER"
122 #endif
123
124 #if !defined (cpp_HELLO)
125 #  define cpp_HELLO "$DT_BINPATH/dthello &"
126 #endif
127
128 #if !defined (cpp_XDMSYS)
129 #  define cpp_XDMSYS "/usr/lib/X11/xdm/Xsession"
130 #endif
131
132 XCOMM ##########################################################################
133 XCOMM 
134 XCOMM 
135 XCOMM   This script starts the user's session. It searches for one of three
136 XCOMM   types of startup mechanisms, in the following order:
137 XCOMM 
138 XCOMM     DT     existence of CDE DT Session Manager on the system
139 XCOMM     XDM    "$HOME/.xsession" (executable)
140 XCOMM     xinit  cpp_XINITUSER  (executable)
141 XCOMM 
142 XCOMM   If none of these startup mechanisms exist, a default window manager
143 XCOMM   and terminal emulator client are started.
144 XCOMM 
145 XCOMM ##########################################################################
146
147 XCOMM
148 XCOMM Variables must be explicitly exported
149 XCOMM 
150 set +a
151
152 XCOMM ##########################################################################
153 XCOMM 
154 XCOMM   Initialize session startup logging
155 XCOMM 
156 XCOMM ##########################################################################
157
158   exec >/dev/null 2>/dev/null
159
160   LOGDIR=$HOME/.dt
161   LOGFILENAME=$LOGDIR/startlog
162   MSGLOGFILENAME=$LOGDIR/errorlog
163   
164   if [ ! -d $LOGDIR ]; then
165     mkdir $LOGDIR
166     if [ -d $LOGDIR ]; then
167       chmod 755 $LOGDIR
168     fi
169   fi
170
171   [ -f $LOGFILENAME.older ] && rm -f $LOGFILENAME.older
172   [ -f $LOGFILENAME.old ] && mv -f $LOGFILENAME.old $LOGFILENAME.older
173   [ -f $LOGFILENAME ] && mv -f $LOGFILENAME $LOGFILENAME.old
174   touch $LOGFILENAME
175   [ ! -f $MSGLOGFILENAME ] && touch $MSGLOGFILENAME
176
177   if [ -w $LOGFILENAME ]; then
178     exec >>$LOGFILENAME 2>&1
179   fi
180
181
182   Log()
183   {
184     echo "--- $1" >>$LOGFILENAME 2>&1
185   }
186
187   Log "$(date)"
188   Log "$0 starting..."
189
190 XCOMM ##########################################################################
191 XCOMM 
192 XCOMM   Global environment section
193 XCOMM 
194 XCOMM    DT pre-sets the following environment variables for each user.
195 XCOMM    
196 XCOMM     (internal)
197 XCOMM 
198 XCOMM     DISPLAY      set to the value of the first field in the Xservers file.
199 XCOMM     HOME         set to the user's home directory (from /etc/passwd)
200 XCOMM     LANG         set to the display's current NLS language (if any)
201 XCOMM     LC_ALL       set to the value of $LANG
202 XCOMM     LOGNAME      set to the user name
203 XCOMM     PATH         set to the value of the Dtlogin "userPath" resource
204 XCOMM     USER         set to the user name
205 XCOMM     SHELL        set to the user's default shell (from /etc/passwd)
206 XCOMM     TZ           set to the value of the Dtlogin "timeZone" resource
207 XCOMM 
208 XCOMM
209 XCOMM     (Xsession)
210 XCOMM 
211 XCOMM     TERM         set to xterm
212 XCOMM     EDITOR       set to the default editor
213 XCOMM     KBD_LANG     set to the value of $LANG for certain languages
214 XCOMM     MAIL         set to cpp_MAIL
215 XCOMM 
216 XCOMM 
217 XCOMM    Three methods are available to modify or add to this list depending 
218 XCOMM    on the desired scope of the resulting environment variable. 
219 XCOMM    
220 XCOMM     1. X server and/or all users on a display       (Xconfig file)
221 XCOMM     2. all users on a display                       (Xsession file)
222 XCOMM     3. individual users                             (.dtprofile file)
223 XCOMM 
224 XCOMM    See DT on-line help, the DT Users Guide, or the Dtlogin(1X) man
225 XCOMM    page for details on setting environment variables.
226 XCOMM     
227 XCOMM     
228 XCOMM ##########################################################################
229
230   [ -z "$EDITOR" ] && EDITOR=CDE_INSTALLATION_TOP/bin/dtpad
231   [ -z "$MAIL" ] && MAIL=cpp_MAIL
232   [ -z "$LANG" ] && LANG="C"
233   TERM=dtterm
234   SESSION_SVR=`hostname`
235
236   export PATH EDITOR MAIL TERM SESSION_SVR LANG
237
238 #if defined (_AIX) && defined (AIXV4)
239 XCOMM
240 XCOMM Clear the LFT message locale override if set
241 XCOMM
242 if [ "$LC_MESSAGES" = "C@lft" ]
243 then
244   unset LC_MESSAGES
245 fi
246 #endif
247
248 #if defined (__osf__)
249   HASH
250   HASH Set XFILESEARCHPATH if necessary
251   HASH
252   if [ -z "$XFILESEARCHPATH" ]
253   then
254       export XFILESEARCHPATH="%D"
255   fi
256   HASH
257   HASH check if network is configured. If not, set environment variable
258   HASH so that tooltalk will use localhost/loopback rather than system
259   HASH name
260   RCMGR=/usr/sbin/rcmgr
261   NUM_NETCONFIG=`$RCMGR get NUM_NETCONFIG`
262   if [ "$NUM_NETCONFIG" = '' -o "$NUM_NETCONFIG" = 0 ]; then
263         export DTNONETWORK=true
264   fi
265 #endif
266  
267 #if defined (__hpux)
268   HASH
269   HASH Set the keyboard language if necessary...
270   HASH
271   if [ ! -z "$LANG" ]
272   then
273       case $LANG in
274             bulgarian | czech   | hebrew | hungarian | \
275             japanese  | korean  | polish | rumanian  | \
276             russian   | serbocroatian) 
277                         KBD_LANG=$LANG
278                         export KBD_LANG;;
279            
280              chinese-t) KBD_LANG=t_chinese
281                         export KBD_LANG;;
282              chinese-s) KBD_LANG=s_chinese
283                         export KBD_LANG;;
284             
285              *);; 
286      esac
287   fi
288 #endif
289
290   HASH
291   HASH Locate configuration file directories
292   HASH
293   XDIR=XPROJECTROOT/bin
294   DT_BINPATH=CDE_INSTALLATION_TOP/bin
295   DT_INSTALL=CDE_INSTALLATION_TOP
296   DT_INSTALL_CONFIG=CDE_INSTALLATION_TOP/config
297   DT_CONFIG=CDE_CONFIGURATION_TOP/config
298   DT_CONFIG_PATH="$DT_INSTALL_CONFIG $DT_CONFIG"
299
300 XCOMM ##########################################################################
301 XCOMM
302 XCOMM  Default desktop component configuration variable settings
303 XCOMM
304 XCOMM  This section sets the default value for variables controlling
305 XCOMM  some desktop components.
306 XCOMM
307 XCOMM ##########################################################################
308
309   HASH 
310   HASH Input method server startup
311   HASH 
312   if [ -z "$DTSTARTIMS" ]; then
313      DTSTARTIMS=True
314   fi
315
316   if [ "$DTSTARTIMS" = "False" ]; then
317      unset DTSTARTIMS
318   fi
319
320   HASH 
321   HASH Default desktop screen saver action list 
322   HASH  
323   export DTSCREENSAVERLIST="StartDtscreenSwarm StartDtscreenQix \
324     StartDtscreenFlame StartDtscreenHop StartDtscreenImage StartDtscreenLife \
325     StartDtscreenRotor StartDtscreenPyro StartDtscreenWorm StartDtscreenBlank"
326
327   HASH 
328   HASH Session startup clients and args
329   HASH 
330   if [ "$SESSIONTYPE" = "altDt" ]; then
331       dtstart_session[0]="$SDT_ALT_SESSION"
332       dtstart_hello[0]="$SDT_ALT_HELLO"
333   else
334       DTSESSION_ARGS=""
335       if [ $# -ge 2 ]; then
336           if [ "$1" = "-session" ]; then
337               DTSESSION_ARGS="$1 $2"
338           fi
339       fi
340       dtstart_session[0]="$DT_BINPATH/dtsession $DTSESSION_ARGS"
341       dtstart_hello[0]=cpp_HELLO
342   fi
343   dtstart_session[1]="$HOME/.xsession"
344   dtstart_session[2]=cpp_XINITUSER
345   dtstart_session[3]="$XDIR/xterm -geometry 80x24+10+10"
346   dtstart_hello[1]="$XDIR/xsetroot -default &"
347   dtstart_searchpath="$DT_BINPATH/dtsearchpath -ksh"
348   dtstart_ttsession="$DT_BINPATH/ttsession -s"
349   dtstart_dtdbcache="$DT_BINPATH/dtdbcache -init"
350   HASH
351   HASH dtdbcache file's directory should match
352   HASH _DTDTSMMTEMPDIR in DtSvc/DtUtil1/DtsMM.h
353   HASH
354 #ifdef __osf__
355   dtdbcacherm="rm -f /var/tmp/dtdbcache_$DISPLAY"
356 #else
357   dtdbcacherm="rm -f /tmp/dtdbcache_$DISPLAY"
358 #endif
359   dtstart_appgather="$DT_BINPATH/dtappgather &"
360 #if defined(sun)
361   dtstart_dsdm="$DT_BINPATH/dsdm &"
362 #endif
363
364   xdmstart_session[0]="$HOME/.xsession"
365   xdmstart_session[1]=cpp_XDMSYS
366   xdmstart_session[2]="xterm -geometry 80x24+10+10 -ls"
367   xdmstart_hello="$XDIR/xsetroot -default &"
368
369
370   SESSIONLOGDIR=$LOGDIR/sessionlogs
371   SESSIONLOGFILENAME="$SESSIONLOGDIR/$SESSION_SVR"_DISPLAY=$DISPLAY
372
373   if [ ! -d $SESSIONLOGDIR ]; then
374     mkdir $SESSIONLOGDIR
375     if [ -d $SESSIONLOGDIR ]; then
376       chmod 755 $SESSIONLOGDIR
377     fi
378   fi
379
380   touch $SESSIONLOGFILENAME
381
382   if [ -w $SESSIONLOGFILENAME ]; then
383       dtstart_sessionlogfile="$SESSIONLOGFILENAME"
384   else
385       dtstart_sessionlogfile="/dev/null"
386   fi
387
388   rm -f $SESSIONLOGFILENAME
389
390 #ifdef sun
391   if [ "$DTXSERVERLOCATION" != "remote" ]
392   then
393   HASH
394   HASH Start fallback console
395   HASH
396      if [ -x $XDIR/fbconsole ]
397      then
398         $XDIR/fbconsole &
399      fi
400   fi
401 #endif
402
403 #define cpp_Xsession
404 #include "_common.ksh.src"
405 #undef cpp_Xsession
406
407 #if defined (__osf__)
408 XCOMM
409 XCOMM Bring up the sysman checklist if it hasn't been run before
410 XCOMM
411   if [ -f /usr/sbin/start_checklist ]
412   then
413       Log "Starting the checklist setup"
414       /usr/sbin/start_checklist&
415   fi
416 #endif
417
418 XCOMM ##########################################################################
419 XCOMM 
420 XCOMM   Source user's desktop profile
421 XCOMM 
422 XCOMM   This section determines if the user has a desktop profile in their
423 XCOMM   home directory. If not, the desktop default profile is copied to
424 XCOMM   the home directory. The desktop profile is then sourced. The purpose
425 XCOMM   is to incorporate any per-user/per-session environment customizations
426 XCOMM   and thereby propagate them to applications and desktop components.
427 XCOMM 
428 XCOMM ##########################################################################
429
430
431   DTSYSPROFILE=sys.dtprofile
432   DTPROFILE=.dtprofile
433
434   if [ ! -f $HOME/$DTPROFILE ]; then
435     for i in $DT_CONFIG_PATH
436     do
437       if [ -f $i/$DTSYSPROFILE ]; then
438         /usr/bin/awk '
439           BEGIN {printit=1}
440           /SYSPROFILE COMMENT START/ {printit=0; next}
441           /SYSPROFILE COMMENT END/ {printit=1; next}
442           printit==1 {print}' <$i/$DTSYSPROFILE >$HOME/$DTPROFILE
443         /bin/chmod 755 $HOME/$DTPROFILE
444         break
445       fi
446     done
447   fi
448
449   HASH
450   HASH source the .dtprofile.
451   HASH
452   if [ -f $HOME/$DTPROFILE ]; then
453     dtprofile_errors=`KORNSHELL -n $HOME/$DTPROFILE 2>&1`
454     if [ "0" = "$?" ]; then
455       Log "sourcing $HOME/$DTPROFILE..."
456       . $HOME/$DTPROFILE
457     else
458       Log "not sourcing $HOME/$DTPROFILE due to errors..."
459       Log "$dtprofile_errors"
460     fi
461   fi
462
463
464 XCOMM ##########################################################################
465 XCOMM 
466 XCOMM  External Xsession processing section
467 XCOMM 
468 XCOMM  This section searches the Xsession.d subdirectory and sources
469 XCOMM  the files contained therein.  The purpose is to set up any
470 XCOMM  per-user/per-session environment customizations and thereby propagate
471 XCOMM  them to applications and desktop components.
472 XCOMM 
473 XCOMM ##########################################################################
474
475   DT_XSESSION_DIR=Xsession.d
476
477   for i in $DT_CONFIG_PATH
478   do
479     if [[ -d $i/$DT_XSESSION_DIR ]]; then
480       HASH 
481       HASH Run custom Xsession scripts for this session.
482       HASH 
483       for SCRIPT in $(ls $i/$DT_XSESSION_DIR); do
484         if [ -x $i/$DT_XSESSION_DIR/$SCRIPT -a \
485             \( ! -d $i/$DT_XSESSION_DIR/$SCRIPT \) ]; then
486                Log "sourcing $i/$DT_XSESSION_DIR/$SCRIPT..."
487                . $i/$DT_XSESSION_DIR/$SCRIPT
488           fi
489       done
490     fi
491   done
492
493
494 XCOMM ##########################################################################
495 XCOMM 
496 XCOMM   Startup section.
497 XCOMM      
498 XCOMM   Note: The ksh syntax ${parameter%% *} is used when appropriate to
499 XCOMM       remove any command line options that may have been included
500 XCOMM       in the definition of a DT executable below.
501 XCOMM      
502 XCOMM ##########################################################################
503
504 XCOMM 
505 XCOMM Return first command in array named by $1 that is executable
506 XCOMM 
507 GetFirst()
508 {
509   let i=0
510   while true; do
511     eval "cmd=\${$1[$i]}"
512     [ -z "$cmd" ] && break
513     [ -x "${cmd%% *}" ] && echo "$cmd" && break
514     Log "could not start $cmd"
515     let i=$i+1
516   done
517 }
518
519 XCOMM 
520 XCOMM Start first command in array named by $1 that is executable. If
521 XCOMM $2 is 'eval', command result will be 'eval'ed. 
522 XCOMM 
523 StartFirst()
524 {
525   first=$(GetFirst $1)
526   if [ ! -z "$first" ]; then
527     Log "starting $first"
528     if [ "$2" = "eval" ]; then
529       eval `eval "PATH=$DT_BINPATH:$PATH $first"`
530     else
531       eval "PATH=$DT_BINPATH:$PATH $first"
532     fi
533   fi
534 }
535
536   HASH 
537   HASH Prepare for session startup
538   HASH 
539
540   if [ "$DTSOURCEPROFILE" = "true" ]
541   then
542     case ${SHELL##*/} in
543        sh | ksh | ksh93 | dtksh) shellprofile="$HOME/.profile";;
544        bash) shellprofile="$HOME/.bash_profile";;
545        csh | tcsh) shellprofile="$HOME/.login";;
546        *) Log "non-standard shell $SHELL"
547     esac
548   fi
549
550   if [ "$shellprofile" -a ! -f "$shellprofile" ]
551   then
552     Log "could not read $shellprofile"
553     unset shellprofile
554   fi
555
556   if [ "$SESSIONTYPE" = "xdm" ]; then
557     startup=$(GetFirst xdmstart_session)    # get xdm session client
558     StartFirst xdmstart_hello               # start xdm hello client
559   else
560     startup=$(GetFirst dtstart_session)     # get desktop session client
561     StartFirst dtstart_hello                # start desktop hello client
562     StartFirst dtstart_searchpath eval      # setup desktop search paths
563
564     tooltalk=$(GetFirst dtstart_ttsession)  # get tooltalk client
565     dtdbcache=$(GetFirst dtstart_dtdbcache) # get dtdbcache client
566
567 #if defined(sun)
568     if [ -z "$SDT_NO_DSDM" ]; then
569         StartFirst dtstart_dsdm             # start drag and drop proxy
570     fi
571 #endif
572     StartFirst dtstart_appgather            # setup session applications
573   fi
574
575   HASH 
576   HASH Start the session.
577   HASH 
578
579   if [ $shellprofile ]; then
580     Log "execing $startup using $shellprofile..."
581
582     case ${SHELL##*/} in
583
584       sh | bash | ksh | ksh93 | dtksh)
585         dotprofile_errors=`$SHELL -n $shellprofile 2>&1`
586         if [ "0" = "$?" ]; then
587           source_profile=". $shellprofile"
588           source_login="source $shellprofile"
589         else
590           Log "parse errors found in $shellprofile..."
591           Log "$dotprofile_errors"
592           source_profile="echo 'not execing $shellprofile due to errors'"
593           source_login="echo 'not execing $shellprofile due to errors'"
594         fi;;
595            
596       *)
597         source_profile=". $shellprofile"
598         source_login="source $shellprofile";; 
599     esac
600
601   else
602     Log "execing $startup..."
603
604     source_profile="echo 'not execing $HOME/.profile (see $HOME/.dtprofile)'"
605     source_login="echo 'not execing $HOME/.login (see $HOME/.dtprofile)'"
606   fi
607
608   if [ -z "$dtdbcache" ]; then
609         dtdbcache="echo could not start $dtstart_dtdbcache"
610   fi
611
612   export DT=true;
613   case ${SHELL##*/} in
614       sh | bash) $SHELL -c "$source_profile; \
615                            unset DT; \
616                            $dtdbcache; \
617                            PATH=$DT_BINPATH:\$PATH $tooltalk;   \
618                            $startup > $dtstart_sessionlogfile 2>&1" ;;
619
620       ksh | ksh93 | dtksh) $SHELL -c "$source_profile; \
621                            unset DT; \
622                            $dtdbcache; \
623                            PATH=$DT_BINPATH:\$PATH $tooltalk;\
624                            $startup >| $dtstart_sessionlogfile 2>&1" ;;
625
626       csh | tcsh) $SHELL -c "unsetenv _ PWD;       \
627                            $source_login; \
628                            unsetenv DT;          \
629                            $dtdbcache; \
630                            (set path = ( $DT_BINPATH \$path ); $tooltalk ); \
631                            $startup  >&! $dtstart_sessionlogfile" ;;
632
633       *) unset DT
634          $dtdbcache
635          StartFirst dtstart_ttsession
636          $startup >| $dtstart_sessionlogfile 2>&1 ;;
637   esac
638
639 $dtdbcacherm            # remove the actions/datatypes cachefile
640
641 XCOMM ####################         eof      #################################