File: Install

package info (click to toggle)
afbackup 3.3.6pl4-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,872 kB
  • ctags: 3,143
  • sloc: ansic: 44,316; tcl: 4,189; sh: 2,263; csh: 2,077; makefile: 566; sed: 93; perl: 80
file content (1957 lines) | stat: -rwxr-xr-x 53,225 bytes parent folder | download
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
#!/bin/csh -f
################### Start of $RCSfile: Install,v $ ##################
#
# $Source: /home/alb/afbackup/afbackup-3.3.6/RCS/Install,v $
# $Id: Install,v 1.2 2002/02/27 10:17:09 alb Exp alb $
# $Date: 2002/02/27 10:17:09 $
# $Author: alb $
#
#
####### description ################################################
#
#
#
####################################################################

set OSNAME=`uname -s|sed 's/[^a-zA-Z1-9]//g'`

unalias cd
unalias cp
unalias mv

umask 22

set servicename="afbackup"

if (-r Install.cache) then
  set noglob
  source Install.cache
  unset noglob
endif

set varstosave=(servinstdir username userid groupid defdev servvarinstdir clntinstdir clntvarinstdir port use_des des_header des_include des_lib des_libdir disable_threads orduserrestore runclientconfig runserverconfig servicename activate_mserver mservicename mport add_mservice use_zlib zlib_include zlib_libdir usegcc chown_server_var libdesbug_enabled do_install)

set exitst=0

set pathext=(/usr/bin /bin /usr/ccs/bin /usr/ccs/lib /opt/gnu/bin /usr/local/bin /usr/local/gnu/bin /opt/bin /opt/gnu)

foreach newdir ($pathext)
  if (! -d $newdir) continue

  set found=0
  foreach dir ($path)
    if ($dir == $newdir) then
      set found=1
      break
    endif
  end
  if (! $found) then
    set path=($path $newdir)
  endif
end

rehash

set stack=()
alias gosub 'set stack=(\!:3 $stack); set __args=(\!:2) ; goto \!:1'
alias return 'set __lab=$stack[1] ; set stack=($stack[2-]) ; goto $__lab'
alias matches 'echo \!:1 |egrep -i \!:2|wc -l'
alias issymlink 'ls -l \!:1 |grep '^l'|wc -l'
alias do_exit 'goto exitlabel'
alias find_program 'sh -c '"'"'if [ `echo \!:1|grep /|wc -l` -gt 0 ] ; then echo \!:1 ; else P=`basename \!:1` ; for d in `echo $PATH|tr : " "` ; do if [ -x $d/$P ] ; then echo $d/$P ; break ; fi ; done ; fi'"'"
alias get_xinetd_entry "sed -n '/^\([ 	]\)\?service[	 ][	 ]*'"'"\!:1"'"'\([	 ].*\)\?/,/^[	 ]*[}][	 ]*/ p' \!:2"
alias get_xinetd_param "sed -n '/^\([ 	]\)\?service[	 ][	 ]*'"'"\!:1"'"'\([	 ].*\)\?/,/^[	 ]*[}][	 ]*/ p' \!:3|grep '^[ 	]*'"'"\!:2"'"'[ 	]*=[ 	]*'|sed 's/^[^=]*=[	 ]*//g'"
alias strip_xinetd_entry "sed '/^\([ 	]\)\?service[	 ][	 ]*'"'"\!:1"'"'\([	 ].*\)\?/,/^[	 ]*[}][	 ]*/ d' \!:2"
alias comb_empty_lines "awk 'BEGIN{s = 0;}{if(NF == 0){if(s == 0)print; s = 1}else{s = 0; print}}'"

set PS1="ps -ef"
set PS2="ps -fp"

if (`matches $OSNAME linux` || `matches $OSNAME FreeBSD` || `matches $OSNAME OpenBSD`) then
  set PS1="ps -uxa"
  set PS2="ps"
endif
if (`matches $OSNAME sunos`) then
  set REV=`uname -r|sed 's/[.].*$//g'`
  if ($REV < 5) then
    set PS1="ps -uxa"
    set PS2="ps"
  endif
endif

#foreach p ($path)
#  if (-x $p/cc) then
#    setenv CC cc
#    break
#  endif
#  if (-x $p/gcc) then
#    setenv CC gcc
#    break
#  endif
#end

set CONF_INTERPR=""
if (`matches $OSNAME HPUX`) set CONF_INTERPR=ksh

set adminprefix=/etc

set inetdfile=$adminprefix/inetd.conf

set use_xinetd=0
set xinetd_running=`$PS1 | grep -v grep | grep xinetd | wc -l`
if (-f $adminprefix/xinetd.conf && $xinetd_running) then
  set use_xinetd=1
  set inetdfile=$adminprefix/xinetd.conf
endif

while (`ls -ld $inetdfile|cut -c1` == l)
  set syml=`ls -l $inetdfile|sed 's/^.*->[ 	]*//g'`
  if (`echo "$syml"|cut -c1` == "/") then
    set inetdfile="$syml"
  else
    set inetdfile=`dirname $inetdfile`/"$syml"
  endif
end

set tmpfile=core.tmp.$$
set tmpfile2=core.tmp2.$$

set saved_files=""

set modes=(servonly clntonly clntrem all)

gosub which_make "" know_make
know_make:
set MAKEOPTS="EXTRA_CFLAGS=-DORIG_DEFAULTS"
set MAKECMD="make"
if ($?GNU_MAKE) then
  set MAKEOPTS="$MAKEOPTS MAKECMD=$GNU_MAKE"
  set MAKECMD=$GNU_MAKE
endif

set configure_options=""

clear
echo " "
echo 'Welcome to the installation procedure for'
echo " "
echo "AF's backup system *"
echo '=================='
echo " "
echo ' '
echo '(* People accustomed to Microsoft-publications please'
echo '   insert: hyper-optimized, ultra-reliable, turbo-speed,'
echo '   multimedia, leading technology, highest performance ...)'
echo ' '
echo 'You can interrupt this program at any time hitting Ctrl-C. With'
echo 'some of the following questions a default answer will be offered'
echo "in square brackets. If you don't want to change this or if you"
echo "are unsure, just hit the Return key."
echo " "
echo "First you have to decide, which functionality you"
echo 'would like to have on this machine.'
echo " "
echo '(1) Backup server only'
echo '(2) Backup client only (also to start backups on other hosts)'
echo '(3) Backup client only with remote start option'
echo '(4) Backup server, client and client remote start option'
echo " "

set sel=0
while (! `matches $sel '^[1-4]$'`)
  echo -n 'Please enter your choice [1-4]: '
  set sel=$<
  if (! `matches $sel '^[1-4]$'`) then
    echo "This is not a valid choice. Please try again."
    echo " "
  endif
end

set mode=$modes[$sel]

onintr exitlabel

if (`matches $OSNAME SunOS` || `matches $OSNAME HPUX`) then
  echo ' '
  echo 'Shall we use gcc to build afbackup (strongly recommended) ?'
  if (! $?usegcc) then
    set usegcc=Yes
  endif
  gosub yes_no $usegcc usegccchecked

  usegccchecked:
  set usegcc="$yesno"
  if ($usegcc == "yes") then
    setenv CC gcc
  endif
endif

switch ($sel)
  case 1:
		gosub server_only "" contlab
		breaksw
  case 2:
		gosub client_only "" contlab
		breaksw
  case 3:
		gosub remclient "" contlab
		breaksw
  case 4:
		gosub all "" contlab
		breaksw
endsw

contlab:
echo " "
echo 'All done. The input supplied during this installation procedure'
echo 'is saved in the file "Install.cache". This file can be copied'
echo 'somewhere else to have the input present as default for the next'
echo 'upgrade or installation on other architectures. The file will be'
echo 'erased when you do a "make distclean".'

