1 |
root |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
|
7 |
|
|
my $debug = 0; |
8 |
|
|
|
9 |
|
|
use Data::Dumper; |
10 |
|
|
|
11 |
|
|
# read arguments from cli |
12 |
|
|
my $settings = {}; |
13 |
|
|
my $args = []; |
14 |
|
|
while (my $arg = shift) { |
15 |
|
|
next if !$arg; |
16 |
|
|
if ($arg =~ m/^--(.+?)$/) { |
17 |
|
|
$settings->{$1} = 1; |
18 |
|
|
next; |
19 |
|
|
} |
20 |
|
|
push @$args, $arg; |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
# transfer arguments to settings |
24 |
|
|
$settings->{target} = pop @$args; |
25 |
|
|
$settings->{source} = $args; |
26 |
|
|
|
27 |
|
|
# debug |
28 |
|
|
print Dumper($settings), "\n" if $debug; |
29 |
|
|
|
30 |
|
|
my $cp_arg = ''; |
31 |
|
|
$cp_arg .= '--symbolic-link ' if $settings->{symlink}; |
32 |
|
|
$cp_arg .= '--remove-destination ' if $settings->{force}; |
33 |
bd |
1.2 |
$cp_arg .= '--recursive ' if $settings->{recursive}; |
34 |
root |
1.1 |
|
35 |
|
|
# run it |
36 |
|
|
foreach my $source (@{$settings->{source}}) { |
37 |
|
|
|
38 |
|
|
$source =~ s/\(/\\(/g; |
39 |
|
|
$source =~ s/\)/\\)/g; |
40 |
|
|
$source =~ s/\s/\\ /g; |
41 |
|
|
|
42 |
|
|
print "linking $source", "\n"; |
43 |
|
|
|
44 |
|
|
my $cmd = <<EOC; |
45 |
|
|
mkdir -p $settings->{target} && \ |
46 |
|
|
cd $settings->{target} && \ |
47 |
|
|
cp $cp_arg $source . |
48 |
|
|
EOC |
49 |
|
|
|
50 |
|
|
#print "cmd: $cmd", "\n"; |
51 |
|
|
#print `$cmd`, "\n"; |
52 |
|
|
|
53 |
|
|
#`$cmd`; |
54 |
|
|
system($cmd); |
55 |
|
|
|
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
1; |
59 |
|
|
|