File: config.sh

package info (click to toggle)
xmcd 2.6-17sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,464 kB
  • ctags: 5,075
  • sloc: ansic: 51,322; sh: 4,039; makefile: 82; pascal: 67
file content (2508 lines) | stat: -rw-r--r-- 46,738 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
#
# @(#)config.sh	6.145 00/01/12
#
# Script to set up the device-dependent configuration files.
#
#    xmcd  - Motif(tm) CD Audio Player
#    cda   - Command-line CD Audio Player
#
#    Copyright (C) 1993-2000  Ti Kan
#    E-mail: ti@amb.org
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/local/bin:/usr/ucb
export PATH

VER=2.6

# Change the following directory to fit your local configuration
# WTA: BINDIR is only used for cddbcmd, so it's safe to change it
BINDIR=/usr/bin
LIBDIR=/usr/X11R6/lib/X11
XMCDLIB=/$LIBDIR/xmcd
CDDBDIR=/var/lib/cddb
DISCOGDIR=/var/lib/xmcd/discog

ERRFILE=`tempfile --prefix xmcd --mode 0600`
TMPFILE=`tempfile --prefix xmcd --mode 0600`
TMPSITES=`tempfile --prefix xmcd --mode 0600`

CFGDIR=/etc/xmcd
SCRDIR=$XMCDLIB/scripts
SITES=$CFGDIR/sites
TBLDIR=$XMCDLIB/tbl
OWNER=root
GROUP=audio
CDIRPERM=03775
DFLT_CGIPATH='/~cddb/cddb.cgi'
CDDBCATS="rock jazz blues newage classical reggae folk country soundtrack misc data"
BROWSERS="mozilla netscape Mosaic"

# Utility functions

do_exit()
{
	if [ $1 -eq 0 ]
	then
		$ECHO "\nXmcd set-up is now complete.\n"
		$ECHO "Please read the README file supplied with the xmcd"
		$ECHO "distribution for hardware configuration information"
		$ECHO "about specific drives.\n"
	else
		$ECHO "\nErrors have occurred configuring xmcd."
		if [ $ERRFILE != /dev/null ]
		then
			$ECHO "See $ERRFILE for an error log."
		fi
	fi
	exit $1
}

log_err()
{
	if [ "$1" = "-p" ]
	then
		$ECHO "Error: $2" >&2
	fi
	$ECHO "$2" >>$ERRFILE
}

get_str()
{
	$ECHO "$* \c"
	read ANS
	if [ -n "$ANS" ]
	then
		return 0
	else
		return 1
	fi
}

get_yn()
{
	if [ -z "$YNDEF" ]
	then
		YNDEF=y
	fi

	while :
	do
		$ECHO "$*? [${YNDEF}] \c"
		read ANS
		if [ -n "$ANS" ]
		then
			case $ANS in
			[yY])
				RET=0
				break
				;;
			[nN])
				RET=1
				break
				;;
			*)
				$ECHO "Please answer y or n"
				;;
			esac
		else
			if [ $YNDEF = y ]
			then
				RET=0
			else
				RET=1
			fi
			break
		fi
	done

	YNDEF=
	return $RET
}


do_link()
{
	source=$1
	target=$2

	# Try symlink first
	ln -s $source $target 2>/dev/null
	if [ $? -ne 0 ]
	then
		# Use hard link
		ln $source $target 2>/dev/null
	fi
	RETSTAT=$?
	if [ $RETSTAT -ne 0 ]
	then
		log_err -p "Cannot link $source -> $target"
	fi
	return $RETSTAT
}


do_chown()
{
	if [ $2 != _default_ ]
	then
		chown $1 $2 2>/dev/null
	fi
}


do_chgrp()
{
	if [ $2 != _default_ ]
	then
		chgrp $1 $2 2>/dev/null
	fi
}


do_chmod()
{
	if [ $2 != _default_ ]
	then
		chmod $1 $2 2>/dev/null
	fi
}


make_dir()
{
	dir=$1
	perm=$2
	owner=$3
	group=$4
	$ECHO "\t$dir"
	if [ ! -d $dir ]
	then
		mkdir -p $dir
	fi
	do_chown $owner $dir 2>/dev/null
	do_chgrp $group $dir 2>/dev/null
	do_chmod $perm $dir 2>/dev/null
	return 0
}


ask_scsi_config()
{
	$ECHO "\n  Since you have an unlisted drive, I will assume"
	$ECHO "  that it is SCSI-2 compliant.  If this is not true then"
	$ECHO "  xmcd will probably not work."

	YNDEF=n
	if get_yn "\n  Do you want to continue"
	then
		METHOD=1
		VENDOR=0
		VOLBASE=0
		VOLTAPER=0
		PLAYNOTUR=False
	else
		return 1
	fi

	$ECHO "\n  You will now be asked several technical questions about"
	$ECHO "  your drive.  If you don't know the answer, try accepting"
	$ECHO "  the default values, and if problems occur when using"
	$ECHO "  xmcd, reconfigure the settings by running this script"
	$ECHO "  again, or editing the $CFGDIR/$CONFIGFILE"
	$ECHO "  file."
	$ECHO "\n  If you get an unlisted drive working with xmcd in this"
	$ECHO "  manner, the author of xmcd would like to hear from you"
	$ECHO "  and incorporate the settings into the next xmcd release."
	$ECHO "  Please send e-mail to \"xmcd@amb.org\"."

	while :
	do
	    YNDEF=n
	    if get_yn "\n  Is your drive on $XMCD_DEV a multi-disc changer"
	    then
		$ECHO "\n  Select one of the following changer methods:\n"
		$ECHO "  1.\tSCSI LUN addressing method"
		$ECHO "  2.\tSCSI medium changer method"
		$ECHO "  3.\tother"
		$ECHO "  q.\tquit (abort configuration)"

		while :
		do
		    if get_str "\n  Enter choice: [1]"
		    then
			case "$ANS" in
			[1-3])
			    break
			    ;;
			q)
			    return 1
			    ;;
			*)
			    $ECHO "  Please answer 1 to 3."
			    ;;
			esac
		    else
			ANS=1
			break
		    fi
		done	

		if [ "$ANS" -eq 3 ]
		then
		    #
		    # Unsupported changer method: just treat it
		    # as a single-disc drive
		    #
		    $ECHO "\n  Your drive will be treated as a single-disc unit."
		    CHGMETHOD=0
		    NUMDISCS=1
		    MULTIPLAY=0
		else
		    CHGMETHOD="$ANS"
		    while :
		    do
			if get_str \
			    "\n  How many discs does the drive support?:"
			then
			    case "$ANS" in
			    [1-9]*)
				NUMDISCS="$ANS"
				break
				;;
			    *)
				$ECHO "  Invalid input.  Try again."
				;;
			    esac
			else
			    $ECHO "  Invalid input.  Try again."
			fi
		    done

		    if [ "$NUMDISCS" -gt 1 ]
		    then
			MULTIPLAY=True
		    else
			CHGMETHOD=0
			MULTIPLAY=False
		    fi
		fi
	    else
		CHGMETHOD=0
		NUMDISCS=1
		MULTIPLAY=False
	    fi

	    $ECHO "\n  Does your drive on $XMCD_DEV support the following:\n"

	    YNDEF=y
	    if get_yn "  - The Play_Audio_MSF SCSI command"
	    then
		    PLAYMSF=True
	    else
		    PLAYMSF=False
	    fi

	    YNDEF=n
	    if get_yn "  - The Play_Audio(12) SCSI command"
	    then
		    PLAY12=True
	    else
		    PLAY12=False
	    fi

	    YNDEF=y
	    if get_yn "  - The Play_Audio(10) SCSI command"
	    then
		    PLAY10=True
	    else
		    PLAY10=False
	    fi

	    YNDEF=y
	    if get_yn "  - The Play_Audio_Track/Index command"
	    then
		    PLAYTI=True
	    else
		    PLAYTI=False
	    fi

	    YNDEF=n
	    if get_yn "  - Caddy load via the Start_Stop_Unit SCSI command"
	    then
		    LOAD=True
	    else
		    LOAD=False
	    fi

	    YNDEF=y
	    if get_yn "  - Caddy eject via the Start_Stop_Unit SCSI command"
	    then
		    EJECT=True
	    else
		    EJECT=False
	    fi

	    YNDEF=y
	    if get_yn \
		"  - Disable block descriptor in the Mode_Sense SCSI command"
	    then
		    MODEDBD=True
	    else
		    MODEDBD=False
	    fi

	    YNDEF=y
	    if get_yn \
		"  - Audio volume control via the Mode_Select SCSI command"
	    then
		    YNDEF=y
		    if get_yn \
		    "  - Independent SCSI Mode_Select volume control for each channel"
		    then
			    VOLSUPP=True
			    BALSUPP=True
		    else
			    VOLSUPP=True
			    BALSUPP=False
		    fi

		    YNDEF=y
		    if get_yn "  - Audio channel routing via SCSI Mode_Select"
		    then
			    CHRSUPP=True
		    else
			    CHRSUPP=False
		    fi
	    else
		    VOLCTL=0
		    VOLSUPP=False
		    BALSUPP=False
		    CHRSUPP=False
	    fi

	    YNDEF=y
	    if get_yn "  - The Pause/Resume SCSI command"
	    then
		    PAUSE=True
	    else
		    PAUSE=False
	    fi

	    YNDEF=y
	    if get_yn "  - The Prevent/Allow_Medium_Removal SCSI command"
	    then
		    CADDYLOCK=True
	    else
		    CADDYLOCK=False
	    fi

	    YNDEF=n
	    if get_yn "  - Data Format 1 of the Read_Subchannel SCSI command"
	    then
		    CURPOSFMT=True
	    else
		    CURPOSFMT=False
	    fi

	    if [ "$PAUSE" = True ]
	    then
		YNDEF=n
		if get_yn \
		"\n  Does the drive require strict pause/resume symmetry"
		then
			STRICTPAUSERESUME=True
		else
			STRICTPAUSERESUME=False
		fi

		YNDEF=n
		if get_yn \
		"\n  Does the drive require a pause before reissuing play"
		then
			PLAYPAUSEPLAY=True
		else
			PLAYPAUSEPLAY=False
		fi
	    else
		    STRICTPAUSERESUME=False
		    PLAYPAUSEPLAY=False
	    fi

	    $ECHO "\n  This is the configuration for ${XMCD_DEV}:\n"
	    $ECHO "  logicalDriverNumber:   $DRVNO"
	    $ECHO "  mediumChangeMethod:    $CHGMETHOD"
	    $ECHO "  numDiscs:              $NUMDISCS"
	    $ECHO "  playAudio12Support:    $PLAY12"
	    $ECHO "  playAudioMSFSupport:   $PLAYMSF"
	    $ECHO "  playAudio10Support:    $PLAY10"
	    $ECHO "  playAudioTISupport:    $PLAYTI"
	    $ECHO "  loadSupport:           $LOAD"
	    $ECHO "  ejectSupport:          $EJECT"
	    $ECHO "  modeSenseSetDBD:       $MODEDBD"
	    $ECHO "  volumeControlSupport:  $VOLSUPP"
	    $ECHO "  balanceControlSupport: $BALSUPP"
	    $ECHO "  pauseResumeSupport:    $PAUSE"
	    $ECHO "  strictPauseResume:     $STRICTPAUSERESUME"
	    $ECHO "  playPausePlay:         $PLAYPAUSEPLAY"
	    $ECHO "  caddyLockSupport:      $CADDYLOCK"
	    $ECHO "  curposFormat:          $CURPOSFMT"
	    $ECHO "  multiPlay:             $MULTIPLAY"

	    YNDEF=y
	    if get_yn "\n  Is this acceptable"
	    then
		    break
	    fi

	    $ECHO "  Try again..."
	done

	return 0
}


