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