aboutsummaryrefslogtreecommitdiff
path: root/unix/hlib/install.csh
blob: 1aa08984359f9bd0a124d7aa2b29e7d9bb1d2896 (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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
#!/bin/csh
#
#  INSTALL -- Install IRAF on a UNIX/IRAF host.  May also be run after the
#  initial installation as a consistency check to verify that all the necessary
#  links and file permissions are still in place (e.g., after updating UNIX
#  itself).
#
#  Installation:
#	This file should be installed in the $iraf directory, if it is being 
#  installed as a patch to a distributed IRAF system the existing iraf$install
#  script should be backed up and then this file used to replace it.  Once 
#  in place the script may be made executable with the command
# 
#		% chmod 755 install
#
#  Please consult the IRAF web pages for the latest information on bug fixes
#  to this script.
#
#
#  Usage:     install [-n] [-r rootdir] [-i imdir] [-b localbindir] \
#		    [-R oldroot] [-I oldimdir] [-u username (e.g., 'iraf')]
#		    [-l locallibdir]  [-m mach (e.g., 'sparc', 'ssun') ]
#		    [-noedit]
#
#  Example:
#		% su
#		% cd $hlib
#		% ./install -n
#		% ./install
#
#  If run with no arguments, INSTALL will make an informed guess and prompt
#  with this value; type <return> to accept the value, or enter a new value.
#
#  Use "install -n" to do a dry run to see what the would be done, without
#  actually modifying the host system and IRAF configuration files.  To do the
#  actual installation one must be superuser, but anyone can run "install -n"
#  to see what it would do.
#
# ----------------------------------------------------------------------------


unset	noclobber
onintr	cleanup_
unalias cd cp cmp echo ln mv rm sed set grep ls chmod chown pwd touch sort which

setenv	path  "(/sbin /usr/sbin /bin /usr/bin /usr/5bin /usr/ucb /etc /usr/etc $path /usr/local/bin /opt/local/bin /local/bin /home/local/bin /usr/openwin/bin /usr/X11R6/bin /usr/X11/bin)"

# set echo



##############################################################################
# START OF MACHDEP DEFINITIONS.
##############################################################################

# MACHDEP definitions which may be reset below.
set LS			= "/bin/ls"				# [MACHDEP]
set LSDF        	= "-lLtgs"				# [MACHDEP]

set VERSION		= "V2.16"
set V 			= `echo $VERSION | cut -c2-5`
set hmach 		= "INDEF"
set shlib 		= "no"
set pciraf 		= 0
set suniraf 		= 0
set do_tapecaps 	= 0
set do_tapes 		= 1
set do_pipes 		= 0
set has_pipes 		= 1
set hilite    		= 1
set no_edit		= 0


# Utility aliases.
#alias PUT      "mv -f \!*; chown $user \!$ "			# [MACHDEP]
alias PUT      "cp -p \!*; chown $user \!$ "			# [MACHDEP]
alias BOLD_ON  "(if ($hilite) tput bold)"
alias BOLD_OFF "(if ($hilite) tput sgr0)"
alias SO_ON    "(if ($hilite) tput smso)"
alias SO_OFF   "(if ($hilite) tput sgr0)"

alias DO_OK    "(echo -n '[ '; BOLD_ON; echo -n ' OK '; BOLD_OFF; echo ' ]')"
alias DO_WARN  "(echo -n '[ '; BOLD_ON; echo -n 'WARN'; BOLD_OFF; echo ' ]')"
alias DO_FAIL  "(echo -n '[ ';   SO_ON; echo -n 'FAIL';   SO_OFF; echo ' ]')"

alias MSG      "(echo -n '   ';BOLD_ON;echo -n '***  ';BOLD_OFF; echo \!*)"
alias MSGB     "(echo -n '   ';BOLD_ON;echo -n '***  ';echo \!*; BOLD_OFF)"
alias MSGN     "(echo -n '   ';BOLD_ON;echo -n '***  ';BOLD_OFF; echo -n \!*)"
alias MSGBN    "(echo -n '   ';BOLD_ON;echo -n '***  ';echo -n \!*; BOLD_OFF)"
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 '')"

alias PROMPT   "(BOLD_ON; echo -n \!*; BOLD_OFF; echo -n ' (yes): ')"
alias PROMPT_N "(BOLD_ON; echo -n \!*; BOLD_OFF; echo -n ' (no): ')"

alias RM	"rm -rf"
alias LN	"ln -s"


#----------------------------------
# Determine platform architecture.
#----------------------------------

set UNAME=""
if (-e /usr/bin/uname) then
    set uname_cmd = /usr/bin/uname
    set UNAME=`/usr/bin/uname | tr '[A-Z]' '[a-z]'`
else if (-e /bin/uname) then
    set uname_cmd = /bin/uname
    set UNAME=`/bin/uname | tr '[A-Z]' '[a-z]'`
else
    WARNING  "No 'uname' command found to determine architecture."
    exit 1
endif

set WHOAMI=`whoami`
if (-e /usr/bin/whoami) then
    set WHOAMI=`/usr/bin/whoami`
else if (-e /usr/ucb/whoami) then
    set WHOAMI=`/usr/ucb/whoami`
else
    WARNING  "No 'whoami' command found for this architecture."
    exit 1
endif




switch ($UNAME) 
    case sunos:
	set do_tapecaps 	= 1
        if (`$uname_cmd -m | cut -c2-` != "86pc") then
	    set suniraf		= 1
            setenv OSVERSION `$uname_cmd -r | cut -c1`
            if ($OSVERSION == 5) then			    # Sparc Solaris
                set mach  	= "ssun"
                set hmach 	= "ssol"
		set TAPES	= "/dev/*st[0-7]*"
		set shlib	= "no"
		set LIBFILES    = ""
                set LS          = "/usr/ucb/ls"
            else			   		    # Sparc SunOS 4.x
                set mach  	= "sparc"
                set hmach 	= "sparc"
		set TAPES	= "/dev/*st[0-7]*"
		set shlib	= "no"
		set LIBFILES    = ""
            endif
        else
	    set pciraf		= 1
            set mach 		= "sunos"	    	    # Intel Solaris
            set hmach 		= "sunos"
	    set TAPES		= "/dev/*st[0-7]*"
	    set shlib		= "no"
	    set LIBFILES    	= ""
	    set LSDF        	= "-lLts"
        endif
        breaksw
    case linux:
	set pciraf		= 1
	set do_tapecaps 	= 1
	if ($?IRAFARCH == 1) then
	    # Let IRAFARCH override the default for the machine.
            set mach 		= "$IRAFARCH"
            set hmach 		= "$IRAFARCH"
        else if (`$uname_cmd -m` == "x86_64") then	    # Linux x86_64
            set mach 		= "linux64"
            set hmach 		= "linux64"
        else if (`$uname_cmd -m` == "ppc") then		    # LinuxPPC
            if (-f /etc/redhat-release) then
                set mach 	= "linuxppc"
                set hmach 	= "linuxppc"
            endif
        else
            set mach 		= "linux"
            set hmach 		= "linux"
        endif
	set TAPES		= "/dev/*st[0-7]"
	set shlib		= "no"
	set LIBFILES    	= ""
        breaksw
    case freebsd: 					    # FreeBSD 4.0
	set do_tapecaps 	= 1
        setenv OSVERSION `$uname_cmd -r | cut -c1`
        if ($OSVERSION == 5) then			    # Sparc Solaris
	    set has_pipes 	= 0
	endif
        set mach 		= "freebsd"
        set hmach 		= "freebsd"
	set TAPES		= "/dev/*st[0-7]*"
	set shlib		= "no"
	set LIBFILES    	= ""
	set pciraf		= 1
        breaksw
    case darwin: 					    # Mac OS X
    case macosx:
    case macintel:
    case ipad:
	# Mac OS X doesn't appear to have tape support 
	# at this point.
	set do_tapecaps 	= 0
	set do_tapes 		= 0
	set has_pipes 		= 0
	if ($?IRAFARCH == 1) then
	    # Let IRAFARCH override the default for the machine.
            set mach 		= "$IRAFARCH"
            set hmach 		= "$IRAFARCH"
        else if (`$uname_cmd -m` == "x86_64") then		    # 64-bit OSX
            set mach 		= "macintel"
            set hmach 		= "macintel"
        else if (`$uname_cmd -m |cut -c1-4` == "iPad") then # iPad/iPod OSX
            set mach 		= "ipad"
            set hmach 		= "ipad"
        else						    # 32-bit OSX
            set mach 		= "macosx"
            set hmach 		= "macosx"
        endif
	set TAPES		= "/dev/*st[0-7]*"
	set shlib		= "no"
	set LIBFILES    	= ""
	set pciraf		= 1
        breaksw
    case hp-ux:						    # HP/UX 10.20
        set mach 		= "hp700"
        set hmach 		= "hp700"
	set TAPES		= "/dev/*st[0-7]*"
	set shlib		= "no"
	set LIBFILES    	= ""
        set LSDF        	= "-lLts"

	# reset for HP/UX
	alias PUT 'mv -f \!*; chown $user \!$ '
        breaksw
    case irix:    					    # IRIX 6.5
    case irix64:  
        set mach 		= "irix"
        set hmach 		= "irix"
	set TAPES		= "/dev/*st[0-7]*"
	set shlib		= "no"
	set LIBFILES    	= ""
        set LSDF        	= "-lLts"
        breaksw
    case aix:     					    # AIX V4
        set mach 		= "rs6000"
        set hmach 		= "rs6000"
	set TAPES		= "/dev/*st[0-7]*"
	set shlib		= "no"
	set LIBFILES    	= ""
        set LSDF        	= "-lLts"
        breaksw
    case osf1:    					    # Alpha OSF/1
        set mach 		= "alpha"
        set hmach 		= "alpha"
	set TAPES		= "/dev/*st[0-7]*"
	set shlib		= "yes"
	set LIBFILES    	= "libiraf.so"
        breaksw
    case ultrix:    					    # DEC Ultrix
        set mach 		= "ultrix"
        set hmach 		= "ultrix"
	set TAPES		= "/dev/*st[0-7]*"
	set shlib		= "no"
	set LIBFILES    	= ""
        breaksw

    default:      
	# We don't want to be limited by the CYGWIN version numbering so
	# look for a truncated match here before punting.
	set os_mach = `echo $UNAME | cut -c1-6`
	if ("$os_mach" == "cygwin") then
            set mach 		= "cygwin"
            set hmach 		= "cygwin"
	    set shlib		= "no"
	    set LIBFILES    	= ""
	    set TAPES		= ""		# no tape support
	    set do_tapecaps 	= 0
	    set do_tapes 	= 0
	    set has_pipes 	= 0
            breaksw

	else
	    ERRMSG  "Unable to determine platform architecture."
	    exit 1
	endif
endsw

##############################################################################
# END OF MACHDEP DEFINITIONS.
##############################################################################


#=============================================================================
# Declarations and initializations.
#=============================================================================

set W		= '\([ 	"]\)'			# match a blank, tab, or quote
set TEMP	= "/tmp/iraf_install.$$"
set exec	= yes
set user	= iraf
set port	= 0

set imdir	= ""				# Initialize paths
set lbin	= ""
set llib	= ""
set cache	= ""
set o_iraf 	= ""
set o_imdir 	= ""
set o_cache 	= ""



#=============================================================================
# Initialize the path variables.
#=============================================================================

set valid_iraf = 1
if ($?iraf == 1) then
  if (! (-d $iraf) || ! (-r $iraf) || \
     ("`$LS -lLd $iraf |& grep '.rw[xs]r.[xs]r.[xt]'`" == "") || \
     ("`$LS -lLd $iraf/.. |& grep '.rw[xs]r.[xs]r.[xt]'`" == "")) then
         set valid_iraf = 0
  endif
  if ($valid_iraf == 0) then
     NEWLINE
     BOLD_ON
     echo -n '    ERROR: invalid $iraf value '
     echo "($iraf)"
     BOLD_OFF
     NEWLINE
     MSG  '    The iraf directory tree set by your environment variable, $iraf'
     MSG  "    is not generally readable.  This will prevent most users from"
     MSG  "    being able to read iraf files, especially the binaries! "
     NEWLINE
     MSG  "    Please reset the permissions on the tree and try again..."
     NEWLINE
     exit 1
  endif
  if (! -d $iraf) then
     NEWLINE
     WARNING  "Env definition of iraf root is incorrect, resetting."
     NEWLINE
     setenv iraf ""
  endif

else
    setenv iraf	""
endif


