OLD | NEW |
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 =head1 NAME | 2 =head1 NAME |
3 | 3 |
4 Linux::Bootloader - Base class interacting with Linux bootloaders | 4 Linux::Bootloader - Base class interacting with Linux bootloaders |
5 | 5 |
6 =head1 SYNOPSIS | 6 =head1 SYNOPSIS |
7 | 7 |
8 | 8 |
9 my $bootloader = new Linux::Bootloader(); | 9 my $bootloader = new Linux::Bootloader(); |
10 my $config_file='/boot/grub/menu.lst'; | 10 my $config_file='/boot/grub/menu.lst'; |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 } elsif ($arch_style eq 'gentoo') { | 784 } elsif ($arch_style eq 'gentoo') { |
785 $arch = `uname -m | sed -e s/i.86/x86/ -e s/sun4u/sparc/ -e s/arm.*/arm/
-e s/sa110/arm/ -e s/x86_64/amd64/ -e s/sparc.*/sparc/ -e s/parisc.*/hppa/`; | 785 $arch = `uname -m | sed -e s/i.86/x86/ -e s/sun4u/sparc/ -e s/arm.*/arm/
-e s/sa110/arm/ -e s/x86_64/amd64/ -e s/sparc.*/sparc/ -e s/parisc.*/hppa/`; |
786 chomp $arch; | 786 chomp $arch; |
787 } else { | 787 } else { |
788 $arch = `uname -m`; | 788 $arch = `uname -m`; |
789 chomp $arch; | 789 chomp $arch; |
790 } | 790 } |
791 return $arch; | 791 return $arch; |
792 } | 792 } |
793 | 793 |
| 794 =head3 detect_os_vendor() |
| 795 |
| 796 Input: |
| 797 Output: string |
| 798 |
| 799 This function determines the OS vendor (linux distribution breed). |
| 800 |
| 801 Return values: "Red Hat", "Fedora", "SUSE", "Ubuntu", "Debian", or |
| 802 "Unknown" if none of the predefined patterns could be found on the |
| 803 issue file. |
| 804 |
| 805 =cut |
| 806 |
| 807 sub detect_os_vendor { |
| 808 my $vendor = ""; |
| 809 my $issue_file = '/etc/issue'; |
| 810 if ( not system("egrep 'Red Hat' $issue_file") ){ |
| 811 $vendor = 'Red Hat'; |
| 812 } elsif ( not system("egrep 'Fedora' $issue_file") ){ |
| 813 $vendor = 'Fedora'; |
| 814 } elsif ( not system("egrep 'SUSE' $issue_file") ){ |
| 815 $vendor = 'SUSE'; |
| 816 } elsif ( not system("egrep 'Ubuntu' $issue_file") ){ |
| 817 $vendor = 'Ubuntu'; |
| 818 } elsif ( not system("egrep 'Debian' $issue_file") ){ |
| 819 $vendor = 'Debian'; |
| 820 } else { |
| 821 $vendor = 'Unknown'; |
| 822 } |
| 823 return $vendor; |
| 824 } |
| 825 |
794 =head3 detect_bootloader(['device1', 'device2', ...]) | 826 =head3 detect_bootloader(['device1', 'device2', ...]) |
795 | 827 |
796 Input: devices to detect against (optional) | 828 Input: devices to detect against (optional) |
797 Output: string | 829 Output: string |
798 | 830 |
799 This function attempts to determine the bootloader being used on the | 831 This function attempts to determine the bootloader being used on the |
800 system by first checking for conf files and then falling back to check | 832 system by first checking for conf files and then falling back to check |
801 the master boot record. | 833 the master boot record. |
802 | 834 |
803 Possible return values: | 835 Possible return values: |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 } | 1620 } |
1589 $x+=1; | 1621 $x+=1; |
1590 } | 1622 } |
1591 } | 1623 } |
1592 } | 1624 } |
1593 | 1625 |
1594 | 1626 |
1595 sub boot_once { | 1627 sub boot_once { |
1596 my $self=shift; | 1628 my $self=shift; |
1597 my $entry_to_boot_once = shift; | 1629 my $entry_to_boot_once = shift; |
| 1630 my $detected_os_vendor = Linux::Bootloader::Detect::detect_os_vendor(); |
1598 | 1631 |
1599 unless ( $entry_to_boot_once ) { print "No kernel\n"; return undef;} | 1632 unless ( $entry_to_boot_once ) { print "No kernel\n"; return undef;} |
1600 $self->read(); | 1633 $self->read(); |
1601 my $default=$self->get_default(); | 1634 my $default=$self->get_default(); |
1602 | 1635 |
| 1636 if ( $self->_get_bootloader_version() < 0.97 ){ |
| 1637 warn "This function works for grub version 0.97 and up. No action taken.
\nUpgrade, then re-try.\n"; |
| 1638 return undef; |
| 1639 } |
| 1640 |
| 1641 if ( $detected_os_vendor eq "Red Hat" or $detected_os_vendor eq "Fedora" ) { |
| 1642 # if not a number, do title lookup |
| 1643 if ( $entry_to_boot_once !~ /^\d+$/ ) { |
| 1644 $entry_to_boot_once = $self->_lookup($entry_to_boot_once); |
| 1645 return undef unless ( defined $entry_to_boot_once ); |
| 1646 } |
| 1647 |
| 1648 return `echo "savedefault --default=$entry_to_boot_once" --once | grub --bat
ch`; |
| 1649 } else { |
1603 if ( $default == $self->_lookup($entry_to_boot_once)){ | 1650 if ( $default == $self->_lookup($entry_to_boot_once)){ |
1604 warn "The default and once-boot kernels are the same. No action taken. \n
Set default to something else, then re-try.\n"; | 1651 warn "The default and once-boot kernels are the same. No action taken. \n
Set default to something else, then re-try.\n"; |
1605 return undef; | 1652 return undef; |
1606 } | 1653 } |
1607 if ( $self->_get_bootloader_version() < 0.97 ){ | |
1608 warn "This function works for grub version 0.97 and up. No action taken.
\nUpgrade, then re-try.\n"; | |
1609 return undef; | |
1610 } | |
1611 | 1654 |
1612 $self->set_default('saved'); | 1655 $self->set_default('saved'); |
1613 if ( ! -f '/boot/grub/default' ){ | 1656 if ( ! -f '/boot/grub/default' ){ |
1614 open FH, '>/boot/grub/default'; | 1657 open FH, '>/boot/grub/default'; |
1615 my $file_contents="default | 1658 my $file_contents="default |
1616 # | 1659 # |
1617 # | 1660 # |
1618 # | 1661 # |
1619 # | 1662 # |
1620 # | 1663 # |
1621 # | 1664 # |
1622 # | 1665 # |
1623 # | 1666 # |
1624 # | 1667 # |
1625 # | 1668 # |
1626 # WARNING: If you want to edit this file directly, do not remove any line | 1669 # WARNING: If you want to edit this file directly, do not remove any line |
1627 # from this file, including this warning. Using `grub-set-default\' is | 1670 # from this file, including this warning. Using `grub-set-default\' is |
1628 # strongly recommended. | 1671 # strongly recommended. |
1629 "; | 1672 "; |
1630 print FH $file_contents; | 1673 print FH $file_contents; |
1631 close FH; | 1674 close FH; |
1632 } | 1675 } |
1633 $self->set_default( "$entry_to_boot_once" ); | 1676 $self->set_default( "$entry_to_boot_once" ); |
1634 $self->update( 'option'=>'','fallback' => $default ); | 1677 $self->update( 'option'=>'','fallback' => $default ); |
1635 $self->update( 'update-kernel'=>"$entry_to_boot_once",'option'=>'','savedefaul
t' => 'fallback' ); | 1678 $self->update( 'update-kernel'=>"$entry_to_boot_once",'option'=>'','savedefaul
t' => 'fallback' ); |
1636 $self->update( 'update-kernel'=>"$default",'option'=>'', 'savedefault' => '' )
; | 1679 $self->update( 'update-kernel'=>"$default",'option'=>'', 'savedefault' => '' )
; |
1637 $self->write(); | 1680 $self->write(); |
1638 | 1681 } |
1639 } | 1682 } |
1640 | 1683 |
1641 sub _get_bootloader_version { | 1684 sub _get_bootloader_version { |
1642 my $self = shift; | 1685 my $self = shift; |
1643 return `grub --version | sed 's/grub (GNU GRUB //' | sed 's/)//'`; | 1686 return `grub --version | sed 's/grub (GNU GRUB //' | sed 's/)//'`; |
1644 } | 1687 } |
1645 | 1688 |
1646 | 1689 |
1647 1; | 1690 1; |
1648 | 1691 |
(...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2770 All Rights Reserved. | 2813 All Rights Reserved. |
2771 | 2814 |
2772 This script is free software; you can redistribute it and/or | 2815 This script is free software; you can redistribute it and/or |
2773 modify it under the same terms as Perl itself. | 2816 modify it under the same terms as Perl itself. |
2774 | 2817 |
2775 =head1 REVISION | 2818 =head1 REVISION |
2776 | 2819 |
2777 Revision: $Revision: 1.10 $ | 2820 Revision: $Revision: 1.10 $ |
2778 | 2821 |
2779 =cut | 2822 =cut |
OLD | NEW |