File: image.postinst

package info (click to toggle)
kernel-package 8.135
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,008 kB
  • ctags: 696
  • sloc: perl: 3,089; makefile: 2,344; sh: 538
file content (1809 lines) | stat: -rwxr-xr-x 63,629 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
#! /usr/bin/perl
#                              -*- Mode: Cperl -*-
# debian.postinst ---
# Author           : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
# Created On       : Sat Apr 27 05:55:26 1996
# Created On Node  : melkor.pilgrim.umass.edu
# Last Modified By : Manoj Srivastava
# Last Modified On : Thu Mar 17 21:03:19 2005
# Last Machine Used: glaurung.internal.golden-gryphon.com
# Update Count     : 269
# Status           : Unknown, Use with caution!
# HISTORY          :
# Description      :
#
#    $Id: image.postinst,v 1.125 2003/10/07 16:24:20 srivasta Exp $
#

#
#use strict; #for debugging

$|=1;

# Predefined values:
my $version           = "=V";
my $link_in_boot      = "=B";   # Should be empty, mostly
my $no_symlink        = "=S";   # Should be empty, mostly
my $reverse_symlink   = "=R";   # Should be empty, mostly
my $do_symlink        = "Yes";  # target machine defined
my $do_boot_enable    = "Yes";  # target machine defined
my $do_bootfloppy     = "Yes";  # target machine defined
my $do_bootloader     = "Yes";  # target machine defined
my $move_image        = '';          # target machine defined
my $kimage            = "=K";   # Should be empty, mostly
my $loader            = "=L";   # lilo, silo, quik, palo, vmelilo, nettrom, arcboot or delo
my $image_dir         = "=D";        # where the image is located
my $clobber_modules   = '';          # target machine defined
my $relative_links    = "";          # target machine defined
my $initrd            = "=I";        # initrd kernel
my $mkimage           = "=M";        # command to generate the initrd image
my $do_initrd         = '';     # Normally we do not
my $warn_initrd       = 'YES';  # Normally we do
my $use_hard_links    = '';          # hardlinks do not work across fs boundaries
my $postinst_hook     = '';          #Normally we do not
my $postrm_hook       = '';          #Normally we do not
my $preinst_hook      = '';          #Normally we do not
my $prerm_hook        = '';          #Normally we do not
my $minimal_swap      = '';          # Do not swap symlinks
my $ignore_depmod_err = '';     # normally we do not
my $relink_src_link   = 'YES';  # There is no harm in checking the link
my $relink_build_link = 'YES';  # There is no harm in checking the link
my $force_build_link  = '';     # There is no harm in checking the link
my $official_image    = "=OF";      # only true for official images
my $arch            = "=A";  #  should be same as dpkg --print-installation-architecture

my $package_name    = "=ST-image-$version";

my $Loader          = "NoLOADER"; #
$Loader             = "LILO"     if $loader =~ /^lilo/io;
$Loader             = "SILO"     if $loader =~ /^silo/io;
$Loader             = "QUIK"     if $loader =~ /^quik/io;
$Loader             = "yaboot"   if $loader =~ /^yaboot/io;
$Loader             = "PALO"     if $loader =~ /^palo/io;
$Loader             = "NETTROM"  if $loader =~ /^nettrom/io;
$Loader             = "VMELILO"  if $loader =~ /^vmelilo/io;
$Loader             = "ZIPL"     if $loader =~ /^zipl/io;
$Loader             = "ELILO"    if $loader =~ /^elilo/io;
$Loader             = "ARCBOOT"  if $loader =~ /^arcboot/io;
$Loader             = "DELO"     if $loader =~ /^delo/io;

# This should not point to /tmp, because of security risks.
my $temp_file_name = "/var/log/$loader" . "_log.$$";

#known variables
my @boilerplate     = ();
my @silotemplate    = ();
my @quiktemplate    = ();
my @palotemplate    = ();
my @vmelilotemplate = ();
my @zipltemplate    = ();
my @arcboottemplate = ();
my @delotemplate    = ();
my $bootdevice      = '';
my $rootdevice      = '';
my $rootdisk        = '';
my $rootpartition   = '';
my $image_dest      = "/";
my $realimageloc    = "/$image_dir/";
my $have_conffile   = "";
my $silent_modules  = '';
my $silent_loader   = '';
my $modules_base    = '/lib/modules';
my $CONF_LOC        = '/etc/kernel-img.conf';

# Ignore all invocations except when called on to configure.
exit 0 unless $ARGV[0] =~ /configure/;

# Do some preliminary sanity checks here to ensure we actually have an
# valid image dir
chdir('/')           or die "could not chdir to /:$!\n";
die "Internal Error: ($image_dir) is not a directory!\n"
  unless -d $image_dir;

