3 if(($#ARGV < 0) || ($ARGV[0] eq "help")) {
4 print STDERR "usage:\n";
5 print STDERR "\tcdtool add {FILES|-g GRAFTPOINT}...\n";
6 print STDERR "\tcdtool ls\n";
7 print STDERR "\tcdtool rm NAME\n";
8 print STDERR "\tcdtool szck\n";
9 print STDERR "\tcdtool setgp [GRAFTPOINT]\n";
10 print STDERR "\tcdtool setimg [IMAGE]\n";
11 print STDERR "\tcdtool mkiso\n";
15 if(-r $ENV{"HOME"} . "/.cdtool") {
16 if(open CF, $ENV{"HOME"} . "/.cdtool") {
19 if(/^(\S+)\s+(.*)$/) {
22 } elsif($1 eq "img") {
25 print STDERR "cdtool: warning: unknown .cdtool directive: $1\n";
35 $path = "./" . $path unless $path =~ m,^/,;
39 $path =~ s,/+([^/]*)$,,;
42 die "weird path given: $_[0]";
45 if(!open CHILD, "-|") {
50 chomp($cpath = <CHILD>);
52 return "$cpath$trailer";
57 $path =~ s,/[^/]+/*$,,;
62 my($file, $graft) = @_;
63 my($dir, $f, $basename);
65 $basename =~ s,^.*/,,;
67 print "add $file to $graft\n" if $verbose;
68 $img{"$graft$basename"} = $file;
70 $dir = canonpath $file;
71 if(opendir DIR, "$dir") {
72 for $f (sort grep !/^\./, readdir DIR) {
73 addfile("$dir/$f", "$graft$basename/");
77 print STDERR "cdtool: could not open $file for listing: $!\n";
80 print STDERR "cdtool: $file: not a regular file or directory\n";
85 my($file, $dieonerr) = @_;
86 $dieonerr = 1 unless defined $dieonerr;
87 if(!open(IMG, "<", $file)) {
95 if(/^file (.*):::(.*)$/) {
97 } elsif(/^name (.*)$/) {
99 } elsif(/^rev (\d+)$/) {
101 } elsif(/^justburned/) {
110 open(IMG, ">", $file) || die "$file: $!";
111 print IMG "rev $rev\n";
112 print IMG "justburned\n" if $justburned;
113 for $f (sort keys %img) {
114 print IMG ("file " . $f . ":::" . $img{$f} . "\n");
122 $imgname =~ s,^.*/,,;
126 while(($arg = shift @ARGV) =~ /^-(.+)/) {
128 while($opts =~ s/^(.)//) {
137 if(!defined $image) {
138 print STDERR "cdtool: no image defined for adding\n";
145 $graft .= "/" unless $graft eq "";
146 while(defined($arg = shift @ARGV)) {
148 $graft = shift @ARGV;
150 $graft .= "/" unless $graft eq "";
152 if(!defined $graft) {
153 print STDERR "cdtool: no graft point defined when adding\n";
156 addfile canonpath($arg), $graft
160 } elsif($cmd eq "ls") {
162 for $gf (sort keys %img) {
165 } elsif($cmd eq "rm") {
166 die "no name specified" unless defined($file = shift @ARGV);
167 $file = canonpath $file;
172 for $gname (grep substr($img{$_}, 0, length $file) eq $file, keys %img) {
177 for $gname (grep $img{$_} eq $file, keys %img) {
183 print STDERR "cdtool: $file not found in image\n";
188 } elsif($cmd eq "szck") {
191 for $file (values %img) {
194 $size =~ s/(\d{3})/$1,/g;
197 } elsif($cmd eq "setgp") {
198 $curgraft = shift @ARGV;
199 $curgraft =~ s,/+$,,;
200 } elsif($cmd eq "setimg") {
201 $curimage = shift @ARGV;
202 } elsif($cmd eq "mkiso") {
204 open(ISO, "|-", "mkisofs", "-J", "-R", "-V", "$imgname r$rev", "-graft-points", "-path-list", "-") || die "mkisofs: $!";
205 for $gf (sort keys %img) {
206 print ISO ($gf . "=" . $img{$gf} . "\n");
215 print STDERR "cdtool: unknown command: $cmd\n";
219 die if(!open CF, ">" . $ENV{"HOME"} . "/.cdtool");
220 if(defined $curgraft) {
221 print CF "gp $curgraft\n";
223 if(defined $curimage) {
224 print CF "img $curimage\n";