#=============================================================================
# Process any command line arguments.
#=============================================================================
while ("$1" != "")
    switch ("$1")
    case -n:				# no execute
	alias PUT "diff \!$ \!^; rm -f $TEMP"
	set exec = no
	breaksw
    case -noedit:			# no-edit installations
	set no_edit = 1
	breaksw
    case -port:				# do a "port" install
	set port = 1
	breaksw
    case -hl:				# disable highlighting
	set hilite = 0
	alias BOLD_ON   "(if ($hilite) tput bold)"
	alias BOLD_OFF  "(if ($hilite) tput sgr0)"
	alias SO_ON     "(if ($hilite) tput smso)"
	alias SO_OFF    "(if ($hilite) tput rmso)"
	breaksw
    case +hl:				# enable highlighting
	set hilite = 1
	alias BOLD_ON   "(if ($hilite) tput bold)"
	alias BOLD_OFF  "(if ($hilite) tput sgr0)"
	alias SO_ON     "(if ($hilite) tput smso)"
	alias SO_OFF    "(if ($hilite) tput rmso)"
	breaksw
    case -f:				# create fifo pipes
	set do_pipes = 1
	breaksw
    case -h:				# print help summary
	goto Usage
    case -help:				# print help summary
	goto Usage
    case --help:			# print help summary
	goto Usage
    case -b:				# set local bin directory
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-b <localbindir>' switch"
	    exit 1
	endif
	set lbin = "$1"
	breaksw
    case -l:                            # set local lib directory
	if ("$shlib" == "yes") then
            if ("$2" != "") then
                shift
            else
                ERRMSG  "missing argument to '-l <locallibdir>' switch"
                exit 1
            endif
            set llib = "$1"
	else
            set llib = ""
            shift
	endif
        breaksw
    case -c:				# set cache directory
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-c <cache>' switch"
	    exit 1
	endif
	set cache = "$1"
	breaksw
    case -i:				# set imdir directory
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-i <imdir>' switch"
	    exit 1
	endif
	set imdir = "$1"
	breaksw
    case -m:				# set machine type
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-m <mach>' switch"
	    exit 1
	endif
	set mach = "$1"
	if ("$1" == "ssun") then
	    set hmach = "ssol"
	else
	    set hmach = "$1"
	endif
	setenv IRAFARCH  $mach
	breaksw
    case -r:				# set root directory
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-r <irafdir>' switch"
	    exit 1
	endif
	setenv iraf "$1"
	breaksw
    case -C:				# set old cache directory
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-C <o_cache>' switch"
	    exit 1
	endif
	set o_cache = "$1"
	breaksw
    case -I:				# set old imdir directory
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-I <o_imdir>' switch"
	    exit 1
	endif
	set o_imdir = "$1"
	breaksw
    case -R:				# set old root directory
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-R <o_iraf>' switch"
	    exit 1
	endif
	set o_iraf = "$1"
	breaksw
    case -u:				# set user name for iraf, e.g, 'iraf'
	if ("$2" != "") then
	    shift
	else
	    ERRMSG  "missing argument to '-u <irafowner>' switch"
	    exit 1
	endif
	set user = "$1"
	breaksw
    default:
	ERRMSG  "install: unknown argument $1"
	goto Usage
	breaksw
    endsw

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



#=============================================================================
# See whether we're gonna work ...
#=============================================================================
if ($exec == yes && $WHOAMI != "root" && $mach != "cygwin") then
  clear
  NEWLINE
  BOLD_ON
  echo "		      IRAF "$VERSION" System Installation"
  echo "		      ================================"
  BOLD_OFF
  NEWLINE ; NEWLINE
  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
  NEWLINE
no_op_proc_:
  PROMPT "Proceed with a no-op installation anyway? "
  setenv ans "$<"
  if ("$ans" == "n" || "$ans" == "N" || "$ans" == "no") then
      exit 0
  endif
  if ("$ans" != "" && "$ans" != "y" && "$ans" != "Y" && "$ans" != "yes") then
      echo "Huh?"
      goto no_op_proc_
  endif
  alias PUT "diff \!$ \!^; rm -f $TEMP"
  set exec = no
endif


#=============================================================================
# Initialize the screen output.
#=============================================================================
clear
NEWLINE
BOLD_ON
echo "		      IRAF "$VERSION" System Installation"
echo "		      ================================"
BOLD_OFF
NEWLINE

echo "       Welcome to the IRAF installation script.  This script will first"
echo "  prompt you for several needed path names.  The system will be verified"
echo "  for proper structure before the actual install begins, all error must"
echo "  must be corrected before you will be allowed to continue.  Recommend-"
echo "  ations for fixing problems will be made but no corrective action will"
echo "  be taken directly.  Once properly installed, you will be allowed to"
echo "  do some minimal configuration."

# Print a quick usage summary.
NEWLINE
echo -n "  For each prompt: hit "
BOLD_ON ; echo -n "<CR>"; BOLD_OFF;
echo -n " to accept the default value, "
BOLD_ON ; echo -n "'q'" ; BOLD_OFF
echo ' to quit,'

echo -n "  or "
BOLD_ON ; echo -n "'help'"; BOLD_OFF
echo -n " or ";
BOLD_ON ; echo -n "'?'"; BOLD_OFF
echo -n " to print an explanation of the prompt."
NEWLINE
NEWLINE


#=============================================================================
# Prompt the user for needed paths.
#=============================================================================

NEWLINE
BOLD_ON
echo "========================================================================"
echo "=====================  Query for System Settings  ======================"
echo "========================================================================"
BOLD_OFF
NEWLINE


#=============================================================================
# Set $iraf, the new root directory for iraf.  The system must already have
# been read in at this directory (e.g., /iraf/iraf), but we assume that no
# files have yet been modified.
#=============================================================================

if ("$iraf" == "") then

    if (-e "IRAF.NET" && -e "IS.PORT.GEN") then
        # Use the current directory.
        set d_iraf = `pwd`

    else
        # Make a guess at what the new root directory is.
        set d_iraf = ""
        if (-d /iraf/iraf) then
	    set d_iraf = /iraf/iraf
        else if (-d /iraf) then
	    set d_iraf = /iraf
        else if (-d /usr/local/iraf) then
	    set d_iraf = /usr/local/iraf
        else if (-d /usr/iraf) then
	    set d_iraf = /usr/iraf
        else
	    # Search for an iraf directory.
	    set IDIRS = "/u* /local /home /opt /iraf* /"
	    foreach i ($IDIRS)
	        if (-d $i/iraf) then
		    set d_iraf = "$i/iraf"
		    break
	        endif
	    end
        endif

        if ("$d_iraf" == "") then
	    set d_iraf = /iraf/iraf
        endif
    endif
else
    set d_iraf = $iraf
endif

# If the given directory doesn't exist, compute the root directory relative
# to $iraf/unix/hlib (our current directory, presumably).

if (! -d $d_iraf) then
    set d_iraf = `(cd ../..;pwd)`
endif

iraf_prompt:
    set d_iraf = `echo $d_iraf | sed -e 's+/\(["]*\)$+\1+'`

    BOLD_ON ; echo -n "New iraf root directory " ; BOLD_OFF
    echo -n "($d_iraf): "
    setenv iraf "$<"
    if ("$iraf" == "") then
        setenv iraf "$d_iraf"
    else if ("$iraf" == "quit" || "$iraf" == "q") then
        exit 0
    else if ("$iraf" == "help" || "$iraf" == "h" || "$iraf" == "?") then
        NEWLINE
            MSG "The iraf root directory is the place where the AS distribution"
            MSG "file was unpacked; it contains subdirectories such as 'dev',"
            MSG "'local', 'noao', 'pkg', and the file IS.PORT.GEN."

	set di = $d_iraf
  	if (((-d $di/dev) && (-d $di/pkg) && (-d $di/noao))) then
	    MSG  ""
            MSG  "The default path '$d_iraf' appears to be correct ..."
  	else 
	    MSG  ""
            MSG  "The default path '$d_iraf' appears to be incorrect ..."
  	endif
        NEWLINE

	setenv iraf $d_iraf
        goto iraf_prompt
    endif


# See whether this looks like a reasonable $iraf directory
if (! (-e $iraf)) then
  NEWLINE
      MSG  "The '$iraf' directory doesn't exist."
      MSG  "Please try again..."
  NEWLINE
  goto iraf_prompt

else if (! (-r $iraf) || \
	("`$LS -lLd $iraf |& grep '.rw[xs]r.[xs]r.[xt]'`" == "") || \
	("`$LS -lLd $iraf/.. |& grep '.rw[xs]r.[xs]r.[xt]'`" == "")) then
  NEWLINE
      MSG  "The iraf directory tree is not generally readable."
      MSG  "This will prevent most users from being able to read iraf"
      MSG  "files, especially the binaries\\! "
      MSG  "Please reset the permissions and try again..."
  NEWLINE
  exit 1

else if (! ((-d $iraf/dev) && (-d $iraf/pkg) && (-d $iraf/noao))) then
  NEWLINE
      MSG  "The definition of '$iraf' looks incorrect."
      MSG  ""
      MSG  "The iraf root directory is the place where the AS distribution"
      MSG  "file was unpacked; it contains subdirectories such as 'dev',"
      MSG  "'local', 'noao', 'pkg', and the file IS.PORT.GEN."
      MSG  ""
  if (((-d $iraf/iraf/dev) && (-d $iraf/iraf/pkg) && (-d $iraf/iraf/noao))) then
      MSG  "The path '$iraf/iraf' appears to be correct ..."
      set iraf = $iraf/iraf
  else if (((-d $iraf/../dev) && (-d $iraf/../pkg) && (-d $iraf/../noao))) then
      if (-d $iraf/..) then
	  pushd $iraf/.. >& /dev/null
	  setenv ip `echo $cwd`
          MSG  "The path '$ip' appears to be correct ..."
	  set iraf = $ip
	  popd >& /dev/null
      endif
  endif
      MSG  ""
      MSG  "Please verify your path and try again ..."
  NEWLINE
  goto iraf_prompt
endif


#=============================================================================
# Get the values of o_iraf and o_imdir from the current mkiraf.csh file, if
# not already otherwise defined.
#=============================================================================

cd $iraf/unix/hlib
set WS = '[ 	]'
if ("$o_iraf" == "") then
    set o_iraf =\
    `grep "^set$WS*iraf" mkiraf.csh | sed -e "s+^.*=$WS*++" | sed -e 's+"++g'`
endif
if ("$o_imdir" == "") then
    set o_imdir =\
    `grep "^set$WS*imdir" mkiraf.csh | sed -e "s+^.*=$WS*++" | sed -e 's+"++g'`
endif
if ("$o_cache" == "") then
    set o_cache =\
    `grep "^set$WS*cachedir" mkiraf.csh | sed -e "s+^.*=$WS*++" | sed -e 's+"++g'`
endif

# Strip any trailing / in the pathname to be matched, so that the trailing /,
# if present, will be LEFT in the occurrence of the path in the file.

set o_iraf  = `echo $o_iraf  | sed -e 's+/\(["]*\)$+\1+'`
set o_imdir = `echo $o_imdir | sed -e 's+/\(["]*\)$+\1+'`
set o_cache = `echo $o_cache | sed -e 's+/\(["]*\)$+\1+'`


#=============================================================================
# Get the iraf parent directory to be used below.
#=============================================================================
pushd $iraf/.. >& /dev/null ; set iraf_p = `echo $cwd` ; popd >& /dev/null


#=============================================================================
# Set $imdir, the default user image storage root directory.  Each user imdir
# will be a subdirectory of this directory by default, when MKIRAF is run.
# Since bulk image data can consume hundreds of megabytes of disk space, IRAF
# likes to keep such data on a public scratch device, which is probably not
# backed up, which has a short file expiration interval, and possibly which
# has been configured (newfs/mkfs) with a large block size for fast seq. i/o.
#=============================================================================

if ("$imdir" == "") then

    if (-d $o_imdir) then
	set d_imdir = $o_imdir
    else if (-d /iraf) then
	set d_imdir = /iraf/imdirs
    else if (-d /home/iraf) then
	set d_imdir = /home/iraf/imdirs
    else if (-d $iraf_p) then
	set d_imdir = $iraf_p/imdirs
    else if (-d /usr/local/iraf) then
	set d_imdir = /usr/local/iraf/imdirs
    else
	set d_imdir = /tmp
    endif

imdir_prompt:
    BOLD_ON ; echo -n "Default root image storage directory " ; BOLD_OFF
    echo -n "($d_imdir): "
    set imdir = "$<"
    if ("$imdir" == "") then
	set imdir = "$d_imdir"
    else if ("$imdir" == "quit" || "$imdir" == "q") then
        exit 0
    else if ("$imdir" == "help" || "$imdir" == "h" || "$imdir" == "?") then
        NEWLINE
            MSG "The root imdir directory is the default image storage dir"
	    MSG 'for OIF images (i.e. the ".imh" format) used by all users on'
	    MSG "this system.   Individual user dirs will be created as needed."
	    MSG "It should be some large data disk on the machine which has a"
	    MSG "regular backup, scratch or tmp disks should be avoided or data"
	    MSG "may be lost."
            MSG ""
            MSG 'The "HDR$" syntax should not be used at this stage, please'
            MSG 'edit the hlib$mkiraf.csh script after installation if you wish'
	    MSG "to make this the default."
        NEWLINE
	setenv imdir $d_imdir
        goto imdir_prompt
    endif

    # Cannot have iraf and imdir the same.
    if ("$imdir" == "$iraf") then
  	NEWLINE
            MSG  "The definition of imdir cannot be the same as the iraf"
	    MSG  "root, please choose a different directory.  Ideally this"
	    MSG  "should be some large data area on your system or a user"
	    MSG  "data area such as /home, /users, /u1, etc."
  	NEWLINE
  	NEWLINE
  	goto imdir_prompt
    endif
endif


#=============================================================================
# Set $cache, the default user file cache root directory.
#=============================================================================

if ("$cache" == "") then

    if (-d /iraf) then
	set d_cache = /iraf/cache
    else if (-d /home/iraf) then
	set d_cache = /home/iraf/cache
    else if (-d $iraf_p) then
	set d_cache = $iraf_p/cache
    else if (-d /usr/local/iraf) then
	set d_cache = /usr/local/iraf/cache
    else
	set d_cache = /tmp
    endif

cache_prompt:
    BOLD_ON ; echo -n "Default root cache directory " ; BOLD_OFF
    echo -n "($d_cache): "
    set cache = "$<"
    if ("$cache" == "") then
	set cache = "$d_cache"
    else if ("$cache" == "quit" || "$cache" == "q") then
        exit 0
    else if ("$cache" == "help" || "$cache" == "h" || "$cache" == "?") then
        NEWLINE
            MSG "The root cache directory is the default storage directory for"
	    MSG "URL-referenced files. Individual user dirs will be created as"
	    MSG "needed. It should be some large data disk on the machine "
	    MSG "which has a regular backup, scratch or tmp disks should be"
	    MSG "avoided or data may be lost."
            MSG ""
        NEWLINE
	setenv cache $d_cache
        goto cache_prompt
    endif

    # Cannot have iraf and cache the same.
    if ("$cache" == "$iraf") then
  	NEWLINE
            MSG  "The definition of cache cannot be the same as the iraf"
	    MSG  "root, please choose a different directory.  Ideally this"
	    MSG  "should be some large data area on your system or a user"
	    MSG  "data area such as /home, /users, /u1, etc."
  	NEWLINE
  	NEWLINE
  	goto cache_prompt
    endif