if (`echo $saved_files | wc -w` > 0) then
  echo " "
  echo "The following files are safety copies of files, that"
  echo "are crucial for your system. If up to now everything"
  echo "worked fine then you can safely remove them:"
  echo " "
  echo $saved_files
  echo ' '
endif

exitlabel:

set noglob
/bin/rm -f Install.cache
touch Install.cache
foreach var ($varstosave)
  eval 'set exists=$?'"$var"
  if ($exists) then
    set valuestr=`eval echo '$'$var`
    echo set $var"=($valuestr)" >> Install.cache
  endif
end

exit $exitst

### SERVER ONLY ###

server_only:
echo " "
echo "Ok, we're going to install only the server side on this"
echo -n "machine. "

gosub server_install "" end_server_only

end_server_only:
return

### CLIENT ONLY ###

client_only:
echo " "
echo "Ok, we're going to install only the client side on this"
echo -n "machine. "

gosub client_install "" end_client_only

end_client_only:
return

### REMOTELY STARTED CLIENT ###

remclient:
echo " "
echo "Ok, we're going to install the client with remote start"
echo -n "option. "

gosub server_install "" end_remclient
end_remclient:
return

### CLIENT, SERVER AND REMOTE START OPTION ###

all:
echo " "
echo "Ok, we will install the client, server and remote start"
echo -n "option. "

gosub server_install "" end_allinst
end_allinst:
return

################ SERVER INSTALLATION #################

server_install:

if (! $?servinstdir) then
  set servinstdir=/usr/local/afbackup
endif

echo "First you have to specify where to install the"
echo "files and programs. Please enter a directory of"
echo 'your choice (you may supply the same directory'
echo 'as for the client side).'
ask_for_servinstdir:
echo "If '$servinstdir' is fine enter yes."
echo 'Otherwise enter an alternate directory, please.'

choose_servinstdir:
echo " "
set choice="blub"
while (! `matches $choice '^(ye?s?|no?|/.*)$'`)
  echo -n 'Your choice (Yes/No/path) [Yes]: '
  set choice=$<
  if ("$choice" == "") set choice="yes"
  if (! `matches $choice '^(ye?s?|no?|/.*)$'`) then
    echo " "
    echo "That's no valid choice. Please Try again."
  endif
end
if (`matches $choice '^no?$'`) then
  echo "Please enter the directory."
  goto choose_servinstdir
endif
if (`matches $choice '^/'`) then
  set servinstdir=$choice
endif

gosub choose_DES "" chosen_DES_servonly
chosen_DES_servonly:
echo " "

gosub choose_ZLIB "" chosen_ZLIB_servonly
chosen_ZLIB_servonly:
echo " "

if (! $?orduserrestore) then
  set orduserrestore=No
endif
if ($mode != "clntrem" && $mode != "servonly") then
  echo " "
  echo "Do you want ordinary users to be able to restore their"
  echo "own files and/or directories without administrator help ?"
  ordusersclnt:
  echo ' '
  echo -n "Your choice (Yes/No) [$orduserrestore]: "
  set c=blub
  while (! `matches $c '^(ye?s?|no?)$'`)
    set c=$<
    if ("$c" == "") set c=$orduserrestore
    while (! `matches $c '^(ye?s?|no?)$'`)
      echo ' '
      echo "Invalid choice. Please try again."
      goto ordusersclnt
    end
  end
  set orduserrestore=$c
endif

gosub choose_threads "" chosen_threads_servonly
chosen_threads_servonly:

echo " "
echo "Now we have to build the programs. Please stand by"
echo "and watch for error messages. If any occur you have"
echo "a problem. Warnings can usually be ignored. If errors"
echo 'occur, drop a mail to the author (af@muc.de)'
echo 'with the fault message(s) of make or try to patch the'
echo "stuff yourself. If you succeed, please also drop a"
echo "mail to the author, so your changes can be added to the"
echo "distribution."
echo " "
echo "Running configure now ..."
echo " "
$CONF_INTERPR ./configure -prefix="$servinstdir" --without-prefixext \
		--with-rexecdir="$servinstdir"/server/rexec \
		$configure_options
set s=$status
echo " "
if ($s != 0) then
  echo "Damn. Something went wrong. Please contact the author."
  echo "Stopping here."
  set exitst=1
  do_exit
endif

if ($?libdesbug_enabled) then
  if (`matches $libdesbug_enabled '^yes$'`) then
    if (`grep LIBDESBUG_COMPATIBILITY des_aux.h|wc -l` < 1) then
      echo '#define	LIBDESBUG_COMPATIBILITY	1' >> des_aux.h
    endif
  endif
endif

echo "Running make now ..."
echo " "
if ($mode == "all" || $mode == "clntrem") then
  $MAKECMD $MAKEOPTS
  set s=$status
else
  $MAKECMD server $MAKEOPTS
  set s=$status
endif

echo " "
if ($s != 0) then
  echo "Damn. Something went wrong. Please contact the author."
  echo "Stopping here."
  set exitst=1
  do_exit
endif

gosub ask_install Yes serv_install_asked

serv_install_asked:

echo " "
echo "We're now going to install the files and programs."
echo " "
if ($mode == "all" || $mode == "clntrem") then
  $MAKECMD install install.rclient $MAKEOPTS
  set s=$status
else
  $MAKECMD install.server $MAKEOPTS
  set s=$status
endif

if ($s == 0 && `matches $orduserrestore 'ye?s?'`) then
  $MAKECMD install.userrestore $MAKEOPTS
  set s=$status
#    /bin/rm -f $servinstdir/client/bin/afrestore \
#		$servinstdir/client/bin/afbackout \
#		$servinstdir/client/bin/backout \
#		$servinstdir/client/bin/restore
#    cp $servinstdir/client/bin/full_backup \
#		$servinstdir/client/bin/afrestore
#    ln $servinstdir/client/bin/afrestore $servinstdir/client/bin/afbackout
#    ln -s afbackout $servinstdir/client/bin/backout
#    ln -s afrestore $servinstdir/client/bin/restore
#    chmod 4755 $servinstdir/client/bin/afrestore
#    chmod 755 $servinstdir/client/bin/xafrestore $servinstdir/client/bin/__packpats
endif

echo " "
if ($s != 0) then
  echo "Oops, something went wrong.  Maybe your directory choice is"
  echo "somewhat problematic. Choose one of:"
  set c=b
  while (! `matches $c '^[ar]'`)
    echo -n 'Abort, Retry (A/R) [R]: '
    set c=$<
    if ("$c" == "" ) set c=r
  end
  if ($c == "a" || $c == "A") then
    set exitst=1
    do_exit
  else
    echo ' '
    goto ask_for_servinstdir
  endif
endif

\rm -f $tmpfile

gosub add_backup_service "servicename port" serv_serv_added

serv_serv_added:

if (! $?username) then
  if ($mode == "all" || $mode == "clntrem") then
    set username=root
  else
    set username=backup
  endif
endif

echo ' '

gosub add_inetd_entry "$servicename nowait afserver" inst_mserver

inst_mserver:
echo ' '

echo 'Do you want to activate the multi stream server ?'
if (! $?activate_mserver) then
  set activate_mserver=Yes
endif
if (! $?mservicename) then
  set mservicename=afmbackup
endif
gosub yes_no $activate_mserver activate_mserver

activate_mserver:
set activate_mserver=$yesno
if ($yesno == "no") then
  goto sel_buserver_usrgrp
endif

echo ' '
echo 'The multi-stream server should use a different port than the'
echo 'normal server, so we now configure the appropriate entries'
echo 'for the system files.'

gosub add_backup_service "mservicename mport" serv_mserv_added

serv_mserv_added:

echo ' '
gosub add_inetd_entry "$mservicename wait afmserver" sel_buserver_usrgrp

