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