endif


#=============================================================================
# Get UNIX directory where HSI commands (links) are to be installed, if not
# set on command line.  IRAF will only install a very few new commands in this
# directory.  Ideally it should be a directory on the standard user $path,
# so that users do not have to customize their . files just to run IRAF.
#=============================================================================

if ("$lbin" == "") then
    # Look around and come up with a likely candidate directory.
    if (-d /usr/local/bin) then
	set d_lbin = /usr/local/bin
    else if (-d /opt/local/bin) then
	set d_lbin = /opt/local/bin
    else if (-d /local/bin) then
	set d_lbin = /local/bin
    else
	set d_lbin = /usr/bin
    endif

lbin_prompt:
    BOLD_ON ; echo -n "Local unix commands directory " ; BOLD_OFF
    echo -n "($d_lbin): "
    set lbin = "$<"
    if ("$lbin" == "") then
	set lbin = "$d_lbin"
    else if ("$lbin" == "quit" || "$lbin" == "q") then
        exit 0
    else if ("$lbin" == "help" || "$lbin" == "h" || "$lbin" == "?") then
        NEWLINE
            MSG "The local bin directory is the system directory into which the"
            MSG "iraf commands (e.g. cl, mkiraf, mkpkg, etc) will be installed"
	    MSG "as symlinks to files in the iraf tree. This should be a common"
	    MSG "dir such as /usr/local/bin which will likely be found in every"
	    MSG "user's path."
        NEWLINE
	setenv lbin $d_lbin
        goto lbin_prompt
    endif

    # Create the local bin directory if it doesn't exist?
    if (! (-e $lbin)) then
  	PROMPT "    Sorry, but $lbin does not exist, create it? "
        set ans = "$<"
	if ("$ans" == "" || "$ans" == "y" || "$ans" == "yes") then
  	    echo "  Creating directory $lbin..."
	    if ($exec == yes) then
		mkdir $lbin
	    endif
    	    if (! (-e $lbin) && $exec == yes) then
  		ERRMSG  "Cannot create $lbin, please retry..."
		setenv lbin $d_lbin
        	goto lbin_prompt
    	    endif
        else
            goto lbin_prompt
	endif
  	NEWLINE
    endif
endif



#=============================================================================
# Get UNIX directory where IRAF shared library should be installed.
#=============================================================================

if ("$shlib" == "yes") then
    if ("$llib" == "") then
        # Look around and come up with a likely candidate directory.
        if (-d /usr/local/lib) then
            set d_llib = /usr/local/lib
        else if (-d /local/lib) then
            set d_llib = /local/lib
        else if (-d /usr/lib) then
            set d_llib = /usr/lib
        else if (-d /var/shlib) then
            set d_llib = /var/shlib
        else
            set d_llib = /usr/shlib
        endif

llib_prompt:
        BOLD_ON ; echo -n "Directory for local shared libraries " ; BOLD_OFF
 	echo -n "($d_llib): "
        set llib = "$<"
        if ("$llib" == "") then
            set llib = "$d_llib"
        else if ("$llib" == "quit" || "$llib" == "q") then
            exit 0
        else if ("$llib" == "help" || "$llib" == "h" || "llib" == "?") then
            NEWLINE
                MSG "The local lib directory is the system directory into which"
                MSG "the IRAF shared library will be installed as a symlink to"
                MSG "the library in the iraf tree.  The default prompt dir is"
                MSG "one which will be used on this system w/out special user"
                MSG "setup, choose another one with care."
            NEWLINE
	    setenv llib $d_llib
            goto llib_prompt
        endif

        # Create the local lib directory if it doesn't exist?
        if (! (-e $llib)) then
  	    PROMPT "    Sorry, but $llib does not exist, create it? "
            set ans = "$<"
	    if ("$ans" == "" || "$ans" == "y" || "$ans" == "yes") then
  	        echo "  Creating directory $llib..."
	        if ($exec == yes) then
		    mkdir $llib
		endif
    	        if (! (-e $llib) && $exec == yes) then
  		    ERRMSG  "Cannot create $lbin, please retry..."
		    setenv llib $d_llib
        	    goto llib_prompt
    	        endif
            else
                goto llib_prompt
	    endif
  	    NEWLINE
        endif
    endif
endif



##############################################################################
#
#  Step 1: VERIFICATION
#
#  Run some simple checks to be sure the system was unpacked correctly 
#  and the settings used are correct.  Verification tests include:
#
#       o  Verify the machine type and document settings.
#       o  Check iraf root directory looks correct.
#       o  Check iraf root and imdir aren't the same
#       o  Check iraf user exists in passwd file/NIS.
#       o  Check iraf user login path in passwd file is iraf$local.
#       o  Check iraf tree for proper structure.
#       o  Check binary dirs are both populated correctly.
#       o  Check that the local bin directory exists.
#       o  Check that the local lib directory exists.
#
#  An error at this stage will cause the script to exit so we can reset
#  and try again.  
#
##############################################################################

set err_stat	= 0				# initialize error stats
set err_count 	= 0
set warn_stat	= 0				# initialize warning stats
set warn_count 	= 0

NEWLINE
BOLD_ON
echo "========================================================================"
echo "=====================  Verifying System Settings  ======================"
echo "========================================================================"
BOLD_OFF


# Verify the machine type and document the old root pathnames.
NEWLINE
BOLD_ON; echo -n "Hostname      = "; \
    BOLD_OFF; echo `hostname` | awk '{printf("%-20.20s  ", $1)}'
BOLD_ON; echo -n "OS version    = "; \
    BOLD_OFF; echo `$uname_cmd`" "`$uname_cmd -r`
BOLD_ON; echo -n "Architecture  = "; \
    BOLD_OFF; echo $mach | awk '{printf("%-20s  ", $1)}'
BOLD_ON; echo -n "HSI arch      = "; \
    BOLD_OFF; echo $hmach | awk '{printf("%-20s\n", $1)}'
BOLD_ON; echo -n "New iraf root = "; \
    BOLD_OFF; echo $iraf | awk '{printf("%-20s  ", $1)}'
BOLD_ON; echo -n "Old iraf root = "; \
    BOLD_OFF; echo $o_iraf | awk '{printf("%-20s\n", $1)}'
BOLD_ON; echo -n "New imdir     = "; \
    BOLD_OFF; echo $imdir | awk '{printf("%-20s  ", $1)}'
BOLD_ON; echo -n "Old imdir     = "; \
    BOLD_OFF; echo $o_imdir | awk '{printf("%-20s\n", $1)}'
BOLD_ON; echo -n "New cache     = "; \
    BOLD_OFF; echo $cache | awk '{printf("%-20s  ", $1)}'
BOLD_ON; echo -n "Old cache     = "; \
    BOLD_OFF; echo $o_cache | awk '{printf("%-20s\n", $1)}'
BOLD_ON; echo -n "Local bin dir = "; \
    BOLD_OFF; echo $lbin | awk '{printf("%-20s\n", $1)}'
if ("$shlib" == "yes") then
    BOLD_ON; echo -n "Local lib dir = "; \
        BOLD_OFF; echo $llib | awk '{printf("%-20s\n", $1)}'
endif
NEWLINE ; NEWLINE


# Check iraf root directory looks correct.
echo -n "Checking definition of iraf root directory ...			"
if (! ((-d $iraf/dev) && (-d $iraf/pkg) && (-d $iraf/noao))) then
  DO_FAIL ; set err_stat = 1 ; set iraf_root_ok = 0
  NEWLINE
      MSG  "The definition of '$iraf' looks incorrect.  The iraf root"
      MSG  "directory is the place where the AS distribution was unpacked,"
      MSG  "it contains subdirectories such as 'dev', 'local', 'noao', and"
      MSG  "'pkg' and the binary directory links."
      MSG  ""
  if (((-d $iraf/iraf/dev) && (-d $iraf/iraf/pkg) && (-d $iraf/iraf/noao))) then
      MSG  "The path '$iraf/iraf' appears to be correct ..."
      set iraf = $iraf/iraf
  else if (((-d $iraf/../dev) && (-d $iraf/../pkg) && (-d $iraf/../noao))) then
      if (-d $iraf/..) then
          pushd $iraf/.. >& /dev/null
          setenv ip `echo $cwd`
          MSG  "The path '$ip' appears to be correct ..."
          set iraf = $ip
          popd >& /dev/null
      endif
  endif
      MSG  "Please verify your path and try again ..."
  NEWLINE
  set err_count = `expr $err_count + 1`
else
  DO_OK ; set iraf_root_ok = 1
endif


# Cannot have iraf and imdir the same.
echo -n "Checking iraf root and imdir directory ...			"
if ($iraf == $imdir) then
  DO_FAIL ; set err_stat = 1
  NEWLINE
      MSG  "The 'imdir' pixel storage directory cannot be the same as the"
      MSG  "iraf root directory.  Please choose another directory."
  NEWLINE
  set err_count = `expr $err_count + 1`
else
  DO_OK
endif

# Cannot have iraf and cache the same.
echo -n "Checking iraf root and cache directory ...			"
if ($iraf == $cache) then
  DO_FAIL ; set err_stat = 1
  NEWLINE
      MSG  "The 'cache' storage directory cannot be the same as the"
      MSG  "iraf root directory.  Please choose another directory."
  NEWLINE
  set err_count = `expr $err_count + 1`
else
  DO_OK
endif



if ($no_edit == 0) then

# Check for write permission on iraf directory...
echo -n "Checking iraf directory write permissions ...			"

  set TEST	= "_inst.check"
  if ($exec == "yes") then
    set back 	= $cwd/
    chdir $iraf_p/iraf
    touch $TEST 	>& /dev/null
    if (-e $TEST) then
        rm $TEST
        DO_OK
    else
        DO_WARN ; set warn_stat = 1
        NEWLINE
            MSG  "You do not have write permission on the iraf directory."
            MSG  "This will prevent the install script from modifying files"
            MSG  "in the tree needed to complete the setup.  If this is an"
            MSG  "NFS disk there can be several explanations aside from just"
	    MSG  "the usual permissions problems:"
	    MSG  ""
	    MSG  "  1) The NFS disk is mounted read-only"
	    MSG  "  2) The NFS disk is mounted with the 'nosuid' option"
	    MSG  "  3) The NFS disk is exported with the 'all_squash' option"
	    MSG  "     which remaps your userid to 'anonymous'"
	    MSG  ""
	    MSG  "The script can continue by installing the command links on"
	    MSG  "the local machine, but will not edit the iraf path into the"
	    MSG  "files.  If you choose not to do this the verification stage"
	    MSG  "will be completed but the installation will then abort."
	    MSG  ""
	    MSG  "In either case, you should verify the server iraf path is"
	    MSG  "correct for this machine and rerun the install script or"
	    MSG  "make the appropriate links as needed."
	    MSG  ""
	    MSG  ""

	    echo -n '   '
	    BOLD_ON
	    echo -n '***  Would you like to continue with a no-edit install? '
	    BOLD_OFF
	    echo -n "(yes) "

            set ans = "$<"
            if ("$ans" == "" || "$ans" == "y" || "$ans" == "yes") then
		set no_edit = 1
	    else
		set err_stat = 1
	    endif
        NEWLINE
        set warn_count = `expr $warn_count + 1`
    endif
    chdir $back
  else
    DO_OK
  endif
endif



# Check iraf user.

goto _no_user_check

#  Check for iraf user disabled for all platforms with v2.15
if ($mach == "macosx" || $mach == "macintel" || $mach == "cygwin") then
    goto _no_user_check
endif

echo -n "Checking for iraf user account ...				"
set pass = ""
if (($pciraf && ($mach == "macosx" || $mach == "macintel" || $mach == "cygwin")) || (!(-r /etc/passwd)) ) then
  # Special-case user info check for OS X and systems where the /etc/passwd
  # file may not contain the user info or isn't readable.

  set id_found = 0
  foreach d ($path)
      if (-e $d/id) then
          set id_found = 1
          break
      endif
  end
  if ($id_found == 1) then
    if (`id iraf |& grep -i 'no such user'` != "") then
      DO_WARN ; set warn_stat = 1
      NEWLINE
          MSG  "No 'iraf' user was found on the system.  The iraf user should"
          MSG  "be created before installing the system to ensure all files"
          MSG  "are owned by the iraf user, and the have the proper environment"
          MSG  "defined for installation and maintanence."
      NEWLINE

    else
      DO_OK

      # Check iraf user login path and shell
      echo -n "Checking iraf user login directory ... 				" 

      set v = `finger iraf |& egrep '^Directory'`
      set ihome = `echo $v[2] | sed -e 's+/\(["]*\)$+\1+'`
      set shel  = `echo $v[4] | sed -e 's+/\(["]*\)$+\1+' | grep csh`
      if ("$ihome" != "$iraf/local" && $shel == "") then
        DO_FAIL ; set errstat = 1
        NEWLINE   
            MSG  "The iraf user login info appears to be incorrect.  For the"
            MSG  "given iraf root this path should be '$iraf/local',"
            MSG  "please run the 'chpass' command to change this.  The iraf"
            MSG  "user account should also be defined to use a C-shell."
        if ("$iraf_root_ok" == 0) then
            MSG  "(This error may be related to the incorrect definition of"
            MSG  "the iraf root directory seen above.)"
        endif
        NEWLINE
      else
        DO_OK
      endif

    else

    endif
  endif

