~ubuntu-branches/debian/sid/eso-midas/sid

« back to all changes in this revision

Viewing changes to .pc/dotlockfile.patch/system/unix/inmidas.sh

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-sl34juxohmn4aty4
Tags: 13.09pl1.2+dfsg-1
Initial release. (Closes: #740702)

Show diffs side-by-side

added added

removed removed

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