]> arthur.barton.de Git - netatalk.git/blob - contrib/shell_utils/apple_cp
Shell utils from http://www.-genome.wi.mit.edu/ftp/distribution/software/Bass/bass...
[netatalk.git] / contrib / shell_utils / apple_cp
1 #!/usr/local/bin/perl
2
3 # $Header: /home/ralph/netatalk/rsync/netatalk/contrib/shell_utils/Attic/apple_cp,v 1.1 2000-08-09 14:08:06 rufustfirefly Exp $
4 #
5 # $Log: apple_cp,v $
6 # Revision 1.1  2000-08-09 14:08:06  rufustfirefly
7 # Shell utils from http://www.-genome.wi.mit.edu/ftp/distribution/software/Bass/bass-1.29/apple_util/ (initial import)
8 #
9 # Revision 1.1  1996/04/03 02:13:12  lstein
10 # Added all these files because they're essential utilities.
11 #
12 # Revision 1.2  1996/02/09  18:44:44  will
13 # fix to usage string
14 #
15 # Revision 1.1  1996/02/09  18:21:35  will
16 # Initial revision
17 #
18 #
19
20 $USAGE = <<USAGE;
21 Usage: $0 filename1 filename2
22        $0 filename ...  directory
23 Do an apple copy, copying the resource fork as well
24 USAGE
25
26 die $USAGE if @ARGV < 2;
27
28 @from = @ARGV; pop(@from);
29 $to = $ARGV[$#ARGV];
30
31 if (-f $to && @from > 1) { die $USAGE; }
32
33 foreach $from (@from) {
34     if (!-f $from) {    
35         print STDERR "file $from does not exist\n";
36         die $USAGE;
37     }
38     
39     if (!-d $to) {
40         print STDERR "directory $to does not exist\n";
41         die $USAGE;
42     }
43     
44     $cmd = "cp '$from' '$to'";
45     system $cmd || die "error executing $cmd";
46     
47     ($from_dir, $from_file) = split_dir_file($from);
48
49     if (-d $to) {
50         if (!-d "$to/.AppleDouble") {
51             mkdir("$to/.AppleDouble", 0777);
52         }       
53         $cmd = "cp '$from_dir/.AppleDouble/$from_file' '$to/.AppleDouble/$from_file'";
54     } else {
55         ($to_dir, $to_file) = split_dir_file($from);
56         if (!-d "$to_dir/.AppleDouble") {
57             mkdir("$to_dir/.AppleDouble", 0777);
58         }       
59         $cmd = "cp '$from_dir/.AppleDouble/$from_file' '$to_dir/.AppleDouble/$to_file'";
60     }
61
62     system $cmd || die "error executing $cmd";
63 }
64
65 # split a file path into a directory and file name.
66 sub split_dir_file {
67     my $path = shift;
68
69     @path_elems = split(/\//, $path);
70
71     my $file = pop(@path_elems);
72     my $dir;
73     if (!@path_elems) {
74         $dir = '.';
75     } else {
76         $dir = join('/', @path_elems);
77     }
78
79     $dir, $file;
80 }
81
82