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