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

« back to all changes in this revision

Viewing changes to install/unix/ed_moptions

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
# @(#)ed_moptions.sh    19.1 (ESO-IPG) 02/25/03 13:51:10
 
3
# .COPYRIGHT: Copyright (c) 1988 European Southern Observatory,
 
4
#                                         all rights reserved
 
5
# .TYPE           command
 
6
# .NAME           ed_make_options.sh
 
7
# .LANGUAGE       shell script
 
8
# .ENVIRONMENT    Unix Systems. Executable under SHELL and C-SHELL
 
9
# .COMMENTS       Editing the file make_options.
 
10
#
 
11
# .AUTHOR         Carlos Guirao
 
12
# .VERSION 1.1    17-Jul-1992:  Implementation
 
13
# .VERSION 2.1    20-Jan-1993:  "ex" instead of "ed" (for PC/Linux)
 
14
# .VERSION 3.1    990324        Checking EDITOR (default ex, otherwise ed)
 
15
 
 
16
if [ $# -lt 1 ]; then
 
17
        echo "Usage: $0 get/replace/add/delete key[=options]"
 
18
        exit 1
 
19
fi
 
20
 
 
21
if [ "$1" != "get" -a "$1" != "replace" -a "$1" != "add" -a "$1" != "delete" ]; then
 
22
        echo "Usage: $0 get/replace/add/delete key[=options]"
 
23
        exit 1
 
24
fi
 
25
 
 
26
if [ "$1" != "delete" -a $$ -lt 2 ]; then
 
27
        echo "Usage: $0 replace/add key=options"
 
28
        exit 1
 
29
fi
 
30
 
 
31
#
 
32
# Check if 'ex' editor exists otherwise use 'ed'
 
33
# "ed" is substituted by "ex" for PC/Linux except in SuSE
 
34
#
 
35
EDITOR=ex
 
36
which ex > /dev/null
 
37
if [ $? != 0 ]; then
 
38
   EDITOR=ed
 
39
fi
 
40
 
 
41
if [ -z "$MID_HOME" ]; then
 
42
    cd `echo $0 | sed -e 's/[^\/]*$//' -e 's/^$/./' -e 's/\/$//'`
 
43
    MID_INSTALL=`pwd`
 
44
    VERSDIR=`echo $MID_INSTALL | sed 's/\/install\/unix$//'`
 
45
    MIDVERS=`echo $VERSDIR | sed -e 's/^.*\///'`
 
46
    MIDASHOME=`echo $VERSDIR | sed -e 's/[^\/]*$//' -e 's/^$/./' -e 's/\/$//'`
 
47
    MID_HOME=$MIDASHOME/$MIDVERS
 
48
fi
 
49
 
 
50
file=$MID_HOME/local/make_options
 
51
op=$1
 
52
key=`echo $2 | awk -F= '{print $1}'`
 
53
options=`echo $2 | sed 's/^'$key'=//'`
 
54
options=`eval echo $options`
 
55
oldoptions=""
 
56
 
 
57
if [ -f $file ]; then
 
58
   oldoptions=`grep "^${key}=" $file | sed 's/^'$key'=//'`
 
59
fi
 
60
 
 
61
if [ -n "$oldoptions" ]; then
 
62
    echo $oldoptions
 
63
fi
 
64
 
 
65
if [ "$op" = "get" ]; then
 
66
   exit 0
 
67
fi
 
68
 
 
69
# Remove previous definition of $key if existed
 
70
$EDITOR $file << EOF >/dev/null 2>&1
 
71
1
 
72
/${key}=/d
 
73
w
 
74
q
 
75
EOF
 
76
 
 
77
if [ "$op" = "delete" ]; then
 
78
   exit 0
 
79
fi
 
80
 
 
81
if [ "$op" = "add" ]; then
 
82
     options=`eval echo $oldoptions $options`
 
83
fi
 
84
 
 
85
if [ -n "$options" ]; then
 
86
    echo "$key=$options" >> $file
 
87
fi
 
88
exit 0