ask_nonscsi_config()
{
	$ECHO "\n  Non-SCSI drives are currently supported only on the BSDI,"
	$ECHO "  Digital UNIX, FreeBSD, HP-UX, IBM AIX, Linux, NetBSD,"
	$ECHO "  OpenBSD, QNX, SCO Open Server and Sun Solaris platforms."
	$ECHO "  You must have the appropriate CD-ROM driver configured in"
	$ECHO "  your kernel.  QNX users must use the QNX ioctl method,"
	$ECHO "  even for SCSI drives."

	YNDEF=y
	get_yn "\n  Do you want to continue"
	if [ $? -ne 0 ]
	then
		return 1
	fi

	# WTA: disable the ioctl-selection code: since Debian is a Linux
	# distribution, we already know the answer.
	IOCMETHOD="1"

	if [ -z "$NUMDISCS" ]
	then
		YNDEF=n
		if get_yn "\n  Is your drive on $XMCD_DEV a multi-disc changer"
		then
			while :
			do
				if get_str \
				"\n  How many discs does the drive support?:"
				then
				    case "$ANS" in
				    [1-9]*)
					NUMDISCS="$ANS"
					break
					;;
				    *)
					$ECHO "  Invalid input.  Try again."
					;;
				    esac
				else
				    $ECHO "  Invalid input.  Try again."
				fi
			done

			if [ "$NUMDISCS" -gt 1 ]
			then
				CHGMETHOD=3
				MULTIPLAY=True
			else
				CHGMETHOD=0
				MULTIPLAY=False
			fi
		else
			CHGMETHOD=0
			NUMDISCS=1
			MULTIPLAY=False
		fi
	fi

	# Set the rest of the parameters
	case "$IOCMETHOD" in
	1)	# SunOS/Solaris/Linux/QNX ioctl method
		METHOD=1
		VENDOR=0
		VOLBASE=0
		VOLTAPER=0
		PLAYMSF=True
		PLAY12=False
		PLAY10=False
		PLAYTI=True
		LOAD=True
		EJECT=True
		MODEDBD=False
		VOLSUPP=True
		BALSUPP=True
		CHRSUPP=False
		VOLCTL=3
		PAUSE=True
		STRICTPAUSERESUME=False
		PLAYPAUSEPLAY=False
		CADDYLOCK=False
		CURPOSFMT=False
		PLAYNOTUR=False
		;;
	2)	# FreeBSD/NetBSD ioctl method
		METHOD=2
		VENDOR=0
		VOLBASE=0
		VOLTAPER=0
		PLAYMSF=True
		PLAY12=False
		PLAY10=False
		PLAYTI=True
		LOAD=True
		EJECT=True
		MODEDBD=False
		VOLSUPP=True
		BALSUPP=True
		CHRSUPP=False
		VOLCTL=3
		PAUSE=True
		STRICTPAUSERESUME=False
		PLAYPAUSEPLAY=False
		CADDYLOCK=True
		CURPOSFMT=False
		PLAYNOTUR=False
		;;
	3)	# IBM AIX IDE ioctl method
		METHOD=3
		VENDOR=0
		VOLBASE=0
		VOLTAPER=0
		PLAYMSF=True
		PLAY12=False
		PLAY10=False
		PLAYTI=True
		LOAD=False
		EJECT=True
		MODEDBD=False
		VOLSUPP=True
		BALSUPP=True
		CHRSUPP=False
		VOLCTL=3
		PAUSE=True
		STRICTPAUSERESUME=False
		PLAYPAUSEPLAY=False
		CADDYLOCK=True
		CURPOSFMT=False
		PLAYNOTUR=False
		;;
	4)	# BSDI BSD/OS ATAPI (SCSI emulation)
		# Set up as a "generic" SCSI-2 drive
		METHOD=0
		VENDOR=0
		VOLBASE=0
		VOLTAPER=0
		PLAYMSF=True
		PLAY12=False
		PLAY10=False
		PLAYTI=True
		LOAD=True
		EJECT=True
		MODEDBD=False
		VOLSUPP=False
		BALSUPP=False
		CHRSUPP=False
		VOLCTL=0
		PAUSE=True
		STRICTPAUSERESUME=False
		PLAYPAUSEPLAY=False
		CADDYLOCK=False
		CURPOSFMT=True
		PLAYNOTUR=False
		CHGMETHOD=0
		NUMDISCS=1
		MULTIPLAY=False
		;;
	5)	# SCO Open Server ATAPI BTLD (SCSI emulation)
		# Set up as a "generic" SCSI-2 drive
		METHOD=0
		VENDOR=0
		VOLBASE=0
		VOLTAPER=0
		PLAYMSF=True
		PLAY12=False
		PLAY10=False
		PLAYTI=True
		LOAD=True
		EJECT=True
		MODEDBD=False
		VOLSUPP=True
		BALSUPP=True
		CHRSUPP=False
		VOLCTL=3
		PAUSE=True
		STRICTPAUSERESUME=False
		PLAYPAUSEPLAY=False
		CADDYLOCK=False
		CURPOSFMT=False
		PLAYNOTUR=False
		CHGMETHOD=0
		NUMDISCS=1
		MULTIPLAY=False
		;;
	6)	# Compaq Tru64 UNIX / Digital UNIX ATAPI (SCSI emulation)
		# Set up as a "generic" SCSI-2 drive
		METHOD=0
		VENDOR=0
		VOLBASE=0
		VOLTAPER=0
		PLAYMSF=True
		PLAY12=False
		PLAY10=False
		PLAYTI=True
		LOAD=True
		EJECT=True
		MODEDBD=False
		VOLSUPP=True
		BALSUPP=True
		CHRSUPP=True
		VOLCTL=7
		PAUSE=True
		STRICTPAUSERESUME=False
		PLAYPAUSEPLAY=False
		CADDYLOCK=True
		CURPOSFMT=True
		PLAYNOTUR=False
		CHGMETHOD=0
		NUMDISCS=1
		MULTIPLAY=False
		;;
	7)	# HP-UX ATAPI (SCSI emulation)
		# Set up as a "generic" SCSI-2 drive
		METHOD=0
		VENDOR=0
		VOLBASE=0
		VOLTAPER=0
		PLAYMSF=True
		PLAY12=False
		PLAY10=False
		PLAYTI=True
		LOAD=True
		EJECT=True
		MODEDBD=False
		VOLSUPP=True
		BALSUPP=True
		CHRSUPP=True
		VOLCTL=7
		PAUSE=True
		STRICTPAUSERESUME=False
		PLAYPAUSEPLAY=False
		CADDYLOCK=True
		CURPOSFMT=True
		PLAYNOTUR=False
		CHGMETHOD=0
		NUMDISCS=1
		MULTIPLAY=False
		;;
	*)	# Should not get here
		$ECHO "  Error: unsupported ioctl method."
		return 1
		;;
	esac

	return 0
}