# remove multiple leading slashes; make sure there is at least one.
$realimageloc  =~ s|^/*|/|o;
$realimageloc  =~ s|/+|/|o;
die "Internal Error: ($realimageloc) is not a directory!\n"
  unless -d $realimageloc;

if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
  if (open(CONF, "$CONF_LOC")) {
    while (<CONF>) {
      chomp;
      s/\#.*$//g;
      next if /^\s*$/;

      $do_symlink      = "" if /do_symlinks\s*=\s*(no|false|0)\s*$/ig;
      $no_symlink      = "" if /no_symlinks\s*=\s*(no|false|0)\s*$/ig;
      $reverse_symlink = "" if /reverse_symlink\s*=\s*(no|false|0)\s*$/ig;
      $link_in_boot    = "" if /image_in_boot\s*=\s*(no|false|0)\s*$/ig;
      $link_in_boot    = "" if /link_in_boot\s*=\s*(no|false|0)\s*$/ig;
      $move_image      = "" if /move_image\s*=\s*(no|false|0)\s*$/ig;
      $clobber_modules = '' if /clobber_modules\s*=\s*(no|false|0)\s*$/ig;
      $do_boot_enable  = '' if /do_boot_enable\s*=\s*(no|false|0)\s*$/ig;
      $do_bootfloppy   = '' if /do_bootfloppy\s*=\s*(no|false|0)\s*$/ig;
      $relative_links  = '' if /relative_links \s*=\s*(no|false|0)\s*$/ig;
      $do_bootloader   = '' if /do_bootloader\s*=\s*(no|false|0)\s*$/ig;
      $do_initrd       = '' if /do_initrd\s*=\s*(no|false|0)\s*$/ig;
      $warn_initrd     = '' if /warn_initrd\s*=\s*(no|false|0)\s*$/ig;
      $use_hard_links  = '' if /use_hard_links\s*=\s*(no|false|0)\s*$/ig;
      $silent_modules  = '' if /silent_modules\s*=\s*(no|false|0)\s*$/ig;
      $silent_loader   = '' if /silent_loader\s*=\s*(no|false|0)\s*$/ig;
      $minimal_swap    = '' if /minimal_swap\s*=\s*(no|false|0)\s*$/ig;
      $ignore_depmod_err = '' if /ignore_depmod_err\s*=\s*(no|false|0)\s*$/ig;
      $relink_src_link   = '' if /relink_src_link\s*=\s*(no|false|0)\s*$/ig;
      $relink_build_link = '' if /relink_build_link\s*=\s*(no|false|0)\s*$/ig;
      $force_build_link  = '' if /force_build_link\s*=\s*(no|false|0)\s*$/ig;

      $do_symlink      = "Yes" if /do_symlinks\s*=\s*(yes|true|1)\s*$/ig;
      $no_symlink      = "Yes" if /no_symlinks\s*=\s*(yes|true|1)\s*$/ig;
      $reverse_symlink = "Yes" if /reverse_symlinks\s*=\s*(yes|true|1)\s*$/ig;
      $link_in_boot    = "Yes" if /image_in_boot\s*=\s*(yes|true|1)\s*$/ig;
      $link_in_boot    = "Yes" if /link_in_boot\s*=\s*(yes|true|1)\s*$/ig;
      $move_image      = "Yes" if /move_image\s*=\s*(yes|true|1)\s*$/ig;
      $clobber_modules = "Yes" if /clobber_modules\s*=\s*(yes|true|1)\s*$/ig;
      $do_boot_enable  = "Yes" if /do_boot_enable\s*=\s*(yes|true|1)\s*$/ig;
      $do_bootfloppy   = "Yes" if /do_bootfloppy\s*=\s*(yes|true|1)\s*$/ig;
      $do_bootloader   = "Yes" if /do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
      $relative_links  = "Yes" if /relative_links\s*=\s*(yes|true|1)\s*$/ig;
      $do_initrd       = "Yes" if /do_initrd\s*=\s*(yes|true|1)\s*$/ig;
      $warn_initrd     = "Yes" if /warn_initrd\s*=\s*(yes|true|1)\s*$/ig;
      $use_hard_links  = "Yes" if /use_hard_links\s*=\s*(yes|true|1)\s*$/ig;
      $silent_modules  = 'Yes' if /silent_modules\s*=\s*(yes|true|1)\s*$/ig;
      $silent_loader   = 'Yes' if /silent_loader\s*=\s*(yes|true|1)\s*$/ig;
      $minimal_swap    = 'Yes' if /minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
      $ignore_depmod_err = 'Yes' if /ignore_depmod_err\s*=\s*(yes|true|1)\s*$/ig;
      $relink_src_link   = 'Yes' if /relink_src_link\s*=\s*(yes|true|1)\s*$/ig;
      $relink_build_link = 'Yes' if /relink_build_link\s*=\s*(yes|true|1)\s*$/ig;
      $force_build_link = 'Yes' if /force_build_link\s*=\s*(yes|true|1)\s*$/ig;

      $image_dest      = "$1"  if /image_dest\s*=\s*(\S+)/ig;
      $postinst_hook   = "$1"  if /postinst_hook\s*=\s*(\S+)/ig;
      $postrm_hook     = "$1"  if /postrm_hook\s*=\s*(\S+)/ig;
      $preinst_hook    = "$1"  if /preinst_hook\s*=\s*(\S+)/ig;
      $prerm_hook      = "$1"  if /prerm_hook\s*=\s*(\S+)/ig;
      $mkimage         = "$1"  if /mkimage\s*=\s*(.+)$/ig;
    }
    close CONF;
    $have_conffile = "Yes";
  }
}



# For some versions of kernel-package, we had this warning in the
# postinst, but the rules did not really interpolate the value in.
# Here is a sanity check.
my $pattern = "=" . "I";
$initrd=~ s/^$pattern$//;

# no floppy disk support available for m68k VME, and it is not very useful
# to make a boot floppy on PowerMac hardware at all.
$do_bootfloppy = "" if $loader =~ /^vmelilo/io;
$do_bootfloppy = "" if $loader =~ /^quik/io;
$do_bootfloppy = "" if $loader =~ /^yaboot/io;
$do_bootfloppy = "" if $loader =~ /^noloader/io;
$do_bootfloppy = "" if $loader =~ /^zipl/io;
$do_bootfloppy = "" if $loader =~ /^elilo/io;
$do_bootfloppy = "" if $loader =~ /^arcboot/io;
$do_bootfloppy = "" if $loader =~ /^delo/io;

# We can't have boot floppies for initrd kernels
$do_bootfloppy = "" if $initrd;

if ($link_in_boot) {
  $image_dest = "/$image_dir/";
  $image_dest =~ s|^/*|/|o;
}

$image_dest = "$image_dest/";
$image_dest =~ s|/+$|/|o;

if (! -d "$image_dest") {
  die "Expected Image Destination dir ($image_dest) to be a valid directory!\n";
}

# sanity
if (!($do_bootfloppy || $do_bootloader)) {  $do_boot_enable = ''; }
if ($do_symlink && $no_symlink) {
  warn "Both do_symlinks and no_symlinks options enabled; disabling no_symlinks\n";
  $no_symlink = 0;
}

# Official powerpc images may silently upgrade
if ($official_image =~ /^\s*YES\s*$/o && $arch =~ m/powerpc/) {
  $silent_modules = 'Yes';
}



# most of our work is done in $image_dest (nominally /)
chdir("$image_dest") or die "could not chdir to $image_dest:$!\n";

# Paranoid check to make sure that the correct value is put in there
if (! $kimage)                    { $kimage = "vmlinuz";} # Hmm. empty
elsif ($kimage =~ m/^b?zImage$/o) { $kimage = "vmlinuz";} # these produce vmlinuz
elsif ($kimage =~ m/^[iI]mage$/o) { my $nop = $kimage;  }
elsif ($kimage =~ m/^vmlinux$/o)  { my $nop = $kimage;  }
else                              { $kimage = "vmlinuz";} # Default

die "Internal Error: Could not find image (" . $realimageloc
  . "$kimage-$version)\n" unless -e $realimageloc
  . "$kimage-$version";

# search for the boot loader in the path
my $loader_exec;
($loader_exec = $loader)  =~ s|.*/||;
my ($loaderloc) = grep -x, map "$_/$loader_exec",
  map { length($_) ? $_ : "." }  split /:/, $ENV{PATH};


######################################################################
## Fix the build link
######################################################################
sub fix_build_link {
  return unless -d "$modules_base/$version";
  # if we saved a build link in preinst, restore the link
  if (! -e "$modules_base/$version/build" && 
        -l "$modules_base/$version/build.save" ) {
    rename("$modules_base/$version/build.save", "$modules_base/$version/build") ||
      die "failed to move $modules_base/$version/build:$!";
  }
  if ($relink_build_link || $force_build_link) {
    my $build_target;
    if (-l "$modules_base/$version/build") {
      $build_target = readlink "$modules_base/$version/build";
    }
    else {
      return;
    }
    if (!defined($build_target)) { # Danglink link
      warn qq(
 Hmm. There is a symbolic link $modules_base/$version/build
 However, I can not read it: $!
 Therefore, I am deleting $modules_base/$version/build\n
);
      my $num = unlink "$modules_base/$version/build";
      if ($num != 1) {
        warn "error unlinking $modules_base/$version/build";
      }
      else {
        if ($force_build_link || -d "/usr/src/=ST-headers-$version") {
          my $result = symlink ("/usr/src/=ST-headers-$version",
                                "$modules_base/$version/build");
          if (! $result) {
            warn "Could not link /usr/src/=ST-headers-$version to $modules_base/$version/build:$!"
          }
        }
      }
    }
  }
}

if ($relink_build_link || $force_build_link) {
  &fix_build_link();
}
######################################################################
## Fix the source link
######################################################################
sub fix_source_link {
  return unless -d "$modules_base/$version";
  if ($relink_src_link) {
    my $source_target;
    if (-l "$modules_base/$version/source") {
      $source_target = readlink "$modules_base/$version/source";
    }
    else {
      return;
    }
    if (!defined($source_target)) { # Danglink link
      warn qq(
 Hmm. The package shipped with a symbolic link $modules_base/$version/source
 However, I can not read it: $!
 Therefore, I am deleting $modules_base/$version/source\n
);
      my $num = unlink "$modules_base/$version/source";
      if ($num != 1) {
        warn "error unlinking $modules_base/$version/source";
      }
    }
  }
}

