Merge branch 'master' of gitosis@majnematic.com:davesdots

This commit is contained in:
David Alexander Majnemer 2009-02-08 22:44:59 -06:00
commit 5869fc8195

View file

@ -6,7 +6,7 @@
use strict; use strict;
use warnings; use warnings;
use File::Path 'mkpath'; use File::Path qw(mkpath rmtree);
use File::Glob ':glob'; use File::Glob ':glob';
use Cwd 'cwd'; use Cwd 'cwd';
@ -20,8 +20,8 @@ if(grep /^(?:-h|--help|-\?)$/, @ARGV) {
install.pl: installs symbolic links from dotfile repo into your home directory install.pl: installs symbolic links from dotfile repo into your home directory
Options: Options:
-f force an overwrite existing files -f force an overwrite existing files
-h, -? print this help -h, -? print this help
Destination directory is "$home". Destination directory is "$home".
Source files are in "$scriptdir". Source files are in "$scriptdir".
@ -73,22 +73,36 @@ my %links = (
xmobarrc => '.xmobarrc', xmobarrc => '.xmobarrc',
'xmonad.hs' => '.xmonad/xmonad.hs', 'xmonad.hs' => '.xmonad/xmonad.hs',
'gitconfig' => '.gitconfig', gitconfig => '.gitconfig',
'lock' => 'bin/lock', lock => 'bin/lock',
); );
my $i = 0; # Keep track of how many links we added
for my $file (keys %links) { for my $file (keys %links) {
# See if this file resides in a directory, and create it if needed.
my($path) = $links{$file} =~ m{^ (.+/)? [^/]+ $}x; my($path) = $links{$file} =~ m{^ (.+/)? [^/]+ $}x;
mkpath("$home/$path") if $path; mkpath("$home/$path") if $path;
my $src = "$scriptdir/$file"; my $src = "$scriptdir/$file";
my $dest = "$home/$links{$file}"; my $dest = "$home/$links{$file}";
# Remove the destination if it exists and we were told to force # If a link already exists, see if it points to this file. If so, skip it.
if($force && -e $dest) { # This prevents extra warnings caused by previous runs of install.pl.
unlink($dest) || warn "Couldn't unlink '$dest': $!\n"; if(-e $dest && -l $dest) {
next if readlink($dest) eq $src;
} }
symlink($src => $dest) || warn "Couldn't link '$src' to '$dest': $!\n"; # Remove the destination if it exists and we were told to force an overwrite
if($force && -f $dest) {
unlink($dest) || warn "Couldn't unlink '$dest': $!\n";
} elsif($force && -d $dest) {
rmtree($dest) || warn "Couldn't rmtree '$dest': $!\n";
}
symlink($src => $dest) ? $i++ : warn "Couldn't link '$src' to '$dest': $!\n";
} }
print "$i link";
print 's' if $i != 1;
print " created\n";