aboutsummaryrefslogtreecommitdiff
path: root/unix/hlib/mkiraf.sh
blob: e62072ce4692c03a2df6df8b5b2b0b02a5d155d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
#
#  MKIRAF -- Setup the IRAF environment for a user.  Should be called from the
#  directory from which the user will thereafter type "cl" to start a session.
#
#  Usage:
#
#	% mkiraf [--term=<term>] [--init] [--noinit] [--quiet]
#
#  Where
#	-t,--term=<term>	Set the default terminal type
#	-i,--init		Initialize the uparm directory
#	-n,--noinit		Do not nitialize the uparm directory
#	-q,--quiet		Suppress output
#
#  Use of the -t, -i, or -n options will suppress the corresponding prompts
#  for input.


				# Initialize the script variables.
myterm="none" 			
uparm_init=-1
quiet=0
def=0
defterm="xgterm"

				# Paths edited by the install script.
iraf="/iraf/iraf/" 		
imdir="/iraf/imdir/"
cachedir="/iraf/cache/"


# ------------- (end of site dependent definitions) ------------------------

# The following kludge is for Solaris, which doesn't have whoami.
if [ "$USER" = "" ]; then
    USER=`whoami`
fi


# Parse the command-line options.
for i in "$@"
do
  case $i in
    -t=*|--term=*)			# Set the default terminal type
        myterm=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
    	;;
    -d|--default)			# Create default login dir
        def=1
        quiet=1
	echo ""
    	;;
    -i|--init)				# Initialize uparm directory
        uparm_init=1
    	;;
    -n|--noinit)			# Don't initialize uparm directory
        uparm_init=0
    	;;
    -q|--quiet)				# Suppress output
        quiet=1
    	;;
    *)
        /bin/echo "Error: unknown option '$i'"
	exit 1
    	;;
  esac
done



# Protect against running mkiraf in an iraf system directory.
irafdir=`cd $iraf ; pwd`
if [ ! "`pwd | grep $irafdir`" = "" ]; then
    if [ "`pwd | grep iraf/local`" = "" ]; then
	/bin/echo "Error: current directory is not an iraf user login directory"
	exit 1
    fi
fi

if (( $def == 1 )); then
    imdir=`echo $HOME`"/.iraf/imdir/"
    cachedir=`echo $HOME`"/.iraf/cache/"
    #myterm="xgterm"
    cd $HOME
    if [ ! -e .iraf ]; then
	mkdir $HOME/.iraf
    fi
    cd $HOME/.iraf
    if [ ! -e bin ]; then
        mkdir bin
    fi
    if [ ! -e imdir ]; then
        mkdir imdir
    fi
    if [ ! -e cache ]; then
        mkdir cache
    fi
    cp $iraf/unix/hlib/setup.*sh .
fi


# Make an empty "uparm" (user parameter) directory.
if [ ! -e uparm ]; then
    if (( quiet<1 )); then
      if (( $def == 0 )); then
        /bin/echo '-- creating a new uparm directory'
      fi
    fi
    mkdir uparm
elif [ ! -d uparm ]; then
    /bin/echo "Error: a file uparm exists"
    exit 1
else
    if (( uparm_init<0 )) ; then
      if (( quiet<1 )) ; then
        /bin/echo -n 'Initialize uparm? (y|n): '
        read yesno
      else
	yesno="yes"
      fi
      if [ "$yesno" = "y" -o "$yesno" = "yes" ]; then
	if (( quiet<1 )); then
	    /bin/echo '-- initializing uparm'
	fi
	/bin/rm -rf uparm
	mkdir uparm
      fi
    elif (( uparm_init==1 )); then
	if (( quiet<1 )); then
	    /bin/echo '-- initializing uparm'
	fi
	/bin/rm -rf uparm
	mkdir uparm
    fi
fi

# Edit the login.cl file, setting the user's home directory, default image
# directory, and terminal.

if [ "$myterm" == "none" ]; then
    /bin/echo "Terminal types: xgterm,xtermjh,xterm,etc."
    /bin/echo -n 'Enter terminal type ('$defterm'): '
    read myterm
    if [ "$myterm" == "" ]; then
	myterm=$defterm
    fi
fi

# Initialize the 'imdir' and 'cachedir' paths.
IDIR="${imdir}$USER"
if [ -d $imdir ]; then
    mkdir -p $IDIR &> /dev/null
fi
if [ ! -d $IDIR -o ! -w $IDIR ]; then
    IDIR="HDR$"
fi

CDIR="${cachedir}$USER"
if [ -d $cachedir ]; then
    mkdir -p $CDIR &> /dev/null
fi
if [ ! -d $CDIR -o ! -w $CDIR ]; then
    CDIR="/tmp"
fi


# Back up the old login.cl file.
if [ -e login.cl ]; then
    mv -f login.cl login.cl.OLD
fi

# Create the path editing script.
_sed() {
    /bin/echo $1	| sed -e "s;.*;s+U_TERM+&+;"
    pwd			| sed -e "s;.*;s+U_HOME+&/+;"
    pwd			| sed -e "s;.*;s+U_UPARM+&/uparm/+;"
    /bin/echo $IDIR	| sed -e "s;.*;s+U_IMDIR+&/+;"
    /bin/echo $CDIR	| sed -e "s;.*;s+U_CACHEDIR+&/+;"
    /bin/echo $USER	| sed -e "s;.*;s+U_USER+&+;"
}

sed "`_sed $myterm`" < ${iraf}/unix/hlib/login.cl > login.cl

if (( $def == 0 )); then
 if (( quiet<1 )) ; then
  /bin/echo 'A new LOGIN.CL file has been created in the current directory.'
  /bin/echo 'You may wish to review and edit this file to change the defaults.'
 fi
fi