1
0
mirror of https://github.com/fspc/gbootroot.git synced 2025-02-22 08:33:24 -05:00
gbootroot/gBootRoot

1938 lines
59 KiB
Plaintext
Raw Normal View History

2000-08-13 04:43:39 +00:00
#!/usr/bin/perl -w
# gBootRoot Copyright (C) 2000
# Project Developer and Coordinator
# Jonathan Rosenbaum <mttrader@access.mountain.net>
#
# Lead Programmer and Developer
# Cristian Ionescu-Idbohrn <cii@axis.com>
#
2000-08-13 04:43:39 +00:00
# http://the.netpedia.net/gBootRoot.html
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
2000-08-23 13:44:45 +00:00
# You should have received a copy of the GNU General Public License
2000-08-13 04:43:39 +00:00
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
use Gtk;
use strict;
init Gtk;
#my $check_version = Gtk::check_version("1","0","7");
#print $check_version;
# 1 2 7 ... 0.7002
#Gtk->print('Gtk->major_version, " ", Gtk->minor_version, " ", Gtk->micro_version');
# Perhaps you are wondering where to learn how to program with Gtk-Perl?
2000-08-13 04:43:39 +00:00
# There is an excellent tutorial by Stephen Wilhelm at
# http://personal.riverusers.com/~swilhelm/perlgtk/. Please
# help support his development of this tutorial. Another good place
2000-08-23 13:44:45 +00:00
# to learn from is test.pl in the Gtk/samples directory included with
2000-08-13 04:43:39 +00:00
# Gtk-Perl.
2000-08-23 13:44:45 +00:00
# If you want gBootRoot to do it's stuff somewhere else, change the
2000-08-13 04:43:39 +00:00
# value for $tmp1.
2000-08-23 13:44:45 +00:00
my $tmp1 = "/tmp"; # tmp should be default - Cristian
my $lilo_conf = "/etc/lilo.conf";
2000-08-13 04:43:39 +00:00
# CHANGES
#
# 1.0.3b - 08.24.2000 cretzu
# * replaced 35 occurences of "$tmp/verbose" with the new
# variable $verbosefn
# * some lines contained > 1 rmdir statement separated by ','
# and not ';'; splitted those
#
# 1.0.3a - 08.23.2000 cretzu
2000-08-23 13:44:45 +00:00
# * corrected bugs in norm_root_device (returned always 'hda1')
# a) now closes LIL
# b) chomps all lines in one go
# c) the 'default' value is just a label, not a dev
# d) sane regexp magic
# e) "there's one more bug(tm)": does not cope with multiple
# root device occurences (which might be present in each
# 'image=' block
#
2000-08-23 13:44:45 +00:00
# 1.0.3 - 08.09.2000
# * Tmp and mnt are now created on the fly,
# along with a new error function for mkdir(),
# Gtk clean-up for this, and clean-up by signal handler
# which should please Perlish and helpful Cristian.
2000-08-13 04:43:39 +00:00
#
2000-08-23 13:44:45 +00:00
# 1.0.2 - 08.06.2000
# * Changed logic slightly in submit() with returns rather
# than a scalar to resolve a minor bug caused by some
# changes in the previous version.
#
# 1.0.1 - 08.05.2000
# * Zas provided a correction for a Perl 5.6 error complaint.
# * Zas found some unecessary GDK lines causing some Gtk
# warnings; these were commented out.
# * Cristian Ionescu-Idbohrn found a bug caused by putting
# the Kernel or RootImage below the mount point. An error
# check and error dialog were added.
#
# 1.0.0 - 08.02.2000
# * First public release
2000-08-13 04:43:39 +00:00
#
#######################################################################
# Don't edit from here, but you can if you want to change the HERE docs
# and/or the contents of initrd (in which case you need to make sure the
# right libraries are copied over to initrd and the size is checked).
# I need to remember to edit this
my $version = "v1.0.3";
my $date = "08.09.2000";
my $pwd = `pwd`; chomp $pwd;
use File::Basename;
my $initrd;
my $compress;
my $false = 0;
my $true = 1;
my $ok;
my $box2;
my $label;
my $label_advanced;
2000-08-25 20:19:19 +00:00
my $separator;
2000-08-13 04:43:39 +00:00
my $order;
my $text_window;
my @container;
my @original_container;
my $file_dialog;
my $error_window;
my ($kernel,$root_image,$device,$size);
my $mtab;
my ($tmp,$mnt);
my $norm_root_device;
my ($hbox_advanced);
my $separator_advanced;
my @entry_advanced;
my $entry_advanced;
my ($ea1,$ea2,$ea3);
my $table_advanced;
my $button_count = 0;
my $obj_count = 0;
my ($lib_strip_check,$bin_strip_check);
2000-08-25 20:19:19 +00:00
2000-08-13 04:43:39 +00:00
# My own creation - the roots touch the ground if three lines are added.
my @xpm_data = (
"32 45 3 1",
2000-08-23 13:44:45 +00:00
" c None",
". c SaddleBrown",
"X c black",
2000-08-13 04:43:39 +00:00
" ... ... ",
" ... ... ",
" ... ... ",
" ... ... ",
" ... ... ",
" ... ... ",
" ... ... ",
" ... ... ",
" ... ... ",
" ... .. ",
" ... ... ",
" ... ... ",
" .... ... ",
" .... ... ",
" .... ... ",
" .... ............. ",
" ..... ............. ",
" ...... ............. ",
" ....... ...",
"......... ..",
"................................",
"................................",
"............................... ",
"......... XXXXX ............ ",
"........ XXX .......... ",
"........ XXX ........ ",
" XXXXXX ",
" XXX XXX X XX XX ",
" X XXXXX X X X ",
" XX XXX X XX ",
" X XX X X ",
" X XX X XX X ",
" XX XX X XXXXX ",
" X XXXX XXX XXXXX X ",
" XX XX XX X XX ",
" X X X X X ",
" X XX X XX X ",
" X XX XX X ",
" X XX XXXXXXX XXX ",
" XX XX XXX ",
" XX XX XXXX XX XX ",
" XX XXX X XXXXXXX X ",
" X XXX X XX ",
" XX XXXXXXX XXX ",
" X XX X ",
" X X "
);
$SIG{INT} = \&signal;
$SIG{ABRT} = \&signal;
$SIG{TERM} = \&signal;
$SIG{QUIT} = \&signal;
$SIG{KILL} = \&signal;
(undef,$container[1],$container[11]) = gdkbirdaao();
2000-08-13 04:43:39 +00:00
if (!-d $tmp1) {
if (-e $tmp1) {
error_window(
"gBootRoot: ERROR: A file exists where $tmp1 should be");
}
else {
my @directory_parts = split(m,/,,$tmp1);
my $placement = "/";
2000-08-23 13:44:45 +00:00
for (1 .. $#directory_parts) {
2000-08-13 04:43:39 +00:00
$_ == 1 ? ($placement = "/$directory_parts[$_]")
2000-08-23 13:44:45 +00:00
: ($placement = $placement . "/" . $directory_parts[$_]);
2000-08-13 04:43:39 +00:00
-d $placement or err_custom_perl(
"mkdir $placement","gBootRoot: ERROR: Could not make $tmp1");
2000-08-23 13:44:45 +00:00
}
2000-08-13 04:43:39 +00:00
}
}
if (!-d "$tmp1/gbootroot_tmp$$") {
$tmp = "$tmp1/gbootroot_tmp$$" if err_custom_perl(
"mkdir $tmp1/gbootroot_tmp$$",
"gBootRoot: ERROR: Could not make temporary directory") != 2;
}
if (!-d "$tmp1/gbootroot_mnt$$") {
$mnt = "$tmp1/gbootroot_mnt$$" if err_custom_perl(
"mkdir $tmp1/gbootroot_mnt$$",
"gBootRoot: ERROR: Could not make mount directory") != 2;
}
my $verbosefn = "$tmp/verbose";
2000-08-13 04:43:39 +00:00
my $window = new Gtk::Window("toplevel");
2000-08-25 20:19:19 +00:00
# special policy
$window->set_policy( $false, $true, $true );
2000-08-13 04:43:39 +00:00
$window->set_title("gBootRoot");
$window->set_position('center');
$window->signal_connect("destroy",
sub {
unlink "$verbosefn", "$tmp/initrd_image.gz";
rmdir "$tmp/initrd_mnt";
rmdir "$tmp";
rmdir "$mnt";
Gtk->exit(0);
});
2000-08-13 04:43:39 +00:00
$window->border_width(1);
$window->realize;
# Do the iconizing thing
# "xpm/circles.xpm" can be @pixmap within file if not create_from_xpm.
2000-08-23 13:44:45 +00:00
my ($circles,$mask) = Gtk::Gdk::Pixmap->create_from_xpm_d($window->window,
2000-08-13 04:43:39 +00:00
$window->style->white,
@xpm_data);
2000-08-23 13:44:45 +00:00
$window->window->set_icon(undef, $circles, $mask);
$window->window->set_icon_name("gBootRoot");
2000-08-13 04:43:39 +00:00
#$window->window->set_decorations(['all', 'menu']); # Zas
#$window->window->set_functions(['all', 'resize']); # Zas
my $tooltips = new Gtk::Tooltips();
my $box1 = new Gtk::VBox($false,0);
$window->add($box1);
$box1->show();
# First row
hbox();
my $entry = entry($false,0);
2000-08-13 04:43:39 +00:00
# Menu - later this may be improved if new methods are added.
my $opt = new Gtk::OptionMenu();
$tooltips->set_tip( $opt, "Choose the Boot method.", "" );
my $menu = new Gtk::Menu();
my $item = new Gtk::MenuItem("Method -> lilo" );
$item->show();
$item->signal_connect( 'activate',sub { $entry->set_text("lilo");
$container[0] = "lilo"});
$menu->append( $item );
$opt->set_menu( $menu );
$box2->pack_start( $opt, $true, $true, 0 );
$opt->show();
$box2->show();
# Second row
hbox();
my $entry2 = entry($true,1);
$entry2->set_text($container[1]);
2000-08-13 04:43:39 +00:00
button("Kernel Selection",$entry2,"Kernel Selection",1);
# Third row
hbox();
my $entry3 = entry($true,2);
button("Compressed Filesystem",$entry3,"Compressed Filesystem",2);
2000-08-23 13:44:45 +00:00
# In the future, if experimenters send in data, there will be two
2000-08-13 04:43:39 +00:00
# different devices.
# Fourth row
hbox();
my $entry4 = entry($true,3);
$container[3] = "/dev/fd0";
$entry4->set_text($container[3]);
2000-08-13 04:43:39 +00:00
button("Device Selection",$entry4,"Device Selection",3,$true);
# Fifth row
hbox("what");
my $adj = new Gtk::Adjustment( 1722.0, 0.0, 360000000.0, 282.0, 360.0, 0.0 );
2000-08-13 04:43:39 +00:00
my $spinner = new Gtk::SpinButton( $adj, 0, 0 );
$tooltips->set_tip( $spinner, "Choose the Device Size.", "" );
$spinner->set_wrap( $true );
$spinner->set_numeric( $true );
$spinner->set_shadow_type( 'in' );
$spinner->show();
$container[4] = 1722; # A better value - a rtbt trick.
2000-08-13 04:43:39 +00:00
$adj->signal_connect( "value_changed", sub {
$container[4] = $spinner->get_value_as_int();});
$box2->pack_start( $spinner, $true, $true, 0 );
label("Device Size");
# gz and bz2 radio buttons
my $rbutton = new Gtk::RadioButton( "gz" );
$tooltips->set_tip( $rbutton, "Choose Compression used on the Filesystem.", "" );
my $gz_toggle = $rbutton;
$rbutton->set_active( $true );
$box2->pack_start( $rbutton, $false, $false, 0 );
$rbutton->show();
$rbutton = new Gtk::RadioButton( "bz2", $rbutton );
$rbutton->set_usize(1,1);
$tooltips->set_tip( $rbutton, "Choose Compression used on the Filesystem.", "" );
my $bz2_toggle = $rbutton;
$box2->pack_start( $rbutton, $true, $true, 0);
$rbutton->show();
2000-08-23 13:44:45 +00:00
# Size status entry
2000-08-13 04:43:39 +00:00
my $entry5 = new Gtk::Entry();
$entry5->set_editable( $false );
$tooltips->set_tip( $entry5, "This shows room remaining on the Device.", "" );
$entry5->set_usize(15,20);
$box2->pack_start( $entry5, $true, $true, 0 );
$entry5->show();
# The ADVANCED SECTION
######################
2000-08-25 20:19:19 +00:00
# Separator
$separator = new Gtk::HSeparator();
$box1->pack_start( $separator, $false, $true, 0 );
$separator->show();
# This is cool how this works.
my $vbox_advanced = new Gtk::VBox($false,0);
$box1->add($vbox_advanced);
$vbox_advanced->show();
2000-08-25 20:19:19 +00:00
# The Advanced Section button
hbox_advanced();
my $button_advanced = new Gtk::Button("Advanced Section");
$tooltips->set_tip( $button_advanced, "This is where all the advanced stuff is found.", "" );
$button_advanced->signal_connect("clicked",\&advanced_section );
$hbox_advanced->pack_start( $button_advanced, $true, $true, 0 );
$button_advanced->show();
######################
2000-08-25 20:19:19 +00:00
2000-08-13 04:43:39 +00:00
# Separator
2000-08-25 20:19:19 +00:00
$separator = new Gtk::HSeparator();
2000-08-13 04:43:39 +00:00
$box1->pack_start( $separator, $false, $true, 0 );
$separator->show();
# Status bar
my $align = new Gtk::Alignment( 0.5, 0.5, 0, 0 );
$box1->pack_start( $align, $false, $false, 5);
$align->show();
my $pbar = new Gtk::ProgressBar();
2000-08-23 13:44:45 +00:00
$pbar->set_usize(321,10); # 321 10
2000-08-13 04:43:39 +00:00
$align->add($pbar);
$pbar->show();
# Separator
$separator = new Gtk::HSeparator();
$box1->pack_start( $separator, $false, $true, 0 );
$separator->show();
2000-08-23 13:44:45 +00:00
# Submit button
hbox();
2000-08-13 04:43:39 +00:00
my $sbutton = new Gtk::Button("Submit");
$sbutton->signal_connect( "clicked", \&submit);
$tooltips->set_tip( $sbutton, "Generate the Boot/Root set.", "" );
$sbutton->show();
$box2->pack_start( $sbutton, $true, $true, 0 );
$box2->show();
# Close button
my $cbutton = new Gtk::Button("Close");
$cbutton->signal_connect("clicked",
sub {
unlink "$verbosefn", "$tmp/initrd_image.gz";
rmdir "$tmp/initrd_mnt";
rmdir "$tmp";
rmdir "$mnt";
Gtk->exit(0);
});
2000-08-13 04:43:39 +00:00
$tooltips->set_tip( $cbutton, "Exit gBootRoot.", "" );
$cbutton->show();
$box2->pack_start( $cbutton, $true, $true, 0 );
$box2->show();
# Help button
my $hbutton = new Gtk::Button("Help");
$hbutton->signal_connect( "clicked", \&create_text);
$tooltips->set_tip( $hbutton, "Help about gBootRoot.", "" );
$hbutton->show();
$box2->pack_start( $hbutton, $true, $true, 0 );
$box2->show();
2000-08-25 20:19:19 +00:00
2000-08-13 04:43:39 +00:00
$window->show();
main Gtk;
exit( 0 );
#----------------------------
# This works on GNU/Linux
sub signal {
2000-08-23 13:44:45 +00:00
$SIG{INT} = \&signal;
2000-08-13 04:43:39 +00:00
$SIG{ABRT} = \&signal;
$SIG{TERM} = \&signal;
$SIG{QUIT} = \&signal;
$SIG{KILL} = \&signal;
unlink "$verbosefn", "$tmp/initrd_image.gz";
rmdir "$tmp/initrd_mnt";
rmdir "$tmp";
rmdir "$mnt";
2000-08-13 04:43:39 +00:00
Gtk->exit(0);
}
sub hbox_advanced {
$hbox_advanced = new Gtk::HBox(1,1 );
$hbox_advanced->border_width( 2 ); # was 10
$hbox_advanced->set_usize(321, 20);
$vbox_advanced->pack_start( $hbox_advanced, $false, $false, 0 );
show $hbox_advanced;
}
sub objcopy_right_click_advanced {
my ( @data ) = @_;
my $event = pop( @data );
if ( ( defined( $event->{'type'} ) )
and ( $event->{'type'} eq 'button_press' ) ) {
if ( $event->{'button'} == 3 ) {
if ($obj_count == 0) {
$tooltips->set_tip( $lib_strip_check,
"This is generally a good idea. Press the" .
" right mouse button to change from" .
" [objcopy --strip-all] to" .
" [objcopy --strip-debug].", "" );
$obj_count++;
}
else {
$tooltips->set_tip( $lib_strip_check,
"This is generally a good idea. Press the" .
" right mouse button to change from" .
" [objcopy --strip-debug] to" .
" [objcopy --strip-all].", "" );
$obj_count--;
}
}
}
}
sub advanced_section {
if ($button_count == 0) {
#$vbox_advanced->set_usize(321,300);
2000-08-27 16:21:49 +00:00
my $boolean;
# The strip section
$table_advanced = new Gtk::Table( 4, 3, $true );
$vbox_advanced->pack_start( $table_advanced, $true, $true, 0 );
$table_advanced->show();
# lib_strip_check
label_advanced("Stripping:",0,1,0,1);
!defined $lib_strip_check ? ($boolean = 1)
2000-08-27 16:21:49 +00:00
: ($boolean = $lib_strip_check->get_active());
$lib_strip_check = new Gtk::CheckButton("Libraries");
2000-08-27 16:21:49 +00:00
$lib_strip_check->set_active($boolean);
$lib_strip_check->signal_connect( "button_press_event",
\&objcopy_right_click_advanced);
$tooltips->set_tip( $lib_strip_check,
"This is generally a good idea. Press the" .
" right mouse button to change from" .
" [objcopy --strip-debug] to" .
" [objcopy --strip-all].", "" );
#$hbox_advanced->pack_start( $lib_strip_check, $false, $false, 0);
$table_advanced->attach($lib_strip_check,1,2,0,1,
['expand'],['fill','shrink'],0,0);
show $lib_strip_check;
# bin_strip_check
2000-08-27 16:21:49 +00:00
!defined $bin_strip_check ? ($boolean = 1)
: ($boolean = $bin_strip_check->get_active());
$bin_strip_check = new Gtk::CheckButton("Binaries");
2000-08-27 16:21:49 +00:00
$bin_strip_check->set_active($boolean);
$tooltips->set_tip( $bin_strip_check,
"This is generally a good idea." .
" [objcopy --strip-all]", "" );
#$hbox_advanced->pack_start( $bin_strip_check, $true, $true, 0);
$table_advanced->attach($bin_strip_check,2,3,0,1,
['expand'],['fill','shrink'],0,0);
show $bin_strip_check;
# Development Drive
label_advanced("Devel Device:",0,1,1,2);
$ea1 = entry_advanced(1,2,1,2,0);
$tooltips->set_tip( $ea1, "If the device used for development" .
" is different than the actual boot" .
" device, use this field" .
" to indicate that device." .
" You will have to run" .
" \"lilo -v -C brlilo.conf -r" .
" device-mount\" manually at a" .
" later time on the actual" .
" boot device.",
"" );
$ea1->set_text($container[3]) if defined $container[3];
# Optional Device(s)
label_advanced("Opt. Device(s)",0,1,2,3);
$ea2 = entry_advanced(1,2,2,3,1);
$tooltips->set_tip( $ea2, "Add devices to the boot disk which are" .
" necessary for the kernel to function" .
" properly. Put a space between each" .
" device. For instance, /dev/fb0 for" .
" frame buffer devices.",
"");
$ea2->set_text($entry_advanced[1]) if defined $entry_advanced[1];
# Append Options
label_advanced("append =",0,1,3,4);
$ea3 = entry_advanced(1,2,3,4,2);
my $append; (undef,undef,$append) = gdkbirdaao();
$tooltips->set_tip( $ea3, "Add append options to brlilo.conf.", "");
$ea3->set_text($append) if defined $append;
# Verbosity section
$button_count++;
}
else {
destroy $table_advanced;
$button_count--;
}
} # end sub advanced_section
print @entry_advanced;
sub entry_advanced {
my $numa = $_[4];
my $entry_advanced = new Gtk::Entry();
$entry_advanced->set_editable( $true );
$entry_advanced->signal_connect( "changed", sub {
$entry_advanced[$numa] = $entry_advanced->get_text();} );
$entry_advanced->set_usize(100,20);
$table_advanced->attach($entry_advanced,$_[0],$_[1],$_[2],$_[3],
['expand'],['fill','shrink'],0,0);
show $entry_advanced;
return $entry_advanced;
}
sub separator_advanced {
$separator_advanced = new Gtk::HSeparator();
$vbox_advanced->pack_start( $separator_advanced, $false, $true, 0 );
$separator_advanced->show();
}
sub label_advanced {
my($text) = @_;
$label_advanced = new Gtk::Label( $text );
$label_advanced->set_justify( "fill" );
$table_advanced->attach($label_advanced,$_[1],$_[2],$_[3],$_[4], ['expand'],['fill','shrink'],0,0);
$label_advanced->show();
}
2000-08-13 04:43:39 +00:00
sub create_text {
if (not defined $text_window) {
$text_window = new Gtk::Window "toplevel";
$text_window->signal_connect("destroy", \&destroy_window,
\$text_window);
$text_window->signal_connect("delete_event", \&destroy_window,
\$text_window);
$text_window->set_title("Help");
$text_window->set_usize( 500, 600 );
$text_window->set_policy( $true, $true, $false );
$text_window->set_title( "gBootRoot Help" );
$text_window->border_width(0);
my $main_vbox = new Gtk::VBox( $false, 0 );
$text_window->add( $main_vbox );
$main_vbox->show();
my $vbox = new Gtk::VBox( $false, 10 );
$vbox->border_width( 10 );
$main_vbox->pack_start( $vbox, $true, $true, 0 );
$vbox->show();
my $table = new Gtk::Table( 2, 2, $false );
$table->set_row_spacing( 0, 2 );
$table->set_col_spacing( 0, 2 );
$vbox->pack_start( $table, $true, $true, 0 );
$table->show( );
2000-08-13 04:43:39 +00:00
# Create the GtkText widget
my $text = new Gtk::Text( undef, undef );
$text->set_editable($false);
$table->attach( $text, 0, 1, 0, 1,
[ 'expand', 'shrink', 'fill' ],
[ 'expand', 'shrink', 'fill' ],
0, 0 );
$text->show();
# Add a vertical scrollbar to the GtkText widget
my $vscrollbar = new Gtk::VScrollbar( $text->vadj );
$table->attach( $vscrollbar, 1, 2, 0, 1, 'fill',
[ 'expand', 'shrink', 'fill' ], 0, 0 );
$vscrollbar->show();
$text->freeze();
$text->insert( undef, undef, undef, help() );
$text->thaw();
my $separator = new Gtk::HSeparator();
$main_vbox->pack_start( $separator, $false, $true, 0 );
$separator->show();
$vbox = new Gtk::VBox( $false, 10 );
$vbox->border_width( 10 );
$main_vbox->pack_start( $vbox, $false, $true, 0 );
$vbox->show();
my $button = new Gtk::Button( "Close" );
$button->signal_connect( 'clicked', sub { destroy $text_window; } );
$vbox->pack_start( $button, $true, $true, 0 );
$button->can_default( $true );
$button->grab_default();
$button->show();
}
if (!visible $text_window) {
2000-08-23 13:44:45 +00:00
show $text_window;
2000-08-13 04:43:39 +00:00
} else {
2000-08-23 13:44:45 +00:00
destroy $text_window;
2000-08-13 04:43:39 +00:00
}
} # end sub create_text
sub make_menu_item {
my( $name, $callback, $data ) = @_;
my $item;
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
$item = new Gtk::MenuItem( $name );
$item->signal_connect( "activate", $callback, $data );
$item->show();
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
return $item;
}
sub fileselect {
my ($widget,$ent,$name,$order,$device) = @_;
if (not defined $file_dialog) {
# Create a new file selection widget
2000-08-23 13:44:45 +00:00
$file_dialog = new Gtk::FileSelection( "$name" );
$file_dialog->signal_connect( "destroy",
2000-08-13 04:43:39 +00:00
\&destroy_window, \$file_dialog);
2000-08-23 13:44:45 +00:00
$file_dialog->signal_connect( "delete_event",
2000-08-13 04:43:39 +00:00
\&destroy_window, \$file_dialog);
# Connect the ok_button to file_ok_sel function
2000-08-23 13:44:45 +00:00
$file_dialog->ok_button->signal_connect( "clicked",
\&file_ok_sel,
$file_dialog,$ent,$order);
2000-08-13 04:43:39 +00:00
# Connect the cancel_button to destroy the widget
2000-08-23 13:44:45 +00:00
$file_dialog->cancel_button->signal_connect( "clicked",
2000-08-13 04:43:39 +00:00
sub { destroy $file_dialog } );
2000-08-23 13:44:45 +00:00
$file_dialog->set_filename( "/dev/fd0" ) if defined $device;
2000-08-13 04:43:39 +00:00
$file_dialog->set_position('mouse');
}
if (!visible $file_dialog) {
show $file_dialog;
}
else {
destroy $file_dialog;
}
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
} # end sub fileselect
# Get the selected filename and print it to the text widget
sub file_ok_sel {
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
my( $widget, $file_selection,$entry,$order) = @_;
my $file = $file_selection->get_filename();
2000-08-23 13:44:45 +00:00
$entry->set_text($file);
2000-08-13 04:43:39 +00:00
$container[$order] = $file;
# auto-detect compression if system has file
if ($container[2]) {
my $file = system "which file > /dev/null 2>&1";
2000-08-23 13:44:45 +00:00
if ($file == 0) {
open(F,"file $container[2]|"); # no error check here
2000-08-13 04:43:39 +00:00
while (<F>) {
if (/gzip/) {
$gz_toggle->set_active( $true );
}
elsif (/bzip2/) {
$bz2_toggle->set_active( $true );
}
}
}
}
destroy $file_dialog;
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
}
# pulled from test.pl
2000-08-23 13:44:45 +00:00
sub destroy_window {
my($widget, $windowref, $w2) = @_;
$$windowref = undef;
2000-08-13 04:43:39 +00:00
$w2 = undef if defined $w2;
2000-08-23 13:44:45 +00:00
0;
2000-08-13 04:43:39 +00:00
}
sub hbox {
my $homogeneous;
defined $_[0] ? ($homogeneous = 0) : ($homogeneous = 1);
$box2 = new Gtk::HBox( $homogeneous, 5 );
$box2->border_width( 2 ); # was 10
$box1->pack_start( $box2, $true, $true, 0 );
#$box1->pack_start( $box2, $false, $true, 0 );
$box2->show();
}
sub label {
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
my($text) = @_;
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
$label = new Gtk::Label( $text );
$label->set_justify( "fill" );
$box2->pack_start( $label, $false, $false, 5 );
$label->show();
}
sub entry {
my($edit,$num) = @_;
my $entry = new Gtk::Entry();
$entry->set_editable( $true );
if ($num == 0) {
$entry->signal_connect( "activate", sub {
$container[$num] = $entry->get_text();});
}
else {
$entry->signal_connect( "changed", sub {
$container[$num] = $entry->get_text();
if (defined $ea1 and $num == 3) {
$ea1->set_text($container[$num]);
}
});
}
if (defined $num and $num != 0) {
2000-08-23 13:44:45 +00:00
my $todo;
if ($num == 1) {
$todo = "the Kernel";
2000-08-13 04:43:39 +00:00
}
elsif ($num == 2) {
$todo = "the Compressed Filesystem";
}
else {
$todo = "the Device to use";
}
2000-08-23 13:44:45 +00:00
$tooltips->set_tip( $entry,
"Type in the location of $todo.", "" );
2000-08-23 13:44:45 +00:00
}
2000-08-13 04:43:39 +00:00
$box2->pack_start( $entry, $true, $true, 0 );
$entry->show();
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
return $entry;
}
sub button {
my ($text,$ent,$name,$order,$device) = @_;
my $button = new Gtk::Button($text);
if ($order == 1) {
$tooltips->set_tip( $button, "Select the Kernel.", "" );
}
elsif ($order == 2) {
$tooltips->set_tip( $button, "Select the Compressed Filesystem.", "" );
}
else {
$tooltips->set_tip( $button, "Select the Device.", "" );
2000-08-23 13:44:45 +00:00
}
2000-08-13 04:43:39 +00:00
$button->signal_connect( "clicked",\&fileselect,$ent,$name,$order,$device);
$button->show();
$box2->pack_start( $button, $true, $true, 0 );
$box2->show();
}
sub submit {
2000-08-23 13:44:45 +00:00
my($kernel,$root_image);
2000-08-13 04:43:39 +00:00
# comment this out for testing
unlink("$verbosefn");
2000-08-13 04:43:39 +00:00
open (MTAB, "/etc/mtab") or die "no mtab!\n";
while (<MTAB>) {
if (m,$mnt,) {
system "umount $mnt >> $verbosefn 2>&1";
2000-08-13 04:43:39 +00:00
}
}
close(MTAB);
$entry5->set_text("");
pb("boot",0);
if ($gz_toggle->active) {
$compress = "gzip";
}
elsif ($bz2_toggle->active) {
$compress = "bzip2";
}
# Run some checks
if (!defined $container[0]) {
error_window("gBootRoot: ERROR: No method supplied");
return;
}
if (defined $container[1] && -e $container[1] && !-d $container[1]) {
$kernel = $container[1];
# Better be sure it isn't in the mount directory
if ($kernel =~ m,^$mnt,) {
error_window("gBootRoot: ERROR: Kernel found below Device mount point: $mnt");
return;
}
}
elsif (defined $container[0]) {
error_window("gBootRoot: ERROR: Kernel not found");
return;
}
if (defined $container[2] && -e $container[2] && !-d $container[2] ) {
$root_image = $container[2];
if ($root_image =~ m,^$mnt,) {
# Bug revealed by Cristian Ionescu-Idbohrn <cii@axis.com>
error_window("gBootRoot: ERROR: Rootimage found below Device mount point: $mnt");
return;
}
}
elsif (defined $container[0] && defined $container[1]) {
error_window("gBootRoot: ERROR: Rootimage not found");
return;
}
# we need to check for this, too.
if (defined $container[3] && -e $container[3] && !-d $container[3] ) {
$device = $container[3];
}
2000-08-23 13:44:45 +00:00
elsif (defined $container[0] && defined $container[1]
2000-08-13 04:43:39 +00:00
&& defined $container[2]) {
error_window("gBootRoot: ERROR: Device not found");
return;
}
if (defined $container[4]) {
2000-08-23 13:44:45 +00:00
$size = $container[4];
2000-08-13 04:43:39 +00:00
}
# pretty unlikely
elsif (defined $container[0] && defined $container[1] &&
defined $container[2] && defined $container[3]) {
error_window("gBootRoot: ERROR: No size specified");
return;
}
2000-08-13 04:43:39 +00:00
# kernel value can change without effecting initrd
# no sense doing this until important stuff is filled in
2000-08-23 13:44:45 +00:00
if (defined $kernel && defined $root_image &&
2000-08-13 04:43:39 +00:00
defined $device && defined $size) {
$container[5] = $compress;
2000-08-27 16:21:49 +00:00
# 1 .. 4 - its a hash .. not too simple
!defined $lib_strip_check ? ($container[6] = 1)
: ($container[6] = $lib_strip_check->get_active());
!$container[6] ? ($container[6] = 2) : ($container[6] = 1);
!defined $bin_strip_check ? ($container[7] = 3)
: ($container[7] = $bin_strip_check->get_active());
!$container[7] ? ($container[7] = 4) : ($container[7] = 3);
if ($container[6] == 1) {
$obj_count == 0 ? ($container[8] = 5) : ($container[8] = 6);
}
if (!defined $entry_advanced[0]) {
$container[9] = $device . "ea1";
$entry_advanced[0] = $device;
}
else {
$container[9] = $entry_advanced[0] . "ea1";
}
# Works now .. whoosh!
if ($container[10]) {
if ($container[10] ne "") {
$container[10] = $entry_advanced[1] if $entry_advanced[1];
}
if (defined $entry_advanced[1] and $entry_advanced[1] eq "") {
$container[10] = "";
}
elsif ($container[10] eq "") {
push(@original_container,$entry_advanced[1]);
}
}
else {
push(@original_container,$entry_advanced[1])
if $entry_advanced[1];
}
# pretty complex and works properly even for !-e lilo.conf
if ($container[11]) {
if ($container[11] ne "") {
$container[11] = $entry_advanced[2] if $entry_advanced[2];
}
if (defined $entry_advanced[2] and $entry_advanced[2] eq "") {
$container[11] = "";
}
elsif ($container[11] eq "") {
push(@original_container,$entry_advanced[2]);
}
}
else {
push(@original_container,$entry_advanced[2])
if $entry_advanced[2];
}
2000-08-13 04:43:39 +00:00
if (@original_container) { # defined array deprecate Perl 5.6 - zas@metaconcept.com
# a hash check isn't perfect for two values which are the same
# no need to check all the values
2000-08-13 04:43:39 +00:00
my @temp_container = @container;
# Got it! - how to deal with fields with no init value
if (defined $container[10] and $container[10] eq "") {
$container[10] = $entry_advanced[1];
}
if (!defined $container[10]) {
$container[10] = $entry_advanced[1];
}
if (defined $container[11] and $container[11] eq "") {
$container[11] = $entry_advanced[2];
}
if (!defined $container[11]) {
$container[11] = $entry_advanced[2];
}
# no sense looking at undef values
my (@temp_container2,@original_container2);
for (@temp_container) {
if ($_) {
push(@temp_container2,$_);
}
}
for (@original_container) {
if ($_) {
push(@original_container2,$_);
}
}
@temp_container = @temp_container2;
@original_container = @original_container2;
2000-08-13 04:43:39 +00:00
splice(@temp_container,1,1);
# A test which I've had to run too often
#print "BEFORE @temp_container\nAFTER @original_container\n";
2000-08-13 04:43:39 +00:00
my %diff;
2000-08-23 13:44:45 +00:00
grep($diff{$_}++,@temp_container);
my @diff = grep(!$diff{$_},@original_container);
2000-08-13 04:43:39 +00:00
if ($#diff >= 0) {
# unlink initrd_image.gz, do initrd()
2000-08-23 13:44:45 +00:00
$ok = 1;
$initrd = "initrd_image";
2000-08-13 04:43:39 +00:00
}
else {
2000-08-23 13:44:45 +00:00
$ok = 0;
}
2000-08-13 04:43:39 +00:00
}
else {
2000-08-23 13:44:45 +00:00
$ok = 2; # this is actually first (1 = diff, 0 = same)
$initrd = "initrd_image";
2000-08-13 04:43:39 +00:00
}
2000-08-13 04:43:39 +00:00
# reset
2000-08-27 16:21:49 +00:00
@original_container = ($container[0],$root_image,$device,$size,
$compress,$container[6],$container[7],
$container[8],$container[9],$container[10],
$container[11]);
2000-08-13 04:43:39 +00:00
lilo();
}
} # end sub submit
sub error_window {
my ($error) = @_;
if (not defined $error_window) {
2000-08-23 13:44:45 +00:00
$error_window = new Gtk::Dialog;
2000-08-13 04:43:39 +00:00
$error_window->signal_connect("destroy", \&destroy_window, \$error_window);
2000-08-23 13:44:45 +00:00
$error_window->signal_connect("delete_event", \&destroy_window, \$error_window);
2000-08-13 04:43:39 +00:00
$error_window->set_title("gBootRoot ERROR");
2000-08-23 13:44:45 +00:00
$error_window->border_width(15);
2000-08-13 04:43:39 +00:00
my $label = new Gtk::Label($error);
$error_window->vbox->pack_start( $label, $true, $true, 15 );
$label->show();
my $button = new Gtk::Button("OK");
$button->signal_connect("clicked", sub {destroy $error_window});
$button->can_default(1);
$error_window->action_area->pack_start($button, $false, $false,0);
$button->grab_default;
$button->show;
}
if (!visible $error_window) {
show $error_window;
}
else {
destroy $error_window;
}
} # end sub error_window
sub errmk {
error_window("gBootRoot: ERROR: Could not make important directories") if $? != 0;
if (defined $error_window) {
if ($error_window->visible) {
return 2;
}
}
}
sub errcp {
2000-08-23 13:44:45 +00:00
error_window("gBootRoot: ERROR: Could not copy over important stuff") if $? != 0;
2000-08-13 04:43:39 +00:00
if (defined $error_window) {
if ($error_window->visible) {
return 2;
}
}
}
sub errum {
2000-08-23 13:44:45 +00:00
error_window("gBootRoot: ERROR: Could not umount the device") if $? != 0;
2000-08-13 04:43:39 +00:00
if (defined $error_window) {
if ($error_window->visible) {
return 2;
}
}
}
sub errm {
error_window("gBootRoot: ERROR: Could not mount device") if $? != 0;
if (defined $error_window) {
if ($error_window->visible) {
return 2;
}
}
}
sub errrm {
2000-08-23 13:44:45 +00:00
error_window("gBootRoot: ERROR: Could not remove a directory or file")
2000-08-13 04:43:39 +00:00
if $? != 0;
if (defined $error_window) {
if ($error_window->visible) {
return 2;
}
}
}
2000-08-23 13:44:45 +00:00
sub err {
error_window("gBootRoot: ERROR: Not enough space after all") if ($? > 0);
2000-08-13 04:43:39 +00:00
if (defined $error_window) {
if ($error_window->visible) {
return 2;
}
}
}
2000-08-23 13:44:45 +00:00
sub err_custom {
2000-08-13 04:43:39 +00:00
if (defined $_[2]) {
system("$_[0] > /dev/null 2>&1");
}
else {
system("$_[0] >> $verbosefn 2>&1");
2000-08-13 04:43:39 +00:00
}
2000-08-23 13:44:45 +00:00
error_window($_[1]) if ($? != 0);
2000-08-13 04:43:39 +00:00
if (defined $error_window) {
if ($error_window->visible) {
return 2;
}
}
}
2000-08-23 13:44:45 +00:00
sub err_custom_perl {
2000-08-13 04:43:39 +00:00
if ((split(/ /, $_[0]))[0] eq "mkdir") {
my $two = (split(/ /, $_[0]))[1];
mkdir($two,0755); # Anyone allowed in
}
2000-08-23 13:44:45 +00:00
error_window($_[1]) if ($? != 0);
2000-08-13 04:43:39 +00:00
if (defined $error_window) {
if ($error_window->visible) {
return 2;
}
}
}
sub lilo {
# Do a little cleanup just in case
2000-08-23 13:44:45 +00:00
system "rm $tmp/initrd_image.gz 2> /dev/null" if $ok == 1;
system "umount $tmp/initrd_mnt 2> /dev/null";
2000-08-13 04:43:39 +00:00
$kernel = $container[1];
$root_image = $container[2];
$device = $container[3];
$size = $container[4];
if ($ok == 1 || $ok == 2) {
my $value = initrd($kernel,$root_image,$device,$size);
mtab(0) if defined $value;
}
elsif ($ok == 0) {
mtab(0);
}
} # end sub lilo
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
sub lilo_put_it_together {
my $B = "boot";
2000-08-23 13:44:45 +00:00
# Time to do a little calculations
my $device_size = (split(/\s+/,`df $mnt`))[8];
my $boot_size = (stat($kernel))[12]/2 + (stat("$tmp/$initrd"))[12]/2;
2000-08-13 04:43:39 +00:00
my $remain_boot = $device_size - $boot_size;
pb($B,1);
# A little output
2000-08-23 13:44:45 +00:00
if ($remain_boot =~ /^-+\d+$/) {
2000-08-13 04:43:39 +00:00
error_window("gBootRoot: ERROR: Not enough room: boot stuff = $boot_size k, device = $device_size k");
return;
}
else {
$entry5->set_text("$remain_boot k");
}
# Better do this first
#V#print "Copy over initrd ramdisk\n";
return if err_custom("cp $tmp/$initrd $mnt/$initrd","gBootRoot: ERROR: Could not copy over initrd") == 2;
pb($B,2);
#V#print "Copying over kernel\n";
return if
err_custom("rm -rf $mnt/lost+found; cp $kernel $mnt/kernel",
"gBootRoot: ERROR: Could not copy over the kernel") == 2;
pb($B,3);
#V#print "Making stuff for lilo\n";
return if err(system "mkdir $mnt/{boot,dev} >> $verbosefn 2>&1; cp -a /dev/{null,fd?,hda1} $mnt/dev >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
# Hopefully, this works, but have never tested it
if ($device !~ m,/dev/fd\d{1}$,) {
return if err(
system "cp -a $device $mnt/dev >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
}
# This adds that next device
($norm_root_device) = gdkbirdaao();
if (!-e "$mnt/dev/$norm_root_device") {
return if err(
system "cp -a /dev/$norm_root_device $mnt/dev >> $verbosefn 2>&1") == 2;
}
2000-08-23 13:44:45 +00:00
# For frame buffer devices and the like.
if ($entry_advanced[1]) {
return if errcp(system "cp -a $entry_advanced[1] $mnt/dev >> $verbosefn 2>&1") == 2;
}
2000-08-13 04:43:39 +00:00
#pb($B,3);
#V#print "Copy over important lilo stuff\n";
2000-08-23 13:44:45 +00:00
return if
2000-08-13 04:43:39 +00:00
err_custom("cp /boot/boot.b $mnt/boot",
"gBootRoot: ERROR: Not enough space or can't find /boot/boot.b") == 2;
pb($B,4);
# 3k sort of accounts for dev & dirs assuming dev is reasonable
$remain_boot = $remain_boot - (stat("/boot/boot.b"))[12]/2 - 3;
$entry5->set_text("$remain_boot k");
# Write out the HEREDOCS
open(LC, ">$mnt/brlilo.conf") or die "Couldn't write $mnt/brlilo.conf\n";
print LC brlilo($device); close(LC);
open(M, ">$mnt/message") or die "Couldn't write $mnt/message\n";
print M message(); close(M);
pb($B,5);
2000-08-23 13:44:45 +00:00
$remain_boot = $remain_boot - ( (stat("$mnt/brlilo.conf"))[12]/2 +
2000-08-13 04:43:39 +00:00
(stat("$mnt/message"))[12]/2 );
$entry5->set_text("$remain_boot k");
# Got to umount,mount, and umount again to make sure everything is
# copied over before doing lilo
return if errum(system "umount $mnt >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
#V#print "Umount device\n";
#V#print "Remount device\n";
pb($B,6);
return if errm(system "mount -t ext2 $entry_advanced[0] $mnt >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
#V#print "Configuring lilo\n";
pb($B,7);
chdir("$mnt"); #"boot_root: ERROR: Could not change directories\n";
if ($device eq $entry_advanced[0]) {
if (err_custom("lilo -v -C brlilo.conf -r $mnt",
"gBootRoot: ERROR: lilo failed") == 2) {
chdir($pwd); return;
}
2000-08-13 04:43:39 +00:00
}
2000-08-13 04:43:39 +00:00
$remain_boot = $remain_boot - (stat("$mnt/boot/map"))[12]/2;
$entry5->set_text("$remain_boot k");
pb($B,8);
chdir($pwd); # or die "boot_root: ERROR: Could not change directories\n";
#V#print "Umounting $mnt\n";
my $um = errum(system "umount $mnt >> $verbosefn 2>&1");
2000-08-13 04:43:39 +00:00
pb($B,10);
if ($ok == 1 || $ok == 2) {
return if
errrm(system "rmdir $tmp/initrd_mnt >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
}
# Here's where we copy over that compressed filesystem
2000-08-23 13:44:45 +00:00
# We could separate $device = boot,root allowing two
2000-08-13 04:43:39 +00:00
# different devices to be used.
if ($um == 0 ) {
2000-08-23 13:44:45 +00:00
mtab(1);
2000-08-13 04:43:39 +00:00
}
else {
error_window("gBootRoot: ERROR: Boot disk was never umounted");
} # copy over the compressed
2000-08-23 13:44:45 +00:00
} # end sub lilo_put_it_together
2000-08-13 04:43:39 +00:00
sub device2 {
2000-08-23 13:44:45 +00:00
my $device_size = (split(/\s+/,`df $mnt`))[8];
2000-08-13 04:43:39 +00:00
my $root_image_size = (stat($root_image))[12]/2;
my $remain_root = $device_size - $root_image_size;
2000-08-23 13:44:45 +00:00
if ($remain_root =~ /^-+\d+$/) {
2000-08-13 04:43:39 +00:00
error_window("gBootRoot: ERROR: Not enough room: root stuff = $root_image_size k, device = $device_size k");
}
else {
$entry5->set_text("$remain_root k");
}
2000-08-23 13:44:45 +00:00
#V#print "Copy over the compressed filesystem\n";
return if errrm(system "rmdir $mnt/lost+found >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
my $broot_image = basename($root_image);
my $FS = "filesystem";
my $line_count = `wc -l < $root_image`; chomp $line_count;
my $half_line_count = $line_count/2;
my $count = 1;
open(CF, ">$mnt/$broot_image") or error_window(
"gBootRoot: ERROR: Could not copy over the root filesystem") and return;
open(CR, "$root_image") or error_window(
2000-08-23 13:44:45 +00:00
"gBootRoot: ERROR: Could not copy over the root filesystem") and return;
2000-08-13 04:43:39 +00:00
while (<CR>) {
2000-08-23 13:44:45 +00:00
print CF $_;
2000-08-13 04:43:39 +00:00
pb($FS,$count,$line_count) if $count < $half_line_count;
$count++;
}
close(CF); close(CR);
2000-08-23 13:44:45 +00:00
return if
err_custom("umount $mnt",
"gBootRoot: ERROR: Root disk did not properly umount") == 2;
2000-08-13 04:43:39 +00:00
pb($FS,$count,$line_count);
#V#print "Finished!\n";
} # end sub device 2
2000-08-27 16:21:49 +00:00
# Checks if lib or bin is stripped, if not proceeds to strip. Returns
# full file path and strip result. Right now this is specific to initrd.
sub stripper {
# stripper (program,bin|lib);
if ((!defined $lib_strip_check && !defined $bin_strip_check) or
($lib_strip_check->active || $bin_strip_check->active)) {
my $not_stripped = `file $_[0]`;
my $filename = basename($_[0]);
if ($not_stripped =~ m,not stripped,) {
if (($_[1] eq "lib" && !defined $lib_strip_check) or
($_[1] eq "lib" && $lib_strip_check->active)) {
# --strip-all works for initrd
if ($obj_count == 0) {
system "objcopy --strip-debug $_[0] $tmp/$filename";
return ( "$tmp/$filename", 1 );
}
elsif ($obj_count == 1) {
system "objcopy --strip-all $_[0] $tmp/$filename";
return ( "$tmp/$filename", 1 );
}
2000-08-27 16:21:49 +00:00
}
elsif (($_[1] eq "bin" && !defined $bin_strip_check) or
($_[1] eq "bin" && $bin_strip_check->active)) {
system "objcopy --strip-all $_[0] $tmp/$filename";
return ( "$tmp/$filename", 1 );
}
}
else {
return ( $_[0], 0 );
}
}
return ( $_[0], 0);
}
2000-08-13 04:43:39 +00:00
sub initrd_size {
my ($linuxrc_size) = @_;
my ($what,$lib);
2000-08-27 16:21:49 +00:00
my ($path,$value);
2000-08-13 04:43:39 +00:00
#V#print "Checking size needed for initrd\n";
# the size of the loop device should be at least 1.63% larger than what
# it will contain (i.e. 8192 inode), but to keep on the safe size it will
# be 2.00% larger.
# 9 dirs = 1024 each (increase if modified)
# {ash,gzip,mount,umount} (required executables)
# bzip2 if $compress eq bzip2 (optional)
# 1 for ld.so.cache
# change dir size if needed
my $dir_size = 9 + 1;
my $initrd_size = $dir_size + $linuxrc_size;
# add other executables here
my @initrd_stuff = qw(ash gzip mount umount);
foreach (@initrd_stuff) {
2000-08-27 16:21:49 +00:00
($path,$value) = stripper("/bin/$_","bin");
$initrd_size = $initrd_size + ((stat($path))[12]/2);
unlink($path) if $value == 1;
2000-08-13 04:43:39 +00:00
}
2000-08-27 16:21:49 +00:00
# path for bzip2 assumes too much
2000-08-13 04:43:39 +00:00
if ($compress eq "bzip2" && -e "/usr/bin/$compress") {
2000-08-27 16:21:49 +00:00
($path,$value) = stripper("/usr/bin/$compress","bin");
$initrd_size = $initrd_size + ((stat($path))[12]/2);
unlink($path) if $value == 1;
2000-08-13 04:43:39 +00:00
}
# lib sizes
2000-08-25 20:19:19 +00:00
# for testing purposes change $lib_place value
2000-08-13 04:43:39 +00:00
open(L,"ldd /sbin/init|") or die "Oops, no init could be found :)\n"; # safe to use ldd
2000-08-23 13:44:45 +00:00
while (<L>) {
$lib = (split(/=>/,$_))[0];
$lib =~ s/\s+//;
$lib = basename($lib);
$lib =~ s/\s+$//;
open (SL,"ls -l /lib/$lib|") or die "humm: $!\n";
2000-08-23 13:44:45 +00:00
while (<SL>) {
2000-08-13 04:43:39 +00:00
# symbolic link
if (-l "/lib/$lib") {
2000-08-23 13:44:45 +00:00
$what = (split(/\s+/,$_))[10];
2000-08-13 04:43:39 +00:00
$initrd_size = $initrd_size + 1;
2000-08-27 16:21:49 +00:00
($path,$value) = stripper("/lib/$lib","lib");
$initrd_size = $initrd_size + ((stat($path))[12]/2);
unlink($path) if $value == 1;
2000-08-23 13:44:45 +00:00
}
2000-08-13 04:43:39 +00:00
# no symbolic link
2000-08-23 13:44:45 +00:00
else {
2000-08-27 16:21:49 +00:00
($path,$value) = stripper("/lib/$lib","lib");
$initrd_size = $initrd_size + ((stat($path))[12]/2);
unlink($path) if $value == 1;
2000-08-23 13:44:45 +00:00
}
2000-08-13 04:43:39 +00:00
}
}
$initrd_size = $initrd_size + ($initrd_size * 0.02);
2000-08-23 13:44:45 +00:00
# For perfection 1 (rounded up) is o.k., but for safety 10 would be
# better
2000-08-13 04:43:39 +00:00
$initrd_size = sprintf("%.f",$initrd_size) + 10;
return $initrd_size;
} # end sub initrd_size
sub pb {
# Will have to count by hand
if ($_[0] eq "initrd") {
2000-08-23 13:44:45 +00:00
$pbar->configure( 10, 0, 10 );
2000-08-13 04:43:39 +00:00
}
elsif ($_[0] eq "boot") {
2000-08-23 13:44:45 +00:00
$pbar->configure( 10, 0, 10 );
2000-08-13 04:43:39 +00:00
}
elsif ($_[0] eq "filesystem") {
$pbar->configure($_[2], 0, $_[2]);
}
2000-08-23 13:44:45 +00:00
$pbar->set_value($_[1]);
# Found this at Gnome ..
2000-08-13 04:43:39 +00:00
# http://www.uk.gnome.org/mailing-lists/archives/gtk-list/
# 1999-October/0401.shtml
# Also, http://www.gtk.org/faq/ 5.14
2000-08-23 13:44:45 +00:00
while (Gtk->events_pending) { Gtk->main_iteration; }
2000-08-13 04:43:39 +00:00
}
sub initrd {
my($kernel,$root_image,$device,$size) = @_;
2000-08-27 16:21:49 +00:00
my($lib,$what,$path,$value,$tool);
2000-08-23 13:44:45 +00:00
my $I = "initrd";
my $broot_image = basename($root_image);
2000-08-13 04:43:39 +00:00
open(LC, ">$tmp/linuxrc") or die "Couldn't write linuxrc to loop device\n";
2000-08-23 13:44:45 +00:00
print LC initrd_heredoc($broot_image); close(LC);
2000-08-13 04:43:39 +00:00
pb($I,1);
my $size_needed = initrd_size((stat("$tmp/linuxrc"))[12]/2);
unlink("$tmp/linuxrc");
#print V "Using loop device to make initrd\n";
#V#print V "Make sure you have loop device capability in your running kernel\n";
system "dd if=/dev/zero of=$tmp/$initrd bs=1024 count=$size_needed >> $verbosefn 2>&1";
2000-08-13 04:43:39 +00:00
pb($I,2);
# no need to enter y every time
open(T,"|mke2fs -m0 -i8192 $tmp/$initrd >> $verbosefn 2>&1") or die "Problem here: $!\n"; print T "y\n"; close(T);
2000-08-13 04:43:39 +00:00
pb($I,3);
#V#print V "Mounting initrd in tmp\n";
return if errmk(system "mkdir $tmp/initrd_mnt >> $verbosefn 2>&1; mount -o loop -t ext2 $tmp/$initrd $tmp/initrd_mnt >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
pb($I,4);
#V#print "Putting everything together\n";
open(LC, ">$tmp/initrd_mnt/linuxrc") or die "Couldn't write linuxrc to loop device\n";
2000-08-23 13:44:45 +00:00
print LC initrd_heredoc($broot_image); close(LC);
2000-08-13 04:43:39 +00:00
# I could test this but somebody's system may do permissions differently
system "chmod 755 $tmp/initrd_mnt/linuxrc >> $verbosefn 2>&1";
system "rmdir $tmp/initrd_mnt/lost+found >> $verbosefn 2>&1";
2000-08-13 04:43:39 +00:00
pb($I,5);
#V#print "... the dirs\n";
return if errmk(system "mkdir $tmp/initrd_mnt/{bin,dev,etc,lib,mnt,proc,sbin,usr} >> $verbosefn 2>&1; mkdir $tmp/initrd_mnt/usr/lib >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
pb($I,6);
return if errcp(system "cp -a /dev/{console,null,ram0,ram1,tty0} $tmp/initrd_mnt/dev >> $verbosefn 2>&1") == 2;
return if errcp(system "cp -a $device $tmp/initrd_mnt/dev >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
pb($I,7);
#V#print ".. the bins\n";
2000-08-27 16:21:49 +00:00
my @initrd_stuff = qw(ash gzip mount umount);
foreach (@initrd_stuff) {
($path,$value) = stripper("/bin/$_","bin");
$value == 0 ? ($tool = "cp -a") : ($tool = "mv");
return if errcp(system "$tool $path $tmp/initrd_mnt/bin >> $verbosefn 2>&1") == 2;
}
# path for bzip2 assumes too much
if ($compress eq "bzip2" && -e "/usr/bin/$compress") {
($path,$value) = stripper("/usr/bin/$compress","bin");
$value == 0 ? ($tool = "cp -a") : ($tool = "mv");
return if errcp(system "$tool $path $tmp/initrd_mnt/bin >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
}
# Testing init is sufficient for grabbing the correct libraries for the
# executables immediately above. This could be modified to test a
2000-08-23 13:44:45 +00:00
# list of executables.
2000-08-13 04:43:39 +00:00
#V#print ".. the libs\n";
open(L,"ldd /sbin/init|") or die "Oops, no init could be found :)\n"; # safe to use ldd
2000-08-23 13:44:45 +00:00
while (<L>) {
$lib = (split(/=>/,$_))[0];
$lib =~ s/\s+//;
$lib = basename($lib);
$lib =~ s/\s+$//;
open (SL,"ls -l /lib/$lib|") or die "humm: $!\n";
while (<SL>) {
2000-08-13 04:43:39 +00:00
# symbolic link
if (-l "/lib/$lib") {
2000-08-23 13:44:45 +00:00
$what = (split(/\s+/,$_))[10];
2000-08-27 16:21:49 +00:00
($path,$value) = stripper("/lib/$lib","lib");
$value == 0 ? ($tool = "cp -a") : ($tool = "mv");
return if errcp(system "$tool $path $tmp/initrd_mnt/lib >> $verbosefn 2>&1") == 2;
($path,$value) = stripper("/lib/$what","lib");
$value == 0 ? ($tool = "cp -a") : ($tool = "mv");
return if errcp(system "$tool $path $tmp/initrd_mnt/lib >> $verbosefn 2>&1") == 2;
2000-08-23 13:44:45 +00:00
}
2000-08-13 04:43:39 +00:00
# no symbolic link
2000-08-23 13:44:45 +00:00
else {
2000-08-27 16:21:49 +00:00
($path,$value) = stripper("/lib/$lib","lib");
return if errcp(system "cp -a $path $tmp/initrd_mnt/lib >> $verbosefn 2>&1") == 2;
2000-08-23 13:44:45 +00:00
}
2000-08-13 04:43:39 +00:00
}
}
2000-08-27 16:21:49 +00:00
2000-08-13 04:43:39 +00:00
#V#print "Determine run-time link bindings\n";
# Has a return code of 0 regardless
system "ldconfig -r $tmp/initrd_mnt";
#V#print "Umounting loop device, and compressing initrd";
return if errum(system "umount $tmp/initrd_mnt >> $verbosefn 2>&1") == 2;
system "gzip -f9 $tmp/$initrd >> $verbosefn 2>&1";
2000-08-13 04:43:39 +00:00
pb($I,10); # This takes the longest.
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
$initrd = $initrd . ".gz";
} # end sub initrd
# This was submitted by Cristian "cretzu."
sub gdkbirdaao
{
# Guess Default Kernel Boot Image Root Device And Append Options (gdbirdaao)
#
# We return a list with 3 elements:
#
# root device, kernel boot image path and append options
#
# The last list element (append options) could be returned as a list
# of options, but it probably might be cleaner if the caller splitted it.
#
# this should cover the following cases:
#
# 1. we have a 'root=...' somewhere above the 'image=...' block(s), and
# the image block may or may not have a root specified
#
# 2. there is no default label, in which case, we take the first one
#
# 3. there is a default label, and that's what we pick up
#
my $ret_image_path = '';
my $ret_root_dev = '';
my $ret_append = '';
if (-e $lilo_conf and !-d $lilo_conf)
{
open(LIL, $lilo_conf) or die "*** $lilo_conf not found,";
my @lilo_lines = <LIL>;
close(LIL);
chomp(@lilo_lines);
my $default_label = '';
my %image_blocks;
my $image_block_name_prefix = 'ImageBlock';
my $image_block_no = 1;
my $image_block_name = '';
my $root_dev = '';
for (@lilo_lines)
{
# ignore comment lines
next if m/^\s*[#]/;
# cleanup whitespace
s/\s*//;
s/\s*$//;
s/\s*=\s*/=/;
# 'default=whatever' returns just a label
if (m/default=(.+)\s*/)
{
$default_label = $1;
}
# start of a new 'image=<kernel path>' image block or similar
elsif (m/(image|other)=(.+)\s*/)
{
$image_block_name = sprintf("%s%02d",
$image_block_name_prefix,
$image_block_no);
$image_blocks{$image_block_name}{'kernel_image_path'} = $2;
$image_blocks{$image_block_name}{'root_device'} = $root_dev;
$image_block_no += 1;
}
# image block label
elsif (m/label=(.+)\s*/)
{
$image_blocks{$image_block_name}{'block_label'} = $1;
}
# 'root=<root device>'
elsif (m#root=/dev/(.+)\s*#)
{
# inside an image block
if ($image_block_name and
defined($image_blocks{$image_block_name}{'root_device'}))
{
$image_blocks{$image_block_name}{'root_device'} = $1;
}
# loose
else
{
$root_dev = $1 if !$root_dev;
}
}
elsif (m#append=\"(.+)\"#)
{
$image_blocks{$image_block_name}{'append'} = $1;
}
else
{
# Ignore everything else
}
}
# we'll now find the kernel image and root device
foreach $image_block_name (sort keys %image_blocks)
{
# Assume there's no specified default label; take the first
$ret_root_dev = $image_blocks{$image_block_name}{'root_device'}
if !$ret_root_dev;
$ret_image_path = $image_blocks{$image_block_name}{'kernel_image_path'}
if !$ret_image_path;
$ret_append = $image_blocks{$image_block_name}{'append'}
if !$ret_append;
# do we have a default kernel?
if ($image_blocks{$image_block_name}{'block_label'} eq $default_label)
{
# Found the block match for the default label
$ret_root_dev = $image_blocks{$image_block_name}{'root_device'};
$ret_image_path = $image_blocks{$image_block_name}{'kernel_image_path'};
$ret_append = $image_blocks{$image_block_name}{'append'};
last;
}
}
}
# and some a small portion of paranoia
$ret_root_dev = 'hda1' if !$ret_root_dev;
return ($ret_root_dev, $ret_image_path, $ret_append);
} # end sub gdkbirdaao
2000-08-13 04:43:39 +00:00
sub mtab_window {
# Will just use a dialog box.
my ($dialog,$error,$count,$pattern) = @_;
if (not defined $mtab) {
2000-08-23 13:44:45 +00:00
$mtab = new Gtk::Dialog;
2000-08-13 04:43:39 +00:00
$mtab->signal_connect("destroy", \&destroy_window, \$mtab);
2000-08-23 13:44:45 +00:00
$mtab->signal_connect("delete_event", \&destroy_window, \$mtab);
2000-08-13 04:43:39 +00:00
$mtab->set_title("gBootRoot: Device check");
2000-08-23 13:44:45 +00:00
$mtab->border_width(15);
2000-08-13 04:43:39 +00:00
$mtab->set_position('center');
my $label = new Gtk::Label($dialog);
$label->set_justify( 'left' );
$label->set_pattern("_________") if defined $pattern;
$mtab->vbox->pack_start( $label, $true, $true, 15 );
$label->show();
my $button = new Gtk::Button("OK");
$button->signal_connect("clicked", \&mtab_check, $count);
$button->can_default(1);
$mtab->action_area->pack_start($button, $false, $false,0);
$button->grab_default;
$button->show;
2000-08-23 13:44:45 +00:00
$button = new Gtk::Button("Cancel");
2000-08-13 04:43:39 +00:00
$button->signal_connect("clicked", sub { destroy $mtab} );
$mtab->action_area->pack_start($button, $false, $false,0);
$button->show;
}
if (!visible $mtab) {
show $mtab;
}
else {
destroy $mtab;
mtab_window($dialog,$error,$count) if $error == 0;
}
} # end sub mtab_window
sub mtab{
2000-08-23 13:44:45 +00:00
2000-08-13 04:43:39 +00:00
# /proc/mount could be used, but maybe there is no /proc
# Press OK when drive and storage medium are ready. The drive should not
2000-08-23 13:44:45 +00:00
# be mounted.
2000-08-13 04:43:39 +00:00
if ($_[0] == 0) {
my $dialog = "BOOTDISK:\n"
."Press OK when the drive and its storage medium is ready.\n"
2000-08-13 04:43:39 +00:00
."The Boot Disk will now be made. All data already on\n"
2000-08-23 13:44:45 +00:00
."the storage medium will be erased.";
2000-08-13 04:43:39 +00:00
mtab_window($dialog,1,$_[0],1);
}
elsif ($_[0] == 1) {
2000-08-23 13:44:45 +00:00
my $dialog = "ROOTDISK:\n"
."Press OK when the drive and its storage medium is ready.\n"
2000-08-13 04:43:39 +00:00
."The Root Disk will now be made. All data already on\n"
2000-08-23 13:44:45 +00:00
."the storage medium will be erased.";
2000-08-13 04:43:39 +00:00
mtab_window($dialog,1,$_[0],1);
}
} # end sub mtab
sub mtab_check {
my($widget,$count) = @_;
my $dialog;
my $error = 1;
# Check to see if $device is mounted
open (MTAB, "/etc/mtab") or die "no mtab!\n";
while (<MTAB>) {
if (m,$entry_advanced[0],) {
2000-08-13 04:43:39 +00:00
# Safety Check:
$dialog = "Please umount the device first.\nPress OK when you are ready.";
$error = 0;
}
}
close(MTAB);
mtab_window($dialog,$error,$count) if $error == 0;
2000-08-23 13:44:45 +00:00
# Make sure the drive and storage medium are accessible
2000-08-13 04:43:39 +00:00
# Keep asking until they are.
if ($error == 1) {
destroy $mtab;
system "mke2fs -m0 -i8192 $entry_advanced[0] $size >> $verbosefn 2>&1";
2000-08-13 04:43:39 +00:00
if ($? != 0) {
$dialog = "gBootRoot: ERROR: You need to insert a disk\n";
mtab_window($dialog,$error,$count);
return;
}
return if errm(system "mount -t ext2 $entry_advanced[0] $mnt >> $verbosefn 2>&1") == 2;
2000-08-13 04:43:39 +00:00
lilo_put_it_together() if $count == 0;
device2() if $count == 1;
}
} # end sub mtab_check
sub initrd_heredoc {
my($broot_image) = @_;
# Here's where the initrd is put together using a loop device
# HEREDOC
my $initrd_exec = << "INITRD";
#!/bin/ash
export PATH=/bin:/sbin:/usr/bin:
echo Preparing to setup ramdisk.
mount -o remount,rw / 2>/dev/null
echo Mounting proc...
mount -t proc none /proc
echo -n 'Please insert the root floppy, and press [Enter]: '
read ENTER
echo Mounting $device readonly ...
mount -o ro -t ext2 $device /mnt
2000-08-13 04:43:39 +00:00
echo -n Copying new root to ramdisk .. please wait ...
$compress -cd /mnt/$broot_image > /dev/ram1
2000-08-13 04:43:39 +00:00
echo done.
echo -n Unmounting $device ...
umount /mnt
2000-08-13 04:43:39 +00:00
echo done.
echo Changing to the new root.
echo 257 >/proc/sys/kernel/real-root-dev
echo -n Unmounting proc ...
umount /proc
echo done.
echo Continuing normal boot procedure from ramdisk.
INITRD
return $initrd_exec;
} # end sub initrd_heredoc
sub brlilo {
my ($device) = @_;
$entry_advanced[2] ? $entry_advanced[2] = $entry_advanced[2]
: $entry_advanced[2] = $container[11];
2000-08-13 04:43:39 +00:00
# HEREDOC
my $brlilo = << "LILOCONF";
boot = $device
message = message
delay = 50
vga = normal
install = /boot/boot.b
map = /boot/map
backup = /dev/null
compact
# bootdisk
2000-08-23 13:44:45 +00:00
image = kernel
append = "load_ramdisk = 1 debug $entry_advanced[2]"
2000-08-13 04:43:39 +00:00
initrd = $initrd
root = $device
label = bootdisk
read-write
# normalboot
2000-08-23 13:44:45 +00:00
image = kernel
append = "$entry_advanced[2]"
root = /dev/$norm_root_device
2000-08-13 04:43:39 +00:00
label = normalboot
read-only
LILOCONF
return $brlilo;
} # end sub brlilo
sub message {
# HEREDOC
my $message = << "MESSAGE";
gBootRoot $version $date GNU GPL
mailto: Jonathan Rosenbaum <mttrader\@access.mountain.net>
2000-08-13 04:43:39 +00:00
Press [Ctrl] to see the lilo prompt.
Press [Tab] to see a list of boot options.
bootdisk = This will boot a compressed root filesystem
on another floppy.
2000-08-23 13:44:45 +00:00
normalboot = This will boot up a specified filesystem.
default: /dev/$norm_root_device
2000-08-13 04:43:39 +00:00
Use root=/dev/(h or s)dXX
h = IDE Drive
s = SCSI Drive
Trouble: Do not forget boot: option single
2000-08-23 13:44:45 +00:00
Fix a filesystem: e2fsck /dev/(h or s)dXX
2000-08-13 04:43:39 +00:00
Bad superblock: e2fsck -b 8192 /dev/(h or s)dXX
MESSAGE
return $message;
} # end sub message
sub help {
<< "HELP";
gBootRoot $version $date GNU GPL
email: Jonathan Rosenbaum <mttrader\@access.mountain.net>
2000-08-13 04:43:39 +00:00
site -> http://the.netpedia.net/gBootRoot.html
2000-08-23 13:44:45 +00:00
gBootRoot is a Gtk+/Perl program useful for both beginners and advanced
GNU/Linux users. It makes the construction/development of emergency and
mini distributions simple.
2000-08-13 04:43:39 +00:00
2000-08-23 13:44:45 +00:00
- A GNU/Linux user can easily create an emergency Boot/Root set. There
are a multitude of pre-existing compressed filesystems readily available.
Please check the gBootRoot FAQ at the gBootRoot site listed above.
** If you are a developer please send me links to Kernel/Filesystems which
I can share with users of gBootRoot.
2000-08-13 04:43:39 +00:00
2000-08-23 13:44:45 +00:00
- A developer creating a mini distribution can concentrate his efforts on
perfecting the filesystem, and then he can use gBootRoot to quickly create a
Boot/Root set to run tests.
2000-08-13 04:43:39 +00:00
- Disk sets allow for more space to include interesting and necessary things.
The size of the Kernel is increasing every day making sets advantageous.
How to Use gBootRoot:
gBootRoot is similar to BootRoot, but it is more efficient
2000-08-23 13:44:45 +00:00
and powerful. The most important button to familiarize yourself
2000-08-13 04:43:39 +00:00
with is the Submit button which starts the whole process, dialogs are
presented as the process continues asking you if you want to continue "OK" or
2000-08-23 13:44:45 +00:00
stop "Cancel".
2000-08-13 04:43:39 +00:00
2000-08-23 13:44:45 +00:00
There are 5 rows. The boot method column has only one choice "lilo."
2000-08-13 04:43:39 +00:00
Clicking on the menu on the right selects the method.
2000-08-23 13:44:45 +00:00
The second row allows you to select the kernel for the Boot/Root set. You
may either use the file selector button on the right hand side, or you may
type in the location on the left hand side.
2000-08-13 04:43:39 +00:00
2000-08-23 13:44:45 +00:00
The third row allows you to select the compressed filesystem you are
2000-08-13 04:43:39 +00:00
providing, using either of the two ways mentioned before.
The fourth row allows you to select the device you want to use. The default
device is the first floppy disk (/dev/fd0).
The fifth row allows you to choose the size of the device being used.
2000-08-23 13:44:45 +00:00
If you choose the compressed filesystem with the file selector the program
should automatically detect the compression used, otherwise, click on the
2000-08-13 04:43:39 +00:00
appropriate radio button to choose either gzip or bzip2 compression.
Little things you may want to know:
* gBootRoot requires ash for initrd. Ash is a feather weight version of Bash.
HELP
}