config_drive()
{
	if [ "$OS_SYS" = QNX ]
	then
		ask_nonscsi_config
		return $?
	fi

	eval `\
	(
		$ECHO "ENTRIES=\""
		cd $TBLDIR
		for i in *
		do
			if [ -f $i ]
			then
				if fgrep tblver=4 $TBLDIR/$i \
			   		>/dev/null 2>&1
				then
					$ECHO "$i \c"
				else
					log_err -p \
					"$TBLDIR/$i version mismatch"
				fi
			fi
		done
		$ECHO "\""
	)`

	j=1
	>$TMPFILE
	if [ -n "$ENTRIES" ]
	then
		for i in $ENTRIES
		do
			brand=`fgrep tblalias= $TBLDIR/$i 2>/dev/null | \
				sed 's/^.*tblalias=//'`
			if [ -z "$brand" ]
			then
				brand=$i
			fi
			$ECHO "  $j.\t$brand" >>$TMPFILE
			j=`expr $j + 1`
		done
	fi
	$ECHO "  $j.\tother (SCSI)" >>$TMPFILE
	j=`expr $j + 1`
	$ECHO "  $j.\tother (non-SCSI)" >>$TMPFILE
	$ECHO "  q.\tquit (abort configuration)" >>$TMPFILE

	$ECHO "\n  Device ($XMCD_DEV) configuration"
	$ECHO "  Please select the drive brand:\n"

	PGLEN=`wc -l $TMPFILE | $AWK '{ print $1 + 1 }'`
	if [ $PGLEN -gt 18 ]
	then
		PGLEN=`expr $PGLEN / 2`
		pr -t -2 -w78 -l$PGLEN $TMPFILE
	else
		cat $TMPFILE
	fi

	rm -f $TMPFILE

#	while :
#	do
		if ! get_str "\n  Enter choice [$j]:"
		then
		  ANS=$j
		fi
			if [ "$ANS" = q ]
			then
				return 1
			elif [ "$ANS" -lt 1 -o "$ANS" -gt $j ]
			then
				$ECHO "  Please answer 1 to $j."
			elif [ "$ANS" = "`expr $j - 1`" ]
			then
				ask_scsi_config
				return $?
			elif [ "$ANS" = "$j" ]
			then
				ask_nonscsi_config
				return $?
			else
				k=1
				for i in $ENTRIES
				do
					if [ $k = $ANS ]
					then
						model_sel $i $TBLDIR/$i
						return $?
					fi
					k=`expr $k + 1`
				done

				# Should not get here.
				return 1
			fi
#	done

	# Should not get here.
	return 1
}


model_sel()
{
	BRAND=$1
	CFGFILE=$2

	$ECHO "\n  Device ($XMCD_DEV) configuration"
	$ECHO "  Please select the $BRAND drive model:\n"

	$AWK -F: '
	BEGIN {
		n = 1
	}
	!/^#/ {
		if ($2 == 0) {
			if ($3 == 1)
				mode = "OS driver ioctl"
			else
				mode = "other"
		}
		else if ($2 == 1)
			mode = "SCSI-1"
		else if ($2 >= 2)
			mode = "SCSI-2"

		printf("  %d.\t%-12s%s\n", n, $1, mode)
		n++
	}
	END {
		printf("  %d.\t%-12s%s\n", n, "other", "SCSI")
		printf("  %d.\t%-12s%s\n", n+1, "other", "non-SCSI")
		printf("  q.\tquit (abort configuration)\n")
	}
	' $CFGFILE >$TMPFILE


	PGLEN=`wc -l $TMPFILE | $AWK '{ print $1 + 1 }'`
	if [ $PGLEN -gt 18 ]
	then
		$ECHO "\tModel       Mode\c"
		$ECHO "                       Model       Mode\n"
		PGLEN=`expr $PGLEN / 2`
		pr -t -2 -w78 -l$PGLEN $TMPFILE
	else
		$ECHO "\tModel       Mode\n"
		cat $TMPFILE
	fi

	rm -f $TMPFILE

	while :
	do
		if get_str "\n  Enter choice:"
		then
			j=`grep -v "^#" $CFGFILE | wc -l | sed 's/^[ 	]*//'`
			j=`expr $j + 2`

			if [ "$ANS" = q ]
			then
				return 1
			elif [ "$ANS" -lt 1 -o "$ANS" -gt $j ]
			then
				$ECHO "  Please answer 1 to $j."
			elif [ "$ANS" = "`expr $j - 1`" ]
			then
				ask_scsi_config
				return $?
			elif [ "$ANS" = "$j" ]
			then
				ask_nonscsi_config
				return $?
			else
				read_config $CFGFILE $ANS
				if [ "$METHOD" != 0 ]
				then
					ask_nonscsi_config
				fi
				return $?
			fi
		else
			$ECHO "  Please answer 1 to $j."
		fi
	done

	# Should not get here.
	return 1
}


read_config()
{
	eval `$AWK -F: '
	BEGIN {
		n = 1
	}
	!/^#/ {
		if (n == sel) {
			if ($2 > 0) {
				print "METHOD=1"
				printf("VENDOR=%d\n", $3)
			}
			else {
				printf("METHOD=%d\n", $3)
				print "VENDOR=0"
			}

			if ($4 == 0)
				print "PLAYMSF=False"
			else
				print "PLAYMSF=True"
			if ($5 == 0)
				print "PLAY12=False"
			else
				print "PLAY12=True"
			if ($6 == 0)
				print "PLAY10=False"
			else
				print "PLAY10=True"
			if ($7 == 0)
				print "PLAYTI=False"
			else
				print "PLAYTI=True"
			if ($8 == 0)
				print "LOAD=False"
			else
				print "LOAD=True"
			if ($9 == 0)
				print "EJECT=False"
			else
				print "EJECT=True"
			if ($10 == 0)
				print "MODEDBD=False"
			else
				print "MODEDBD=True"

			printf("VOLCTL=%d\n", $11)
			printf("VOLBASE=%d\n", $12)
			printf("VOLTAPER=%d\n", $13)

			if ($14 == 0)
				print "PAUSE=False"
			else
				print "PAUSE=True"
			if ($15 == 0)
				print "STRICTPAUSERESUME=False"
			else
				print "STRICTPAUSERESUME=True"
			if ($16 == 0)
				print "PLAYPAUSEPLAY=False"
			else
				print "PLAYPAUSEPLAY=True"
			if ($17 == 0)
				print "CADDYLOCK=False"
			else
				print "CADDYLOCK=True"
			if ($18 == 0)
				print "CURPOSFMT=False"
			else
				print "CURPOSFMT=True"
			if ($19 == 0)
				print "PLAYNOTUR=False"
			else
				print "PLAYNOTUR=True"

			printf("CHGMETHOD=%d\n", $20)
			printf("NUMDISCS=%d\n", $21)
			if ($18 == 0)
				print "MULTIPLAY=False"
			else
				print "MULTIPLAY=True"
		}
		n++
	}
	' sel=$2 $1`

	return $?
}


