aboutsummaryrefslogtreecommitdiff
path: root/unix/hlib/uninstall
blob: 0eaaa6947a48406a801193aaaba3c93be9f7c88e (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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#!/bin/csh
#
# ----------------------------------------------------------------------------
#
# UNINSTALL -- Remove IRAF on a UNIX/IRAF host.
#
# Usage:   uninstall [-n] [-h] [-hl] [-c] [-v] [-b <directory>]
#
#     where	-n	# no execute
# 		-h	# print this help summary
# 		-hl	# disable text highlighting
# 		-c	# remove command links only
# 		-v	# print verbage output
# 		-b	# specify local bin directory to search
#
# Use "uninstall -n" to do a dry run to see what the would be done, without
# actually modifying the host system.  To do the actual un-install one must
# be superuser, but anyone can run "uninstall -n" to see what it would do.
#
# ----------------------------------------------------------------------------

unset		noclobber
unalias 	rm set grep ls pwd
onintr		uninstall_cleanup_

set exec	= yes
set lbin	= ""
set cmd_only	= no
set verbage	= no
set hilite      = 1

set FILES	= "/usr/include/iraf.h /usr/local/lib/imtoolrc"
set DEVS	= "/dev/imt1i /dev/imt1o /dev/imt1"
set CMDS	= "cl mkiraf mkmlist generic mkpkg rmbin rmfiles rtar sgidispatch wtar rpp xpp xyacc xc"

alias RM	"/bin/rm -f"

# Utility aliases.
alias BOLD_ON   "(if ($hilite) tput bold)"
alias BOLD_OFF  "(if ($hilite) tput sgr0)"

alias ERRMSG   "(echo -n '   ';BOLD_ON;echo -n 'ERROR: ';BOLD_OFF; echo \!*)"
alias WARNING  "(echo -n '   ';BOLD_ON;echo -n 'WARNING: ';BOLD_OFF; echo \!*)"
alias NEWLINE  "(echo '')"


#=============================================================================
# Process any command line arguments.
#=============================================================================
while ("$1" != "")
    switch ("$1")
    case -n:				# no execute
	set exec = no
  	alias RM "echo -n \!* >& /dev/null"
	breaksw
    case -hl:                           # disable highlighting
        set hilite = 0
    case +hl:                           # enable highlighting
        set hilite = 1
        breaksw
    case -h:				# print usage
	goto Usage
    case -c:				# command file links only
	set cmd_only = yes
	breaksw
    case -q:				# quiet output
	set verbage = no
	breaksw
    case -v:				# verbage output
	set verbage = yes
	breaksw
    case -b:                            # set local bin directory (unix)
        if ("$2" != "") then
            shift
        else
            echo "missing argument to '-b <localbindir>' switch"
            exit 1
        endif
        set lbin = "$1"

	if (! -e $lbin) then
	    echo "ERROR: Local bin dir '$lbin' not found."
	    exit 1
	endif
        breaksw
    default:
	echo "ERROR:  unrecognized command-line argument '$1'"
        goto Usage
    endsw

    if ("$2" == "") then
        break
    else
	shift
    endif
end

# Initialize.
clear
NEWLINE
BOLD_ON
echo "		     IRAF System Un-installation"
echo "		     ---------------------------"
BOLD_OFF
NEWLINE


# See whether we're gonna work....
if ($exec == yes && `whoami` != "root") then

  BOLD_ON
  echo "**********************************************************************"
  echo -n "WARNING"
  BOLD_OFF
  echo ": This script must be run as root for changes to take effect."
  echo "         If you decide to proceed,  the 'no-op' flag will be enabled"
  echo "         by default.   No changes will be made to the system  files,"
  echo "         however you will be able to see what the script does."
  BOLD_ON
  echo "**********************************************************************"
  BOLD_OFF
  echo ""
  echo -n "Proceed with a no-op uninstallation anyway (y)? " ; setenv ans "$<"
  if ("$ans" == "n" || "$ans" == "no") then
      echo "Quitting."
      exit 0
  endif
  NEWLINE; NEWLINE

  set exec = no
  alias RM "echo -n \!* >& /dev/null"
endif


set iraf_paths 	  = ""
set n_iraf_paths  = 0

# Search the path for iraf command directories, assume we may have more than
# one so build up a list of all of them.
if ("$lbin" == "") then
    foreach i ($path) 
        if (-d $i && -e $i/cl && -e $i/mkiraf) then
	    set iraf_paths = ($iraf_paths $i)
	    set n_iraf_paths = `expr $n_iraf_paths + 1`
        endif
    end

    # Look around and come up with a likely candidate directory.
    if ($n_iraf_paths == 0) then
        set d_lbin = ""
        foreach dir (/usr/local/bin /opt/local/bin /local/bin /usr/bin /bin)
            if (-d $i && -e $i/cl && -e $i/mkiraf) then
	        set iraf_paths = ($iraf_paths $i)
	        set n_iraf_paths = `expr $n_iraf_paths + 1`
	    endif
        end

        if (! $n_iraf_paths) then
	    echo "WARNING: no IRAF command directories found."
	endif
    endif
endif


echo "Files to be deleted to remove IRAF from this machine:"
NEWLINE
BOLD_ON
if ("$cmd_only" == "no") then
    foreach i ($FILES $DEVS)
        if (-e $i) echo "	$i"
    end
endif

foreach i ($iraf_paths)
    echo "	All IRAF commands found in $i, including"
end
echo ""
echo "	    cl      mkiraf     mkmlist     generic       mkpkg"
echo "	    rmbin   rmfiles    rtar        wtar          xc"
echo "	    xpp     rpp        xyacc       sgidispatch"
echo ""
BOLD_OFF


NEWLINE
echo 'You will be prompted before any files are removed. The system may'
echo 'be restored by rerunning the IRAF install script on this machine.'
NEWLINE

echo -n "Hit <CR> to proceed, 'q' to quit: "
            
set ans = "$<"
if ("$ans" == "q" || "$ans" == "quit") exit 0
NEWLINE ; NEWLINE


# Initialize the local bin dir to delete.
set npath = 1
set d_lbin = $iraf_paths[$npath]



# ============================================================================
# Delete the miscellaneous files associated with the system. 
# ============================================================================

if ("$cmd_only" == "no") then

    # See whether we want to delete the <iraf.h> symlink.
    foreach file ($FILES)
	if ($verbage == yes) NEWLINE
        if (-e $file) then
            echo -n "Remove the $file link (y/n/q)? (y) "
            set ans = "$<"
            if ("$ans" == "y" || "$ans" == "Y" || "$ans" == "") then
                if ($verbage == yes) echo -n "    Deleting $file...."
                RM $file
	    	if (-e $i && $exec == yes && $verbage == yes) then
            	    echo "file '$i' could not be deleted."
	    	else if ($verbage == yes) then
            	    echo "ok"
	    	endif
            else if ("$ans" == "q" || "$ans" == "q") then
	        echo "Quitting."
	        exit 0
            endif
        endif
    end

    # See whether we want to delete the fifo pipes.
    if (-e /dev/imt1i || -e /dev/imt1o) then
	if ($verbage == yes) NEWLINE
        echo -n "Remove the /dev fifo pipes (y/n/q)? (y) "
        set ans = "$<"
        if ("$ans" == "y" || "$ans" == "Y" || "$ans" == "") then
    	    foreach i ($DEVS)			# remove fifo devs
		if ($verbage == yes) echo -n "    Deleting $i...."
        	if (-e $i) then
                    RM $file
	    	    if (-e $i && $exec == yes && $verbage == yes) then
            	        echo "file '$i' could not be deleted."
	    	    else if ($verbage == yes) then
            	        echo "ok"
	    	    endif
        	endif
	    end
        else if ("$ans" == "q" || "$ans" == "q") then
	    echo "Quitting."
	    exit 0
        endif
    endif

endif


#=============================================================================
# Get UNIX directory where commands (links) are installed, if not found then
# set it on command line. 
#=============================================================================

if ($n_iraf_paths > 0) then
    # Initialize the local bin dir to delete.
    set npath = 1
    set d_lbin = $iraf_paths[$npath]
endif


if ("$d_lbin" == "") then
again_:
    echo -n "Local iraf commands directory? "
    set lbin = "$<"
    if ("$lbin" == "") goto again_

    if (!( -e $lbin/cl && -e $lbin/mkiraf)) then
	echo "IRAF commands not found in $lbin, please try again..."
	set lbin = ""
	goto again_
    endif

else
next_:
    if ($verbage == yes) NEWLINE
    echo -n "Remove IRAF Commands in $d_lbin (y/n/q)? (y) "
    set ans = "$<"
    if ("$ans" == "y" || "$ans" == "Y" || "$ans" == "") then
	set lbin = $d_lbin
    else if ("$ans" == "n" || "$ans" == "no") then
	goto no_delete_
    else if ("$ans" == "q" || "$ans" == "quit") then
	echo "Quitting."
	exit 0
    else
        set npath = `expr $npath + 1`
        set d_lbin = $iraf_paths[$npath]
	goto next_
    endif
endif

foreach i ($CMDS)				# remove the iraf commands
    set file = $lbin/$i
    if (-e $file) then
        if ($verbage == yes) echo -n "    Deleting $file...."
        if (-e $file) then
	    RM $file
	    if (-e $file && $exec == yes && $verbage == yes) then
                echo "[ ERROR: file '$file' could not be deleted. ]"
	    else if ($verbage == yes) then
                echo "ok"
	    endif
        endif
    else
	echo -n "    Warning: $file was not found on this machine...."
    endif
end


#=============================================================================
# Delete the iraf commands and files.
#=============================================================================

set npath = `expr $npath + 1`

# See whether this was the only instance and quit.
if ($npath <= $n_iraf_paths) then
    set d_lbin = $iraf_paths[$npath]
    goto next_
endif

no_delete_:

set back = `pwd` ; chdir $iraf/.. ; set iraf_p = `pwd` ; chdir $back
NEWLINE
NEWLINE
echo "IRAF has been successfully uninstalled from this system.  To fully"
echo "remove the system you must delete the iraf directory tree using the"
echo "command: "
NEWLINE
BOLD_ON
echo "	% /bin/rm -rf $iraf_p"
BOLD_OFF
NEWLINE
echo "External packages, X11IRAF and/or other display servers and packages"
echo "will also need to be deleted separately."
NEWLINE
exit 0

uninstall_cleanup_:

exit 0



# Print usage information.  We will not get here unless the "-help" flag
# was issued.

Usage:
    echo "Usage:    uninstall [-n] [-h] [-hl] [-c] [-v] [-b <directory>]"
    echo " "
    echo "    where	-n	# no execute"
    echo "		-h	# print this help summary"
    echo "		-hl	# disable text highlighting"
    echo "		-c	# remove command links only"
    echo "		-v	# print verbage output"
    echo "		-b	# specify local bin directory to search"
    exit 0