sel_buserver_usrgrp:

echo ' '

gosub add_user_group "username userid groupid" chowntapedev

chowntapedev:

set RESTRSERVERFILES="afmserver afserver label_tape cartready"
foreach SF ($RESTRSERVERFILES)
  chown $username $servinstdir/server/bin/$SF
end

if ("$username" != "root") then
  echo ' '
  echo "The user ID the server will run under is not root."
  echo "So we are now going do change the ownership of the"
  echo "directory containing varying serverside files and"
  echo "storing persistent information for the server to the"
  echo "user $username. Furthermore all the files residing in"
  echo "this directory will change the owner the same way. If"
  echo "we wouldn't do so, the server would not be able to modify"
  echo "these files. That could result in really bad situations."
  echo "If you consider this as dangerous or disadvantageous, or "
  echo "if there's any reason to not like it then enter no now."
  echo ' '
  echo "Change owner of $servinstdir/server/var/* to $username ?"
  if (! $?chown_server_var) then
    set chown_server_var=Yes
  endif
  gosub yes_no $chown_server_var got_chown_var_server

 got_chown_var_server:
  set chown_server_var=$yesno
  if ($chown_server_var == yes) then
    chown $username $servinstdir/server/var $servinstdir/server/var/*
  endif
  echo ' '
endif

if ($mode != "clntrem") then
  echo " "
  echo "Now we should change the owner of your tape device"
  echo "to user $username and grant him exclusive access to it."
  echo "You may now enter a filename pattern or no if you"
  echo "want to skip this step. Here are the usual streamer"
  echo "device name patterns for some OS-es:"
  echo " "
  echo "Solaris:       /dev/rmt/[0-9]*"
  echo "AIX:           /dev/rmt[0-9]*"
  echo "IRIX:          /dev/rmt/tps[0-9]*"
  echo "HP-UX:         /dev/rmt/[0-9]*"
  echo "Linux:         /dev/st[0-9]* /dev/nst[0-9]*"
  echo "Digital UNIX:  /dev/rmt[0-9]* /dev/nrmt[0-9]*"
  echo "FreeBSD:       /dev/rst[0-9]* /dev/nrst[0-9]*"
  echo "OpenBSD:       /dev/rst[0-9]* /dev/nrst[0-9]*"

  if (! $?defdev) then
    switch ($OSNAME)
      case SunOS:
		set defdev="/dev/rmt/0*"
		breaksw
      case AIX:
		set defdev="/dev/rmt0*"
		breaksw
      case IRIX:
		set defdev="/dev/rmt/tps0d4*"
		breaksw
      case HPUX:
		set defdev="/dev/rmt/0*"
		breaksw
      case Linux:
		set defdev="/dev/st0* /dev/nst0*"
		breaksw
      case OSF1:
		set defdev="/dev/rmt0* /dev/nrmt0*"
		breaksw
      case FreeBSD:
		set defdev="/dev/sa0* /dev/nsa0*"
		breaksw
      case OpenBSD:
		set defdev="/dev/rst0* /dev/nrst0*"
		breaksw
      default:
		set defdev=""
    endsw
  endif

 seldev:
  echo " "
  echo -n "Your choice [$defdev]: "
  set c=""
  set c=$<
  if ("$c" == "") set c="$defdev"
  if (! `matches "$c" '^no?$'`) then
    chown $username $c
    set r=$status
    chmod 600 $c
    set r2=$status
    if ($r || $r2) then
      echo "Oops, this did not work. Please do it manually by "
      echo 'entering the following and replacing <devicenames> '
      echo 'with your device-names pattern:'
      echo " "
      echo " chown $username <devicenames>"
      echo " chmod 600 <devicenames>"
      echo " "
      echo "Please hit return when you are done with it or"
      echo "want to skip this step."
      set c=$<
    endif
  endif
  set defdev="$c"
endif


echo ' '

set inetdline=("`$PS1|grep -v grep|grep inetd`")
set running_inetds=`$PS1|grep -v grep|grep inetd|wc -l`
if ($running_inetds == 0) then
  echo "Sorry, i'm unable to determine the process ID of "
  echo 'inetd.  Would you do me a favour and enter it here?'
  askforinetdpid:
  echo ' '
  echo -n 'Process ID: '
  set pid=""
  set pid=$<
  if ("$pid" == "" || ! `matches $pid '^[0-9][0-9]*$'`) then
    echo ' '
    echo "Invalid input. Please try again."
    goto askforinetdpid
  endif
  $PS2 $pid >& /dev/null
  if ($status) then
    echo ' '
    echo "This is not the pid of the inetd. Please try again."
    goto askforinetdpid
  endif
  set inetdline=("`$PS2 $pid|grep -v grep|grep inetd`")
endif
if ($running_inetds > 1) then
  echo "Sorry, I found several processes looking like inetd."
  echo "Would you please give me a hint and tell me the real"
  echo 'process ID ? You may evaluate the following lines:'
  echo ' '
  $PS1|grep -v grep|grep inetd
  askfipid2:
  echo ' '
  echo -n 'Process ID: '
  set pid=""
  set pid=$<
  if ("$pid" == "" || ! `matches $pid '^[0-9][0-9]*$'`) then
    echo ' '
    echo "Invalid input. Please try again."
    goto askfipid2
  endif
  $PS2 $pid >& /dev/null
  if ($status) then
    echo ' '
    echo "This is not the pid of the inetd. Please try again."
    goto askfipid2
  endif
  set inetdline=("`$PS2 $pid|grep -v grep|grep inetd`")
endif
set inetdline=(`echo "$inetdline"|sed 's/[?*\[]/_/g;s/\]/_/g'`)
if ($running_inetds == 1) then
  set pid=$inetdline[2]
endif

echo ' '
echo "The process ID of the inetd seems to be $pid, the"
echo "appropriate entry in the process list is:"
echo ' '
echo "$inetdline"
asksendhup:
echo ' '
if (! $use_xinetd) then
  echo "To activate the backup service we can now send a HUP signal"
  echo -n 'to inetd. Do you want to do this (Yes/No) [Yes] ? '
  set SIG="HUP"
else
  echo "To activate the backup service we can now send a USR2 signal"
  echo -n 'to xinetd. Do you want to do this (Yes/No) [Yes] ? '
  set SIG="USR2"
endif
set c=blub
while (! `matches $c '^(ye?s?|no?)$'`)
  set c=$<
  if ("$c" == "") set c=Yes
  if (! `matches $c '^(ye?s?|no?)$'`) then
    echo ' '
    echo "Invalid choice. Please try again."
    goto asksendhup
  endif
end
if (`matches $c '^ye?s?$'`) then
  sh -c "kill -$SIG $pid"
endif

if (! $?servvarinstdir) then
  set servvarinstdir=/var/logs/backup
endif
echo " "
echo "You might now want to move the variable part of the"
if ($mode == "all" || $mode == "clntrem") then
  echo -n "backup service"
else
  echo -n "server side"
endif
echo " installation to the /var-directory. The"
echo "default directory is $servvarinstdir. If you want to"
echo "do this and this directory is ok, just enter yes. If"
echo 'the directory is not ok, enter the desired one (you'
echo 'may supply the same as for the client side). If you'
echo "want to skip this step, just enter no."
mvservvar:
echo ' '
echo -n 'Your choice (Yes/No/path) [No]: '
set c=blub
while (! `matches $c '^(ye?s?|no?|/.*)$'`)
  set c=$<
  if ("$c" == "") set c=no
  if (! `matches $c '^(ye?s?|no?|/.*)$'`) then
    echo ' '
    echo "Invalid choice. Please try again."
    goto mvservvar
  endif
end
if (`matches $c '^/'`) then
  set servvarinstdir=$c
endif
if (! `matches $c '^no?$'`) then
  mkdir -p $servvarinstdir
  set curwd=`pwd`
  cd $servinstdir/server
  if (`issymlink var`) then
    echo "Warning: The directory seems to have already been moved."
    echo "         Please check where $servinstdir/server/var"
    echo "         points to. Not moving anything."
    goto eosvmove
  endif
  tar cf - var | (cd $servvarinstdir; tar xf -)
  mv $servvarinstdir/var $servvarinstdir/server
  \rm -rf var
  ln -s $servvarinstdir/server var
  eosvmove:

  if ($mode == "all" || $mode == "clntrem") then
    cd $servinstdir/client
    if (`issymlink var`) then
      echo "Warning: The directory seems to have already been moved."
      echo "         Please check, where $servinstdir/client/var"
      echo "         points to. Not moving anything."
      goto eoclsvmove
    endif
    tar cf - var | (cd $servvarinstdir; tar xf -)
    mv $servvarinstdir/var $servvarinstdir/client
    \rm -rf var
    ln -s $servvarinstdir/client var
    eoclsvmove:
  endif

  cd $curwd
endif

if ($mode == "all" || $mode == "servonly") then
  if (! $?runserverconfig) then
    set runserverconfig=Yes
  endif
  echo ' '
  echo "Now we may run the program $servinstdir/server/bin/serverconfig"
  echo "so you can configure the server side of the backup system. Would"
  echo 'you like to do this now ?'
  confserv:
  echo ' '
  echo -n "Your choice (Yes/No) [$runserverconfig]: "
  set c=blub
  while (! `matches $c '^(ye?s?|no?)$'`)
    set c=$<
    if ("$c" == "") set c=$runserverconfig
    if (! `matches $c '^(ye?s?|no?)$'`) then
      echo ' '
      echo "Invalid choice. Please try again."
      goto serv
    endif
  end
  set runserverconfig="$c"
  if (`matches $c 'ye?s?'`) then
    $servinstdir/server/bin/serverconfig
  endif
endif

if ($mode == "all" || $mode == "clntrem") then
  if (! $?runclientconfig) then
    set runclientconfig=Yes
  endif
  echo ' '
  echo "Now we may run the program $servinstdir/client/bin/clientconfig"
  echo "so you can configure the client side of the backup system. Would"
  echo 'you like to do this now ?'
  confsclnt:
  echo ' '
  echo -n "Your choice (Yes/No) [$runclientconfig]: "
  set c=blub
  while (! `matches $c '^(ye?s?|no?)$'`)
    set c=$<
    if ("$c" == "") set c=$runclientconfig
    if (! `matches $c '^(ye?s?|no?)$'`) then
      echo ' '
      echo "Invalid choice. Please try again."
      goto confsclnt
    endif
  end
  set runclientconfig="$c"
  if (`matches $c 'ye?s?'`) then
    $servinstdir/client/bin/clientconfig
  endif
endif

return


################## CLIENT INSTALLATION ##################

client_install:
if (! $?clntinstdir) then
  set clntinstdir=/usr/local/afbackup
endif

echo "First you have to choose where we should install"
echo "the files and programs. Please enter a directory"
echo 'of your choice (you may supply the same directory'
echo 'as for the server side).'
ask_for_clntinstdir:
echo 'Enter yes if '$clntinstdir' is ok.'
echo 'Otherwise please enter an alternate directory.'

choose_clntinstdir:
echo " "
set choice="blub"
while (! `matches $choice '^(ye?s?|no?|/.*)$'`)
  echo -n 'Your choice (Yes/No/path) [Yes]: '
  set choice=$<
  if ("$choice" == "") set choice="yes"
  if (! `matches $choice '^(ye?s?|no?|/.*)$'`) then
    echo " "
    echo "This is not a valid choice. Please Try again."
  endif
end
if (`matches $choice '^no?$'`) then
  echo "Please enter the directory."
  goto choose_clntinstdir
endif
if (`matches $choice '^/'`) then
  set clntinstdir=$choice
endif

gosub choose_DES "" chosen_DES_clnt
chosen_DES_clnt:
echo " "

gosub choose_ZLIB "" chosen_ZLIB_clnt
chosen_ZLIB_clnt:
echo " "

if (! $?orduserrestore) then
  set orduserrestore=No
endif
echo " "
echo "Do you want ordinary users to be able to restore their"
echo "own files and/or directories without administrator help ?"
orduserclnt:
echo ' '
echo -n "Your choice (Yes/No) [$orduserrestore]: "
set c=blub
while (! `matches $c '^(ye?s?|no?)$'`)
  set c=$<
  if ("$c" == "") set c=$orduserrestore
  while (! `matches $c '^(ye?s?|no?)$'`)
    echo ' '
    echo "Invalid choice. Please try again."
    goto orduserclnt
  end
  set orduserrestore=$c
end

echo " "
echo "Now we have to build the programs. Please stand by"
echo "and watch for error messages. If any occur you have"
echo "a problem. Warnings can usually be ignored. If errors"
echo "occur, drop a mail to the author"
echo '(af@muc.de)'
echo 'with the fault message(s) of make or try to patch the'
echo "stuff yourself. If you succeed, please also drop a"
echo "mail to the author, so your changes can be added to the"
echo "distribution."
echo " "
echo "Running configure now ..."
echo " "
$CONF_INTERPR ./configure -prefix="$clntinstdir" --without-prefixext \
		--with-rexecdir="$clntinstdir"/server/rexec \
		$configure_options
set s=$status
echo " "
if ($s != 0) then
  echo "Damn. Something went wrong. Please contact the author."
  echo "Stopping here."
  set exitst=1
  do_exit
endif

if ($?libdesbug_enabled) then
  if (`matches $libdesbug_enabled '^yes$'`) then
    if (`grep LIBDESBUG_COMPATIBILITY des_aux.h|wc -l` < 1) then
      echo '#define	LIBDESBUG_COMPATIBILITY	1' >> des_aux.h
    endif
  endif
endif

echo "Running make now ..."
echo " "
$MAKECMD client $MAKEOPTS
set s=$status
echo " "
if ($s != 0) then
  echo "Damn. Something went wrong. Please contact the author."
  echo "Stopping here."
  set exitst=1
  do_exit
endif

gosub ask_install Yes clnt_install_asked

clnt_install_asked:

echo " "
echo "We're now going to install the files and programs."
echo " "
$MAKECMD install.client $MAKEOPTS
set s=$status

if ($s == 0 && `matches $orduserrestore 'ye?s?'`) then
  $MAKECMD install.userrestore $MAKEOPTS
  set s=$status
#  /bin/rm -f $clntinstdir/client/bin/afrestore \
#		$clntinstdir/client/bin/afbackout \
#		$clntinstdir/client/bin/backout \
#		$clntinstdir/client/bin/restore
#  cp $clntinstdir/client/bin/full_backup \
#		$clntinstdir/client/bin/afrestore
#  ln $clntinstdir/client/bin/afrestore $clntinstdir/client/bin/afbackout
#  ln -s afbackout $clntinstdir/client/bin/backout
#  ln -s afrestore $clntinstdir/client/bin/restore
#  chmod 4755 $clntinstdir/client/bin/afrestore
#  chmod 755 $clntinstdir/client/bin/xafrestore $clntinstdir/client/bin/__packpats
endif

echo " "
if ($s != 0) then
  echo "Oops. This failed. Maybe your directory choice is"
  echo "somewhat problematic. Choose one of:"
  set c=b
  while (! `matches $c '^[ar]'`)
    echo -n 'Abort, Retry (A/R) [R]: '
    set c=$<
    if ("$c" == "" ) set c=r
  end
  if ($c == "a" || $c == "A") then
    return
  else
    echo ' '
    goto ask_for_clntinstdir
  endif
endif

gosub add_backup_service "servicename port" clnt_add_mservice

clnt_add_mservice:

echo ' '
echo 'Do you want to add an entry to '"$adminprefix/services"
echo 'for the multi stream server ?'

if (! $?add_mservice) then
  set add_mservice=Yes
endif
if (! $?mservicename) then
  set mservicename=afmbackup
endif

gosub yes_no $add_mservice clnt_mservice_added
clnt_mservice_added:
set add_mservice=$yesno
if ($yesno == "no") then
  goto clnt_chvardir
endif

gosub add_backup_service "mservicename mport" clnt_chvardir

clnt_chvardir:

if (! $?clntvarinstdir) then
  set clntvarinstdir=/var/logs/backup
endif
echo " "
echo "You might now want to move the variable part of the"
echo "client side installation to the /var-directory. The"
echo "default directory is $clntvarinstdir. If you want to"
echo "do this and this directory is ok, just enter yes. If"
echo 'the directory is not ok, enter the desired one (you'
echo 'may supply the same as for the server side). If you'
echo "want to skip this step, just enter no."
mvclntvar:
echo ' '
echo -n 'Your choice (Yes/No/path) [No]: '
set c=blub
while (! `matches $c '^(ye?s?|no?|/.*)$'`)
  set c=$<
  if ("$c" == "") set c=no
  if (! `matches $c '^(ye?s?|no?|/.*)$'`) then
    echo ' '
    echo "Invalid choice. Please try again."
    goto mvclntvar
  endif
end
if (`matches $c '^/'`) then
  set clntvarinstdir=$c
endif
if (! `matches $c '^no?$'`) then
  mkdir -p $clntvarinstdir
  set curwd=`pwd`
  cd $clntinstdir/client
  if (`issymlink var`) then
    echo " "
    echo "Warning: The directory seems to have been moved already."
    echo "         Please check where $clntinstdir/client/var"
    echo "         points to. Not moving anything."
    goto eoclmove
  endif
  tar cf - var | (cd $clntvarinstdir; tar xf -)
  mv $clntvarinstdir/var $clntvarinstdir/client
  \rm -rf var
  ln -s $clntvarinstdir/client var
  eoclmove:
  cd $curwd
endif

if (! $?runclientconfig) then
  set runclientconfig=Yes
endif
echo ' '
echo "Now we may run the program $clntinstdir/client/bin/clientconfig"
echo "so you can configure the client side of the backup system. Would"
echo 'you like to do this now ?'
confclnt:
echo ' '
echo -n "Your choice (Yes/No) [$runclientconfig]: "
set c=blub
while (! `matches $c '^(ye?s?|no?)$'`)
  set c=$<
  if ("$c" == "") set c=$runclientconfig
  if (! `matches $c '^(ye?s?|no?)$'`) then
    echo ' '
    echo "Invalid choice. Please try again."
    goto confclnt
  endif
end
set runclientconfig="$c"
if (`matches $c 'ye?s?'`) then
  $clntinstdir/client/bin/clientconfig
endif

return

####### add user and group entry to /etc/passwd and /etc/group

add_user_group:

set usrnamvar=`echo $__args|awk '{print $1}'`
set usridvar=`echo $__args|awk '{print $2}'`
set grpidvar=`echo $__args|awk '{print $3}'`
eval set usrnam='$'$usrnamvar
eval set usridexists='$?'"$usridvar"
if ($usridexists) then
  eval set usrid='$'"$usridvar"
else
  unset usrid
endif
eval set grpidexists='$?'"$grpidvar"
if ($grpidexists) then
  eval set grpid='$'"$grpidvar"
else
  unset grpid
endif

set passwdfile=$adminprefix/passwd
if (`matches $OSNAME OpenBSD`) then
  set passwdfile=$adminprefix/master.passwd
endif

if (`grep '[ 	]*'"$usrnam": $passwdfile |wc -l` < 1) then
  echo "No user entry found for $usrnam in $passwdfile."
  askadduser:
  echo ' '
  echo -n 'Should we add an entry (Yes/No) [Yes] ? '
  set c=blub
  while (! `matches $c '^(ye?s?|no?)$'`)
    set c=$<
    if ("$c" == "") set c=Yes
    if (! `matches $c '^(ye?s?|no?)$'`) then
      echo ' '
      echo "Invalid choice. Please try again."
      goto askadduser
    endif
  end
  if (`matches $c '^ye?s?$'`) then
    if (! $?usrid) then
      set usrid=2988
    endif
    while (`cut -f3 -d: $passwdfile|grep "^$usrid"'$'|wc -l` > 0)
      @ usrid++
    end
    echo " "
    echo "The default user-ID is $usrid. If this is ok, just"
    echo "enter yes. If not, enter the desired ID."
    set c=blub
    askforuserid:
    while (! `matches $c '^(ye?s?|no?|[0-9][0-9]*)$'`)
      echo " "
      echo -n 'Your choice (Yes/No/userid) [Yes]: '
      set c=$<
      if ("$c" == "") set c='Yes'
      if (! `matches $c '^(ye?s?|no?|[0-9][0-9]*)$'`) then
        echo ' '
        echo 'This is not a valid choice. Please try again.'
      endif
    end
    if (`matches $c '^[0-9][0-9]*$'`) then
      set usrid=$c
    else
      if (`matches $c '^n'`) then
        echo "Please enter the desired user-ID."
        goto askforuserid
      endif
    endif
    if (`cut -f3 -d: $passwdfile|grep "^$usrid"'$'|wc -l` > 0) then
      echo "Warning: A user entry with the user-ID $usrid already exists"
      echo "     on the system. Using it nonetheless."
    endif

    if (! $?grpid) then
      set grpid=14
    endif
    while (`cut -f3 -d: $adminprefix/group|grep "^$grpid"'$'|wc -l` < 1)
      @ grpid--
      if ($grpid == 0) then
        break
      endif
    end
    while (`cut -f3 -d: $adminprefix/group|grep "^$grpid"'$'|wc -l` < 1)
      @ grpid++
    end
    echo " "
    echo "The default group-ID is $grpid. If this is ok, just"
    echo "enter yes. If not, enter the desired ID."
    set c=blub
    askforgroupid:
    while (! `matches $c '^(ye?s?|no?|[0-9][0-9]*)$'`)
      echo " "
      echo -n 'Your choice (Yes/No/groupid) [Yes]: '
      set c=$<
      if ("$c" == "") set c='Yes'
      if (! `matches $c '^(ye?s?|no?|[0-9][0-9]*)$'`) then
        echo ' '
        echo 'This is not a valid choice. Please try again.'
      endif
    end
    if (`matches $c '^[0-9][0-9]*$'`) then
      set grpid=$c
      if (`cut -f3 -d: $adminprefix/group|grep "^$grpid"'$'|wc -l` < 1) then
	echo "Warning: A group entry with this group-ID does not exist"
	echo "    in the system. Using it nonetheless."
      endif
    else
      if (`matches $c '^n'`) then
        echo "Please enter the desired group-ID."
        goto askforgroupid
      endif
    endif

    set panic=0
    cp $passwdfile $passwdfile.$$
    set saved_files=($saved_files $passwdfile.$$)
    set tmppasswdfile=$passwdfile.tmp.$$

    if (! -e $passwdfile.$$) then
      echo "Panic: cannot make backup copy of $passwdfile."
      echo "I'll not go on to add the user. You have to do it yourself."
      set panic=1
    else
      if (`grep '^+' $passwdfile|wc -l` > 0) then
        \rm -f $tmpfile $tmpfile2
        echo "/^+/ i\\" >! $tmpfile
        echo "$usrnam":x:"$usrid":"$grpid":"Backup Server:$servinstdir/server:" \
  		>> $tmpfile
        sed -f $tmpfile $passwdfile >! $tmpfile2
        if ($status) then
	  echo "Error: adding the user to the system file failed."
  	  set panic=1
        else
	  if (! `matches $OSNAME OpenBSD`) then
  	    cp $tmpfile2 $passwdfile
	  else
	    /bin/cp $tmpfile2 $tmppasswdfile \
	     && pwd_mkdb $tmppasswdfile \
	     && /bin/cp $tmpfile2 $tmppasswdfile \
	     && pwd_mkdb -p $tmppasswdfile \
	     && /bin/rm -f $tmppasswdfile # just in case pwd_mkdb forgets it
	  endif
          if ($status) then
  	    echo "Error: adding the user to the system file failed."
  	    set panic=1
	  endif
        endif
      else
        if (! `matches $OSNAME OpenBSD`) then
	  echo "$usrnam":x:"$usrid":"$grpid":"Backup Server:$servinstdir/server:" \
		>> $passwdfile
	else
	  \rm -f $tmpfile \
	   && /bin/cp $passwdfile $tmpfile \
	   && echo "$usrnam":x:"$usrid":"$grpid":"Backup Server:$servinstdir/server:" \
		>> $tmpfile \
	   && /bin/cp $tmpfile $tmppasswdfile \
	   && pwd_mkdb $tmppasswdfile \
	   && /bin/cp $tmpfile $tmppasswdfile \
	   && pwd_mkdb -p $tmppasswdfile # just in case pwd_mkdb forgets it
          if ($status) then
  	    echo "Error: adding the user to the system file failed."
  	    set panic=1
	  endif
	endif
      endif
    endif

    if ($panic) then
      echo "The following line must be added to $passwdfile"
      echo '(before the line starting with a +, if present):'
      echo ' '
      echo "$usrnam":x:"$usrid":"$grpid":"Backup Server:$servinstdir/server:"
      echo " "
      echo "Please hit enter when you are done with it."
      set a=$<
    endif
  endif
endif

eval set "$usrnamvar"=$usrnam
if ($?usrid) then
  eval set "$usridvar"=$usrid
endif
if ($?grpid) then
  eval set "$grpidvar"=$grpid
endif

return


####### add afbackup entry to /etc/services

add_backup_service:

set servnamvar=`echo $__args|awk '{print $1}'`
set portnumvar=`echo $__args|awk '{print $2}'`
set portnumexists=`eval echo '$?'$portnumvar`
eval set servnam='$'"$servnamvar"
if ($portnumexists) then
  eval set portnum='$'"$portnumvar"
else
  unset portnum
endif
echo ' '
echo 'An entry for the backup service is necessary in the system'
echo "file $adminprefix/services."
add_service:
set servicesline=`egrep '^[ 	]*'"$servnam"'([ 	].*)?$' $adminprefix/services`
set serviceslinen=`echo $servicesline|wc -w`
if ($serviceslinen > 0) then
  echo "There exists an entry for this service in $adminprefix/services."
  echo "It looks like this:"
  echo ' '
  echo $servicesline
  echo ' '
  echo 'Should we remove this entry and create a new one, or add another ?'
  serventry:
  echo ' '
  echo -n 'Your choice (Yes/No/Add) [No]: '
  set c=blub
  while (! `matches $c '^(ye?s?|no?|ad?d?)$'`)
    set c=$<
    if ("$c" == "") set c=no
    if (! `matches $c '^(ye?s?|no?|ad?d?)$'`) then
      echo ' '
      echo "Invalid choice. Please try again."
      goto serventry
    endif
  end
  if (`matches $c '^ad?d?'`) then
   newservname:
    echo " "
    echo -n "Enter a name for the new service: "
    set c=@
    set c=$<
    if (! `matches $c '^[a-zA-Z0-9_-]*$'`) then
      echo " "
      echo "A service name should contain only A-Z, a-z, 0-9, _ or -"
      echo "Please try again."
      goto newservname
    endif
    set servnam="$c"
    goto add_service
  endif
  if (`matches $c '^ye?s?$'`) then
    set panic=0
    cp $adminprefix/services $adminprefix/services.$$
    set saved_files=($saved_files $adminprefix/services.$$)

    if (! -e $adminprefix/services.$$) then
      echo "Panic: cannot make backup copy of $adminprefix/services."
      echo "I'll not go on to add the entry. You have to do it yourself."
      set panic=1
    else
      egrep -v '^[ 	]*'"$servnam"'([ 	].*)?$' $adminprefix/services >! $tmpfile
      if (! -e $tmpfile) then
	echo "Error: removing entry from the system file failed."
	set panic=1
      else
        cp $tmpfile $adminprefix/services
	if ($status) then
	  echo "Error: removing entry from the system file failed."
	  set panic=1
	endif
      endif
    endif
    if ($panic) then
      echo "The following line must be removed from $adminprefix/services"
      echo ' '
      egrep '^[ 	]*'"$servnam"'([ 	].*)?$'
      echo " "
      echo "Please hit enter when you are done with it."
      set a=$<
    endif
    goto add_service
  endif    
  if (`matches $c '^no?$'`) then
    set portnum=`echo $servicesline|awk '{print $2}'|cut -d/ -f1|awk '{print $1}'`
  endif
else
  if (! $?portnum) then
    set portnum=2988
  endif
  while (`grep -i $portnum/tcp $adminprefix/services|grep -v $servnam|wc -l` > 0)
    @ portnum++
  end
 portserviceselection:
  if ($portnum == 2988) then
    set hint=' (hex 0xbac)'
  else
    set hint=''
  endif
  echo ' '
  echo "Should we add an entry to $adminprefix/services for this"
  echo 'service ? Default port number is '$portnum$hint'. If'
  echo 'you do not want to add an entry, just enter no. If you'
  echo 'would like to use a different port number, enter it. If'
  echo 'you want a service name different from '"$servnam"','
  echo 'enter it (all lowercase letters, numbers or -, please).'
  echo 'If everything is ok, enter yes.'
  set c="_-_"
  while (! `matches $c '^(ye?s?|no?|[0-9][0-9]*|[a-z][a-z0-9-]*)$'`)
    echo " "
    echo -n 'Your choice (Yes/No/port/servicename) [Yes]: '
    set c=$<
    if ($c == "") set c='Yes'
    if (! `matches $c '^(ye?s?|no?|[0-9][0-9]*|[a-z][a-z0-9-]*)$'`) then
      echo ' '
      echo 'This is not a valid choice. Please try again.'
    endif
  end
  if (`matches $c '^[0-9][0-9]*$'`) then
    set portnum=$c
    echo " "
    echo "Ok, port number changed to $c."
    if (`grep '^[ 	]*[a-z][a-z0-9-]*[ 	][ 	]*'"$c/"'[tT][Cc][Pp]' $adminprefix/services|wc -l` > 0) then
      echo "Warning: Port number $c is already used in $adminprefix/services."
    endif
    goto portserviceselection
  endif
  if (`matches $c '^[a-z][a-z0-9-]*$'` && ! `matches $c '^(ye?s?|no?)$'`) then
    set servnam="$c"
    echo " "
    echo "Ok, service name changed to $c."
    if (`grep '^[ 	]*'"$c"'[ 	][ 	]*[1-9][0-9]*/[tT][Cc][Pp]' $adminprefix/services|wc -l` > 0) then
      echo "Error: Service name $c is already used in $adminprefix/services."
      goto add_service
    endif
    goto portserviceselection
  endif
  if (! `matches $c '^no?$'`) then
    echo "$servnam		$portnum/tcp" >> $adminprefix/services
  endif