get_protocol()
{
	$ECHO "\nYou should choose HTTP if your system is behind a"
	$ECHO "firewall that only allows web access to the Internet."
	$ECHO "Otherwise, choose CDDBP.  There are more public CDDB"
	$ECHO "servers supporting CDDBP than HTTP."
	while :
	do
		$ECHO "\n  Protocol Selection\n"
		$ECHO "  1.\tCDDBP (CD Database Protocol)"
		$ECHO "  2.\tHTTP  (Hyper-Text Transport Protocol)"
		$ECHO "  q.\tquit (abort configuration)"

		if get_str "\n  Enter Choice: [1]"
		then
			case "$ANS" in
			1)
				PROTOCOL=cddbp
				break
				;;
			2)
				PROTOCOL=http
				break
				;;
			q)
				$ECHO "\nConfiguration aborted." >&2
				log_err -n "Configuration aborted by user"
				do_exit 3
				;;
			*)
				$ECHO "\nInvalid selection.  Try again."
				;;
			esac
		else
			PROTOCOL=cddbp
			return
		fi
	done
}


get_proxy()
{
	YNDEF=n
	get_yn "\n  Do you want to use a proxy server"
	if [ $? -ne 0 ]
	then
		USEPROXY=False
		PROXYSERVER="yourproxyhost:80"
		return
	fi

	USEPROXY=True
	while :
	do
		if get_str "  Enter the proxy server host name or IP number:"
		then
			if ($ECHO "$ANS" | grep "[ 	]") >/dev/null 2>&1
			then
				$ECHO "  Invalid input.  Try again."
				continue
			else
				PROXYSERVER="$ANS"
			fi

			if get_str "  Enter the proxy server port number: [80]"
			then
				PROXYSERVER="${PROXYSERVER}:${ANS}"
			fi

			break
		else
			$ECHO "  Invalid input.  Try again."
		fi
	done
}


get_useserver()
{
	$ECHO "\nThis configuration procedure can connect to the central"
	$ECHO "CD database server to retrieve the latest list of categories"
	$ECHO "and public server sites.  A built-in list can also be used"
	$ECHO "that is correct at the time this version of xmcd is released."

	USESERVER=0
	while :
	do
		$ECHO "\n  CDDB Information\n"
		$ECHO "  1.\tConnect to CDDB server and get current list"
		$ECHO "  2.\tUse built-in list"
		$ECHO "  q.\tquit (abort configuration)\n"

		get_str "  Enter choice: [1]"
		if [ $? -ne 0 ]
		then
			ANS=1
		fi

		case "$ANS" in
		1)
			if [ -x $BINDIR/cddbcmd ]
			then
				return 0
			else
				$ECHO "\nCannot find the cddbcmd(1) utility."
				$ECHO "This is needed to connect to the server."
			fi
			;;
		2)
			return 1
			;;
		q)
			$ECHO "\nConfiguration aborted." >&2
			do_exit 3
			;;
		*)
			$ECHO "\nInvalid input.  Please try again."
			;;
		esac
	done
	return 1
}


get_host()
{
	if get_str "    Server host name or IP number:"
	then
		HOST="$ANS"
		return 0
	else
		$ECHO "    No host specified."
		return 1
	fi
}


get_port()
{
	if [ "$PROTOCOL" = http ]
	then
		DFLT_PORT=80
	else
		DFLT_PORT=888
	fi

	if get_str "    TCP port number: [$DFLT_PORT]"
	then
		PORT="$ANS"
	else
		PORT=$DFLT_PORT
	fi
}


get_cgipath()
{
	if get_str "    Enter CGI path: [$DFLT_CGIPATH]"
	then
		CGIPATH="$ANS"
	else
		CGIPATH="$DFLT_CGIPATH"
	fi
}


print_servers()
{
	$ECHO "\n  CDDB server sites selection"
	$ECHO "  Number of CDDB servers selected so far: $1"
	$ECHO "\n\tServer host               Proto Port   Location\n"
	$AWK '
	BEGIN	{
		n = 1
	}
	{
		printf("  %d.\t%-25s %-5s %-6s ", n, $1, $2, $3)
		for (i = 7; i <= NF; i++)
			printf("%s ", $i);
		printf("\n")
		n++;
	}
	END	{
		printf("  %d.\tother site not listed\n", n++)
		printf("  ?.\tshow this list again\n")
		printf("  q.\tquit (abort configuration)\n")
		printf("  c.\tdone adding servers\n\n")
	}
	' $TMPFILE
}


set_server_entry()
{
	if [ ! $1 -eq 0 ]
	then
		eval `\
		(
			$AWK '
			BEGIN	{
				n = 1
			}
			{
				if (n == i) {
					printf("HOST=%s\n", $1)
					printf("PORT=%s\n", $3)
					printf("CGIPATH=%s\n", $4)
				}
				n++;
			}
			' i=$1 $TMPFILE
		)`
	fi

	if [ -z "$HOST" -o -z "$PORT" ]
	then
		log_err -p "Internal error: undefined HOST or PORT!"
		do_exit 1
	fi

	case "$PROTOCOL" in
	cddbp)
		if [ $PORT -eq 888 ]
		then
			ENTRY="cddbp://${HOST}"
		else
			ENTRY="cddbp://${HOST}:${PORT}"
		fi
		;;
	http)
		if [ $PORT -eq 80 ]
		then
			ENTRY="http://${HOST}${CGIPATH}"
		else
			ENTRY="http://${HOST}:${PORT}${CGIPATH}"
		fi
		;;
	*)
		return
		;;
	esac

	CDDBPATH="$CDDBPATH;$ENTRY"
	$ECHO "    Added \"$ENTRY\" to cddbPath."
}


prompt_server()
{
	get_host
	if [ $? -ne 0 ]
	then
		return 1
	fi

	get_port

	if [ "$PROTOCOL" = http ]
	then
		get_cgipath
	fi

	set_server_entry 0
	return 0
}


sel_servers()
{
	$AWK '
	/^#/ || /^$/ { next }
	{ if ($2 == protocol) print }
	' protocol="$PROTOCOL" $SITES >$TMPFILE

	NUMSERVERS=`wc -l $TMPFILE | $AWK '{ print $1 }'`
	USRSPEC=`expr $NUMSERVERS + 1`

	$ECHO "\nYou may configure more than one server site.  Choose the"
	$ECHO "servers closest to you.  Enter the selections one at a time."
	$ECHO "Type 'c' when done."

	cnt=0
	print_servers $cnt
	while :
	do
		if get_str "  Enter CDDB server selection:"
		then
			case "$ANS" in
			[0-9]*)
			    if [ "$ANS" -lt 1 -o "$ANS" -gt $NUMSERVERS ]
			    then
				if [ "$ANS" -eq $USRSPEC ]
				then
				    if prompt_server
				    then
					cnt=`expr $cnt + 1`
				    fi
				else
				    $ECHO "\nInvalid selection.  Try again."
				fi
			    else
				set_server_entry $ANS
				cnt=`expr $cnt + 1`
			    fi
			    ;;
			'?')
			    print_servers $cnt
			    ;;
			c)
			    $ECHO "\nTotal CDDB servers configured: $cnt"
			    break
			    ;;
			q)
			    $ECHO "\nConfiguration aborted." >&2
			    log_err -n "Configuration aborted by user"
			    do_exit 3
			    ;;
			*)
			    $ECHO "  Please enter 1-${USRSPEC}, c, ? or q."
			    ;;
			esac
		else
			$ECHO "  Please enter 1-${USRSPEC}, c, ? or q."
		fi
	done
	rm -f $TMPSITES $TMPFILE
}


check_local_cddb()
{
	$ECHO "\nChecking local CD database...\n"
	if [ -z "$CDDBCATS" ]
	then
		$ECHO "\nNo CD database categories defined!"
		return
	fi

	if [ -n "$CDDBDIR" ]
	then
		for i in $CDDBCATS
		do
			make_dir $CDDBDIR/$i $CDIRPERM $OWNER $GROUP
		done
		for i in $CDDBCATS
		do
			make_dir $DISCOGDIR/$i $CDIRPERM $OWNER $GROUP
		done
		if [ -x $XMCDLIB/scripts/genidx ]
		then
			$XMCDLIB/scripts/genidx
		fi
	else
		$ECHO "\nA local CD database directory was not defined."
	fi
}


