2 # This script will either prefix all symlink values with the string
3 # "/rsyncd-munged/" or remove that prefix.
8 my $SYMLINK_PREFIX = '/rsyncd-munged/';
13 'munge' => sub { $munge_opt = 1 },
14 'unmunge' => sub { $munge_opt = 0 },
15 'all' => \
( my $all_opt ),
16 'help|h' => \
( my $help_opt ),
19 &usage
if $help_opt || !defined $munge_opt;
21 my $munged_re = $all_opt ?
qr/^($SYMLINK_PREFIX)+(?=.)/ : qr/^$SYMLINK_PREFIX(?=.)/;
23 push(@ARGV, '.') unless @ARGV;
25 open(PIPE
, '-|', 'find', @ARGV, '-type', 'l') or die $!;
29 my $lnk = readlink($_) or next;
31 next if !$all_opt && $lnk =~ /$munged_re/;
32 $lnk =~ s/^/$SYMLINK_PREFIX/;
34 next unless $lnk =~ s/$munged_re//;
37 warn "Unable to unlink symlink: $_ ($!)\n";
38 } elsif (!symlink($lnk, $_)) {
39 warn "Unable to recreate symlink: $_ -> $lnk ($!)\n";
51 Usage: munge-symlinks --munge|--unmunge [--all] [DIR|SYMLINK...]
53 --munge Add the $SYMLINK_PREFIX prefix to symlinks if not already
54 present, or always when combined with --all.
55 --unmunge Remove one $SYMLINK_PREFIX prefix from symlinks or all
56 such prefixes with --all.
58 See the "munge symlinks" option in the rsyncd.conf manpage for more details.