else
  set pass1 = "`grep ^iraf: /etc/passwd`"
  set pass2 = "`ypcat passwd |& grep ^iraf:`"

  if ("$pass1" == "" && "$pass2" == "") then
    DO_WARN ; set warn_stat = 1
    NEWLINE
        MSG  "No 'iraf' user was found in the /etc/passwd file.  The iraf"
        MSG  "user should be created before installing the system to ensure"
        MSG  "all files are owned by the iraf user, and the have the proper"
        MSG  "environment defined for installation and maintanence."
    NEWLINE
  else
    DO_OK

    # Check iraf user login path in passwd file is iraf$local.
    echo -n "    Checking iraf user login directory ...			"
    if ("$pass1" != "") then
        set pass = `grep ^iraf: /etc/passwd |sed -e 's/[ \*]/_/g' |sed -e 's/:/ /g'`
    else
        set pass = `ypcat passwd | grep ^iraf: |sed -e 's/[ \*]/_/g' |sed -e 's/:/ /g'`
    endif

    set c = `echo $pass | wc -w`
    set indx = `expr $c - 1`

    set ihome = `echo $pass[$indx] | sed -e 's+/\(["]*\)$+\1+'`
    if ("$ihome" != "$iraf/local") then
      DO_FAIL ; set errstat = 1
      NEWLINE
          MSG  "The iraf user login directory appears to be incorrect."
          MSG  "For the given iraf root this path should be '$iraf/local',"
          MSG  "please edit the /etc/passwd file to change this."
      if ("$iraf_root_ok" == 0) then
          MSG  "(This error may be related to the incorrect definition of"
          MSG  "the iraf root directory seen above.)"
      endif
      NEWLINE
    else
      DO_OK
    endif

    echo -n "    Checking iraf user account shell ...			"
    set shel =  `echo $pass[$c] | sed -e 's+/\(["]*\)$+\1+' | grep csh`
    if ($shel == "") then
      DO_FAIL ; set errstat = 1
      NEWLINE
          MSG  "The iraf user login directory appears to be incorrect."
          MSG  "The account should be configured to use a C-shell in order"
          MSG  "to take advantage of a preconfigured environment which will"
          MSG  "make maintainence easier.  Please edit the passwd file or"
          MSG  "use the 'chsh' command (if available) to change this."
      NEWLINE
    else
      DO_OK
    endif
  endif
endif

_no_user_check:


# Skip the ownership check on some platforms.
if ($V != "2.15" && $V != "2.16") then
 if ($mach != "cygwin" && $mach != "macosx" && $mach != "macintel") then

  # Check file ownership.
  if ($mach == "hp700" || $mach == "rs6000") then
    set downr = `$LS -lLd $iraf_p/iraf | awk '{print ($4)}'`
    set fownr = `$LS -lLd $iraf_p/iraf/mkpkg | awk '{print ($4)}'`
  else
    set downr = `$LS -lLd $iraf_p/iraf | awk '{print ($3)}'`
    set fownr = `$LS -lLd $iraf_p/iraf/mkpkg | awk '{print ($3)}'`
  endif
  set dperm = `$LS -lLd $iraf_p/iraf | awk '{print ($1)}'`
  set fperm = `$LS -lLd $iraf_p/iraf/mkpkg | awk '{print ($1)}'`


  echo -n "Checking file ownerships ...					"
  if ("$downr" == "iraf" && "$fownr" == "iraf") then
    DO_OK
  else if ("$downr" == "tody" && "$fownr" == "tody") then
    # Special exemption for NOAO installations.
    DO_OK
  else 
    DO_WARN ; set warn_stat = 1
    NEWLINE
        MSG  "(root dir owned by $downr, iraf files owned by $fownr)"
        MSG  "The iraf tree should be owned by the iraf user so it can"
        MSG  "be updated and maintained properly."
        MSG  ""
        MSG  'To fix this, login as root, set the iraf environment, and'
        MSG  'issue the commands:'
        MSG  ""
        MSG  "	cd " `echo $iraf_p`
        MSG  '	chown -R iraf .		# change dir owner'
        MSG  '	cd $hbin		# go to HSI bin dir'
        MSG  '	chown 0 alloc.e		# fix alloc.e ownership'
        MSG  '	chmod 4755 alloc.e	# fix permissions'
    NEWLINE
    set warn_count = `expr $warn_count + 1`
  endif

 endif

# Check file/directory permissions.
echo -n "Checking file permissions ...					"

set err_seen 	= 0
foreach dir ($iraf_p $iraf_p/iraf $iraf_p/iraf/unix $iraf_p/iraf/unix/hlib)
    if ("`$LS -lLd $dir | grep '.rw[xs]r.[xs]r.[xt]'`" == "") then
 	set err_seen = 1
	break
    endif
end

if ("$err_seen" == 0) then
    DO_OK
else
    DO_FAIL ; set err_stat = 1
    NEWLINE
        MSG  "The permissions on the iraf directory tree appear to be too"
        MSG  "restrictive to allow group or world user to access the file"
        MSG  "This may prevent users other than $downr from starting the system"
    NEWLINE
    set err_count = `expr $err_count + 1`
endif

endif


# Check iraf tree for proper structure.
set check_iraf_tree = 0			# for v214 and earlier

set iraf_r  = $iraf			# iraf root directory
set iraf_p  = $iraf_r:h			# iraf parent directory
set iraf_b  = $iraf_p/irafbin		# irafbin directory
set iraf_tree_ok = 1

set iraf_ib = $iraf/bin.$mach		# irafbin IB directory
set iraf_nb = $iraf/noao/bin.$mach	# irafbin NB directory


if ($check_iraf_tree == 1) then

set iraf_ib = $iraf_b/bin.$mach		# irafbin IB directory
set iraf_nb = $iraf_b/noao.bin.$mach	# irafbin NB directory


echo "Checking proper iraf tree structure in $iraf_p ..."

echo -n "    Checking for 'iraf' subdir ...				"
if (-d "$iraf_p/iraf") then
    DO_OK
else
    DO_FAIL ; set err_stat = 1 ; set iraf_tree_ok = 0
    set err_count = `expr $err_count + 1`
endif

echo -n "    Checking for 'irafbin' subdir ...				"
if (-d "$iraf_p/irafbin") then
    DO_OK
else
    set temp    = $iraf_tree_ok
    #echo -n "[ "; BOLD_ON; echo -n "Not Found" ; BOLD_OFF; echo " ]" ; 
    echo ""
    set iraf_tree_ok = 0

    # Look for a fallback to recover ...
    echo -n "	Checking for fallback tree structure ...	"
    set iraf_p = $iraf/../
    set iraf_b  = $iraf_p/irafbin		# irafbin directory
    set iraf_ib = $iraf_b/bin.$mach		# irafbin IB directory
    set iraf_nb = $iraf_b/noao.bin.$mach	# irafbin NB directory
    if (-d "$iraf_p/irafbin") then
        echo -n "	"; DO_OK ; set iraf_tree_ok = $temp
    else
        echo -n "	"; DO_FAIL; set err_stat = 1 ; set iraf_tree_ok = 0
        set err_count = `expr $err_count + 1`
    endif
endif


echo "'irafbin/bin.$mach'" | \
	awk '{ printf ("    Checking for %s subdir ...   \t", $1) }'
if (-d "$iraf_p/irafbin/bin.$mach") then
    echo -n "	"; DO_OK
else
    echo -n  "	"; DO_FAIL; set err_stat = 1 ; set iraf_tree_ok = 0
    set err_count = `expr $err_count + 1`
endif

echo "'irafbin/noao.bin.$mach'" | \
	awk '{ printf ("    Checking for %s subdir ...\t\t", $1) }'
if (-d "$iraf_p/irafbin/noao.bin.$mach") then
    DO_OK
else
    DO_FAIL ; set err_stat = 1 ; set iraf_tree_ok = 0
    set err_count = `expr $err_count + 1`
endif

if ("$iraf_tree_ok" == 0) then
  NEWLINE
      MSG  "An error was detected in the structure of the iraf tree."
      MSG  "Your directory tree should look something like:"
      MSG  ""
      MSG  "                    	$iraf_p"
      MSG  "                    	  /  \"
      MSG  "          	(AS) /iraf  /irafbin"
      MSG  "                              /  \"
      MSG  "            	(IB) bin.$mach  noao.bin.$mach (NB)"
      MSG  ""
      MSG  "The AS, IB, and NB distribution files are shown where they"
      MSG  "should be unpacked.  Please verify the structure and the"
      MSG  "system architecture."
  NEWLINE
endif

endif	# if (check_iraf_tree)




# Check binary dirs are both populated correctly.
echo -n "Checking Core system binary directory ...			"
if (! (-e "$iraf_ib/cl.e" && -e "$iraf_ib/x_system.e")) then
  if ($port == 1) then
      DO_WARN ; set warn_stat = 1
  else
      DO_FAIL ; set err_stat = 1
  endif
  NEWLINE
      MSG  "The core system binary directory, $iraf_ib, does"
      MSG  "not appear to contain the proper binaries."
  NEWLINE
  set err_count = `expr $err_count + 1`
else
  DO_OK
endif

echo -n "Checking NOAO package binary directory ...			"
if (! (-e "$iraf_nb/x_apphot.e" && -e "$iraf_nb/x_rv.e")) then
  if ($port == 1) then
      DO_WARN ; set warn_stat = 1
  else
      DO_FAIL ; set err_stat = 1
  endif
  if (-e "$iraf_ib/x_apphot.e" && -e "$iraf_ib/x_rv.e") then
      NEWLINE
          MSG  "The NOAO package binary directory, $iraf_nb, is"
          MSG  "empty but the binaries appear to have been unpacked in the"
          MSG  "core system directory, $iraf_ib.  These will need to be moved,"
          MSG  "please delete the binaries and start again, be sure to unpack"
          MSG  "the NB distribution files in the $iraf_nb directory,"
          MSG  "and the core system file in the $iraf_ib directory."
      NEWLINE
  else
      NEWLINE
          MSG  "The NOAO package binary directory, $iraf_nb, does"
          MSG  "not appear to contain the proper files."
      NEWLINE
  endif
  set err_count = `expr $err_count + 1`
else
  DO_OK
endif


# Check that the specified local bin directory exists.
echo -n "Checking that local bin directory exists ...			"
if (-d "$lbin") then
    DO_OK
else
    DO_FAIL ; set err_stat = 1
    NEWLINE
        MSG  "The specified local bin directory does not exist.  This"
        MSG  "directory should be a common local bin directory which "
        MSG  "is found in all user's paths, e.g. /usr/local/bin."
        MSG  "Please create the directory or else reset and try again."
    NEWLINE
    set err_count = `expr $err_count + 1`
endif


# Check that the specified local lib directory exists.
if ("$shlib" == "yes") then
  echo -n "Checking that local lib directory exists ...			"
  if (-d "$llib") then
    DO_OK
  else
    DO_FAIL ; set err_stat = 1
    NEWLINE
        MSG  "The specified local lib directory does not exist.  This"
        MSG  "directory should be a common local lib directory which "
        MSG  "is found in all user's paths, e.g. /usr/local/lib."
        MSG  "This directory is required for the iraf shared library."
        MSG  "Please create the directory or else reset and try again."
    NEWLINE
    set err_count = `expr $err_count + 1`
  endif
endif


# See if we're good to go ...
if ("$err_stat" != "0") then
  NEWLINE ; NEWLINE
  BOLD_ON
  echo "======================================================================"
  echo "|   An error occured during verification.  Please take corrective    |"
  echo "|          action before rerunning the install script.               |"
  echo "======================================================================"
  BOLD_OFF
  NEWLINE
  exit $err_stat
endif



# ============================================
# The following is partially system dependent.
# ============================================

# Set the BINDIRS pathnames - directories where the HSI executables go.
set host	= "$iraf/unix"
set hbin	= "$iraf/unix/bin.$hmach"
set hlib	= "$iraf/unix/hlib"
set fbin	= "$iraf/bin"

# Replace any // by /.
set host	= `echo $host | sed -e "s+//+/+g"`
set hbin	= `echo $hbin | sed -e "s+//+/+g"`
set fbin	= `echo $fbin | sed -e "s+//+/+g"`
set hlib	= `echo $hlib | sed -e "s+//+/+g"`

# Strip any trailing /.
set host	= `echo $host | sed -e 's+/\(["]*\)$+\1+'`
set hbin	= `echo $hbin | sed -e 's+/\(["]*\)$+\1+'`
set fbin	= `echo $fbin | sed -e 's+/\(["]*\)$+\1+'`
set hlib	= `echo $hlib | sed -e 's+/\(["]*\)$+\1+'`
set BINDIRS	= "$hbin $hlib $fbin $host"

# The following file lists are partially system dependent.
set PATHFILES	= "mkiraf.csh libc/iraf.h cl.csh"
set MODEFILES	= "cl.csh fc.csh mkiraf.csh mkfloat.csh mkmlist.csh $host/reboot generic.e mkpkg.e rmbin.e rmfiles.e rpp.e rtar.e wtar.e xc.e xpp.e xyacc.e sgidispatch.e $hbin/sgi2*.e irafarch.csh"
set LINKFILES	= "ecl.e cl.e mkiraf.csh mkmlist.csh generic.e mkpkg.e rmbin.e rmfiles.e rtar.e sgidispatch.e wtar.e rpp.e xpp.e xyacc.e xc.e"
set CMDLINKS	= "ecl cl mkiraf mkmlist generic mkpkg rmbin rmfiles rtar sgidispatch wtar rpp xpp xyacc xc irafarch"


#=============================================================================
# See whether there is an existing commands dir we need to delete.
#=============================================================================

echo -n "Checking for existing commands directory...			"
set cl_found = 0
set clpath   = ""
foreach d ($path)
    if (-e $d/cl) then
	set cl_found = 1
	set clpath = $d/cl
	break
    endif