cddb_config()
{
	# Set up default cddbPath
	cnt=0
	for i in $CDDBCATS
	do
		if [ $cnt -eq 0 ]
		then
			CDDBPATH="$i"
		else
			CDDBPATH="${CDDBPATH};$i"
		fi
		cnt=`expr $cnt + 1`
	done

	$ECHO "\nIf your system has Internet connectivity and functional"
	$ECHO "domain name service (DNS), you should answer 'y' to the next"
	$ECHO "question.  If you have a dial-up Internet connection that"
	$ECHO "needs to be manually started, you should start up the link"
	$ECHO "now before you continue with this configuration procedure."
	$ECHO "If this system is not linked to the Internet, then answer 'n'."

	YNDEF=y
	get_yn "\n  Would you like to use Internet CD database servers"
	if [ $? -ne 0 ]
	then
		$ECHO "\nNo Internet CD database servers are configured."

		# Check and set up local CDDB directories
		check_local_cddb
		return
	fi

	# Get which protocol to use
	get_protocol
	if [ "$PROTOCOL" = http ]
	then
		get_proxy
	fi

	# Get current CDDB categories and servers list
	if get_useserver
	then
	    $ECHO "\nConnecting to the central CDDB server."

	    OPTS=""
	    if [ "$PROTOCOL" = http ]
	    then
		OPTS="$OPTS -m http"
		if [ $USEPROXY = True ]
		then
		    OPTS="$OPTS -p $PROXYSERVER"
		fi
	    fi

	    # Categories
	    $ECHO "Getting CDDB categories... \c"
	    cnt=0
	    while [ $cnt -lt 5 ]
	    do
		CATS=`$BINDIR/cddbcmd $OPTS cddb lscat 2>/dev/null`
		stat=$?
		if [ $stat -eq 0 ]
		then
		    break
		fi
		sleep 5
		$ECHO "retrying \c"
		cnt=`expr $cnt + 1`
	    done
	    if [ $stat -ne 0 -o -z "$CATS" ]
	    then
		$ECHO "Failed"
		$ECHO "Cannot obtain CDDB categories list from central server."
		$ECHO "Using built-in list."
	    else
		$ECHO "Success"
		CDDBCATS="$CATS"

		# Set up cddbPath
		cnt=0
		for i in $CDDBCATS
		do
		    if [ $cnt -eq 0 ]
		    then
			CDDBPATH="$i"
		    else
			CDDBPATH="${CDDBPATH};$i"
		    fi
		    cnt=`expr $cnt + 1`
		done
	    fi

	    # Sites
	    $ECHO "Getting CDDB public server sites list... \c"
	    cnt=0
	    while [ $cnt -lt 5 ]
	    do
		$BINDIR/cddbcmd $OPTS sites 2>/dev/null | \
		    grep -v unofficial >$TMPSITES
		stat=$?
		if [ $stat -eq 0 ]
		then
		    break
		fi
		sleep 5
		$ECHO "retrying \c"
		cnt=`expr $cnt + 1`
	    done
	    if [ $stat -ne 0 -o ! -s $TMPSITES ]
	    then
		$ECHO "Failed"
		$ECHO "Cannot obtain server sites list from central server."
		$ECHO "Using built-in list."
	    else
		$ECHO "Success"
		SITES=$TMPSITES
	    fi
	fi

	if [ ! -r $SITES ]
	then
		$ECHO "Warning: Cannot read $SITES."
		SITES=/dev/null
	fi

	$ECHO "\nPress <RETURN> to continue. \c"
	read ANS

	# Let user choose the CDDB servers
	sel_servers

	# Check and set up local CDDB directories
	check_local_cddb
}


browser_config()
{
	$ECHO "\nSearching for installed web browsers..."
	BROWSER=
	WORD=A
	for j in $BROWSERS
	do
		for i in	/usr/bin \
				/usr/X11R6/bin 
		do
		    if [ -x $i/$j ]
		    then
			$ECHO "\nThe following is found on your system:"
			$ECHO "    $i/$j"
			YNDEF=y
			if get_yn "\n  Do you want xmcd to use this browser"
			then
				BDIR=$i
				BROWSER=$j
				break
			else
				WORD=Another
			fi
		    fi
		done
		if [ -n "$BROWSER" ]
		then
		    break
		fi
	done

	if [ -z "$BROWSER" ]
	then
		$ECHO "\n$WORD web browser cannot be found on your system."
		$ECHO "You must have Mozilla, Netscape or similar"
		$ECHO "in order to use the wwwWarp feature in xmcd."
		$ECHO "If you have one of these browsers, please"
		$ECHO "enter its full path name."

		while :
		do
		    BDIR=/usr/bin
		    i=mozilla

		    $ECHO "\n  Enter web browser path, type \"c\" to \c"
		    $ECHO "continue without\n  specifying a browser path, \c"
		    $ECHO "or type \"q\" to abort."
		    if get_str "  [$BDIR/$i]:"
		    then
			    if [ "$ANS" = c ]
			    then
				break
			    elif [ "$ANS" = q ]
			    then
				$ECHO "\nConfiguration aborted." >&2
				log_err -n "Configuration aborted by user"
				do_exit 3
			    fi

			    if [ -x "$ANS" ]
			    then
				BDIR=`dirname $ANS`
				i=`basename $ANS`
				BROWSER=$i
				break
			    else
				$ECHO "\n$ANS does not exist!"
			    fi
			else
			    BROWSER=$i
			    break
			fi
		done
	fi

	if [ -n "$BROWSER" ]
	then
	    #
	    # Make netscape the default setting
	    #
	    BROWSER_RMT="$BROWSER -remote 'openURL(%U)' >/dev/null 2>&1"
	    BROWSER_DIR="$BROWSER '%U' >/dev/null 2>&1 &"

	    #
	    # Set up browser configuration
	    #
	    BROWSER_RMT="$BDIR/$BROWSER_RMT"
	    BROWSER_DIR="$BDIR/$BROWSER_DIR"

	    $ECHO "\nXmcd has been configured to use the $BROWSER browser."
	else
	    $ECHO "\nNo web browser specified."
	    $ECHO "\n  Do you have a supported web browser that can be run"
	    YNDEF=n
	    if get_yn "  from a remote system"
	    then
		while :
		do
		    $ECHO "\n  Enter the remote system host name, \c"
		    $ECHO "type \"c\" to continue without\n  specifying \c"
		    $ECHO "a host name, \c"
		    if get_str "or type \"q\" to abort:"
		    then
			case "$ANS" in
			c)
			    break
			    ;;
			q)
			    $ECHO "\nConfiguration aborted." >&2
			    log_err -n "Configuration aborted by user"
			    do_exit 3
			    ;;
			*)
			    RMTSYS="$ANS"
			    break
			esac
		    fi
		done

		if [ -n "$RMTSYS" ]
		then
		    while :
		    do
			BDIR=/usr/bin
			i=mozilla

			$ECHO "\n  Enter web browser path on \"$RMTSYS\", \c"
			$ECHO "type \"c\" to\n  continue without specifying \c"
			$ECHO "a path, or type \"q\" to abort."
			if get_str "  [$BDIR/$i]: "
			then
			    if [ "$ANS" = c ]
			    then
				break
			    elif [ "$ANS" = q ]
			    then
				$ECHO "\nConfiguration aborted." >&2
				log_err -n "Configuration aborted by user"
				do_exit 3
			    fi

			    BDIR=`dirname $ANS`
			    i=`basename $ANS`
			    BROWSER=$i
			    break
			else
			    BROWSER=$i
			    break
			fi
		    done
		fi
	    fi

			SCR=$SCRDIR/nswrap
		BROWSER_RMT="$SCR -remote $RMTSYS $BDIR/$BROWSER '%U'"
		BROWSER_DIR="$SCR -direct $RMTSYS $BDIR/$BROWSER '%U' &"

		$ECHO "\nXmcd has been configured to use the $BROWSER"
		$ECHO "browser remotely on host \"$RMTSYS\".  Xmcd"
		$ECHO "users must have rsh(1) permissions on $RMTSYS"
		$ECHO "in order to use the wwwWarp feature.  See"
		$ECHO "rhosts(4) and hosts.equiv(4) for details."
		$ECHO "\nThe Local Discography feature will work in this"
		$ECHO "mode, only if the host \"$RMTSYS\" and your"
		$ECHO "system has a NFS-shared $DISCOGDIR"
		$ECHO "directory."
	fi
}