if ($relink_src_link) {
  &fix_source_link();
}
######################################################################
######################################################################
###########        Test whether a relative symlinkwould be OK #######
######################################################################
######################################################################
sub test_relative {
  my %params = @_;
  my $cwd;

  die "Internal Error: Missing Required paramater 'Old Dir' "
    unless $params{'Old Dir'};
  die "Internal Error: Missing Required paramater New Dir' "
    unless  $params{'New Dir'};


  die "Internal Error: No such dir $params{'Old Dir'} "
    unless -d $params{'Old Dir'};
  die "Internal Error: No such dir $params{'New Dir'} "
    unless -d $params{'New Dir'};

  chomp($cwd = `pwd`);
  chdir ($params{'New Dir'}) or die "Could not chdir to $params{'New Dir'}:$!";
  my $ok = 0;
  $params{'Old Dir'}  =~ s|^/*||o;
  if (-d $params{'Old Dir'} ) {
    if (defined $params{'Test File'}) {
      if (-e $params{'Old Dir'} . $params{'Test File'}) {
        $ok  = 1;
      }
    }
    else {
      $ok = 1;                  # well, backward compatibility
    }
  }
  chdir ($cwd) or die "Could not chdir to $params{'New Dir'}:$!";
  return $ok;
}

######################################################################
######################################################################
############
######################################################################
######################################################################
sub CanonicalizePath {
  my $path = join '/', @_;
  my @work = split '/', $path;
  my @out;
  my $is_absolute;

  if (@work && $work[0] eq "") { $is_absolute = 1; shift @work; }

  while (@work) {
    my $seg = shift @work;
    if ($seg eq "." || $seg eq "") {
    } elsif ($seg eq "..") {
      if (@out && $out[-1] ne "..") {
        pop @out;
      } else {
        # Leading "..", or "../..", etc.
        push @out, $seg;
      }
    } else {
      push @out, $seg;
    }
  }

  unshift @out, "" if $is_absolute;
  return join('/', @out);
}
######################################################################
######################################################################
############
######################################################################
######################################################################

sub spath {
  my %params = @_;

  die "Missing Required paramater 'Old'" unless $params{'Old'};
  die "Missing Required paramater 'New'" unless  $params{'New'};

  my @olddir  = split '/', CanonicalizePath $params{'Old'};
  my @newdir  = split '/', CanonicalizePath $params{'New'};
  my @outdir  = @olddir;

  my $out = '';
  my $i;
  for ($i = 0; $i <= $#olddir && $i <= $#newdir; $i++) {
    $out++ if ($olddir[$i] ne $newdir[$i]);
    shift @outdir unless $out;
    unshift @outdir, ".." if $out;
  }
  if ($#newdir > $#olddir) {
    for ($i=$#olddir; $i < $#newdir; $i++) {
      unshift @outdir, "..";
    }
  }
  return join ('/', @outdir);
}
######################################################################
######################################################################
############
######################################################################
######################################################################

sub really_move_image {
  my $kimage = $_[0];
  my $image_dest = $_[1];

  if (-e "$kimage-$version") {  # we should be in dir /, normally
    rename("$kimage-$version", "$kimage-$version.$$") ||
      die "failed to move " . $image_dest . "$kimage:$!";
  }
  my $ret = system("mv -f " . $realimageloc . "$kimage-$version " .
                   " $kimage-$version");
  if ($ret) {
    die("Failed to move " . $realimageloc . "$kimage-$version to "
        . $image_dest . "$kimage-$version.\n");
  }
  # Ok, now we may clobber the previous .old files
  if (-e "$kimage-$version.$$") {
    rename("$kimage-$version.$$", "$kimage-$version.old") ||
      die "failed to move " . $image_dest . "$kimage:$!";
  }
  if ($reverse_symlink) {
    my $Old = $image_dest;
    if (test_relative ('Old Dir' => $Old, 'New Dir' => $realimageloc,
                      'Test File' => "$kimage-$version")) {
      $Old   =~ s|^/*||o;
    } elsif ($relative_links) {
      $Old = spath('Old' => "$Old", 'New' => "$realimageloc" );
    }
    if ($use_hard_links =~ m/YES/i) {
      link($Old . "$kimage-$version",
           $realimageloc . "$kimage-$version")
        || die("Failed to symbolic-link " . $image_dest .
               "$kimage-$version to " . $realimageloc .
               "$kimage-$version .\n");
    } else {
      symlink($Old . "$kimage-$version",
              $realimageloc . "$kimage-$version")
        || die("Failed to link " . $image_dest .
               "$kimage-$version to " . $realimageloc .
               "$kimage-$version .\n");
    }
  }
}

# This routine is responsible for setting up the symbolic links.
sub image_magic {
  my $kimage = $_[0];   # Nmae of the symbolic link
  my $image_dest = $_[1];       # The directory the links goes into

  # Well, in any case, if the destination (the symlink we are trying
  # to create) is a directory, we should do nothing, except throw a
  # diagnostic.
  if (-d "$kimage" ) {
    die ("Hmm. $kimage is a directory, which I did not expect.  I am\n" .
         "trying to create a symbolic link with that name linked to \n" .
         "$image_dest . Since a directory exists here, my assumptions \n" .
         "are way off, and I am aborting.\n" );
    exit (3);
  }


  if ($move_image)
    {     # Maybe $image_dest is in on dos, or something?
      really_move_image($kimage, $image_dest);
      return;
    }


  if (-l "$kimage")
    {  # There is a symbolic link
      my $force_move = 0;

      if ($no_symlink || $reverse_symlink)
        {       # we do not want links, yet we have a symbolic link here!
          warn "found a symbolic link in " . $image_dest . "$kimage \n" .
            "even though no_symlink is defined\n" if $no_symlink;
          warn "found a symbolic link in " . $image_dest . "$kimage \n" .
            "even though reverse_symlink is defined\n" if $reverse_symlink;
          # make sure we change this state of affairs
          $force_move = 1;
        }
      else
        {
          # OK. We found symlink, and we should have a symlink here.
          my $vmlinuz_target = readlink "$kimage";
          my $target = CanonicalizePath("$realimageloc" . "$kimage-$version");

          if (!defined($vmlinuz_target))
            {   # what, a dangling symlink?
              warn "The link "  . $image_dest . "$kimage is a dangling link\n";
              $force_move = 1;
            }
          else
            {                   # Found where the link points to
              my $cwd;
              chomp ($cwd=`pwd`);
              if ($vmlinuz_target !~ m|^/|o)
                {
                  $vmlinuz_target = $cwd . "/" . $vmlinuz_target;
                  $vmlinuz_target =~ s|/+|/|o;
                }
              $vmlinuz_target = CanonicalizePath($vmlinuz_target);
              if ("$vmlinuz_target" ne "$target")
                {
                  if ($minimal_swap) 
                    {
                      if (-l "$kimage.old")
                        {
                          my $old_target = readlink "$kimage.old";
                          if ($old_target !~ m|^/|o)
                            {
                              $old_target = $cwd . "/" . $old_target;
                              $old_target =~ s|/+|/|o;
                            }
                          $old_target = CanonicalizePath($old_target);
                          if ("$old_target"  ne "$target")
                            {
                              $force_move = 1;
                            }
                          else
                            {
                              warn "$kimage.old --> $target -- doing nothing";
                              $force_move = 0;
                            }
                        }
                      else
                        {
                          $force_move = 1;
                        }
                    }
                  else 
                    {
                      $force_move = 1;
                    }
                }
              else
                {
                  warn "$vmlinuz_target points to $target -- doing nothing";
                  $force_move = 0;
                }
            }
        }
      if ($force_move)
        {      # don't clobber $kimage.old quite yet
          rename("$kimage", "$kimage.$$") ||
            die "failed to move " . $image_dest . "$kimage:$!";
          my $Old = $realimageloc;
          my $cwd;
          chomp($cwd=`pwd`);
          if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
                             'Test File' => "$kimage-$version"))
            {
              $Old   =~ s|^/*||o;
            }
          elsif ($relative_links)
            {
              $Old = spath('Old' => "$Old", 'New' => $cwd);
            }
          if ($use_hard_links =~ m/YES/i)
            {
              if (! link($Old . "$kimage-$version", "$kimage"))
                {
                  rename("$kimage.$$", "$kimage");
                  die("Failed to link " . $realimageloc .
                      "$kimage-$version to "  . $image_dest . "$kimage .\n");
                }
            }
          else
            {
              if (! symlink($Old . "$kimage-$version", "$kimage"))
                {
                  rename("$kimage.$$", "$kimage");
                  die("Failed to symbolic-link " . $realimageloc .
                      "$kimage-$version to " . $image_dest . "$kimage .\n");
                }
            }

          # Ok, now we may clobber the previous .old file
          if (-l "$kimage.old" || ! -e "$kimage.old" )
            {
              rename("$kimage.$$", "$kimage.old");
            }
          else
            {
              warn "$kimage.old is not a symlink, not clobbering\n";
              unlink "$kimage.$$";
            }
        }
    }
  elsif (! -e "$kimage")
    {
      # Hmm. Pristine system? How can that be?
      # Possibly they do not want a link here. (we should be in /
      # here[$image_dest, really]
      warn "$image_dest" .
        "$kimage does not exist. Installing from scratch, eh?\n";
      warn "Or maybe you don't want a symbolic link here. Hmm? Lets See.\n";
      if ($no_symlink) {
        my $ret = system("cp -a --backup=t " . $realimageloc .
                         "$kimage-$version "   . " $kimage");
        if ($ret)
          {
            die("Failed to copy " . $realimageloc . "$kimage-$version to "
                . $image_dest . "$kimage .\n");
          }
      }
      elsif ($reverse_symlink)
        {
          my $ret = system("mv -f " . $realimageloc . "$kimage-$version "
                           . "$kimage");
          if ($ret)
            {
              die("Failed to move " . $realimageloc . "$kimage-$version to "
                  . $image_dest . "$kimage .\n");
            }
        }
      else
        {
          if (! $have_conffile)
            {
              my $answer='';
              $do_symlink = "Yes";
              print STDERR "I notice that you do not have $kimage symbolic\n";
              print STDERR "link. I can create one for you, and it shall be\n";
              print STDERR "updated by newer kernel image packages. This is\n";
              print STDERR "useful if you use a boot loader like lilo.\n";
              print STDERR "Do you want me to create a link from " .
                $realimageloc . "$kimage-$version to $kimage?[Yn] ";
              $answer=<STDIN>;
              $answer =~ s/^\s+//;
              $answer =~ s/\s+$//;
              $do_symlink = "No" if $answer =~ /n/i;

              if (open(CONF, ">$CONF_LOC"))
                {
                  print CONF "# Kernel Image management overrides\n";
                  print CONF "# See kernel-img.conf(5) for details\n";
                  if ($loader =~ /palo/i)
                    {
                      print CONF "link_in_boot = Yes\n";
                      print CONF "do_symlinks = Yes\n";
                      print CONF "relative_links = Yes\n";
                      print CONF "do_bootfloppy = No\n";
                      print CONF "do_bootloader = No\n";
                    }
                  else
                    {
                      print CONF "do_symlinks = $do_symlink\n";
                    }
                  close CONF;
                }
              $have_conffile = "Yes";
            }
        }

      if (! $no_symlink && $do_symlink =~ /Yes/i)
        {
          if ($reverse_symlink)
            {
              my $Old = $image_dest;
              if (test_relative ('Old Dir' => $Old,
                                 'New Dir' => $realimageloc,
                                 'Test File' => "$kimage"))
                {
                  $Old   =~ s|^/*||o;
                }
              elsif ($relative_links)
                {
                  $Old = spath('Old' => "$Old", 'New' => $realimageloc);
                }
              symlink($Old . "$kimage", $realimageloc . "$kimage-$version")
                || die("Failed to symbolic-link " . $realimageloc
                       . "$kimage-$version to " . $image_dest . "$kimage .\n");
            }
          else
            {
              my $Old = $realimageloc;
              if (test_relative ('Old Dir' => $Old,
                                 'New Dir' => $image_dest,
                                 'Test File' => "$kimage-$version"))
                {
                  $Old   =~ s|^/*||o;
                }
              elsif ($relative_links)
                {
                  $Old = spath('Old' => "$Old", 'New' => $image_dest);
                }
              symlink($Old . "$kimage-$version", "$kimage") ||
                die("Failed to symbolic-link " . $realimageloc
                    . "$kimage-$version to "  . $image_dest . "$kimage .\n");
            }
        }
    }
  elsif (-e "$kimage" && $no_symlink)# OK, $kimage exists -- but is not a link
    {           # Maybe /$image_dest is on a dos system?
      rename("$kimage", "$kimage.$$") ||
        die "failed to move " . $image_dest . "$kimage:$!";

      my $ret = system("cp -a --backup=t " . $realimageloc
                       . "$kimage-$version " . "$kimage");

      if ($ret)
        {
          if (-e "$kimage.$$") { rename("$kimage.$$", "$kimage"); }
          die("Failed to copy " . $realimageloc . "$kimage-$version to "
              . $image_dest . "$kimage .\n");
        }

      # Ok, now we may clobber the previous .old files
      if (-e "$kimage.$$") { rename("$kimage.$$", "$kimage.old");  }
    }
  elsif (-e "$kimage" && $reverse_symlink)
    {  # Maybe /$image_dest is on a dos system?
      rename("$kimage", "$kimage.$$") ||
        die "failed to move " . $image_dest . "$kimage:$!";
      my $ret = system("mv -f " . $realimageloc . "$kimage-$version "
                       . $image_dest . "$kimage");
      if ($ret)
        {
          if (-e "$kimage.$$") {rename("$kimage.$$", "$kimage");}
          die("Failed to move " . $realimageloc . "$kimage-$version to "
              . $image_dest . "$kimage .\n");
        }

      my $Old = $image_dest;
      if (test_relative ('Old Dir' => $Old, 'New Dir' => $realimageloc,
                         'Test File' => "$kimage"))
        {
          $Old   =~ s|^/*||o;
        }
      elsif ($relative_links)
        {
          $Old = spath('Old' => "$Old", 'New' => $realimageloc);
        }
      if ($use_hard_links =~ m/YES/i)
        {
          if (! link($Old . "$kimage", $realimageloc . "$kimage-$version"))
            {
              warn "Could not link " . $image_dest .
                "$kimage to $kimage-$version :$!";
            }
        }
      else
        {
          if (! symlink($Old . "$kimage", $realimageloc . "$kimage-$version"))
            {
              warn "Could not symlink " . $image_dest .
                "$kimage to $kimage-$version :$!";
            }
        }

      # Ok, now we may clobber the previous .old files
      if (-e "$kimage.$$") { rename("$kimage.$$", "$kimage.old");}
    }
  elsif (-f "$kimage" && $use_hard_links =~ m/YES/i )
    {
      # Ok then. this ought to be a hard link, and hence fair game
      # don't clobber $kimage.old quite yet
      rename("$kimage", "$kimage.$$") ||
        die "failed to move " . $image_dest . "$kimage:$!";
      my $Old = $realimageloc;
      my $cwd;
      chomp($cwd=`pwd`);
      if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
                         'Test File' => "$kimage-$version")) {
        $Old   =~ s|^/*||o;
      }
      elsif ($relative_links)
        {
          $Old = spath('Old' => "$Old", 'New' => $cwd);
        }
      if (! link($Old . "$kimage-$version", "$kimage"))
        {
          rename("$kimage.$$", "$kimage");
          die("Failed to link " . $realimageloc . "$kimage-$version to "
              . $image_dest . "$kimage .\n");
        }

      # Ok, now we may clobber the previous .old file
      rename("$kimage.$$", "$kimage.old");
    }
}

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

if ( -f "$modules_base/$version/modules.dep" ) {
  my $running = '';
  chop($running=`uname -r`);
  if ($running eq $version) {
    print STDERR <<"EOFERR";

 You are attempting to install a kernel version that is the same as
 the version you are currently running (version $running). The modules
 list is quite likely to have been changed, and the modules dependency
 file $modules_base/$version/modules.dep needs to be re-built. It can
 not be built correctly right now, since the module list for the
 running kernel are likely to be different from the kernel installed.
 I am creating a new modules.dep file, but that may not be
 correct. It shall be regenerated correctly at next reboot.

 I repeat: you have to reboot in order for the modules file to be
 created correctly. Until you reboot, it may be impossible to load
 some modules. Reboot as soon as this install is finished (Do not
 reboot right now, since you may not be able to boot back up until
 installation is over, but boot immediately after). I can not stress
 that too much. You need to reboot soon.

EOFERR
  ;
    if ($silent_modules !~ m/YES/i) {
      my $answer='';
      print "Please Hit return to continue.  ";
      $answer=<STDIN>;
    }
  }
}

# We may not have any modules installed
if ( -d "$modules_base/$version" ) {
  my $ret = system("depmod -a -F $realimageloc/System.map-$version $version");
  my $exit_value  = $? >> 8;
  my $signal_num  = $? & 127;
  my $dumped_core = $? & 128;
  if ($ret) {
    if ( -f "$modules_base/$version/modules.dep") {
      unlink "$modules_base/$version/modules.dep" unless $initrd;
    }
    print "There was a problem running depmod.  This may be benign, \n";
    print "(You may have versioned symbol names, for instance).\n";
    print "Or this could be an error.\n";
    print "\tdepmod exited with return value $exit_value\n";
    print "\tdepmod got a signal $signal_num \n" if $signal_num ;
    print "\tdepmod dumped core \n" if $dumped_core ;
    if ($initrd) {
      print "Since this image uses initrd, I am not deleting the file\n";
      print "$modules_base/$version/modules.dep. However, there is no\n";
      print "guarantee that the file is valid. I would strongly advice\n";
      print "you to either abort and fix the errors in depmod, or \n";
      print "regenerate the initrd image with a known good modules.dep\n";
      print "file. I repeat, an initrd kernel image with a bad modules.dep\n";
      print "shall fail to boot.\n";
    }
    else {
      print "In any case, since depmod is run at install time, \n";
      print "we could just defer running depmod\n";
    }

    if (! $ignore_depmod_err) {
      if (&ask( "Would you like to abort now")) {
        exit (1);
      }
      else {
        print STFERR "Ok, continuing as directed\n";
      }
    }
  }
}



# The initrd symlink should probably be in the same dir that the
# symlinks are in
if ($initrd) {
  my $initrd_path = $realimageloc . "initrd.img-$version";
  my $ret = system("mkinitrd " .
                   ($mkimage ? "-m '$mkimage' " : "") .
                   "-o $initrd_path.new $modules_base/$version");
  die("Failed to create initrd image.\n") if $ret;
  rename("$initrd_path.new", "$initrd_path")
    or die("Failed to rename initrd ($initrd_path)\n");

  if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
    image_magic("initrd.img", $image_dest) if $initrd;
  }
  else {
    print STDERR "Not touching initrd symlinks since we are being reinstalled ($ARGV[1])\n";
  }

  if ($initrd && -l "initrd" ) {
    print STDERR <<"EOIMG";

I note that you have an old initrd symbolic link in place. The name of
the symbolic link is being changed to initrd.img I have two options
here.  I can: (A) delete the old symbolic link (default).  You shall
need to update the boot loader (b) Igore it and do nothing

EOIMG
  ;
   my $answer='';
    print "Please select one of a, or b: ";
    $answer=<STDIN>;
    $answer =~ s/^\s+//;
    $answer =~ s/\s+$//;
    if ($answer =~ /^\s*a/i) {
      unlink "initrd";
    }
    else {
      print STDERR
        "Please note that initrd points to the wrong image now\n";
    }
  }

  if ($initrd && -l "$image_dir/initrd" && ! $link_in_boot) {
    print STDERR <<"EOIMG";
I note that you have an old $image_dir/initrd symbolic link in place.
The location of the symbolic link is now the same location as the kernel
image symbolic links, names, in $image_dest.  I have two options here.
I can:
 (A) delete the old symbolic link (default).  You shall need to update the
      boot loader
 (b) Igore it and do nothing
EOIMG
  ;
    my $answer='';
    print "Please select one of a, or b: ";
    $answer=<STDIN>;
    if ($answer =~ /^\s*a/i) {
      unlink "$image_dir/initrd";
    }
    else {
      print STDERR
        "Please note that $image_dir/initrd points to the wrong image now\n";
    }
  }
}
else {                          # Not making an initrd emage
  if (-l "initrd.img") {
    # Ooh, last image was an initrd image? in any case, we should move it. 
    my $target = readlink "initrd.img";
    if (!defined($target)){
      # Eh. dangling link. can safely be removed.
      unlink("initrd.img");
    }
    else {
      if (-l "initrd.img.old" || ! -e "initrd.img.old" )      {
        rename("initrd.img", "initrd.img.old");
      }
      else      {
        warn "initrd.img.old is not a symlink, not clobbering\n";
        unlink("initrd.img");
      }
    }

  }
}

# Only change the symlinks if we are not being upgraded
if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
  image_magic($kimage, $image_dest);
}
else {
  print STDERR "Not updating image symbolic links since we are being updated ($ARGV[1])\n";
}

# We used to have System.* files in /
if (-e "/System.map" || -e "/System.old") {
  print STDERR <<"EOMAP";
 I notice that you have System.map symbolic links in /. These were
 installed by older kernel image packages. However, all the programs
 that look at the information in the map files (including top, ps, and
 klogd) also will look at /boot/System.map-<version>, we just need to
 ensure that that file is present, and no longer require the symbolic
 link.

 Actually, having the symbolic link in / is technically detrimental
 (apart from cluttering up /); many programs, though looking in /boot,
 still allow /System.map to override. If you use $Loader to choose
 between multiple kernels, then the /System.map symbolic link only
 applies to one such kernel, for all other choices the symbols loaded
 will be wrong. Not having the symbolic links at all prevents this.

 I can delete these symbolic links for you, if you wish.
EOMAP
  ;
  if ( &ask_y("Would you like to delete the obsolete links now" ) ) {
    unlink '/System.map' if -e '/System.map';
    unlink '/System.old' if -e '/System.old';
    print STFERR "Obsolete links removed.\n";
  }
  else {
    print STFERR
      "Ok, not deleting the files. Please remember to remove them manually.\n";
  }
}

my $linktarget;
$linktarget = "../share/doc/=ST-image-$version";


## Run user hook script here, if any
if (-x "$postinst_hook") {
    system ("$postinst_hook", $version, $realimageloc . "$kimage-$version") &&
        warn "User hook script $postinst_hook failed";
}

if (-d "/etc/kernel/postinst.d") {
  system ("run-parts", "--verbose", "--exit-on-error", "--arg=$version",
          "--arg=$realimageloc" . "$kimage-$version",
          "/etc/kernel/postinst.d") &&
            die "Failed to process /etc/kernel/postinst.d";
}

if (-d "/etc/kernel/postinst.d/$version") {
  system ("run-parts", "--verbose", "--exit-on-error", "--arg=$version",
          "--arg=$realimageloc" . "$kimage-$version",
          "/etc/kernel/postinst.d/$version") &&
            die "Failed to process /etc/kernel/postinst.d/$version";
}


exit (0) unless $do_boot_enable;        # Exit if explicitly asked to

if ($loader =~ /noloader/io) {
    print STDERR << "MSGEND";
I have determined no bootloader is required for your architecure.  This is
either because there is no boot loader for your architecture, or because I
did not change anything that would cause the boot loader to be run.  However,
I could be wrong, and, if that is the case, I would appreciate it if you would
please report a bug against the kernel-package package.

Done.
MSGEND
;
    exit (0);
}


exit (0) if $loader =~ /silo/i; # SILO does not have to be executed.
exit (0) if $loader =~ /yaboot/i; # yaboot does not have to be executed.
exit (0) if $loader =~ /milo/i; # MILO does not have to be executed.
exit (0) if $loader =~ /nettrom/i; # NETTROM does not have to be executed.
exit (0) if $loader =~ /arcboot/i; # ARCBOOT does not have to be executed.
exit (0) if $loader =~ /delo/i; # DELO does not have to be executed.
if ($official_image =~ /^\s*YES\s*$/o) {
  exit (0) if $loader =~ /quik/i; # maintainer asked quik invocation to be ignored
}

exit (0) unless $loaderloc;


undef $rootdevice;
undef $rootdisk;
undef $rootpartition;
undef $bootdevice;

open(FSTAB, "</etc/fstab") || die "Could not open /etc/fstab:$!";

my $line = '';
while ( $line=<FSTAB> ) {
  my $device;
  my $filesystem;
  my $ftype;
  my $foption;
  my $islilo;

  if ( $line =~ m/^\#/ ) {
    next;
  }

  # ignore leading spaces.
  $line =~ s/^\s+//og;

#  ($device,$filesystem)=split(/[ \t]+/, $line);
  ($device,$filesystem,$ftype,$foption)=split(/[ \t]+/, $line);

  if ($device =~ m/^(LABEL|UUID)=/) {
    # Hmm. using labels in fstab.
    $device = `mount -nfv $device 2>/dev/null`;
    chomp($device);
    $device =~ s/ on\s+.*$//g;
    next if $device =~ m|^\s*$|;
  }

  next unless $device =~ m|^/dev/|; #ignore NFS and proc systems

  next if $device =~ m|^/dev/fd|;   #ignore floppy drives
  next if $device =~ m|^/dev/pty|;  #ignore Pseudo-TTY masters
  next if $device =~ m|^/dev/tty|;  #ignore Pseudo-TTY slaves
  next if $device =~ m|^/dev/cu|;   #ignore obsolete device
  next if $device =~ m|^/dev/lp|;   #ignore printers
  next if $device =~ m|^/dev/vcs|;  #ignore Virtual console capture

  next if $filesystem =~ m|^none$|; #swap? in any case, do not run dd
  next if $ftype      =~ m|^none$|; #ignore unknown file types
  next if $foption    =~ m|noauto|; #any FS not mounted at bootup time
  next if $foption    =~ m|bind|;   #ignore bind mounts

  # Looking at linux/Documentation/devices.txt, We see that really we
  # should be looking for /dev/hd* (hard disk),  /dev/sd*. What about
  # metadisk devices? ram drives? I think I'll just leave this mess
  # well enough alone.

  if ( $filesystem =~ m!^/$! ) {
    $rootdevice = $device;
  }
  unless ($loader =~ /vmelilo/io) {
    $islilo=`dd if=$device ibs=1 skip=2 count=4 2>/dev/null`;
    if ($islilo =~ /$Loader/o) {
      $bootdevice = $device;
    }
  }
  if (defined($rootdevice) && defined($bootdevice)) {
    last;
  }
}
close(FSTAB);

if (! defined($rootdevice)) {
  my $answer;
  print "Could not find where the current root file system is mounted!\n";
  print "Please make some arrangements for your system to boot the new\n";
  print "kernel (like running LILO, loadlin, SILO, QUIK, VMELILO, or  \n";
  print "getting a boot floppy).                                      \n";
  print "Please hit return to continue.                               \n";
  $answer = <STDIN>;
  exit (0);
}
else {
  $rootdisk = $rootdevice;
  $rootdisk =~ s/[0-9]+$//;
  $rootpartition = $rootdevice;
  $rootpartition =~ s/$rootdisk//;
}

print "A new kernel image has been installed, and usually that means  \n";
print "that some action has to be taken to make sure that the new     \n";
print "kernel image is used next time the machine boots. Usually,     \n";
print "this entails running a ``bootloader'' like SILO, loadlin, LILO,\n";
print "ELILO, QUIK, VMELILO, ZIPL, or booting from a floppy.   (Some  \n";
print "boot loader, like grub, for example, do not need to be run on  \n";
print "each new image install, so please ignore this if you are using \n";
print "such a boot loader).\n\n";

if ( ! -x "$loaderloc" ) {
  print "Hmm. $Loader";
  printf " (LInux LOader)"                     if $loader =~ /^lilo/i;
  printf " (Efi LInux LOader)"                 if $loader =~ /^elilo/i;
  printf " (Sparc Improved Linux lOader)"      if $loader =~ /^silo/i;
  printf " (QUIK: PowerMac Boot Loader)"       if $loader =~ /^quik/i;
  printf " (yaboot: PowerMac Boot Loader)"     if $loader =~ /^yaboot/i;
  printf " (PALO: PA-RISC Boot Loader)"        if $loader =~ /^palo/i;
  printf " (VMELILO: m68k VME Boot Loader)"    if $loader =~ /^vmelilo/i;
  printf " (ZIPL: s390 & zSeries Boot Loader)" if $loader =~ /^zipl/i;
  printf " (ARCBOOT: MIPS SGI IP22  Boot Loader)" if $loader =~ /^arcboot/i;
  printf ", which is the boot loader I    \n";
  print "have additional help for, is not installed (it is, after all,\n";
  print "just one of many options). I am assuming you have made some  \n";
  print "other arrangements for your system to boot the new kernel.   \n";
  print "Please hit return to continue.                               \n";
  my $answer = <STDIN>;
  exit (0) unless defined $rootdevice;
  exit (0) if $loader =~ /^silo/i; # No idea how to make non SILO floppies
  exit (0) if $loader =~ /^quik/i;
  exit (0) if $loader =~ /^yaboot/i;
  exit (0) if $loader =~ /^palo/i; # No such thing as PALO floppies
  exit (0) if $loader =~ /^vmelilo/i;
  exit (0) if $loader =~ /^zipl/i;
  exit (0) if $loader =~ /^arcboot/i;

  if ($do_bootfloppy) {
    print "I can make a non-LILO diskette instead, but it won't be as useful.\n";

    if (&ask_y("Would you like to create a boot floppy now")) {
      &makefloppy();
    }
  }
  exit(0);
}

@boilerplate = (
    "compact\n",
    "install=/boot/boot.b",
    "\nmap=/boot/map\n",
    "vga=normal\n",
    "delay=20\n",
    "image=" . $image_dest . "$kimage\n",
    "label = Linux\n",
    "read-only\n"
);

@silotemplate = (
   "partition=$rootpartition\n",
   "root=$rootdevice\n",
   "timeout=100\n",
   "image=" . $image_dest . "$kimage\n",
   "\tlabel = Linux\n",
   "\tread-only\n",
   "other=1\n",
   "\tbootblock=" . $rootpartition .  "/boot/old.b\n",
   "\tlabel = oldsys\n"
                );

@quiktemplate = (
   "partition=$rootpartition\n",
   "root=$rootdevice\n",
   "timeout=100\n",
   "image=" . $image_dest . "$kimage\n",
   "\tlabel = Linux\n",
   "\tread-only\n",
   "other=1\n",
   "\tbootblock=" . $rootpartition .  "/boot/old.b\n",
   "\tlabel=oldsys\n"
                );

@palotemplate = (
   "# See /usr/share/doc/palo/README.html and run 'palo --help' for\n",
   "# more information\n\n",
   "# $rootdevice $rootdisk $rootpartition $bootdevice\n",
   "--init-partitioned=$rootdisk\n",
   "--bootloader=/usr/share/palo/iplboot\n",
   "--recoverykernel=" . $image_dest . "$kimage\n",
   "--commandline=$rootpartition" . $image_dest . "$kimage root=$rootdevice\n",
                );

@vmelilotemplate = (
  "default   = Linux\n",
  "delay     = 2\n",
  "\n",
  "[boot]\n",
  "label     = Linux\n",
  "image     = " . $image_dest . "$kimage\n",
  "read-only\n"
                );

@zipltemplate = (
  "[defaultboot]\n",
  "default=debian\n",
  "\n",
  "[debian]\n",
  "target=/boot\n",
  "image=" . $image_dest . "$kimage\n",
  "parmfile=/boot/parmfile\n"
                );

@arcboottemplate = (
    "label=arcdefault\n",
    "image=" . $image_dest . "$kimage\n",
);

if($loader =~ /^zipl/io)
  {
    $install_boot_method = "VM-reader or a boot tape";
  }
else
  {
    $install_boot_method = "a boot floppy";
  }


# creating some info about kernel and initrd
my $ksize=sprintf("%.0f",(stat($realimageloc .
                               "$kimage-$version"))[7]/1024)."kB";
my $initrdsize='';
if ($initrd) {
  $initrdsize=sprintf("%.0f",(stat($realimageloc .
                                   "initrd.img-$version"))[7]/1024)."kB";
}


print STDERR <<"EOMSG";
A new kernel image has been installed at $realimageloc$kimage-$version
 (Size: $ksize)

EOMSG
;

if ($initrd) {
  print STDERR <<"EOMSGA";

 Initial rootdisk image: ${realimageloc}initrd.img-$version (Size: $initrdsize)
EOMSGA
  ;
}

print STDERR <<"EOMSGB";

Symbolic links, unless otherwise specified, can be found in $image_dest

$Loader sets up your system to boot Linux directly from your hard
disk, without the need for booting from $install_boot_method.

EOMSGB
;

if ($do_bootloader) {
  print STDERR <<"EOMSGC";

WARNING
If you are keeping another operating system or another version
of Linux on a separate disk partition, you should not have $Loader
install a boot block now. Wait until you read the $Loader documentation.
That is because installing a boot block now might make the other
system un-bootable. If you only want to run this version of Linux,
go ahead and install the boot block here. If it does not work, you
can still boot this system from $install_boot_method.

EOMSGC
  ;
}

if ($do_bootfloppy) {
  if (&ask("Would you like to create a boot floppy now")) {
    &makefloppy();
  }
}

exit 0 unless $do_bootloader;


if (-T "/etc/$loader.conf") {
  # Trust and use the existing lilo.conf.
  print "You already have a $Loader configuration in /etc/$loader.conf\n";
  if ($silent_loader) {
    my $ret = &run_lilo();
    exit $ret;
  }
  elsif( &ask_y("Install a boot block using the existing /etc/$loader.conf")) {
    my $ret = &run_lilo();
    exit $ret;
  }
  elsif ($loader =~ /^elilo/io) {
    print "I don't know how to create an elilo.conf file from scratch,\n";
    print "sorry.  elilo can do that for you, if you invoke it with the\n";
    print "correct options.  Aborting.\n";
    exit(0);
  }
  else {
    if (&ask("Wipe out your old $Loader configuration and make a new one")){
      my $ret = system("savelog /etc/$loader.conf");
      if ($ret) {
        print "There was a problem saving a copy of your /etc/$loader.conf\n";
        print "Since this could have grave repercussions, I am aborting.\n";
        exit(0);
      }
    }
    else {
      exit (0);
    }
  }
}
elsif ($loader =~ /^elilo/io) {
  print "I don't know how to create an elilo.conf file from scratch,\n";
  print "sorry.  elilo can do that for you, if you invoke it with the\n";
  print "correct options.  Aborting.\n";
  exit(0);
}

if (! &ask_y("Do you wish to set up Linux to boot from the hard disk")) {
  exit (0);
}

if ($loader =~ /^lilo/io) {
  print <<EOF;

You must do three things to make the Linux system boot from the hard
disk. Install a partition boot record, install a master boot record,
and set the partition active. You will be asked to perform each of
these tasks. You may skip any or all of them, and perform them
manually later on
EOF
  ;

}

# If we get this far, we need to make a new lilo conf, and run lilo
&make_liloconf();

{ my $q;
  if ($loader =~ /vmelilo/io) {
    $q = "Install a boot block on $bootdevice";
  } else {
    $q = "Install a partition boot block on partition $bootdevice";
  }
  if (&ask_y($q)) {
    my $ret = &run_lilo();
    exit $ret if $ret;
  }
}

if ($loader =~ /^lilo/io) {
  print "\n";
  print "A master boot record is required to run the partition boot record.\n";
  if (-f "/boot/mbr.b") {
    print "If you are already using a boot manager, and want to keep it,\n";
    print "answer \"no\" to the following question. If you don't know\n";
    print "what a boot manager is or whether you have one, answer \"yes\".\n";
    if ( &ask_y("Install a master boot record (/boot/mbr.b) on $rootdisk")) {
      my $ret = system("dd if=/boot/mbr.b of=$rootdisk bs=444 count=1");
      if ($ret) {
        print "There was a problem copying the master boot record.\n";
        print "Please run \"dd if=/boot/mbr.b of=$rootdisk bs=444 count=1\"\n";
        print "by hand. Please hit return to continue.\n";
        my $ans = <STDIN>;
      }
    }
  }
  else {
    print "However, you do not have /boot/mbr.b, a common location of a \n";
    print "backup copy of the mbr.  I hope that your master boot record or \n";
    print "boot manager does boot the active partition.  If not, you have\n";
    print "to acquire the package mbr and install it. Please hit return to\n";
    print "proceed.\n";
    my $ans = <STDIN>;
  }
  print "\n";
  print "The master boot record will boot the active partition.\n";
  print "If you want your system to boot another operating system,\n";
  print "such as DOS or Windows, by default, answer \"no\" to the following\n";
  print "question. You may still use your boot manager or the master\n";
  print "boot record to boot Linux. If you want the system to boot Linux.\n";
  print "by default, answer \"yes\".\n";
  if ( &ask_y("Make $rootdevice the active partition") ) {
    my $ret = system("/sbin/activate $rootdisk $rootpartition");
    if ($ret) {
      print "There was an error trying to activate $rootdevice.\n";
      print "Please run \"/sbin/activate $rootdisk $rootpartition\"\n";
      print "by hand. Please hit return to proceed.\n";
      my $ans = <STDIN>;
    }
  }
  else {
    print "\n";
    print "OK. If you installed the master boot record, and the partition\n";
    print "boot record, you may boot Linux by holding down the shift key\n";
    print "as the system boots, and then pressing the $rootpartition key\n";
    print "when you see the \"1234F:\" prompt.\n";
    print "";
    print "For more information, see /usr/share/doc/mbr/README, and the files\n";
    print "in the /usr/share/doc/$loader directory.\n";
  }
}
else {
  if (-f "/boot/old.b") {
    print "$loader has overwritten the original boot loader and saved it under\n";
    print "/boot/old.b.  You can boot your old system (if any) using the\n";
    print "oldsys label at the $loader prompt.\n";
  }
}

sub ask {
  my $answer;
  print @_,"? [No] ";
  $answer=<STDIN>;
  return ( $answer =~ /^\s*y/i );
}

sub ask_y {
  my $answer;
  print @_,"? [Yes] ";
  $answer=<STDIN>;
  return ( $answer !~ /^\s*n/i );
}

sub makefloppy {
  my $answer;
  my $done = 0;
  my $drive = 0;
  my $imageloc = '';

  return unless $do_bootfloppy;

  if ($no_symlink || $reverse_symlink) {
    $imageloc = $image_dest . $kimage;
  }
  else {
    $imageloc = $realimageloc . "$kimage-$version";
  }

  if (-e $imageloc) {
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
        $atime,$mtime,$ctime,$blksize,$blocks)
      = stat ($imageloc);
    if ($size >= 520192) {
      print STDERR "Please note that the system size is $size\n";
      print STDERR "This is greater than the size that the kernel\n";
      print STDERR "loader supports on i386 machines. What this\n";
      print STDERR "means is that you need to use lilo to boot\n";
      print STDERR "this kernel on i386 machines; the floppy is\n";
      print STDERR "not going to be sufficient by itself on an \n";
      print STDERR "i386 box. Of course, things may have changed since\n";
      print STDERR "July 2000, when this diagnostic was written. Your\n";
      print STDERR "Mileage may indeed vary. Please consider yourselves\n";
      print STDERR "warned.\n";
      print STDERR "Please hit return to continue.";
      $answer=<STDIN>;
    }
  }
  else {
    print STDERR "Ulp!. I couldn't find the image where I expected\n";
    print STDERR "it to be, namely, $imageloc\n";
    print STDERR "You shall have to create the floppy manually, I'm\n";
    print STDERR "afraid, using commands like\n";
    print STDERR "\tdd if=/path/to/$kimage-$version of=/dev/fd$drive\n";
    print STDERR "\trdev /dev/fd$drive $rootdevice\n";
    print STDERR "\trdev -R /dev/fd$drive 1\n";
    print STDERR "Aborting\n";
    return;
  }


  print <<EO_MSG_A;

This process needs a formatted floppy. Please note that an unformatted
floppy will cause this process to fail, and may well need a reboot to
fix, and unfortunately, the system is not bootable yet.

The first thing to determine is which floppy drive you wish to use.
For most people, the default, which is the the default floppy drive,
referred to as /dev/fd0, or A: would work.  Some people may want the
second floppy drive which is drive 1, or /dev/fd1, or B:.
(Theoretically there could be 8 floppy drives on a machine) If
in doubt, accept the default [0], which should work in most cases.

EO_MSG_A
  ;

  print "Which floppy drive [0-7] do you want to use? [0] ";
  $answer=<STDIN>;
  if ($answer =~ m/^\s*(\d+)\s*$/) {
    $drive = $1;
  }
  print "\nOk, using drive at /dev/fd$drive.\n\n";

  if (-x "/usr/bin/superformat") {
      print "If there is no formatted floppy available, I could attempt\n";
      print "to format it for you.\n";
      if (&ask("Do you wish me to format the floppy")){
         my $ret;
         my $format_command = '/usr/bin/superformat';

         print "Insert a floppy diskette into your boot drive \n";
         print "(/dev/fd$drive) and press <Return> when ready:";
         $answer=<STDIN>;
        FMTFLOPPY: while (! $done) {
         DOFORMAT:{
              $ret = system $format_command, "/dev/fd$drive";
              last DOFORMAT if $ret;
              $done = 1;
           }
           if (! $done) {
             print <<EO_MSG_B;

There was a problem formatting the floppy diskette in /dev/fd$drive

Please make sure that you inserted the disk in the correct drive and
that the disk is not write-protected.  Also, you may have to run
setfdprm for fdformat to work.

In some rare cases, it may mean a problem with the Floppy or the drive
it self (try formatting the floppy with
      % $format_command  /dev/fd$drive
manually to make sure if the problem persists).  In case the problem
persists, it maybe because you have an older fdformat which has a
problem auto- detecting the floppy drive.  Upgrading to the latest
fdutils may help, or maybe you need to run
      % setfdprm /dev/fd$drive 1440/1440
(or something like that) or you may try some thing like
      % $format_command  /dev/fd0H1440
 or even
      % $format_command  /dev/fd0u1440
manually which _may_ work. Or else, try a new floppy.

EO_MSG_B
  ;


             if (! &ask_y("Would you like to try again")) {
                print "\n";
                print "If there are no pre-formatted floppies available, \n";
                print "you should stop right here. \n";
                if (! &ask_y("Do you have a blank pre-formatted floppy")){
                  print "Ok, aborting.\n";
                  print "\n";
                  return 1;
                }
                print "\n";
                last FMTFLOPPY;
             }
           }
         }
      }
  }
  else {
       print "If there are no pre-formatted floppies available, you\n";
       print "should stop right here. \n";
      if (! &ask_y("Do you have a blank pre-formatted floppy")){
        print "Ok, aborting.\n";
        return 1;
      }
  }
  if (!$done) {
      print "\n";
      print "Insert a (formatted) floppy diskette into your boot drive\n";
      print "(/dev/fd$drive) and press <Return> when ready:";
      $answer=<STDIN>;
  }
  $done=0;
  while (! $done) {
  MKBOOT:{
      my $ret;

      if ($loader =~ /^lilo/io) {
        if (-e "$imageloc") {
          $ret = system '/bin/dd', "if=$imageloc", "of=/dev/fd$drive";
          last MKBOOT if $ret;
          $ret = system '/usr/sbin/rdev', "/dev/fd$drive", "$rootdevice";
          last MKBOOT if $ret;
          $ret = system '/usr/sbin/rdev', '-R', "/dev/fd$drive", '1';
        }
        else {
          print STDERR "Ulp!. I couldn't find the image where I expected\n";
          print STDERR "it to be, namely, $imageloc\n";
          print STDERR "You shall have to create the floppy manually, I'm\n";
          print STDERR "afraid, using commands like\n";
          print STDERR "\tdd if=/path/to/$kimage-$version of=/dev/fd$drive\n";
          print STDERR "\trdev /dev/fd$drive $rootdevice\n";
          print STDERR "\trdev -R /dev/fd$drive 1\n";
          print STDERR "Aborting\n";
          return;
        }
      }
      else {
        $ret = &silo_floppy( $drive );
      }
      last MKBOOT if $ret;
      $done = 1;
      print "\n";
    }
    if (! $done) {
      print "\nThere was a problem creating the boot diskette in \n";
      print "/dev/fd$drive\n.";
      print "Please make sure that you inserted the diskette into the\n";
      print "correct drive and that the diskette is not write-protected.\n";
      print "In some rare cases, it may mean a problem with the\n";
      print "Floppy or the drive it self.\n";
      if (! &ask_y("Would you like to try again")) {
        $done = 1;
      }
      else {
        # don't display the next message if no more tries
        print "\n";
        print "Insert a (formatted) floppy diskette into your boot drive\n";
        print "/dev/fd$drive and press <Return> when ready:";
        $answer=<STDIN>;
      }
    }
  }
}

sub silo_floppy {
  my $drive = shift;
  my $mountpoint = "/var/lib/kernel.mntpoint.$$";
  my $ret = system '/sbin/mke2fs', "/dev/fd$drive";
  return $ret if $ret;
  $ret = mkdir $mountpoint, 0755;
  return $ret if $ret;
  $ret = system '/bin/mount', '-t', 'ext2', "/dev/fd$drive", $mountpoint;
  do { rmdir $mountpoint; return $ret } if $ret;
  do {
    mkdir $mountpoint . "/boot", 0755;
    last unless system '/bin/cp', '/boot/first.b', $mountpoint . '/boot';
    last unless system '/bin/cp', '/boot/second.b', $mountpoint . '/boot';
    if ($no_symlink || $reverse_symlink) {
      $ret = system '/bin/cp', $image_dest . $kimage, $mountpoint . '/linux';
    }
    else {
      $ret = system '/bin/cp', "$realimageloc" . "$kimage-$version",
                       $mountpoint . '/linux';
    }
    last if $ret;
    mkdir( $mountpoint . "/etc", 0755 ) || last;
    open SILO, ">$mountpoint/etc/silo.conf" || last;
    print SILO
       "partition=1\n",
       "root=/dev/fd$drive\n",
       "read-write\n",
       "timeout=100\n",        # 10s
       "image = /linux\n",
       "\tlabel = Linux\n",
       "\tappend=root=$rootdevice\n";
    close SILO;
    $ret = system '/sbin/silo', '-r', $mountpoint;
  };
  system '/bin/umount', $mountpoint;
  rmdir $mountpoint;
  return $ret;
}


sub make_liloconf {
  # Create a lilo.conf if one doesn't exist.
  print STDERR "I'll try and create a bootloader configuration filefor \n";
  print STDERR "$loader. However, please note that this is merely a best\n";
  print STDERR "effort attempt, the file /etc/$loader.conf should really\n";
  print STDERR "be checked by a human.\n";

  if (!defined($bootdevice)) {
    if ($loader =~ /vmelilo/io) {
      print "\nPutting the boot record on to $rootdisk which is\n";
      print "the device where the root file system lives.\n\n";
      $bootdevice = $rootdisk;
    }
    else {
      print "\nHmm... I can't determine which partition to put the \n";
      print "partition boot record on. I'm defaulting to the $rootdevice\n";
      print "which is where the root file system lives.\n";
      $bootdevice = $rootdevice;
    }
  }

  open(CONF, ">/etc/$loader.conf");
  if ($loader =~ /^lilo/io) {
    print CONF "boot=".$bootdevice, "\n", "root=".$rootdevice, "\n",
               @boilerplate;
    if ($initrd) {
      print CONF "initrd=" . $image_dest . "initrd.img\n";
    }
  }
  elsif ($loader =~ /^vmelilo/io) {
    print CONF "boot      = $bootdevice\n",
               "root      = $rootdevice\n",
               @vmelilotemplate;
  }
  elsif ($loader =~ /^quik/io) {
    print CONF @quiktemplate;
  }
  elsif ($loader =~ /^palo/io) {
    print CONF @palotemplate;
  }
  elsif ($loader =~ /^zipl/io) {
    print CONF @zipltemplate;
  }
  else {
    print CONF @silotemplate;
  }
  close(CONF);
  chmod("/etc/$loader.conf", 0644);
  chown("/etc/$loader.conf", 0, 0);
}

sub run_lilo (){
  my $ret;
  if ($loader =~ /^lilo/io or $loader =~ /vmelilo/io) {
    print "Testing $loader.conf ... \n";
    unlink $temp_file_name;                        # security
    $ret = system("$loaderloc -t >$temp_file_name 2>&1");
    if ($ret) {
      my $ans;
      print "An error occurred while running $loader in test mode, a log is\n";
      print "available in $temp_file_name. Please edit /etc/$loader.conf\n";
      print "manually and re-run $loader, or make other arrangements to boot \n";
      print "your machine. \n\t Please hit return to continue";
      $ans = <STDIN>;
      return $ret;
    }
    unlink "$temp_file_name";
    print "Testing successful.\n";
    print "Installing the ";
    print "partition " if $loader =~ /^lilo/io;
    print "boot sector... \n";
  }

  if ($loader =~ /^elilo/io) {
    $ret = system("$loaderloc 2>&1 | tee $temp_file_name");
  }
  else {
    $ret = system("$loaderloc >$temp_file_name 2>&1");
  }

  if ($ret) {
    my $ans;
    print "There was an error with running $loader, a log file is \n";
    print "available in file $temp_file_name.  Please edit /etc/$loader.conf\n";
    print "manually and re-run $loader, or make other arrangements to boot \n";
    print "your machine. \n\t Please hit return to continue";
    $ans = <STDIN>;
    return $ret;
  }
  unlink $temp_file_name;
  print "Installation successful.\n";
  return 0;
}

exit 0;

__END__