end
if ($cl_found == 1) then
    set o_lbin = $clpath:h

    if ("$o_lbin" != "$lbin") then
        DO_WARN
	NEWLINE
 	    MSG  "IRAF commands were found in the directory:"
 	    MSG  ""
 	    MSG  "	$o_lbin"
	    MSG  ""
 	    MSG  "    These commands may conflict with the commands now being"
  	    MSG  "installed in:  '$lbin'"
	    MSG  ""
del_cmd_:
	PROMPT "Do you want to delete commands in the old directory? "
        set ans = "$<"

	if ("$ans" == "" || "$ans" == "y" || "$ans" == "yes") then
	    NEWLINE
	    foreach i ($CMDLINKS)               # remove the iraf commands
	        set file = $o_lbin/$i
	        if (-e $file) then
	            MSG  "Deleting command $file ..."
	            if ($exec == yes) then
	                RM $file
	            endif
	        endif
	    end
	else if ("$ans" == "quit" || "$ans" == "q") then
	    exit 1
	else if ("$ans" == "no" || "$ans" == "n") then
	    ;	# fall through
	else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
	    NEWLINE
	        MSG "Multiple commands such as 'cl' or 'mkiraf' on a machine"
	        MSG "may cause errors (such as 'command not found' due to an"
		MSG "invalid link), or confusions as to which version of iraf"
		MSG "is being run if the old link is still valid.  This is"
		MSG "because the command being used depends on the order in"
		MSG 'which the directories occur in the users "$path" environ-'
		MSG "ment variable (which may vary by user)."
		MSG ""
		MSG "It is recommended there be only one iraf command directory"
		MSG "on a given system, other methods can be used to start a"
		MSG "different IRAF installation.  This script will not auto-"
		MSG "matically remove those links, and will only correct the"
		MSG "path is the local bin directory is the same as before."
		MSG ""
		MSG "Type 'q' to quit and rerun the install script to specify"
		MSG "a different local bin directory, 'yes' to remove the old"
		MSG "links, and 'no' to leave the old commands around."
		MSG ""
	    NEWLINE
	    goto del_cmd_
        endif
	NEWLINE
    else
        DO_OK
    endif

else
    DO_OK
endif


#=============================================================================
# Prompt for the go-ahead ...
#=============================================================================
NEWLINE
proceed_:
PROMPT "Proceed with installation? "
set ans = "$<"
if ("$ans" == "" || "$ans" == "y" || "$ans" == "yes") then
    NEWLINE
else if ("$ans" == "quit" || "$ans" == "q") then
    exit 0
else if ("$ans" == "no" || "$ans" == "n") then
    exit 0
else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
    NEWLINE
        MSG  "If you proceed, the system will be installed on this machine."
        MSG  "This means that command links will be placed in the local bin"
        MSG  "directory, needed system files will be created, and the iraf"
	MSG  "root path will be edited into key files.  Stopping at this stage"
	MSG  "will have no side effects on your system or the iraf files."
	MSG  "Type <cr> to continue, or 'q' to quit to exit the installation."
    NEWLINE
    goto proceed_
else 
    echo "Huh?"
    goto proceed_
endif


##############################################################################
#
#  Step 2: INSTALLATION
#
#  Do the actual installation.  This involves:
#	
#	1) Editing the $iraf path into system files
#	2) Creating the <iraf.h> link
#	3) Creating the system command links
#	4) Creating the image directory (imdir)
#	5) Creating the cache directory (cache)
#	6) Tape setup (modes on alloc.e and /dev tape devices)
#	7) Graphics/Display file installation/setup
#
##############################################################################

# Begin installation.
# ------------------

set err_seen = 0


NEWLINE
BOLD_ON
echo "========================================================================"
echo "=========================  Begin Installation  ========================="
echo "========================================================================"
BOLD_OFF

# Skip ahead if we're not editing the files or touching the disk.
if ($no_edit == 1) then
    goto end_no_edit
endif


NEWLINE
BOLD_ON
echo "                             Editing Paths"
echo "                             -------------"
BOLD_OFF

# Edit the $iraf pathname in the .login file for user 'iraf'.
echo -n "Editing the iraf user .login/.cshrc paths ...			"
cd $iraf/local

foreach file (.cshrc .login)
    if (-e $file) then
        RM $TEMP >& /dev/null
        sed -e "s+$W$o_iraf+\1$iraf+" $file > $TEMP
        cmp -s $file $TEMP
        if ($status) then
	    PUT $TEMP $file
        endif
        RM $TEMP >& /dev/null
    else
        if ("$err_seen" == 0) then
            DO_FAIL
            set err_seen = 1
            set err_count = `expr $err_count + 1`
        endif
        MSG  "Cannot find the iraf $file file"
        RM $TEMP >& /dev/null
    endif
end
if ("$err_seen" == 0) then
    DO_OK
endif


# If we're on a Mac OS X or Cygwin system the iraf login directory isn't easy 
# to change and as of OSX 10.1 the default is to create this in /Users/iraf.  
# If this is how things are set up then link the .login/.cshrc files in this 
# directory so the account has the proper environment.

set err_seen = 0

if ($V != "2.15" && $V != "2.16") then

 if ($pciraf && ($mach == "macosx" || $mach == "macintel" || $mach == "cygwin")) then
 echo -n "Creating iraf user .login/.cshrc links ...			"

    set v = `finger iraf |& egrep '^Directory'`
    set ihome = `echo $v[2] | sed -e 's+/\(["]*\)$+\1+'`

    if ("$ihome" != "$iraf/local") then
      cd $ihome				# go to account login dir

      if (! (-e bugs.log)) then		# make sure it's not iraf$local
          foreach file (.cshrc .login)
              if ($exec == yes) then
		if (-e $file) then
                    RM $file >& /dev/null	# remove old file
		endif
		ln -s $iraf/local/$file $file	# make local link

		if (! (-e $file) && $exec == yes) then
		    if ("$err_seen" == 0) then
		        DO_FAIL
                        set err_seen = 1
                        set err_count = `expr $err_count + 1`
		    endif
        	    MSG  "Cannot find the iraf $file file in $ihome"
        	    RM $TEMP >& /dev/null
		endif

	      endif
          end
      endif
      cd $iraf/local

    else
	DO_OK
    endif

    if ("$err_seen" == 0) then
        DO_OK
    endif
 endif

endif


# Edit the $iraf and $imdir paths in mkiraf.csh, cl.csh, and libc/iraf.h files.

echo -n "Editing iraf/imdir paths into system files ...			"
cd $iraf/unix/hlib

set err_seen = 0
foreach i ($PATHFILES)
    if (-e $i) then
	RM $TEMP >& /dev/null
	sed -e "s+$W$o_iraf+\1$iraf+" $i |\
	    sed -e "s+$W$o_cache+\1$cache+" | \
	    sed -e "s+$W$o_imdir+\1$imdir+" > $TEMP
	cmp -s $i $TEMP
	if ($status) then
	    if ($exec == yes) then
	        PUT $TEMP $i
		chmod 755 $i
	    endif
	endif
        RM $TEMP >& /dev/null
    else
	if ("$err_seen" == 0) then
	    DO_FAIL
	    set err_seen = 1
            set err_count = `expr $err_count + 1`
	endif
	MSG  "File $i not found."
        RM $TEMP >& /dev/null
    endif
end
if ("$err_seen" == 0) then
    DO_OK
endif



NEWLINE
BOLD_ON
echo "                       Checking File Permissions"
echo "                       -------------------------"
BOLD_OFF

# Set default file permissions for the executable files in the BINDIRS,
# in case the file mode has somehow been changed, e.g., in a file restore
# or copy.

echo -n "Checking iraf file permissions ...				"

set err_seen = 0
foreach i ($MODEFILES)
    set file = $i
    if (! -e $file) then
	foreach j ($BINDIRS)
	    if (-e $j/$i) then
		set file = $j/$i
		break
	    endif
	end
    endif
	
    if (-e $file) then
	if ("`$LS -l $file | grep '^.rw[xs]r.[xs]r.[xt]'`" == "") then
	    if ("$err_seen" == 0) then
	        DO_WARN
		set err_seen = 1
                set err_count = `expr $err_count + 1`
	    endif
	    MSG  "Setting $file:t to mode 0755."
	    if ($exec == yes) then
		chmod 755 $file
	    endif
	endif
    else
	if ("$err_seen" == 0) then
	    DO_FAIL
	    set err_seen = 1
            set err_count = `expr $err_count + 1`
	endif
	MSG  "File $file:t not found."
    endif
end
if ("$err_seen" == 0) then
    DO_OK
endif


# Create the root imdir as a public scratch directory, if not already created.
set err_seen = 0
if (-d $imdir) then
    if ("`$LS -ld $imdir | grep '^.rw[xs]r.[xs]r.[xt]'`" != "") then
	echo -n 'Checking imdir permissions ...'
	echo -n '					'
    else
	echo -n 'Setting mode for $imdir to 0777			'
	if ($exec == yes) then
	    chmod 777 $imdir
	endif
    endif
else
    echo -n "Creating root imdir at $imdir ...				"
    if ($exec == yes) then
	mkdir $imdir; chmod 777 $imdir
    endif
endif
if ("$err_seen" == 0) then
    DO_OK
endif


# Create the root cache as a public scratch directory, if not already created.
set err_seen = 0
if (-d $cache) then
    if ("`$LS -ld $cache | grep '^.rw[xs]r.[xs]r.[xt]'`" != "") then
	echo -n 'Checking cache permissions ...'
	echo -n '					'
    else
	echo -n 'Setting mode for $cache to 0777			'
	if ($exec == yes) then
	    chmod 777 $cache
	endif
    endif
else
    echo -n "Creating root cache at $cache ...				"
    if ($exec == yes) then
	mkdir $cache; chmod 777 $cache
    endif
endif
if ("$err_seen" == 0) then
    DO_OK
endif



# Allow deletion of files in /tmp - needed for multiuser tape allocation.
echo -n "Reset /tmp sticky bit setting ...				"
if ($exec == yes) then
    chmod -t /tmp
endif
DO_OK

# Initialize permissions of tape devices.
if ($do_tapes) then
echo -n "Setting tape device permissions ...				"
    if ($exec == yes) then
        chmod 666 $TAPES >& /dev/null
	chown root $TAPES >& /dev/null
    endif
    DO_OK
endif



# Set owner=root for the device allocation task, alloc.e.

echo -n "Checking alloc.e permissions ...				"

set err_seen = 0
foreach i ($BINDIRS)
    if (-e $i/alloc.e) then
	if ("`$LS -l $i/alloc.e | grep 'rwsr-.*root'`" == "") then
	    if ($exec == yes) then
		chown 0 $i/alloc.e
		chmod u+s $i/alloc.e
	    endif
	endif
	break
    else
	if ("$err_seen" == 0) then
	    DO_FAIL
	    set err_seen = 1
            set err_count = `expr $err_count + 1`
	endif
	MSG  "Cannot find alloc.e executable."
    endif
end
if ("$err_seen" == 0) then
    DO_OK
endif


# Target for no-edit install.
end_no_edit:


NEWLINE
BOLD_ON
echo "                         Creating File Links"
echo "                         -------------------"
BOLD_OFF


# Create a /iraf symlink on the system to establish a /iraf/iraf root
# path regardless of the actual root dir.  We only do this if there is
# no /iraf on the system already.

echo -n "Checking for /iraf symlink ...					"
if (! -e /iraf) then
    if ($exec == yes) then
	ln -s $iraf_p /iraf
    endif
    if ($exec == no || -e /iraf/iraf ) then
	DO_OK
    else
	DO_FAIL
        set err_count = `expr $err_count + 1`
    endif
else
    DO_OK
endif


# Link $hlib/libc/iraf.h to <iraf.h>.  This is needed not only to compile C
# source files in iraf, but also to define $iraf, $host, etc. for iraf tasks.

# Verify we have a /usr/include directory (some MacOSX systems won't)
echo -n "Checking /usr/include directory ...				"
if (! -e /usr/include) then
    if ($exec == yes) then
        mkdir /usr/include
        if (-d /usr/include) then
            DO_OK
        else
            DO_FAIL
            set err_count = `expr $err_count + 1`
        endif
    else
        DO_OK
    endif
else
    DO_OK
endif


echo -n "Creating <iraf.h> symlink ...					"
set file1 = /usr/include/iraf.h
set file2 = $iraf/unix/hlib/libc/iraf.h

set err_seen = 0
if (-e $file1) then
    if ("`$LS -l $file1 | grep $file2`" == "") then
	if ($exec == yes) then
	    RM $file1
	endif
	if ($exec == yes) then
	    ln -s $file2 $file1
	endif
    endif
else
    if ($exec == yes) then
	ln -s $file2 $file1
    endif
endif
if (("$err_seen" == 0 && -e $file1) || $exec == "no") then
    DO_OK
else
    DO_FAIL
    set err_count = `expr $err_count + 1`
endif


# Establish the remaining symbolic links to HSI tasks.
echo -n "Creating iraf command links in local bin dir ...		"
cd $lbin

set err_seen = 0
foreach i ($LINKFILES)
    # Locate the file to be linked to.
    set file1 = $i:r
    foreach j ($BINDIRS)
	set file2 = $j/$file1.csh
	if (-e $file2) then
	    break
	endif
	set file2 = $j/$i
	if (-e $file2) then
	    break
	endif
    end

    # Verify or set the link.
    if (-e $file1) then
	if ("`$LS -l $file1 | grep $file2`" == "") then
	    if ($exec == yes) then
	        RM $file1
	    endif
	    if ($exec == yes) then
		ln -s $file2 $file1
	    endif
	endif
    else
	if ($exec == yes) then
	    RM $file1
	    ln -s $file2 $file1
	endif
    endif

    if (! (-e $file1) && "$exec" == "yes") then
        if ("$err_seen" == 0) then
            DO_FAIL
        endif
        MSG  "Could not make link $file1 -> $file2"
	set err_seen = 1
        set err_count = `expr $err_count + 1`
    endif