#
# Main starts here
#

# Catch some signals
trap "rm -f $TMPFILE $TMPSITES; exit 1" 1 2 3 5 15

# Get platform information
OS_SYS=`(uname -s) 2>/dev/null`
OS_REL=`(uname -r) 2>/dev/null`
OS_MACH=`(uname -m) 2>/dev/null`
OS_NODE=`(uname -n) 2>/dev/null`

if [ -z "$OS_SYS" ]
then
	OS_SYS=unkn
fi
if [ -z "$OS_REL" ]
then
	OS_REL=unkn
fi
if [ -z "$OS_MACH" ]
then
	OS_MACH=unkn
fi
if [ -z "$OS_NODE" ]
then
	OS_NODE=unkn
fi

# Use Sysv echo if possible
if [ -x /usr/5bin/echo ]				# SunOS SysV echo
then
	ECHO=/usr/5bin/echo
elif [ -z "`(echo -e a) 2>/dev/null | fgrep e`" ]	# GNU bash, etc.
then
	ECHO="echo -e"
else							# generic SysV
	ECHO=echo
fi
if [ "$OS_SYS" = QNX ]
then
	ECHO=echo
fi

# If awk doesn't work well on your system, try changing the
# following to nawk or gawk.
AWK=awk

# Error log file handling
if [ -f $ERRFILE -a ! -w $ERRFILE ]
then
	ERRFILE=/dev/null
fi

$ECHO "\nXmcd version $VER Configuration Program"
$ECHO "Setting up for host: ${OS_NODE}"
$ECHO "--------------------------------------"

# Sanity check

if [ ! -w $CFGDIR ]
then
	log_err -p "No write permission in $CFGDIR"
	do_exit 1
fi

if [ ! -r $CFGDIR/device.cfg ]
then
	log_err -p "Cannot find $CFGDIR/device.cfg"
	do_exit 2
fi

fgrep cfgver=1 $CFGDIR/device.cfg >/dev/null 2>&1
if [ $? -ne 0 ]
then
	log_err -p "$CFGDIR/device.cfg version mismatch"
	do_exit 2
fi

if [ ! -d $TBLDIR ]
then
	log_err -p "The directory $TBLDIR is missing"
	do_exit 2
fi

# Configure platform-dependent and device-dependent parameters

DEVPREF=/dev/rcdrom
DEVSUFF=
FIRST=0
BLKDEV=0
VOLMGT=False
STOPONLOAD=True
EJECTONEXIT=False
STOPONEXIT=True
EXITONEJECT=False
CLOSEONEJECT=False
MAILCMD="mailx -s '%S' %A <%F >/dev/null 2>&1"
USEPROXY=False
PROXYSERVER="yourproxyhost:80"
CDDBPATH=

# Determine what platform we are running on

if [ "$OS_SYS" = AIX ]
then
	# IBM AIX
	DEVPREF=/dev/rcd
	DEVSUFF=
	FIRST=0
elif [ "$OS_SYS" = A/UX ]
then
	# Apple A/UX
	DEVPREF=/dev/scsi/
	DEVSUFF=
	FIRST=3
	MAILCMD="mush -s '%S' %A <%F >/dev/null 2>&1"
elif [ "$OS_SYS" = BSD/OS ]
then
	# BSDI BSD/OS
	DEVPREF=/dev/rsd
	DEVSUFF=c
	FIRST=2
	MAILCMD="Mail -s '%S' %A <%F >/dev/null 2>&1"
elif [ "$OS_SYS" = dgux ]
then
	# Data General DG/UX
	DEVPREF="/dev/scsi/scsi(ncsc@7(FFFB0000,7),"
	DEVSUFF=",0)"
	FIRST=2
elif [ "$OS_SYS" = FreeBSD ]
then
	# FreeBSD
	DEVPREF=/dev/rcd
	DEVSUFF=c
	FIRST=0
	MAILCMD="Mail -s '%S' %A <%F >/dev/null 2>&1"
elif [ "$OS_SYS" = HP-UX ]
then
	case "$OS_REL" in
	[AB].09*)	# HP-UX 9.x
		DEVPREF=/dev/rdsk/c201d
		DEVSUFF=s0
		FIRST=4
		;;
	B.10*)		# HP-UX 10.x
		DEVPREF=/dev/rdsk/c0t
		DEVSUFF=s0
		FIRST=4
		;;
	B.11*)		# HP-UX 11.x
		DEVPREF=/dev/rdsk/c0t
		DEVSUFF=s0
		FIRST=4
		;;
	*)
		OS_REL=unknown
		;;
	esac
elif [ "$OS_SYS" = IRIX -o "$OS_SYS" = IRIX64 ]
then
	# SGI IRIX
	DEVPREF=`hinv | grep CDROM | line | \
		sed 's/^.*controller \([0-9]*\).*$/\/dev\/scsi\/sc\1d/'`
	DEVSUFF=l0
	FIRST=`hinv | grep CDROM | line | sed 's/^.*unit \([0-9]*\).*$/\1/'`
elif [ "$OS_SYS" = Linux ]
then
	# Linux
	DEVPREF=/dev/cdrom
	DEVSUFF=
	DEVNO=
	FIRST=0
	BLKDEV=1
	MAILCMD="mail -s '%S' %A <%F >/dev/null 2>&1"
elif [ "$OS_SYS" = NetBSD ]
then
	# NetBSD
	DEVPREF=/dev/rcd
	case "$OS_MACH" in
	*86)
		DEVSUFF=d
		;;
	*)
		DEVSUFF=c
		;;
	esac
	FIRST=0
	MAILCMD="Mail -s '%S' %A <%F >/dev/null 2>&1"
elif [ "$OS_SYS" = OpenBSD ]
then
	# OpenBSD
	DEVPREF=/dev/rcd
	case "$OS_MACH" in
	*86)
		DEVSUFF=d
		;;
	*)
		DEVSUFF=c
		;;
	esac
	FIRST=0
	MAILCMD="Mail -s '%S' %A <%F >/dev/null 2>&1"
elif [ "$OS_SYS" = OSF1 ]
then
	case "$OS_MACH" in
	alpha)	# Digital OSF/1
		if [ -d /devices/rdisk ]
		then
			DEVPREF=/devices/rdisk/cdrom
			DEVSUFF=c
			FIRST=2
		else
			DEVPREF=/dev/rrz
			DEVSUFF=c
			FIRST=4
		fi
		;;
	*)
		OS_REL=unknown
		;;
	esac
elif [ "$OS_SYS" = QNX ]
then
	# QNX
	DEVPREF=/dev/cd
	DEVSUFF=
	FIRST=0
	BLKDEV=1
elif [ "$OS_SYS" = SINIX-N ]
then
	# SNI SINIX-N
	DEVPREF=/dev/ios0/rsdisk
	DEVSUFF=s0
	FIRST=005
elif [ "$OS_SYS" = SINIX-P ]
then
	# SNI SINIX-P
	DEVPREF=/dev/ios0/rsdisk
	DEVSUFF=s0
	FIRST=006
elif [ "$OS_SYS" = SunOS -o "$OS_SYS" = Solaris ]
then
	case "$OS_REL" in
	4.*)	# SunOS 4.x
		case `arch -k` in
		sun4[cm])
			DEVPREF=/dev/rsr
			DEVSUFF=
			FIRST=0
			MAILCMD="Mail -s '%S' %A <%F >/dev/null 2>&1"
			;;
		*)
			OS_REL=unknown
			;;
		esac
		;;
	5.*)	# SunOS 5.x
		YNDEF=y
		if get_yn \
		"Does your system support the Volume Manager (/usr/sbin/vold)"
		then
			DEVPREF=/vol/dev/aliases/cdrom
			DEVSUFF=
			FIRST=0
			VOLMGT=True
			CLOSEONEJECT=True
		else
			DEVPREF=/dev/rdsk/c0t
			DEVSUFF=d0s0
			FIRST=6
		fi
		;;
	*)
		OS_REL=unknown
		;;
	esac
elif [ "$OS_SYS" = ULTRIX ]
then
	case "$OS_MACH" in
	RISC)	# Digital Ultrix
		DEVPREF=/dev/rrz
		DEVSUFF=c
		FIRST=4
		MAILCMD="Mail -s '%S' %A <%F >/dev/null 2>&1"
		;;
	*)
		OS_REL=unknown
		;;
	esac