endif
eval set "$servnamvar"=$servnam
eval set "$portnumvar"=$portnum

\rm -f $tmpfile

return

################### add entry to /etc/inetd.conf file

add_inetd_entry:

set servnam=`echo $__args|awk '{print $1}'`
set waitforexit=`echo $__args|awk '{print $2}'`
set prognam=`echo $__args|awk '{print $3}'`

set waityesno=no
if ($waitforexit == "wait") set waityesno=yes

echo 'An entry for this service is necessary in the system'
echo "file $inetdfile."
add_inetdentry:
if ($use_xinetd) then
  set inetdentry="`get_xinetd_entry $servnam $inetdfile`"
else
  set inetdentry=(`egrep '^[ 	]*'"$servnam"'([ 	].*)?$' $inetdfile`)
endif
set inetdentryn=`echo $inetdentry|wc -w`
if ($inetdentryn > 0) then
  echo "There exists an entry in $inetdfile."
  echo "It looks like this:"
  echo ' '
  if ($use_xinetd) then
    get_xinetd_entry $servnam $inetdfile
  else
    echo "$inetdentry"
  endif
  echo ' '
  set def=No
  if(! $use_xinetd) then
    set i=($inetdentry)
    if (! `matches $i[6]"/" ^$servinstdir"/"`) then
      echo 'The directory path in this entry seems to be wrong (It'
      echo 'should be '$servinstdir'/... )'
      set def="Yes"
    endif
    if (! `matches $i[6] /$prognam'$'` || ! `matches $i[7] /$prognam'$'`) then
      echo "The program name in this entry is wrong (it must be $prognam)."
      set def="Yes"
    endif
    if (! `matches $i[7]"/" ^$servinstdir"/"`) then
      echo 'The program path in this entry is wrong (it must be '$servinstdir'/$prognam).'
      set def="Yes"
    endif
    if ($i[5] != $username) then
      echo 'The username in this entry is wrong (should be '$username').'
      set def="Yes"
    endif
    if ($i[3] != "tcp" || $i[4] != "$waitforexit" || $i[2] != "stream") then
      echo 'The protocol in this entry is wrong (we are allowing'
      if ("$waitforexit" == "nowait") then
        echo 'several server processes).'
      else
        echo 'only one server process)'
      endif
      set def="Yes"
    endif
  else
    # xinetd
    set server="`get_xinetd_param $servnam server $inetdfile`"
    if (! `matches $server"/" ^$servinstdir"/"`) then
      echo 'The directory path in this entry seems to be wrong (It'
      echo 'should be '$servinstdir'/... )'
      set def="Yes"
    endif
    set server_args=(`get_xinetd_param $servnam server_args $inetdfile`)
    if (! `matches $server /$prognam'$'` || ! `matches $server_args[1] /$prognam'$'`) then
      echo "The program name in this entry is wrong (it must be $prognam)."
      set def="Yes"
    endif
    if (! `matches $server_args[1]"/" ^$servinstdir"/"`) then
      echo 'The program path in this entry is wrong (it must be '$servinstdir'/$prognam).'
      set def="Yes"
    endif
    set user="`get_xinetd_param $servnam user $inetdfile`"
    if ($user != $username) then
      echo 'The username in this entry is wrong (should be '$username').'
      set def="Yes"
    endif
    set prot="`get_xinetd_param $servnam protocol $inetdfile`"
    set wait="`get_xinetd_param $servnam wait $inetdfile`"
    set sockt="`get_xinetd_param $servnam socket_type $inetdfile`"
    if ($prot != "tcp" || $wait != "$waityesno" || $sockt != "stream") then
      echo 'The protocol in this entry is wrong (we are allowing'
      if ("$waitforexit" == "nowait") then
        echo 'several server processes).'
      else
        echo 'only one server process)'
      endif
      set def="Yes"
    endif
    set flags="`get_xinetd_param $servnam flags $inetdfile`"
    echo "$flags" | egrep '^(.* )?REUSE( .*$)?' >/dev/null
    set reuse=$status
    echo "$flags" | egrep '^(.* )?NAMEINARGS( .*$)?' >/dev/null
    set nameinargs=$status
    if ($nameinargs != 0 || $reuse != 0) then
      echo 'The flags in this entry are wrong (REUSE and NAMEINARGS must be set)'
      set def="Yes"
    endif
  endif

  if ($def != "No") then
    echo " "
  endif
  echo 'Should we remove this entry and create a new one ?'
  inetdentry:
  echo ' '
  echo -n 'Your choice (Yes/No) ['$def']: '
  set c=blub
  while (! `matches $c '^(ye?s?|no?)$'`)
    set c=$<
    if ("$c" == "") set c=$def
    if (! `matches $c '^(ye?s?|no?)$'`) then
      echo ' '
      echo "Invalid choice. Please try again."
     goto inetdentry
    endif
  end
  if (`matches $c '^ye?s?$'`) then
    set panic=0
    cp $inetdfile $inetdfile.$$
    set saved_files=($saved_files $inetdfile.$$)

    if (! -e $inetdfile.$$) then
      echo "Panic: cannot make backup copy of $inetdfile."
      echo "I'll not go on to add the entry. You have to do it yourself."
      set panic=1
    else
      if ($use_xinetd) then
        strip_xinetd_entry $servnam $inetdfile | comb_empty_lines >! $tmpfile
      else
        egrep -v '^[ 	]*'"$servnam"'([ 	].*)?$' $inetdfile >! $tmpfile
      endif
      if (! -e $tmpfile) then
	echo "Error: removing entry from the system file failed."
	set panic=1
      else
        cp $tmpfile $inetdfile
	if ($status) then
	  echo "Error: removing entry from the system file failed."
	  set panic=1
	endif
      endif
    endif
    if ($panic) then
      echo "The following line must be removed from $inetdfile"
      echo ' '
      echo "$inetdline"
      echo " "
      echo "Please hit enter when you are done with it."
      set a=$<
    endif
    goto add_inetdentry
  else
    if ($use_xinetd) then
      set user="`get_xinetd_param $servnam user $inetdfile`"
    else
      set line=(`egrep '^[ 	]*'"$servnam"'([ 	].*)?$' $inetdfile`)
      set username=$line[5]
    endif
  endif
