Debian Codegraph @

install/unix/systems/SunOS_5.8/inmidas.sh

raw symbols SCIP
1 #! /bin/shscip-shell filesystem . . `/bin/sh`.
2 # .COPYRIGHT: Copyright (c) 1988-2007 European Southern Observatory,
3 #
4 # .TYPE command
5 # .NAME inmidas
6 # .LANGUAGE Bourne-shell script
7 # .ENVIRONMENT Unix Systems. Executable under any SHELL.
8 # .USAGE inmidas [ unit ] [-h midashome] [-r midvers] [-d display]
9 # [-m mid_work] [-p/-np] [-noh ] [-j midas-comman-line]
10 # unit: MIDAS unit (00, 01, ..., 99, xa, ..., zz)
11 # (default: 00 if NOPARALLE mode)
12 # display: X server for display and graphical windows.
13 # midashome: Home directory for MIDAS. (default: MIDASHOME0)
14 # midvers: Version of MIDAS. (default: MIDVERS0)
15 # mid_work: MIDAS startup directory (default: $HOME/mid_work)
16 # -p/-nop: Set MIDOPTIONS to PARALLEL/NOPARALLE
17 # (default: NOPARALLEL)
18 # -noh: No welcome header.
19 # -drs: reuse keyfile from drs commands
20 # -j: Execute next argument as a MIDAS command.
21 #
22 # .COMMENTS Script to start MIDAS. It uses the following environment:
23 # MIDASHOME, MIDVERS and MIDOPTION.
24 # variables if they exist, otherwise takes defaults.
25 # It checks arguments if any and exec to
26 # $MIDASHOME/$MIDVERS/monit/prepa.exe
27 #
28 # .REMARKS MIDASHOME0 & MIDVERS0 are set to defaults values by option
29 # "8- MIDAS setup" in the MIDAS "config" script.
30 #
31 # .VERSION 1.0 this is the modified inmidas script for Sun Solaris 8
32 # where we don't have the shell command "lockfile"
33 #
34 # 070716 last modif
35 #
36 #**************************************************************************
37
38 #**************************************************************************
39 # Configure Here:
40 # ---------------
41 # Modify the default values of MIDASHOME0 and MIDVERS0
42 # according to your site.
43 #
44 # Environment variables MIDASHOME and MIDVERS overwrite these defaults.
45 #
46 # Done automaticaly by option "8- setup MIDAS" in the "config" script.
47 #
48
49 MIDASHOME0=/home/esomidasscip-shell filesystem . . `/home/esomidas`.
50 MIDVERS0=test
51
52 #
53 # END of Configure Here
54 #**************************************************************************
55
56 #
57 DAZUNIT=''
58 MIDASDRS=''; export MIDASDRS
59 #
60 # Check command "echo"
61 #
62 echo=echo
63 SV_NONL=
64 if [scip-shell system . . `[`. "`echoscip-shell system . . echo. -n`" = "-n" ] ; then
65 SV_NONL="\c"
66 else
67 echo="echo -n"
68 fi
69 #
70 # Strip "/dev/", strip "pty/" (HP), "pts/" (IBM), and "tty" (all)
71 #
72 if ( ttyscip-shell system . . tty. -s )
73 then
74 tt=`ttyscip-shell system . . tty. | sedscip-shell system . . sed. -e 's/^.*dev\///' -e 's/pty\///' -e 's/pts\///' -e 's/tty//'`
75 else
76 tt=none
77 fi
78
79 #**************************************************************************
80
81 #
82 # Check for options:
83 #
84 while [scip-shell system . . `[`. -n "$1" ]
85 do
86 case $1 in
87 -help)
88 echoscip-shell system . . echo. "Usage: inmidas [unit] [-h midashome] [-r midvers] [-d display] [-p/-P/-nop]"
89 echoscip-shell system . . echo. " [-m mid_work] [-noh] [-j \"midas-command-line\"] [-drs] [-help]"
90 echoscip-shell system . . echo. "Options:"
91 echoscip-shell system . . echo. "-h midashome"
92 echoscip-shell system . . echo. " Home directory for MIDAS. Sets variable MIDASHOME to midashome"
93 echoscip-shell system . . echo. "-r midvers"
94 echoscip-shell system . . echo. " Release of MIDAS. Sets variable MIDVERS to midvers and it must exist as "
95 echoscip-shell system . . echo. " a subdirectory under MIDASHOME."
96 echoscip-shell system . . echo. "-d display"
97 echoscip-shell system . . echo. " This option specifies the X server to contact."
98 echoscip-shell system . . echo. "-p/-P/-nop"
99 echoscip-shell system . . echo. " -p and -P options set variable MIDOPTION to PARALLEL. -nop option"
100 echoscip-shell system . . echo. " sets MIDOPTION to NOPARALLEL."
101 echoscip-shell system . . echo. " With -nop (NOPARALLEL) all working files from previous MIDAS sessions"
102 echoscip-shell system . . echo. " located in the directory MID_WORK are deleted. Only one MIDAS session can"
103 echoscip-shell system . . echo. " run at a time. With -p and -P (PARALLEL) no working files are removed"
104 echoscip-shell system . . echo. " from MID_WORK and several sessions can run simultaneously."
105 echoscip-shell system . . echo. " With -P and -nop options and if not unit is given the system will select"
106 echoscip-shell system . . echo. " automatically one free unit for you (in [01, ..., 99])."
107 echoscip-shell system . . echo. " With -p option and no unit, the user will be requested to enter one."
108 echoscip-shell system . . echo. "unit"
109 echoscip-shell system . . echo. " Unit to be associated to the MIDAS session. Valid values for this option"
110 echoscip-shell system . . echo. " are in the range (00 to 99) for X environments, or (xa to zz) for ASCII"
111 echoscip-shell system . . echo. " terminals other than X (no graphics). If no unit is provided the "
112 echoscip-shell system . . echo. " system will select one for you except with -p option."
113 echoscip-shell system . . echo. "-m mid_work"
114 echoscip-shell system . . echo. " This option sets the MID_WORK variable that specifies the MIDAS working"
115 echoscip-shell system . . echo. " directory. By default MID_WORK is set to ~/midwork and it will be created"
116 echoscip-shell system . . echo. " if it does not exist."
117 echoscip-shell system . . echo. "-noh"
118 echoscip-shell system . . echo. " Starts a MIDAS session without clearing the terminal and without any"
119 echoscip-shell system . . echo. " welcome message. This option is meant for background purposes."
120 echoscip-shell system . . echo. "-j \"midas_command_line\""
121 echoscip-shell system . . echo. " Execute \"midas_command_line\" as the first command typed in the MIDAS"
122 echoscip-shell system . . echo. " monitor. This option sets also -noh option."
123 echoscip-shell system . . echo. "-drs"
124 echoscip-shell system . . echo. " Starts a MIDAS session which reuses an existing FORGRdrs.KEY in the "
125 echoscip-shell system . . echo. " current directory, by default this keyfile is recreated each time."
126 echoscip-shell system . . echo. "-help"
127 echoscip-shell system . . echo. " Display this help page."
128 exit 0 ;;
129 -h) MIDASHOME=$2; export MIDASHOME; shift; shift ;;
130 -r) MIDVERS=$2; export MIDVERS; shift; shift ;;
131 -d) DISPLAY=$2; export DISPLAY; shift; shift ;;
132 -m) MID_WORK=$2; export MID_WORK; shift; shift ;;
133 -P) SELECT_UNIT=AUTO; MIDOPTION=PARALLEL; export SELECT_UNIT MIDOPTION; shift ;;
134 -p) MIDOPTION=PARALLEL; export MIDOPTION; shift ;;
135 -nop) MIDOPTION=NOPARALLEL; export MIDOPTION; shift ;;
136 -noh) MIDASHD=noheader; export MIDASHD; shift ;;
137 -drs) MIDASDRS=yes; export MIDASDRS; shift ;;
138 -j) MIDASJOB=$2; export MIDASJOB; shift; shift ;;
139
140 -*) echoscip-shell system . . echo. "Usage: inmidas [unit] [-h midashome] [-r midvers] [-d display] [-p/-P/-nop]"
141 echoscip-shell system . . echo. " [-m mid_work] [-noh] [-j \"midas-command-line\"] [-help]" >&2
142 exit 1 ;;
143 *) DAZUNIT=$1; export DAZUNIT; shift ;;
144 esac
145 done
146
147
148 #
149 # If MIDASHOME or MIDVERS variable not defined then set to default
150 #
151 if [scip-shell system . . `[`. -z "$MIDASHOME" ]; then
152 MIDASHOME="$MIDASHOME0"; export MIDASHOME
153 fi
154 if [scip-shell system . . `[`. -z "$MIDVERS" ]; then
155 MIDVERS="$MIDVERS0"; export MIDVERS
156 fi
157
158 #
159 # Check access to Midas directory
160 #
161 if [scip-shell system . . `[`. ! -d $MIDASHOME/$MIDVERS ]; then
162 echoscip-shell system . . echo. "$MIDASHOME/${MIDVERS}: no such directory."
163 echoscip-shell system . . echo. "Call your MIDAS operator. EXIT."
164 exit 1
165 fi
166
167 #
168 # if necessary create MIDAS work directory
169 #
170 if [scip-shell system . . `[`. -z "$MID_WORK" ]; then
171 MID_WORK=$HOME/midwork/ ; export MID_WORK
172 fi
173
174 #
175 # if last char. of MID_WORK != '/' append a '/'
176 #
177 if [scip-shell system . . `[`. `exprscip-shell system . . expr. $MID_WORK : '.*\(.\)'` != '/scip-shell filesystem . . `/`.' ]; then
178 MID_WORK=$MID_WORK/ ; export MID_WORK
179 fi
180
181 if [scip-shell system . . `[`. ! -d $MID_WORK ]; then
182 mkdirscip-shell system . . mkdir. `exprscip-shell system . . expr. $MID_WORK : '\(.*\).'` #use MID_WORK except last char.
183 if [scip-shell system . . `[`. $? != 0 ]; then
184 echoscip-shell system . . echo. Could not create directory `exprscip-shell system . . expr. $MID_WORK : '\(.*\).'`
185 exit 1
186 fi
187 fi
188
189 #
190 # get all the variables (logical names)
191 #
192 if [scip-shell system . . `[`. -f $MIDASHOME/$MIDVERS/monit/midlogs.sh ]; then
193 . $MIDASHOME/$MIDVERS/monit/midlogs.sh
194 else
195 echoscip-shell system . . echo. "$MIDASHOME/$MIDVERS/monit/midlogs.sh - no such file."
196 echoscip-shell system . . echo. "Call your MIDAS operator. EXIT."
197 exit 1
198 fi
199
200 #
201 # Set default DAZUNIT to first unit free (~/midwork/RUNNING<unit>)
202 #
203 if [scip-shell system . . `[`. -z "$DAZUNIT" -a \( -z "$MIDOPTION" -o "$MIDOPTION" = "NOPARALLEL" -o "$SELECT_UNIT" = "AUTO" \) ]
204 then
205
206 #
207 # we don't have this command in Solaris 8
208 #
209 ### lockfile -1 -r 10 $MID_WORK/running.lock
210 #
211 #
212 if [scip-shell system . . `[`. $? != 0 ] ; then
213 DAZUNIT=99
214
215 else
216 DAZUNIT=`(lsscip-shell system . . ls. $MID_WORK/RUNNING?? 2>/dev/nullscip-shell filesystem . . `/dev/null`.) | awkscip-shell system . . awk. ' \
217 { \
218 tmp = index($1,"RUNNING"); \
219 unit[substr($1,tmp+7,2)+0] = 1 \
220 } \
221
222 END { \
223 i = 1; \
224 while (i < 100) { \
225 if (!unit[i]) { \
226 if (i < 10) printf "0%d\n",i; \
227 else printf "%d\n",i ; \
228 break \
229 } \
230 else i++ \
231 } \
232
233 if (i == 100) { \
234 printf "inmidas - Error: Too many MIDAS sessions already running.\n"; \
235 exit 1 \
236 } \
237 exit 0 \
238 }' `
239 fi
240
241
242 if [scip-shell system . . `[`. $? -ne 0 ]; then
243 echoscip-shell system . . echo. $DAZUNIT >&2
244 exit 1
245 fi
246 fi
247
248 #
249 # If AUTOPARALLEL, DAZUNIT is now selected, and MIDOPTION is set to PARALLEL
250 #
251 if [scip-shell system . . `[`. "$MIDOPTION" = "AUTOPARALLEL" ]; then
252 MIDOPTION = PARALLEL
253 fi
254
255 #
256 # logical assignements to devices.
257 #
258 if [scip-shell system . . `[`. -f $MID_WORK/devices.sh ] ; then
259 . $MID_WORK/devices.sh
260 else
261 . $MIDASHOME/$MIDVERS/monit/devices.sh
262 fi
263
264 #
265 # test, if DAZUNIT defined
266 #
267 while :
268 do
269 if [scip-shell system . . `[`. -z "$DAZUNIT" ]; then
270 $echo "Enter Midas unit (00, 01, ..., 99, xa, ..., zz) " $SV_NONL
271 read DAZUNIT
272 if [scip-shell system . . `[`. -z "$DAZUNIT" ]; then
273 DAZUNIT=''
274 continue
275 fi
276 fi
277
278 case $DAZUNIT in
279 # here for X Workstations
280 [0123456789]?)
281 WORK_STATION=DAZ$DAZUNIT
282 I_TYPE="SXW "
283 ;;
284 AX)
285 WORK_STATION=DAZAX
286 I_TYPE="SXW "
287 ;;
288 # here for any other
289 *)
290 DAZUNIT=`echoscip-shell system . . echo. $DAZUNIT | trscip-shell system . . tr. "[a-z]" "[A-Z]" ` # convert to upper case
291 case $DAZUNIT in
292 # no graphics capabilities
293 [XYZ]?)
294 WORK_STATION=DAZ$DAZUNIT
295 I_TYPE="NULL "
296 ;;
297 *)
298 echoscip-shell system . . echo. "invalid Midas unit: $DAZUNIT"
299 DAZUNIT=''
300 continue
301 ;;
302 esac
303 ;;
304 #
305 esac
306 break
307 done
308 #
309 export DAZUNIT WORK_STATION I_TYPE AGL3DEV
310
311 #
312 # Check if there is a running session already for DAZUNIT.
313 #
314 if [scip-shell system . . `[`. -f "$MID_WORK/RUNNING$DAZUNIT" ]; then
315 echoscip-shell system . . echo. "Unit $DAZUNIT is locked by another MIDAS session."
316 echoscip-shell system . . echo. "To unlock just continue."
317 $echo "Do you want to continue [yn]? (n): " $SV_NONL
318 read answ
319 if [scip-shell system . . `[`. -z "$answ" ]; then
320 answ=n
321 fi
322 if [scip-shell system . . `[`. "$answ" != "y" -a "$answ" != "Y" ]; then
323 exit 1
324 fi
325 rmscip-shell system . . rm. -f $MID_WORK/RUNNING$DAZUNIT
326 fi
327
328 #
329 # Check PARALLEL option in MIDOPTION.
330 #
331 if [scip-shell system . . `[`. -z "$MIDOPTION" ]; then
332 MIDOPTION=NOPARALLEL; export MIDOPTION
333 fi
334 #
335
336 if [scip-shell system . . `[`. "$MIDOPTION" != "PARALLEL" -a "$MIDOPTION" != "parallel" ] ; then
337 # echo Deleting old MIDAS files ...
338 # Ensure at least one file is deleted.
339 HERE=`pwdscip-shell system . . pwd.`
340 cd $MID_WORK
341 if (lsscip-shell system . . ls. * 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -s RUNNING)
342 then
343 echoscip-shell system . . echo. "WARNING: Other MIDAS sessions might be running."
344 echoscip-shell system . . echo. "Exit and use option <-p> for PARALLEL mode."
345 echoscip-shell system . . echo. "If you continue all previous MIDAS sessions will be removed."
346 $echo "Do you want to continue [yn]? (n): " $SV_NONL
347 read answ
348 if [scip-shell system . . `[`. -z "$answ" ]; then
349 answ=n
350 fi
351 if [scip-shell system . . `[`. "$answ" != "y" -a "$answ" != "Y" ]; then
352 exit 1
353 fi
354 fi
355 rmscip-shell system . . rm. -f middum* midtemp* midjob*.prg midlis*.prg midtab*.prg \
356 IDISERV* idiserv* idisave*.dat .inmidas* CODE*.SAV sxw*.dat \
357 getXdepth* midas_xw* MIDAS*.PID RUNNING* xhelp*
358
359 cd $HERE
360 # delete all &a,&b, ... files
361 rmscip-shell system . . rm. -f middum* midtemp* >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
362 fi
363
364 #
365 # Catch any possible interrupt and remove the lock file
366 #
367 trap "rm -f $MID_WORK/RUNNING$DAZUNIT; exit 1" 1 2 3 15
368 touchscip-shell system . . touch. $MID_WORK/RUNNING$DAZUNIT
369
370 #
371 # no lockfile for Solaris 8
372 #
373 ### rm -f $MID_WORK/running.lock
374 #
375
376 #
377 # Prepare $MID_WORK/.inmidas for next gomidas command
378 #
379 rmscip-shell system . . rm. -f $MID_WORK/.inmidas $MID_WORK/.inmidas.$tt >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
380 echoscip-shell system . . echo. "# Date: " `datescip-shell system . . date.` > $MID_WORK/.inmidas
381 echoscip-shell system . . echo. "MIDASHOME=$MIDASHOME; export MIDASHOME" >> $MID_WORK/.inmidas
382 echoscip-shell system . . echo. "MIDVERS=$MIDVERS; export MIDVERS" >> $MID_WORK/.inmidas
383 echoscip-shell system . . echo. "MIDOPTION=$MIDOPTION; export MIDOPTION" >> $MID_WORK/.inmidas
384 echoscip-shell system . . echo. "DAZUNIT=$DAZUNIT; export DAZUNIT" >> $MID_WORK/.inmidas
385 echoscip-shell system . . echo. "WORK_STATION=$WORK_STATION; export WORK_STATION" >> $MID_WORK/.inmidas
386 echoscip-shell system . . echo. "I_TYPE=$I_TYPE; export I_TYPE" >> $MID_WORK/.inmidas
387 if [scip-shell system . . `[`. -n "$AGL3DEV" ]; then
388 echoscip-shell system . . echo. "AGL3DEV=$AGL3DEV; export AGL3DEV" >> $MID_WORK/.inmidas
389 fi
390 if [scip-shell system . . `[`. -n "$graph_term" ]; then
391 echoscip-shell system . . echo. "graph_term=$graph_term; export graph_term" >> $MID_WORK/.inmidas
392 fi
393
394 #
395 # Copy .inmidas to inmidas.<tt> that will be used by gomidas afterwards.
396 #
397 cpscip-shell system . . cp. $MID_WORK/.inmidas $MID_WORK/.inmidas.$tt
398
399 #
400 # Set PATH for shared libraries
401 #
402 os=`unamescip-shell system . . uname.`
403 case "$os" in
404 "SunOS"|"Linux")
405 if [scip-shell system . . `[`. -z "$LD_LIBRARY_PATH" ] ; then
406 LD_LIBRARY_PATH=$MIDASHOME/$MIDVERS/lib
407 else
408 LD_LIBRARY_PATH=$MIDASHOME/$MIDVERS/lib:$LD_LIBRARY_PATH
409 fi
410 export LD_LIBRARY_PATH
411 ;;
412 "HP-UX")
413 if [scip-shell system . . `[`. -z "$SHLIB_PATH" ] ; then
414 SHLIB_PATH=$MIDASHOME/$MIDVERS/lib
415 else
416 SHLIB_PATH=$MIDASHOME/$MIDVERS/lib:$SHLIB_PATH
417 fi
418 export SHLIB_PATH
419 ;;
420 *)
421 ;;
422 esac
423
424 #
425 # run MIDASGO
426 #
427 $MID_MONIT/midasgo.exe
428 if [scip-shell system . . `[`. $? = 1 ] ; then
429 echoscip-shell system . . echo. "...Midas session aborted..."
430 rmscip-shell system . . rm. -f $MID_WORK/RUNNING$DAZUNIT
431 exit 1
432 fi
433
434 #
435 # Ignore CTRL-C before runnning prepa.exe
436 #
437 trap "" 2
438
439 # run PREPA
440 #
441 $MID_MONIT/prepa.exe
442 if [scip-shell system . . `[`. $? = 1 ] ; then
443 echoscip-shell system . . echo. "...Midas session aborted..."
444 rmscip-shell system . . rm. -f $MID_WORK/RUNNING$DAZUNIT
445 exit 1
446 fi
447
448 #
449 # remove lock file
450 #
451 rmscip-shell system . . rm. -f $MID_WORK/RUNNING$DAZUNIT
452
453 exit 0