end
if ("$err_seen" == 0) then
    DO_OK
endif


# Establish the remaining symbolic links to shared libraries.
if ("$shlib" == "yes") then
    echo -n "Creating iraf library links in local lib dir ...		"
    cd $llib

    set err_seen = 0
    foreach i ($LIBFILES)
        # Locate the file to be linked to.
        set file1 = $i
        foreach j ($iraf/bin.$mach $iraf/bin.$hmach)
	    set file2 = $j/$i
	    if (-e $file2) then
	        break
	    endif
        end

        # Verify or set the link.
        if (-e $file1) then
	    if ("`$LS -l $file1 | grep $file2`" == "") then
	        if ($exec == yes) then
	            RM $file1
	        endif
	        if ($exec == yes) then
		    ln -s $file2 $file1
	        endif
	    endif
        else
	    if ($exec == yes) then
	        RM $file1
	        ln -s $file2 $file1
	    endif
        endif

        if (! (-e $file1) && "$exec" == "yes") then
            if ("$err_seen" == 0) then
                DO_FAIL
            endif
            MSG  "Could not make link $file1 -> $file2"
	    set err_seen = 1
            set err_count = `expr $err_count + 1`
        endif
    end
    if ("$err_seen" == 0) then
        DO_OK
    endif
endif


# Mark the system update time.
if ($no_edit == 0) then
    echo -n 'Marking system update time hlib$utime ...			'
    if ($exec == yes) then
        touch $hlib/utime
    endif
    DO_OK
endif


#=============================================================================
# Install the VOClient Daemon code.
#=============================================================================

NEWLINE
BOLD_ON
echo "                    Installing VOClient Code"
echo "                    ------------------------"
BOLD_OFF


echo -n "Creating 'voclientd' symlink ...				"
set file1 = $lbin/voclientd
set file2 = $iraf/vo/java/voclientd

set err_seen = 0
if (-e $file1) then
    if ("`$LS -l $file1 | grep $file2`" == "") then
	if ($exec == yes) then
	    RM $file1
	endif
	if ($exec == yes) then
	    ln -s $file2 $file1
	endif
    endif
else
    if ($exec == yes) then
	ln -s $file2 $file1
    endif
endif
if (("$err_seen" == 0 && -e $file1) || $exec == "no") then
    DO_OK
else
    DO_FAIL
    set err_count = `expr $err_count + 1`
endif


echo -n "Creating 'voclient.jar' symlink ...				"
set file1 = $lbin/voclient.jar
set file2 = $iraf/vo/java/voclient.jar

set err_seen = 0
if (-e $file1) then
    if ("`$LS -l $file1 | grep $file2`" == "") then
	if ($exec == yes) then
	    RM $file1
	endif
	if ($exec == yes) then
	    ln -s $file2 $file1
	endif
    endif
else
    if ($exec == yes) then
	ln -s $file2 $file1
    endif
endif
if (("$err_seen" == 0 && -e $file1) || $exec == "no") then
    DO_OK
else
    DO_FAIL
    set err_count = `expr $err_count + 1`
endif



#=============================================================================
# Common code for XGTERM/XIMTOOL installation.
#=============================================================================

NEWLINE
BOLD_ON
echo "                    Creating Graphics Device Files"
echo "                    ------------------------------"
BOLD_OFF

if ($do_pipes == 0 || $has_pipes == 0) then
    goto _no_pipes
endif

# Make sure special device entries for the display servers exist in /dev.
echo -n "Creating /dev/imt1 fifo pipes for image display ...		"

set err_seen = 0
foreach i (/dev/imt1i /dev/imt1o)
    if (-e $i) then
	# Check the file permissions.
	if ("`$LS -l $i | grep '^.rwxrwxrwx'`" == "") then
	    if ($exec == yes) then
	        chmod 777 $i
	    endif
	endif
    else
	if ($exec == yes) then
	    set mkfifo_found = 0
	    foreach d ($path)
	        if (-e $d/mkfifo) then
	            set mkfifo_found = 1
	            break
	        endif
	    end
	    if ($mkfifo_found == 1) then
		mkfifo $i
	    else
		mknod $i p
	    endif
	    chmod 777 $i
	endif
    endif

    if (! (-e $i) && $exec == "yes") then
        if ("$err_seen" == 0) then
            DO_FAIL
        endif
        MSG  "Could not create fifo $i"
	set err_seen = 1
        set err_count = `expr $err_count + 1`
    endif
end
if ("$err_seen" == 0) then
    DO_OK
endif


# The old /dev/imt1 entry is now just a link to /dev/imt1o.
echo -n "Creating /dev/imt fifo pipes link ...				"
set file = /dev/imt1

set err_seen = 0
if (-e $file) then
    if ("`$LS -l $file | grep imt1o`" == "") then
	if ($exec == yes) then
	    RM $file
	    ln -s /dev/imt1o $file
	endif
    endif
else
    if ($exec == yes) then
	ln -s /dev/imt1o $file
    endif
endif
if (("$err_seen" == 0 && -e $file) || $exec == "no") then
    DO_OK
else
    DO_FAIL
    set err_count = `expr $err_count + 1`
endif

_no_pipes:

if ($mach == "cygwin") then
 echo -n "Creating special graphcap file ...				"
 cp $iraf/dev/graphcap.inet $iraf/dev/graphcap
 DO_OK
endif

#=============================================================================
# Install the default IMTOOLRC frame buffer configuration file.  The path
# /usr/local/lib path hardwired in to imtool and cannot easily be changed, but
# if installation of the default imtoolrc in this directory is not possible,
# the file can be installed in each imtool user's login directory as .imtoolrc,
# or the environment variable IMTOOLRC can be defined in each imtool user's
# .login or .cshrc to define the path to the file.
#=============================================================================

# Verify imtoolrc link.
echo -n "Checking /usr/local/lib directory ...				"
if (! -e /usr/local/lib) then
    if ($exec == yes) then
	if (! -e /usr/local) then
	    mkdir /usr/local
	endif
	mkdir /usr/local/lib
	if (-d /usr/local/lib) then
	    DO_OK
	else
	    DO_FAIL
    	    set err_count = `expr $err_count + 1`
	endif
    else
	DO_OK
    endif
else
    DO_OK
endif


# Verify or set the IMTOOLRC link.
if ($exec == yes) then
    cd /usr/local/lib
endif
set file1 = imtoolrc
set file2 = $iraf/dev/imtoolrc

echo -n "Creating /usr/local/lib/imtoolrc link ...			"

set err_seen = 0
if (-e $file1) then
    if ("`$LS $file1`" == "$file1") then
        if ("`$LS -l $file1 | grep $file2`" == "") then
	    if ($exec == yes) then
	        RM $file1
	        ln -s $file2 $file1
	    endif
        endif
    endif
else
    if ($exec == yes) then
	ln -s $file2 $file1
    endif
endif
if (("$err_seen" == 0 && -e $file1) || $exec == "no") then
    DO_OK
else
    DO_FAIL
    set err_count = `expr $err_count + 1`
endif


#=============================================================================
# Make sure there are entries in the the termcap and graphcap files for xgterm
# and imtool.  This is almost a no-op however we check in case there's an
# ancient local version which may have been replaced repeatedly rather than
# diff/merged over time.
#=============================================================================

echo -n "Checking if termcap file contains an XGterm entry ...		"
set temp = `grep -l xgterm $iraf/dev/termcap | grep -v '^#'`
if ("$temp" == "") then
    DO_FAIL
    set err_count = `expr $err_count + 1`
else
    DO_OK
endif

echo -n "Checking graphcap file for XGterm/imtool entries ...		"
set gcok = yes
foreach i (xgterm imtool)
    set temp = `grep -l $i $iraf/dev/graphcap | grep -v '^#'`
    if ("$temp" == "" && "$gcok" == "yes") then
        DO_FAIL
        set err_count = `expr $err_count + 1`
        set gcok = no
    endif
end
if ($gcok == yes) then
    DO_OK
endif

if ("$err_count" > 0) then
    goto fini_
endif



##############################################################################
#
#  Step 3: POST-INSTALL CONFIGURATION
#
#  Do some of the post-installation config required of all systems.
#  This involves:
#	
#	1) Creating a dev$tapecap for this system
#	2) Adding machine to dev$hosts file
#	3) Check for display servers
#	4) Check for graphics terminals 
#	5) Delete unused HSI binaries
#	6) Strip system sources
#
##############################################################################

# Begin configuration.
# --------------------

set err_seen = 0

NEWLINE ; NEWLINE
BOLD_ON
echo "========================================================================"
echo "=====================  Post-Install Configuration  ====================="
echo "========================================================================"
BOLD_OFF
NEWLINE


echo "    The system should be fully functional at this point however some"
echo "post-install configuration may be required to make use of all the"
echo "features such as networking or tape access.  Additional software such"
echo "as external packages or display servers will need to be installed"
echo "separately.  Some minimal configuration can be accomplished now but"
echo -n "you should consult the "
BOLD_ON
echo -n "IRAF Site Manager's Guide"
BOLD_OFF
echo " for a more complete"
echo "discussion of IRAF system management, configuration of printers, etc."

NEWLINE
post_install_:
PROMPT "Proceed to post-install configuration stage? "
set ans = "$<"
if ("$ans" == "" || "$ans" == "y") then
 NEWLINE
 BOLD_ON
 echo "------------------------------------------------------------------------"
 BOLD_OFF
else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
  NEWLINE
      MSG  "    If you continue, some minimal configuration of the IRAF net-"
      MSG  "working and tapecap file will be performed.  Additional checks"
      MSG  "on the availability of display servers and graphics terminals will"
      MSG  "also be done."
  NEWLINE
  goto post_install_
else if ("$ans" == "no" || "$ans" == "n") then
  NEWLINE; NEWLINE
  goto fini_
else if ("$ans" == "q" || "$ans" == "quit") then
  exit 0
else
  echo "Huh?"
  goto post_install_
endif


#==============================================================================
#  Set up the dev$hosts file to enable iraf networking on this system.
#==============================================================================


# Get the networking values.
set hname       = "`hostname`"
set lhost_abbr  = `hostname | awk '{printf ("%16.16s\n", $1 ) }'`
set ihosts      = $iraf/dev/hosts
set tmp_host    = /tmp/_host$$

    
if (`echo $hname | grep "\."` != "") then
    # When using FQDN lnode may not be set....
    set is_fqdn = yes
    set domain  = "`hostname | sed -e 's/^[a-zA-Z0-9_\-]*\.//g'`"
    set lhost = "`hostname | sed -e 's/\.[a-zA-Z0-9]*//g'`"
else
    set is_fqdn = no
    set domain  = "<unknown>"
    set lhost = $hname
endif
set nnode = "`hostname`"

# Compute the recommended hosts entry.
set irafks = $iraf/bin.$mach/irafks.e
set bang = '\\!'
if ("$is_fqdn" == "no") then
    set rec = `echo $lhost "	: " ${hname}${bang}${irafks}`
else
    set rec = `echo $lhost $lhost_abbr " : " ${nnode}${bang}${irafks}`
endif



NEWLINE
BOLD_ON
echo "                        IRAF Networking Config"
echo "                        ----------------------"
BOLD_OFF
NEWLINE

echo "    IRAF Networking can be used to access a remote image, tape device,"
echo "display server, or other network service. It's configuration is not"
echo "a requirement for normal IRAF operations and it can be updated at any"
echo 'time by editing the IRAF dev$hosts file with new entries.'
NEWLINE
echo "    In this stage we will add an entry for the current platform to the"
echo "hosts file.  In a local network installation this script should be run"
echo "on each system to add a networking entry as well as to install other"
echo "system files needed by IRAF."

net_conf_:
NEWLINE
PROMPT "Configure IRAF Networking on this machine? "
set ans = "$<"
if ("$ans" == "" || "$ans" == "y") then

    # Check to see if the current machine is already in the hosts file.
    set overwrite = 0
    set have_entry = 0
    grep $lhost $ihosts >& /dev/null
    if ($status == 0) then
	# Compare the recommended entry with the one already in the file.
	echo $rec 		>& /tmp/_net_rec.$$
	grep $lhost $ihosts 	>& /tmp/_net_exists.$$
	diff -bitw /tmp/_net_rec.$$ /tmp/_net_exists.$$ >& /dev/null
	if ($status == 0) then
	    RM  /tmp/_net_*.$$
    	    set have_entry = 1
	    NEWLINE
	    echo "Host '$lhost' exists with recommended entry in $ihosts."
	    NEWLINE
	    goto net_proc_

	else
	    RM  /tmp/_net_*.$$
	    NEWLINE
	    echo "Host '$lhost' exists with entry in $ihosts other than what"
	    echo "would be computed by this script:"
	    NEWLINE
    	    echo '  Recommended dev$hosts file entry used for this machine: '
    	    NEWLINE
            if ("$is_fqdn" == "no") then
                echo "    "$lhost "       : "$hname"\!"$irafks
            else
                echo "    "$lhost $lhost_abbr " : " $nnode"\!"$irafks
            endif
    	    NEWLINE
    	    echo '  Existing entry found in the dev$hosts file: '
    	    NEWLINE
	    echo -n "    "; grep $lhost $ihosts
	    NEWLINE

