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