else
  echo ' '
  echo "Should we add an entry to $inetdfile for this"
  echo 'service ? Default username is '$username'. If you do not'
  echo 'want to add an entry, just enter no. If you would like'
  echo 'to run the server under a different username, enter it.'
  echo 'If everything is ok, enter yes.'
  askaddinetd:
  echo ' '
  echo -n "Your choice (Yes/No/username) [Yes]: "
  set c=""
  set c=$<
  if ("$c" == "") set c=Yes
  if (! `matches $c '^(ye?s?|no?)$'`) then
    set username=$c
  endif
  if (! `matches $c '^no?$'`) then
    if ($use_xinetd) then
      cut -c10- >> $inetdfile << EOF
       > 
       > service $servnam
       > {
       >         flags           = REUSE NAMEINARGS
       >         socket_type     = stream
       >         protocol        = tcp
       >         wait            = $waityesno
       >         user            = $username
       >         server          = $servinstdir/server/bin/$prognam
       >         server_args     = $servinstdir/server/bin/$prognam $servinstdir/server/etc/backup.conf
       > }
EOF
    else
      echo "$servnam	stream	tcp	$waitforexit	$username	$servinstdir/server/bin/$prognam $servinstdir/server/bin/$prognam $servinstdir/server/etc/backup.conf" >> $inetdfile
    endif
  endif