net_overwrite_:
	    NEWLINE
	    PROMPT_N "Overwrite the existing entry with recommended one?"
	    set ans = "$<"
    	    if ("$ans" == "" || "$ans" == "no" || "$ans" == "n") then
		set overwrite = 0
	        goto net_check_
    	    else if ("$ans" == "y" || "$ans" == "yes") then
		set overwrite = 1
		# fall through
    	    else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
		NEWLINE
		    MSG "Answering 'yes' will replace the entry in the file"
		    MSG "with the one created by this script, answering 'no'"
		    MSG "will leave the current entry (which may be correct)"
		    MSG "intact."
		NEWLINE
		goto net_overwrite_
            else if ("$ans" == "q" || "$ans" == "quit") then
	    	exit 0
            else 
	        echo "Huh? "
	        goto net_overwrite_
            endif

	endif

    else
	# This host isn't currently in the file.
net_rec_:
        NEWLINE
        echo 'Recommended dev$hosts file entry used for this machine: '
        NEWLINE
        if ("$is_fqdn" == "no") then
            echo "    "$lhost "       : "$hname"\!"$irafks
        else
            echo "    "$lhost $lhost_abbr " : " $nnode"\!"$irafks
        endif
        NEWLINE

net_proc_:
        PROMPT "Proceed with this entry? "
        set ans = "$<"
        if ("$ans" == "" || "$ans" == "y") then
	    ;
        else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
          NEWLINE
              MSG  'If you continue the recommended entry will be added to the'
	      MSG  "IRAF dev$hosts file as is, otherwise you will be asked if"
              MSG  "you wish to edit the file manually."
          NEWLINE
          goto net_proc_

        else if ("$ans" == "q" || "$ans" == "quit") then
	    exit 0
        else if ("$ans" == "no" || "$ans" == "n") then
net_edit_:
          PROMPT 'Do you wish to edit the dev$hosts file manually? '
          set ans = "$<"

          if ("$ans" == "" || "$ans" == "y") then
	      if ($?EDITOR) then
	          $EDITOR $ihosts
	      else
	          vi $ihosts
	      endif
	      goto net_check_
          else if ("$ans" == "no" || "$ans" == "n") then
	      MSG "Skipping network configuration."
	      goto net_check_
          else if ("$ans" == "q" || "$ans" == "quit") then
	      exit 0
          else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
	      NEWLINE
	      MSG  'If you say yes you will be allowed to edit the dev$hosts'
	      MSG  "file manually.  You should use the existing entries as a"
	      MSG  "template.  Be sure the host name and iraf path are correct"
	      MSG  "for this machine."
	      NEWLINE
	      goto net_edit_
          else 
	      echo "Huh? "
	      goto net_edit_
          endif
        else
          echo "Huh?"
          goto net_proc_
        endif

    endif

    # If we have an entry already in the file skip ahead to the check.
    if ($have_entry == 1) then
	goto net_check_
    endif

    # When exported to other sites the default dev$hosts file is the one
    # configured for the NOAO network.  Check to see whether we really *are*
    # running at NOAO so we don't wipe this out assuming it's a fresh install
    # and we can treat the file as an existing installation (i.e. append to
    # the hosts file).
    set is_noao = 0
    ifconfig -a |& grep 140.252 >& /dev/null
    if ($status == 0) then
	set is_noao = 1
    endif

    grep kpno.noao.edu $ihosts >& /dev/null
    if ($status == 0 && $is_noao == 0) then
	# If we're here then the hosts file is the NOAO default, but we are
	# not running on an NOAO network machine.  So, we want to initialize
	# the hosts file by getting rid of the NOAO hosts, adding a standard
	# "header" and adding the current platform.	

	NEWLINE
	echo 'Creating backup of default dev$hosts file...'
	if ($exec == yes) then
	    cp $iraf/dev/hosts $iraf/dev/hosts.ORIG
	endif

	echo 'Initializing dev$hosts file ...'


	echo "# HOSTS -- IRAF local network host table."	>  $tmp_host
	echo ""							>> $tmp_host
	echo -n "# Logical nodes (lpnode = line printer"	>> $tmp_host
	echo "output, plnode = plotter output)."		>> $tmp_host
	echo "#lpnode                 : @ursa"			>> $tmp_host
	echo "#plnode                 : @ursa"			>> $tmp_host
	echo ""							>> $tmp_host
	echo "# Host table."					>> $tmp_host
	echo ""							>> $tmp_host

    	if ("$is_fqdn" == "no") then
      	  echo $lhost $hname $iraf/bin.$mach/irafks.e | \
	    awk '{printf("%-16s\t: %s\!%s\n",$1,$2,$3)}'	>> $tmp_host
    	else
      	  echo $lhost $lhost_abbr $hname $iraf/bin.$mach/irafks.e | \
	    awk '{printf("%-16s %s\t: %s\!%s\n",$1,$2,$3,$4)}'	>> $tmp_host
    	endif

	# Copy the header to the file
	if ($exec == yes) then
	    cp $tmp_host $ihosts
	else 
	    cat $tmp_host
	endif

	RM  $tmp_host
        echo "Host '$hname' has been added to the network configuration file..."

    else
	# If we get to this point we're appending a hosts file that is
	# correct for the current network, NOAO or not.  


	# Pull off the file "header" and "data" to separate segments.
	head -7 $ihosts				>& /tmp/_hhdr$$
	if ($overwrite == 1) then
	    more +8 $ihosts | grep -v $lhost	>& /tmp/_hdat$$
	else
	    more +8 $ihosts			>& /tmp/_hdat$$
	endif

    	if ("$is_fqdn" == "no") then
      	  echo $lhost $hname $iraf/bin.$mach/irafks.e | \
	    awk '{printf("%-16s\t: %s\!%s\n",$1,$2,$3)}'	>> /tmp/_hdat$$
    	else
      	  echo $lhost $lhost_abbr $hname $iraf/bin.$mach/irafks.e | \
	    awk '{printf("%-16s %s\t: %s\!%s\n",$1,$2,$3,$4)}'	>> /tmp/_hdat$$
    	endif

net_sort_:
	# See if we want to sort the file.
	PROMPT "Do you want to sort the hosts file by node name? "
	set ans = "$<"
    	if ("$ans" == "" || "$ans" == "y" || "$ans" == "yes") then
	    sort /tmp/_hdat$$ >& /tmp/_hsdat$$
    	else if ("$ans" == "no" || "$ans" == "n") then
	    cp /tmp/_hdat$$ /tmp/_hsdat$$
    	else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
	    NEWLINE
	        MSG "Answering 'yes' will sort the hosts file."
	    NEWLINE
	    goto net_sort_
    	else if ("$ans" == "quit" || "$ans" == "q") then
	    exit 0
        else 
	    echo "Huh? "
	    goto net_sort_
	endif

	# Finally, put together the hosts file.
	cat /tmp/_hhdr$$ /tmp/_hsdat$$ 	>& $tmp_host

	# Copy the header to the file
	if ($exec == yes) then
	    cp $tmp_host $ihosts
	else 
	    cat $tmp_host
	endif

	RM  $tmp_host /tmp/_hhdr$$ /tmp/_hdat$$ /tmp/_hsdat$$
    endif


    # Host should be added to the dev$hosts file, let's check to see that
    # it actually works...

    # See what NETSTATUS says about this setup.
net_check_:
    NEWLINE
    echo -n "Checking that iraf networking is properly enabled ...   "
    echo -n "	"
    set system = $iraf/bin.$mach/x_system.e
    setenv iraf $iraf/
    set errstat = 0
    if (-e $system) then
        set net = `$system netstatus | grep -i "interface disabled"`
        if ("$net" == "") then
            DO_OK
        else
            DO_FAIL ; set errstat = 1
            NEWLINE
                MSG "The NETSTATUS task claims that networking is disabled."
                MSG "Please contact http://iraf.net with questions or check"
	        MSG "the Site Manager's Guide for details on how to properly"
	        MSG "configure networking."
            NEWLINE
        endif
    else
        DO_FAIL ; set errstat = 1
        NEWLINE
            MSG  "The NETSTATUS task binary could not be executed or does not"
            MSG  "exist.  Please contact http://iraf.net with questions or"
	    MSG  "check the Site Manager's Guide for details on how to properly"
	    MSG  "configure networking."
        NEWLINE
    endif

net_restart_:
    if ($errstat == 1) then
        PROMPT "Would you like to return to networking setup? "
        set ans = "$<"
	if ("$ans" == "" || "$ans" == "y" || "$ans" == "yes") then
	    goto net_conf_
	else if ("$ans" == "n" || "$ans" == "no") then
	    ;  # fall through
	else if ("$ans" == "h" || "$ans" == "help" || "$ans" == "?") then
	  NEWLINE
	      MSG "Answering 'yes' will return you to the top of the networking"
	      MSG "configuration where you can make changes.  Answering 'no'"
	      MSG "will leave the current (unworking) configuration in place."
	  NEWLINE
	    goto net_restart_
	else if ("$ans" == "q" || "$ans" == "quit") then
	    exit 1
	else 
	    echo "Huh? "
	    goto net_restart_
	endif
    endif

else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
      NEWLINE
          MSG  'If you continue a recommended entry can be added to the'
	  MSG  'IRAF dev$hosts file, otherwise you will be asked if'
          MSG  "you wish to edit the file manually."
      NEWLINE
      goto net_conf_
else if ("$ans" == "q" || "$ans" == "quit") then
      exit 0
else if ("$ans" == "no" || "$ans" == "n") then
      NEWLINE
      goto end_net_
else
      echo "Huh?"
      goto net_conf_
endif

end_net_:
BOLD_ON
echo "------------------------------------------------------------------------"
BOLD_OFF

NEWLINE


#==============================================================================
#  Set up the default tapecap file for the machine.
#==============================================================================

# Skip the configuration if the system already has a default dev$tapecap
# file.  We only need to do this for e.g. PC-IRAF systems where we need
# to create a default based on the OS version.

if (! $do_tapecaps ) then
    goto skip_tape_
endif


NEWLINE
BOLD_ON
echo "                      Tapecap Device File Config"
echo "                      --------------------------"
BOLD_OFF
NEWLINE

echo '    By default IRAF will search for a dev$tapecap.<node> file (where'
echo "<node> is the system name) when looking for a tape configuration file."
echo "Platforms such as PC-IRAF and Sun/IRAF support multiple OS versions"
echo "and so the proper template file must be used.  This configuration will"
echo "allow you to setup a default tapecap for this system, it may be skipped"
echo "if this machine has no tape drive attached."
NEWLINE

tape_conf_:
PROMPT "Create a default tapecap file? "
set ans = "$<"
if ("$ans" == "" || "$ans" == "y") then

    # Figure out what the template should be.
    if ($pciraf == 1) then
	if ("$UNAME" == "linux") then
	    set tapefile = "tapecap.linux"
	else if ("$UNAME" == "sunos") then
	    set tapefile = "tapecap.solaris"
	else if ("$UNAME" == "freebsd") then
	    set tapefile = "tapecap.freebsd"
	endif
    else if ($suniraf == 1) then
        setenv OSVERSION `$uname_cmd -r | cut -c1`
	if ($OSVERSION == 5) then
	    set tapefile = "tapecap.solaris"
	else
	    set tapefile = "tapecap.sunos"
	endif
    else
	set tapefile = tapecap.$UNAME
    endif

    # Get the (possibly abbreviated) local host name.
    set lhost = `hostname | awk '{printf ("%16.16s\n", $1 ) }'`

    set file1 = $iraf/dev/tapecap.$lhost
    set file2 = $tapefile
    if (! -e $file1) then
tape_link1_:
        echo "Creating default file 'tapecap.$lhost' from $tapefile..."
        if ($exec == yes) then
	    chdir $iraf/dev
	    if (-e $file1) then
	        # Remove the link in case it exists but points to a file 
		# which doesn't.  
	        RM tapecap.$lhost >& /dev/null
	    endif
	    ln -s $tapefile tapecap.$lhost
        endif
    else
        if ("`$LS -l $file1 | grep $file2`" != "") then
            echo "Tapecap symlink 'tapecap.$lhost' exists and is ok."
        else
            echo "Tapecap symlink 'tapecap.$lhost' exists but is invalid...."
	    echo "Deleting invalid link...."
	    if ($exec == yes) then
		RM $file1 >& /dev/null
	    endif
	    goto tape_link1_
	endif
    endif


    # See if we want to make this the dev$tapecap default.
    NEWLINE ; NEWLINE
    echo '    In the event a dev$tapecap.<node> file is not found on this'
    echo 'system IRAF will fallback to use just dev$tapecap.  In cases where'
    echo 'the node name changes, this installation is shared with another'
    echo 'machine or in a local network, or any case where a tapecap.<node>'
    echo 'is not found, the dev$tapecap file will be the default tapecap used'
    echo "for all IRAF systems."
    echo ""


tape_def_:
    PROMPT 'Do you wish to create a default dev$tapecap link? '
    set ans = "$<"
    if ("$ans" == "" || "$ans" == "y") then

        set file1 = $iraf/dev/tapecap
	if (! -e $file1) then
tape_link2_:
            echo -n 'Creating default dev$tapecap link to dev$'
	    echo "$tapefile..."
	    if ($exec == yes) then
	        chdir $iraf/dev
		if (-e $file1) then
	            # Remove the link in case it exists but points to a file 
		    # which doesn't.  
		    RM  tapecap >& /dev/null
		endif
	        ln -s $tapefile tapecap
	    endif
	else
            if ("`$LS -l $file1 | grep $tapefile`" != "") then
                echo "Tapecap symlink 'tapecap' exists and is ok."
            else
                echo "Tapecap symlink 'tapecap' exists but is invalid...."
	        echo "Deleting invalid link...."
	        if ($exec == yes) then
		    RM $file1 >& /dev/null
	        endif
		goto tape_link2_
	    endif
	endif

    else if ("$ans" == "no" || "$ans" == "n") then
	;
    else if ("$ans" == "q" || "$ans" == "quit") then
	exit 0
    else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
	NEWLINE
	    MSG 'A dev$tapecap file is the fallback file used if there is no'
	    MSG "tapecap.<node> file found. If you continue a link will be made"
	    MSG "to the template file appropriate for this machine."
	NEWLINE
        goto tape_def_
    else
        echo "Huh?"
        goto tape_def_
    endif