elif [ -x /bin/ftx ] && ftx
then
	case "$OS_REL" in
	4.*)	
		if [ -x /bin/hppa ] && hppa
		then
			# Stratus FTX SVR4/PA-RISC
			DEVPREF=/dev/rcdrom/c0a2d
			DEVSUFF=l0
			FIRST=0
		else
			# On non-supported FTX variants
			OS_REL=unknown
		fi
		;;
	*)
		OS_REL=unknown
		;;
	esac
elif [ -x /bin/i386 -o -x /sbin/i386 ] && i386
then
	case "$OS_REL" in
	3.2)	# SCO UNIX/ODT/Open Server
		DEVPREF=/dev/rcd
		DEVSUFF=
		FIRST=0
		;;
	4.0)	# UNIX SVR4.0/x86
		DEVPREF=/dev/rcdrom/cd
		DEVSUFF=
		FIRST=0
		;;
	4.1)	# UNIX SVR4.1/x86
		DEVPREF=/dev/rcdrom/cdrom
		DEVSUFF=
		FIRST=1
		;;
	4.2)	# UNIX SVR4.2/x86 (UnixWare 1.x)
		DEVPREF=/dev/rcdrom/cdrom
		DEVSUFF=
		FIRST=1
		;;
	4*MP)	# UNIX SVR4.2MP/x86 (UnixWare 2.x)
		DEVPREF=/dev/rcdrom/cdrom
		DEVSUFF=
		FIRST=1
		;;
	5)	# UNIX SVR5/x86 (UnixWare 7)
		DEVPREF=/dev/rcdrom/cdrom
		DEVSUFF=
		FIRST=1
		;;
	5.*)	# UNIX SVR5.*/x86 (UnixWare 7.x)
		DEVPREF=/dev/rcdrom/cdrom
		DEVSUFF=
		FIRST=1
		;;
	*)
		OS_REL=unknown
		;;
	esac
elif [ -x /bin/m88k ] && m88k
then
	case "$OS_REL" in
	4.0)	# UNIX SVR4.0/88k
		DEVPREF=/dev/rdsk/m187_c0d
		DEVSUFF=s7
		FIRST=3
		;;
	*)
		OS_REL=unknown
		;;
	esac
elif [ -r /vmunix ] && (strings /vmunix | fgrep NEWS-OS) >/dev/null 2>&1
then
	# Sony NEWS-OS
	DEVPREF=/dev/rsd
	DEVSUFF=c
	FIRST=06
else
	OS_REL=unknown
fi

NOT_SUPPORTED="Error: You are not running an operating system that's\n\
currently supported by xmcd."

if [ "$OS_REL" = unknown ]
then
	$ECHO "$NOT_SUPPORTED"
	YNDEF=n
	get_yn "Would you like to proceed anyway"
	if [ $? -ne 0 ]
	then
		$ECHO "\nConfiguration aborted." >&2
		log_err -n "Configuration aborted by user"
		do_exit 3
	fi
fi

#
# Configure CD database server access
#
$ECHO "\n*** CDDB CONFIGURATION ***"
cddb_config

#
# Web browser setup
#
$ECHO "\n\n*** WEB BROWSER CONFIGURATION ***"
browser_config