endif

return

#########################
which_make:
set gmake=`find_program gmake`
if (`echo "$gmake" | wc -w` > 0) then
  if (`matches "$gmake" "^/"`) then
    setenv GNU_MAKE gmake
    return
  endif
endif

make -v -n >& /dev/null
if ($status) then
  unsetenv GNU_MAKE
  return
endif

if (`make -v -n|grep GNU|wc -l` > 0) then
  setenv GNU_MAKE make
  return
endif

setenv GNU_MAKE gmake

return

###########################################################################

choose_threads:

echo " "
echo "Do you wish to disable threads even if they are"
echo "available on your system?  If unsure enter no."

if (! $?disable_threads) then
  set disable_threads=No
endif

gosub yes_no $disable_threads threads_yesno
threads_yesno:

set disable_threads=$yesno
if ($yesno == "no") then
  return
endif

set configure_options="$configure_options --disable-threads"

return

###########################################################################

choose_DES:

echo " "
echo "Will we use 128 Bit DES encryption for authenticating the"
echo "client to the server ? (Eric Young's DES library (currently"
echo "version 4.04b) is required and by default expected in the"
echo "directory ../libdes. The defaults can be modified in the"
echo "following section, when answering yes) If no, the old style"
echo "encryption is performed."

if (! $?use_des) then
  set use_des=No