else if ("$ans" == "q" || "$ans" == "quit") then
    exit 0
else if ("$ans" == "no" || "$ans" == "n") then
    NEWLINE
    goto end_tape_
else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
    NEWLINE
        MSG  "If you continue a default tapecap appropriate for this system"
	MSG  'will be created in the $iraf/dev directory'
    NEWLINE
    goto tape_conf_
else
    echo "Huh?"
    goto tape_conf_
endif

end_tape_:
BOLD_ON
echo "------------------------------------------------------------------------"
BOLD_OFF

NEWLINE
skip_tape_:



#==============================================================================
#  Delete the unused HSI binaries in the system to recover disk space.
#==============================================================================

if ($pciraf == 0 && $suniraf == 0) then
    goto skip_hsi_del_
endif


# Get the set of currently installed system binaries.
set archs = ""
foreach i ($iraf/bin.*)
  set dir = $i:t
  if ($dir:r == "bin") then
    set sz = `(chdir $i ; du -s | awk '{printf ("%d", $1)}')`
    if (`$LS -lL $i | wc -l` > 1) then
      if (-e "$i/cl.e" && -e "$i/x_system.e") then
        # Save the list of installed binaries, allow for changes between
        # the binary arch and HSI arch here (e.g. ssun->ssol).
        if ("$dir:e" == "ssun") then
            set archs = `echo $archs ssol`
        else
            set archs = `echo $archs $dir:e`
        endif
      endif
    endif
  endif
end



# Check for HSI bin directories.
set  delete_bin = ""
set  empty_bin  = ""
foreach i ($iraf_p/iraf/unix/bin.*)
  set dir = $i:t
  if ($dir:r == "bin") then
    set sz = `(chdir $i ; du -s | awk '{printf ("%d", $1)}')`
    if (`$LS -lL $i | wc -l` > 1) then
      set d = `$LS $LSDF $i/* | head -2 | tail -1`
      if ("`echo $archs | grep $dir:e`" == "") then
        set delete_bin = `echo $delete_bin $dir`
      endif
    else
        if ($sz > 8 && "`echo $archs | grep $dir:e`" == "") then
            set delete_bin = `echo $delete_bin $dir`
        endif
    endif
  else
    continue
  endif
end

# If there were no unused bin directories found then skip this section.
if ("$delete_bin" == "") then
    goto end_hsi_del_
endif



NEWLINE
BOLD_ON
echo "                     Delete Unneeded HSI Binaries"
echo "                     ----------------------------"
BOLD_OFF
NEWLINE

echo '    The following bin directories in the iraf$unix directories were'
echo "found to be unused on this machine:"
NEWLINE
set tot = 0
foreach i ($delete_bin)
    set p = `echo $iraf/unix/$i | sed -e 's://:/:g'`
    set sz = `du -s $p`
    set tot = `expr $tot + $sz[1]`
    echo $sz[1] $p | awk '{printf ("\t    (%5d Kb)\t%s\n", $1, $2)}'
end
set tot = `expr $tot / 1000`
NEWLINE
echo "The contents of these directories may be safely deleted to reclaim"
echo "about $tot Mb of disk space without affecting the IRAF runtime system."
NEWLINE


hsi_del_:
PROMPT "Do you wish to delete these unused HSI binaries? "
set ans = "$<"
if ("$ans" == "" || "$ans" == "y") then
    NEWLINE
    chdir $iraf/unix
    foreach i ($delete_bin)
        echo -n "Delete HSI binaries in $i ...				"
        if ($exec == yes) then
	    if (-e $i) then
	        rm -rf $i/*
		DO_OK
	    else
		DO_FAIL
		NEWLINE
		    MSG  "Hmm, I can't find '$i' in '$cwd', skipping..."
		NEWLINE
	    endif
	else
	    # No-op okay
	    DO_OK
        endif
    end
else if ("$ans" == "q" || "$ans" == "quit") then
    exit 0
else if ("$ans" == "no" || "$ans" == "n") then
    NEWLINE
    goto end_hsi_del_
else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
    NEWLINE
        MSG  "This system contains binaries needed for multi-architecture"
        MSG  "support, however you do not appear to need all of the binaries"
        MSG  "supplied.  Removing uneeded binaries can recover some disk"
        MSG  "space that could be used for data."
    NEWLINE
    goto hsi_del_
else
    echo "Huh?"
    goto hsi_del_
endif

end_hsi_del_:
BOLD_ON
echo "------------------------------------------------------------------------"
BOLD_OFF

NEWLINE
skip_hsi_del_:


#==============================================================================
#  Strip the system sources.
#==============================================================================

NEWLINE
BOLD_ON
echo "                       Strip IRAF System Sources"
echo "                       -------------------------"
BOLD_OFF
NEWLINE

echo "    Source code for all IRAF tasks and interfaces is included with this"
echo "installation, but is strictly only required if you plan to develop this"
echo "code.  The sources may be deleted from the system without affecting the"
echo "runtime environment (including help pages, compilation of external pack-"
echo "ages or local task development) allowing you to reclaim 50-60Mb of disk"
echo "space for the system.  Stripping sources is recommended for systems very"
echo "short on space, leaving it on the system will allow IRAF site support to"
echo "send code fixes and compilation instructions as needed to fix problems"
echo "which have no other workaround."
NEWLINE

strip_:
PROMPT_N "Do you wish to strip the system of sources? "
set ans = "$<"
if ("$ans" == "y" || "$ans" == "yes") then
    NEWLINE
    echo -n "Stripping core system sources ...				"
    if ($exec == yes) then
	cd $iraf
	$lbin/mkpkg strip
    endif
    DO_OK
    echo -n "Stripping NOAO package sources ...				"
    if ($exec == yes) then
	cd $iraf/noao
	$lbin/mkpkg -p noao strip
    endif
    DO_OK
else if ("$ans" == "q" || "$ans" == "quit") then
    exit 0
else if ("$ans" == "" || "$ans" == "no" || "$ans" == "n") then
    NEWLINE
    goto end_strip_
else if ("$ans" == "help" || "$ans" == "h" || "$ans" == "?") then
    NEWLINE
        MSG  "Stripping system sources can recover considerable amounts of"
        MSG  "disk space while leaving a full runtime system.  Sources should"
        MSG  "be stripp if there is insufficient room and you do not plan to"
        MSG  "do any development of the Core system or NOAO package."
    NEWLINE
    goto strip_
else
    echo "Huh?"
    goto strip_
endif

#BOLD_ON
#echo "------------------------------------------------------------------------"
#BOLD_OFF

end_strip_:
NEWLINE



#==============================================================================
#  Post-Install Verification
#==============================================================================

NEWLINE
BOLD_ON
echo "========================================================================"
echo "=====================  Post-Install Verification  ======================"
echo "========================================================================"
BOLD_OFF
NEWLINE


#==============================================================================
#  Check for available display servers on this system.
#==============================================================================

NEWLINE
BOLD_ON
echo "                     Display Server Availability"
echo "                     ---------------------------"
BOLD_OFF
NEWLINE

set  DISPLAY_SERVERS    = "ximtool ximtool-alt saoimage ds9 saotng"

echo "Display Servers Found on This Machine:"
NEWLINE

set found = 0
foreach i ($DISPLAY_SERVERS)
    set p = `which $i |& grep -i "^\/"`
    if ($status == 0) then
        set d = `$LS $LSDF $p | head -2 | tail -1`
        echo $d | awk '{printf ("  ( Date: %3s %2s %-5s )    ", $7, $8, $9) }'
        echo "    "`which $i`
        set found = 1
    endif
end
if ($found == 0) then
    BOLD_ON
    echo "          No Display Servers Found"
    BOLD_OFF
    NEWLINE
	MSG  "No display servers were found on this machine or in the user"
	MSG  "path.  A display server such as XImtool/SAOimage/SAOtng/DS9"
	MSG  "is required to be running on the local machine before an iraf"
	MSG  "display command (e.g. DISPLAY/TVMARK/IMEXAMINE) will work."
	MSG  ""
	MSG  "Remote displays (i.e. the server on one machine and IRAF on"
	MSG  "another) require either iraf networking be enabled or the X"
	MSG  "'DISPLAY' variable be set so the server appears on the remote"
	MSG  "machine."
	MSG  ""
	MSG  "    XImtool can be downloaded as part of X11IRAF from:"
	MSG  ""
	MSG  "        http://iraf.net/ftp/iraf/x11iraf"
	MSG  ""
	MSG  "or it's mirror sites."
	MSG  "    For information on DS9 please see"
	MSG  ""
	MSG  "         http://hea-www.harvard.edu/RD/ds9/"
	MSG  ""
	MSG  "Please contact http://iraf.net with questions."
endif
NEWLINE

BOLD_ON
echo "------------------------------------------------------------------------"
BOLD_OFF

end_servers_:



#==============================================================================
#  Check for available graphics terminals on this system.
#==============================================================================

NEWLINE
BOLD_ON
echo "                     Graphics Terminal Availability"
echo "                     ------------------------------"
BOLD_OFF
NEWLINE

set  GRAPHICS_TERMS     = "xgterm xterm"

echo "Graphics Terminals Found on This Machine:"
NEWLINE

set found = 0
foreach i ($GRAPHICS_TERMS)
    set p = `which $i |& grep "^\/"`
    if ($status == 0) then
        set d = `$LS $LSDF $p | head -2 | tail -1`
        echo $d | awk '{printf ("  ( Date: %3s %2s %-5s )    ", $7, $8, $9) }'
        echo "    "`which $i`
        set found = 1
    endif
end
if ($found == 0) then
    BOLD_ON
    echo "          No Suitable Graphics Terminals Found"
    BOLD_OFF
    NEWLINE
        MSG  "No 'xterm' or 'xgterm' binary was found on this systen or"
        MSG  "in the user path.  IRAF graphics require some form of "
        MSG  "graphics-enabled terminal window to be running or else"
        MSG  "garbarge characters will appear on the screen.  Windows"
        MSG  "such as 'cmdtool', 'rxvt', 'aixterm', 'hpterm', 'decterm'"
        MSG  "do not support graphics and should not be used for IRAF."
        MSG  ""
        MSG  "The default terminal type is set in the login.cl when"
        MSG  "a user runs MKIRAF, this is the type of window they should"
        MSG  "be running when starting IRAF.  Users can use the 'show"
        MSG  "terminal' command to see the current setting, or 'stty"
        MSG  "xterm' or 'stty xgterm' command (or rerun MKIRAF and reset"
        MSG  "the default terminal type) to change the default iraf terminal."
        MSG  ""
        MSG  "XGterm can be downloaded as part of X11IRAF from"
        MSG  ""
	MSG  "        http://iraf.net/ftp/iraf/x11iraf"
        MSG  ""
        MSG  "or it's mirror sites.  Xterm will normally be a part of the"
 	MSG  "system, if not found please check your path."
        MSG  ""
endif
NEWLINE

#BOLD_ON
#echo "------------------------------------------------------------------------"
#BOLD_OFF

end_terms_:



#=============================================================================
#  Finish up and set the exit status.
#=============================================================================
fini_:

NEWLINE ; NEWLINE
if ("$err_count" > 0) then
 BOLD_ON
 echo "========================================================================"
 echo "=================  Installation Completed With Errors  ================="
 echo "========================================================================"
 BOLD_OFF
 NEWLINE
 exit 1
else
 BOLD_ON
 echo "========================================================================"
 echo -n "Congratulations!  "
 BOLD_OFF
 echo "IRAF has been successfully installed on this system."
 BOLD_ON
 echo "========================================================================"
 BOLD_OFF
 NEWLINE
 echo "    To begin using the system simply log in as any user and from the"
 echo "directory you wish to use as your iraf login directory type:"
 echo ""
 echo -n '	    % ';
 BOLD_ON; echo -n 'mkiraf'; BOLD_OFF
 echo '	    # create a login.cl file'
 echo -n '	    % ';
 BOLD_ON; echo -n 'cl'; BOLD_OFF
 echo '	    # start IRAF'
 echo ""
 echo "The 'iraf' user is already configured with a login.cl file so a simple"
 echo "'cl' command is sufficient to start the system."
 NEWLINE
 echo "Additional information can be found at the IRAF.NET web site:"
 NEWLINE
 BOLD_ON ; echo "		    http://iraf.net" ; BOLD_OFF
 NEWLINE
 echo "Please contact http://iraf.net with any questions or problems."
 NEWLINE
 NEWLINE

 BOLD_ON
 echo "========================================================================"
 echo "================  Installation Completed With No Errors  ==============="
 echo "========================================================================"
 BOLD_OFF
 NEWLINE
 exit 0
endif

cleanup_:
  exit 0



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

Usage:
    echo "Usage:    install [-n] [-h] [-hl] [-f] [-r rootdir] [-i imdir]"
    echo "              [-b localbindir] [-R oldroot] [-I oldimdir]"
    echo "              [-u username ] [-l locallibdir]  [-m mach ]"
    echo "              [-noedit]"
    echo ""
    echo "    where -n          # no execute"
    echo "          -h          # print this help summary"
    echo "          +hl         # enable highlighted text"
    echo "          -hl         # disable highlighted text"
    echo "          -f          # create fifo pipes (if supported)"
    echo "          -r          # set iraf root directory"
    echo "          -c          # set cache directory"
    echo "          -i          # set imdir directory"
    echo "          -b          # set local bin directory"
    echo "          -l          # set local lib directory"
    echo "          -R          # set old iraf root directory"
    echo "          -I          # set old imdir directory"
    echo "          -u          # set username to own files"
    echo "          -m          # set machine type (ssun, linux, etc)"
    echo "          -noedit     # install but don't edit pathnames"
    exit 0