#
# Drive configuration
#
$ECHO "\n\n*** DRIVE CONFIGURATION ***"
$ECHO "\nNote that the default device shown is usually a SCSI CD-ROM."
$ECHO "On some platforms, you may need to specify a different device"
$ECHO "if your CD-ROM drive is not SCSI."
EXITSTAT=0
DRVNO=0
SEDLINE=
while :
do
	$ECHO "\nConfiguring drive $DRVNO..."
	NUMDISCS=

	DEFAULT_DEV="${DEVPREF}${DEVNO}${DEVSUFF}"
	DEVNO=$FIRST

	while :
	do
		if get_str "\n  Enter device path: [$DEFAULT_DEV]"
		then
			XMCD_DEV=$ANS
		else
			XMCD_DEV=$DEFAULT_DEV
		fi

		if [ $VOLMGT = True ]
		then
			break
		fi
		if [ $BLKDEV = 0 -a -c $XMCD_DEV ]
		then
			break
		fi
		if [ $BLKDEV = 1 -a -b $XMCD_DEV ]
		then
			break
		fi

		$ECHO "  $XMCD_DEV does not appear to be a CD-ROM."
		$ECHO "  Continuing anyway as this maybe a removable device."
		break
	done

	if [ $DRVNO -eq 0 ]
	then
		#
		# Configure common.cfg file
		#
		chmod 644 $CFGDIR/common.cfg 2>/dev/null
		if [ -w $CFGDIR/common.cfg ]
		then
			$AWK '
			/^device:/	{
				printf("device:\t\t\t%s\n", device)
				next
			}
			/^solaris2VolumeManager:/ {
				printf("solaris2VolumeManager:\t%s\n", volmgt)
				next
			}
			/^cddbPath:/ {
				printf("cddbPath:\t%s\n", cddbpath)
				next
			}
			/^cddbUseHttpProxy:/ {
				printf("cddbUseHttpProxy:\t%s\n", useproxy)
				next
			}
			/^proxyServer:/ {
				printf("proxyServer:\t\t%s\n", proxyserver)
				next
			}
			/^browserRemote:/ {
				printf("browserRemote:\t%s\n", browserrmt)
				next
			}
			/^browserDirect:/ {
				printf("browserDirect:\t%s\n", browserdir)
				next
			}
			{
				print $0
			}' \
				device="$XMCD_DEV" \
				volmgt="$VOLMGT" \
				cddbpath="$CDDBPATH" \
				useproxy="$USEPROXY" \
				proxyserver="$PROXYSERVER" \
				browserrmt="$BROWSER_RMT" \
				browserdir="$BROWSER_DIR" \
				$CFGDIR/common.cfg > $TMPFILE

			cp $TMPFILE $CFGDIR/common.cfg
			(cd $CFGDIR ;\
			 rm -f common.cfg-${OS_NODE} ;\
			 do_link common.cfg common.cfg-${OS_NODE})
		else
			log_err -p \
			    "Cannot configure $CFGDIR/common.cfg"
			EXITSTAT=1 
		fi
	fi

	CONFIGFILE=`basename $XMCD_DEV`

	config_drive
	CFGSTAT=$?
	if [ $CFGSTAT -ne 0 ]
	then
		$ECHO "\nConfiguration aborted." >&2
		log_err -n "Configuration aborted by user."
		do_exit $CFGSTAT
	fi

	if [ $NUMDISCS -gt 1 ]
	then
		$ECHO "\n  This drive is a ${NUMDISCS}-disc changer."

		case $CHGMETHOD in
		1)
			# SCSI LUN addressing method
			$ECHO "\n  In order to change discs, your system must support separate device"
			$ECHO "  nodes for each LUN of the multi-disc changer."

			YNDEF=y
			if get_yn "  Does your OS platforms support this?"
			then
				$ECHO "\n  Please enter the device nodes now."

				n=1
				DEVLIST=
				LUNDEV=$XMCD_DEV
				while [ $n -le $NUMDISCS ]
				do
					#
					# Construct a default device
					#
					if [ "$OS_SYS" != HP-UX ] && \
					   (echo $LUNDEV | grep "s[0-9]*$") \
					   >/dev/null 2>&1
					then
					    LUNPREF=`echo $LUNDEV | \
						sed 's/\(.*\)[0-9]s[0-9]*/\1/'`
					    LUNNUM=`echo $LUNDEV | \
						sed 's/.*\([0-9]\)s[0-9]*/\1/'`
					    LUNSUFF=`echo $LUNDEV | \
						sed 's/.*[0-9]\(s[0-9]*\)/\1/'`
					else
					    LUNPREF=`echo $LUNDEV | \
						sed 's/\(.*\)[0-9][^0-9]*/\1/'`
					    LUNNUM=`echo $LUNDEV | \
						sed 's/.*\([0-9]\)[^0-9]*/\1/'`
					    LUNSUFF=`echo $LUNDEV | \
						sed 's/.*[0-9]\([^0-9]*\)/\1/'`
					fi

					if [ -n "$LUNNUM" ]
					then
						if [ $n -gt 1 ]
						then
						    LUNNUM=`expr $LUNNUM + 1`
						fi
					else
						LUNNUM=`expr $n - 1`
					fi

					SAVDEV=$LUNDEV
					LUNDEV="${LUNPREF}${LUNNUM}${LUNSUFF}"

					if get_str "  Disc $n: [$LUNDEV]"
					then
						LUNDEV=$ANS
					fi

					if [ $BLKDEV = 0 -a ! -c $LUNDEV ]
					then
						$ECHO "  $LUNDEV is invalid.  Try again."
						LUNDEV=$SAVDEV
						continue
					fi
					if [ $BLKDEV = 1 -a ! -b $LUNDEV ]
					then
						$ECHO "  $LUNDEV is invalid.  Try again."
						LUNDEV=$SAVDEV
						continue
					fi

					if [ -z "$DEVLIST" ]
					then
						DEVLIST=$LUNDEV
					else
						DEVLIST="${DEVLIST};${LUNDEV}"
					fi

					n=`expr $n + 1`
				done
			else
				$ECHO "  It will be treated as a single disc player."
				CHGMETHOD=0
				NUMDISCS=1
				MULTIPLAY=False
				DEVLIST=$XMCD_DEV
			fi
			;;
		2)
			# SCSI medium changer method
			$ECHO "\n  In order to change discs, your system must support a separate device"
			$ECHO "  node for the medium changer mechanism."

			DEVLIST=$XMCD_DEV

			YNDEF=y
			if get_yn "  Does your OS platforms support this?"
			then
			    while :
			    do
				LUNDEV=/dev/changer
				if get_str \
				"\n  Enter the medium changer device: [$LUNDEV]"
				then
					LUNDEV=$ANS
				fi

				if [ ! -c $LUNDEV ]
				then
				    $ECHO "  $LUNDEV is invalid.  Try again."
				    continue
				fi

				DEVLIST="${DEVLIST};${LUNDEV}"
				break
			    done
			else
			    $ECHO \
			    "\n  The drive will be treated as a single disc player."
			    CHGMETHOD=0
			    NUMDISCS=1
			    MULTIPLAY=False
			    DEVLIST=$XMCD_DEV
			fi
			;;
		3)
			# OS ioctl method
			DEVLIST=$XMCD_DEV
			;;
		*)
			# Unsupported changer method
			DEVLIST=$XMCD_DEV
			;;
		esac
	else
		DEVLIST=$XMCD_DEV
	fi

	DRVNOTICE="\n  NOTE: This drive does not support these features:"

	if [ $PLAYTI = False ]
	then
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The Previous Index and Next Index buttons."
	fi

	if [ $CADDYLOCK = False ]
	then
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The caddy lock."
	fi

	if [ $LOAD = False ]
	then
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - Software-controlled caddy load."
	fi

	if [ $PAUSE = False -a $VENDOR = 0 ]
	then
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - Audio pause/resume function."
	fi

	case "$VOLCTL" in
	0)
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The volume, balance and channel routing controls."
		VOLSUPP=False
		BALSUPP=False
		CHRSUPP=False
		;;
	1)
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The balance and channel routing controls."
		VOLSUPP=True
		BALSUPP=False
		CHRSUPP=False
		;;
	2)
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The volume and channel routing controls."
		VOLSUPP=False
		BALSUPP=True
		CHRSUPP=False
		;;
	3)
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The channel routing control."
		VOLSUPP=True
		BALSUPP=True
		CHRSUPP=False
		;;
	4)
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The volume and balance controls."
		VOLSUPP=False
		BALSUPP=False
		CHRSUPP=True
		;;
	5)
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The balance control."
		VOLSUPP=True
		BALSUPP=False
		CHRSUPP=True
		;;
	6)
		$ECHO "$DRVNOTICE"
		DRVNOTICE="\c"
		$ECHO "  - The volume control."
		VOLSUPP=False
		BALSUPP=True
		CHRSUPP=True
		;;
	7)
		VOLSUPP=True
		BALSUPP=True
		CHRSUPP=True
		;;
	*)
		;;
	esac

	$ECHO "\n  Creating the $CFGDIR/$CONFIGFILE file..."
	GDEVLIST=`echo $DEVLIST | sed 's/\//\\\\\//g'`

	sed \
	-e "s/^!.*DO NOT MODIFY.*$/! DEVICE CONFIGURATION FILE/" \
	-e "s/^logicalDriveNumber:.*/logicalDriveNumber:	$DRVNO/" \
	-e "s/^deviceInterfaceMethod:.*/deviceInterfaceMethod:	$METHOD/" \
	-e "s/^mediumChangeMethod:.*/mediumChangeMethod:	$CHGMETHOD/" \
	-e "s/^numDiscs:.*/numDiscs:		$NUMDISCS/" \
	-e "s/^deviceList:.*/deviceList:	$GDEVLIST/" \
	-e "s/^driveVendorCode:.*/driveVendorCode:	$VENDOR/" \
	-e "s/^playAudio12Support:.*/playAudio12Support:	$PLAY12/" \
	-e "s/^playAudioMSFSupport:.*/playAudioMSFSupport:	$PLAYMSF/" \
	-e "s/^playAudio10Support:.*/playAudio10Support:	$PLAY10/" \
	-e "s/^playAudioTISupport:.*/playAudioTISupport:	$PLAYTI/" \
	-e "s/^loadSupport:.*/loadSupport:		$LOAD/" \
	-e "s/^ejectSupport:.*/ejectSupport:		$EJECT/" \
	-e "s/^modeSenseSetDBD:.*/modeSenseSetDBD:	$MODEDBD/" \
	-e "s/^volumeControlSupport:.*/volumeControlSupport:	$VOLSUPP/" \
	-e "s/^balanceControlSupport:.*/balanceControlSupport:	$BALSUPP/" \
	-e "s/^channelRouteSupport:.*/channelRouteSupport:	$CHRSUPP/" \
	-e "s/^volumeControlTaper:.*/volumeControlTaper:	$VOLTAPER/" \
	-e "s/^scsiAudioVolumeBase:.*/scsiAudioVolumeBase:	$VOLBASE/" \
	-e "s/^pauseResumeSupport:.*/pauseResumeSupport:	$PAUSE/" \
	-e "s/^strictPauseResume:.*/strictPauseResume:	$STRICTPAUSERESUME/" \
	-e "s/^playPausePlay:.*/playPausePlay:		$PLAYPAUSEPLAY/" \
	-e "s/^caddyLockSupport:.*/caddyLockSupport:	$CADDYLOCK/" \
	-e "s/^curposFormat:.*/curposFormat:		$CURPOSFMT/" \
	-e "s/^noTURWhenPlaying:.*/noTURWhenPlaying:	$PLAYNOTUR/" \
	-e "s/^spinDownOnLoad:.*/spinDownOnLoad:		$STOPONLOAD/" \
	-e "s/^ejectOnExit:.*/ejectOnExit:		$EJECTONEXIT/" \
	-e "s/^stopOnExit:.*/stopOnExit:		$STOPONEXIT/" \
	-e "s/^exitOnEject:.*/exitOnEject:		$EXITONEJECT/" \
	-e "s/^closeOnEject:.*/closeOnEject:		$CLOSEONEJECT/" \
	-e "s/^multiPlay:.*/multiPlay:		$MULTIPLAY/" \
	   < $CFGDIR/device.cfg > $CFGDIR/$CONFIGFILE
	do_chmod 644 $CFGDIR/$CONFIGFILE 2>/dev/null
	do_chown $OWNER $CFGDIR/$CONFIGFILE 2>/dev/null
	do_chgrp $GROUP $CFGDIR/$CONFIGFILE 2>/dev/null
	(cd $CFGDIR ;\
	 rm -f ${CONFIGFILE}-${OS_NODE} ;\
	 do_link $CONFIGFILE ${CONFIGFILE}-${OS_NODE})

	YNDEF=n
	if get_yn "\n  Do you have more CD-ROM or CD-R drives on your system"
	then
		DRVNO=`expr $DRVNO + 1`

		case `expr $DEVNO : '.*'` in
		0)
			;;
		1)
			DEVNO=`expr $DEVNO + 1`
			;;
		2)
			DEVNO=`echo $DEVNO | \
				$AWK '{ printf("%02d\n", $1 + 1) }'`
			;;
		3)
			DEVNO=`echo $DEVNO | \
				$AWK '{ printf("%03d\n", $1 + 1) }'`
			;;
		4)
			DEVNO=`echo $DEVNO | \
				$AWK '{ printf("%04d\n", $1 + 1) }'`
			;;
		*)
			DEVNO=`expr $DEVNO + 1`
			;;
		esac
	else
		break
	fi
done

do_exit $EXITSTAT