4 ###APPDATE: 2009-05-21 15:08:33
6 ###APPDESC: floppy building system
7 ###APPUSAGE: [-w dir][-c file][-o os] [-d] [-i file] [-t type] name [target]
8 ###APPOPTION: name:name of the disk or image to build (see bfd.cfg)|target:target drive or file (default is "a:")|-o os:os to use (default is "md701")|-d:print debug messages|-i file:create an image file (optional winimage!)|-t type:image type (144 or 288,see "bfi")|-n:don't wait for the user to insert a diskette|-w dir:specify working directory|-c file:specify configure file(default bfd.cfg)
11 #ENV variable MUST be defined somewhere,
12 #FOR perl to search modules from,
14 use lib
$ENV{XR_PERL_MODULE_DIR
};
16 use MyPlace
::Script
::Usage qw
/help_required help_even_empty/;
17 #exit 0 if(help_required($0,@ARGV));
18 exit 0 if(help_even_empty
($0,@ARGV));
19 my ($debug,$os,$filename,$type,$name,$target);
23 if($_ eq '-d' or $_ eq '-d') {
42 #use Data::Dumper;warn Dumper(\%o),"\n";
46 return "$fst/" . uc($sec) if(-f
"$fst/" . uc($sec));
52 print STDERR
"$0: ",@_;
63 print STDERR
"\t[" . "@_" ."]\n";
75 msg
("Invalid exit code while runing \"",join(" ",@_),"\"\n");
90 abort
("Error, name required.\n") unless($o{name
});
91 abort
("Error, filename required.(-i)\n") unless($o{-i
});
93 my $bfd_src= $o{-w
} || ".";
95 $o{-c
} = "bfd.cfg" unless($o{-c
});
96 foreach($o{-c
}, "bfd.cfg","$bfd_src/$o{-c}","$bfd_src/bfd.cfg") {
102 abort
("Error, configure file not found\n") unless($bfd_config);
103 my $bfd_work=$bfd_config;
104 $bfd_work =~ s/\/[^\/]+$//;
105 $bfd_work = "." unless(-d
$bfd_work);
110 return undef unless($fn);
111 return $cached{$fn} if($cached{$fn});
112 # warn("reading $fn ...\n");
113 open FI
,"<",$fn or return undef; my @text=<FI
>; close FI
;
117 next if((!$_) or /^\s*$/ or /^\s*#/);
121 my @files = split(/\s+/,$_);
123 my $rr = &read_cfg
($bfd_work . "/$_");
124 push @result,@
{$rr} if($rr);
131 $cached{$fn} = [@result];
137 return undef unless($text);
138 my %result; my $name = "default";
140 my @arg=split(/\s+/,$_);
142 $arg[0] = lc($arg[0]);
144 $name = $arg[1] if($arg[1]);
147 push @
{$result{$name}},[@arg];
152 my $text = read_cfg
($bfd_config);
153 my %config = parse_cfg
($text);
154 abort
("config name [" . $o{name
} . "] not exist\n") unless($config{$o{name
}});
155 #print STDERR Dumper($config{$o{name}}),"\n";
156 my @cmd = @
{$config{$o{name
}}};
158 use File
::Temp qw
/tempdir/;
159 my $bfd_target = tempdir
();
160 my $bfd_os = $o{-o
} || "md701";
161 my $bfd_file = $o{-i
};
162 my $bfd_label = "boot";
163 my $bfd_type = $o{-t
} || "144";
168 my($name,@args) = @
{$_};
172 elsif($name eq "o" or $name eq "os") {
174 $bfd_os = $args[0] if(@args);
176 elsif($name eq "b") {
177 $bfd_label = $args[0] if(@args);
179 elsif($name eq "it") {
180 $bfd_type = $args[0] if(@args);
183 push @bfd_cmds,[$name,@args];
189 s/%bfd_os%/$bfd_os/g;
190 s/%bfd_file%/$bfd_file/g;
191 s/%bfd_label%/$bfd_label/g;
192 s/%bfd_target%/$bfd_target/g;
193 s/%bfd_type%/$bfd_type/g;
198 ($bfd_label)=expand
($bfd_label);
199 ($bfd_file)=expand
($bfd_file);
203 push @bfd_cmds,[expand
(@
{$_})];
207 return cmd_abort
("Invalid command") unless(@_);
208 my $dst="$bfd_target/" . ($_[1] ?
$_[1] : "");
209 run
("cp","-fa",glob("$bfd_src/$_[0]"),$dst);
212 return cmd_abort
("Invalid command") unless(@_);
213 my $dst="$bfd_target/" . ($_[1] ?
$_[1] : "");
214 t_run
("cp","-fa",glob("$bfd_src/$_[0]"),"$dst");
217 return cmd_abort
("Invalid command") unless(@_);
218 return cmd_abort
("Directory not exist $_[0]") unless(-d
"$bfd_src/$_[0]");
219 my $dst="$bfd_target/" . ($_[1] ?
$_[1] : "");
220 my @src = glob("$bfd_src/$_[0]/*");
221 run
("cp","-fa",@src,$dst) if(@src);
225 return cmd_abort
("Invalid command") unless(@_);
226 run
("mkdir","-p",map("$bfd_target/" . $_,@_));
229 return cmd_abort
("Invalid command") unless($_[2]);
233 return cmd_abort
("Invalid command") unless(@_);
234 run
("rm","-f",map("$bfd_target/" . $_,@_));
237 msg
("Checking OS...\n");
239 abort
("OS directory not readable\n") unless(-d
"$bfd_src/os/$bfd_os");
240 if(-f
"$bfd_src/os/$bfd_os/ibmbio.sys") {
241 @ofile = qw
/ibmbio.sys ibmdos.sys command.com/;
243 elsif(-f
"$bfd_src/os/$bfd_os/kernel.sys") {
244 @ofile = qw
/kernel.sys command.com/;
247 @ofile = qw
/io.sys msdos.sys command.com/;
251 foreach(@tfile,"bootsect.bin") {
252 if (-f
"$bfd_src/os/$bfd_os/$_") {
253 push @ofile,$_ unless($_ eq "bootsect.bin");
255 elsif(-f
"$bfd_src/os/$bfd_os/" . uc($_)) {
256 push @ofile,uc($_) unless($_ eq "bootsect.bin");
259 abort
("OS file not exist \"$bfd_src/os/$bfd_os/$_\"\n");
263 msg
("Processing commands...\n");
266 my ($name,@args)=@
{$_};
267 msg
($name," @args...");# if($o{-d});
268 $name = "cmd_" . $name;
271 print STDERR
"\t[OK]\n";
274 abort
("Aborted...\n");
278 #my @bfi = ("bfi","-t",$bfd_type,"-l",$bfd_label,"-f",$bfd_file,-"b","$bfd_src/os/$bfd_os/bootsect.bin");
279 my @bfi = ("bfi","-t",$bfd_type,"-f",$bfd_file,-"b","$bfd_src/os/$bfd_os/bootsect.bin");
280 push(@bfi,"-o","$bfd_src/os/$bfd_os/$_") foreach(@ofile);
282 #msg("OS \t[$bfd_os]\n");
283 #msg("File \t[$bfd_file]\n");
284 #msg("Label\t[$bfd_label]\n");
285 #msg("Type \t[$bfd_type]\n");
286 #msg("BFI \t[","@bfi","]\n");
287 #system("ls","-l",$bfd_target);
288 system(@bfi,$bfd_target);
289 #system("rm","-fdr",$bfd_target);