endif

gosub yes_no $use_des DES_yesno
DES_yesno:

set use_des=$yesno
if ($yesno == "no") then
  return
endif

set configure_options="$configure_options --with-des"

if (! $?des_header) then
  set des_header=des.h
endif

echo " "
echo "Please enter the name of the DES-library's header file"
gosub mult_choice "$des_header [^ ]*" DES_have_header
DES_have_header:

set des_header="$the_choice"

if (! $?des_include) then
  set des_include=../libdes
endif

echo " "
echo "Please enter the directory where "$des_header" can be found or no,"
echo "if it resides in a place where it is found by default (don't"
echo "supply /usr/include, when comiling with gcc)"

gosub mult_choice "$des_include [^ ]*" DES_have_include
DES_have_include:

set des_include="$the_choice"

if (`matches $des_include '^no?$'`) then
  set des_include="."
else
  if (! -e $des_include/$des_header) then
    echo " "
    echo "Warning: File '$des_include/$des_header' does not exist."
  endif
endif

set configure_options="$configure_options --with-des-include=$des_include"
set configure_options="$configure_options --with-des-header=$des_header"

if (! $?des_lib) then
  set des_lib=-ldes
endif

echo " "
echo "Please enter the specifier of the DES-library for linking"
gosub mult_choice "$des_lib [^ ]*" DES_have_lib
DES_have_lib:

set des_lib="$the_choice"
if (`matches "$des_lib" '^lib'`) then
  set des_lib=`echo $des_lib|sed 's#^lib#-l#g;s#[.].*##g'`
endif
set deslibfile=`echo $des_lib|sed 's#^-l#lib#g'`'.*'

if (! $?des_libdir) then
  if ($?des_include) then
    if ($des_include == ".") then
      set des_libdir=no
    else
      set des_libdir=`echo $des_include|sed 's#/include$#/lib#g'`
    endif
  else
    set des_libdir=../libdes
  endif
endif

echo " "
echo "Please enter the directory where the DES library can be found,"
echo "or no if it resides in a place, where it is found by default"

gosub mult_choice "$des_libdir [^ ]*" DES_have_libdir
DES_have_libdir:

set des_libdir="$the_choice"

if (`matches $des_libdir '^no?$'`) then
  set des_libdir="."
else
  ls $des_libdir/$deslibfile >& /dev/null
  if ($status) then
    echo " "
    echo "Warning: File '$des_libdir/$deslibfile' does not exist."
  else
    set deslibfile=`basename $des_libdir/$deslibfile`
  endif
endif

set configure_options="$configure_options --with-des-libdir=$des_libdir"
set configure_options="$configure_options --with-des-ldflag=$des_lib"

echo " "
echo "Changes in the encryption routines were necessary due to a bug"
echo "in all libdes versions. Thus the newly built programs are unable"
echo "to authenticate successfully with existing installations."
echo "Furthermore if the __descrpt program was used to encrypt files,"
echo "they cannot be decrypted with this program any longer."
echo "Nonetheless it is possible to build the package using the buggy"
echo "function, so backward compatibility for existing installations"
echo "is provided. Should the buggy function be used ?"

if (! $?libdesbug_enabled) then
  set libdesbug_enabled=No
endif

gosub yes_no $libdesbug_enabled libdesbug_yesno
libdesbug_yesno:

set libdesbug_enabled=$yesno

return

###########################################################################

choose_ZLIB:

echo " "
echo "Will we use the libz compression library to have"
echo "built-in compression available ?"

if (! $?use_zlib) then
  set use_zlib=No
endif

gosub yes_no $use_zlib ZLIB_yesno
ZLIB_yesno:

set use_zlib=$yesno
if ($yesno == "no") then
  return
endif

set configure_options="$configure_options --with-zlib"

if (! $?zlib_include) then
  set zlib_include=/usr/local/include
endif

echo " "
echo "Please enter the directory where zlib.h can be found or no,"
echo "if it resides in a place where it is found by default (don't"
echo "supply /usr/include when comiling with gcc)"

gosub mult_choice "$zlib_include [^ ]*" ZLIB_have_include
ZLIB_have_include:

set zlib_include="$the_choice"

if (`matches $zlib_include '^no?$'`) then
  set zlib_include="."
else
  if ( ! -e $zlib_include/zlib.h) then
    echo " "
    echo "Warning: File '$zlib_include/zlib.h' does not exist."
  endif
endif

set configure_options="$configure_options --with-zlib-include=$zlib_include"

if (! $?zlib_libdir) then
  if ($?zlib_include) then
    if ($zlib_include == ".") then
      set zlib_libdir="no"
    else
      set zlib_libdir=`echo $zlib_include|sed 's#/include$#/lib#g'`
    endif
  else
    set zlib_libdir=/usr/local/lib
  endif
endif

echo " "
echo "Please enter the directory where the libz library can be found"
echo "or no, if it resides in a place where it is found by default"

gosub mult_choice "$zlib_libdir [^ ]*" ZLIB_have_libdir
ZLIB_have_libdir:

set zlib_libdir="$the_choice"

if (`matches $zlib_libdir '^no?$'`) then
  set zlib_libdir="."
else
  ls $zlib_libdir/libz.* >& /dev/null
  if ($status) then
    echo " "
    echo "Warning: File '$zlib_libdir/libz.*' does not exist."
  endif
endif

set configure_options="$configure_options --with-zlib-libdir=$zlib_libdir"

return

###########################################################################

yes_no:

set yesno=blub
echo " "
echo -n 'Your choice (Yes/No) ['$__args']: '
set yesno=$<
if ($yesno == "") set yesno=$__args
if (! `matches $yesno '^(ye?s?|no?)$'`) then
  echo ' '
  echo 'This is not a valid choice. Please try again.'
  goto yes_no
endif

if (`matches $yesno '^ye?s?$'`) then
  set yesno="yes"
else
  set yesno="no"
endif

return

###########################################################################

mult_choice:

set noglob
set defaultsel=`echo "$__args"|awk '{print $1}'`
set validch=`echo "$__args"|awk '{printf "%s",$2; for(i=3;i<=NF;i++) printf " %s", $i}'`

echo " "
set the_choice=blub
echo -n 'Your choice ['$defaultsel']: '
set the_choice="$<"
if ("$the_choice" == "") set the_choice=$defaultsel
if (! `matches "$the_choice" '^'"$validch"'$'`) then
  echo ' '
  echo 'This is not a valid choice. Please try again.'
  goto mult_choice
endif
unset noglob

return

##########################################################################

ask_install:

if (! $?do_install) then
  set do_install=Yes
endif

echo ' '
echo 'Now we are going to install the software. If you want to'
echo 'stop here for whatever reason, enter no.'
echo ' '
echo -n 'Install the software now ? '
gosub yes_no "$do_install" install_asked_yesno
install_asked_yesno:
set do_install=$yesno

if ($do_install == no) then
  set exitst=0
  goto exitlabel
endif

return