2008-12-18 18:36:54 -06:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
|
|
|
|
# install.pl
|
|
|
|
# script to create symlinks from the checkout of davesdots to the home directory
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2009-02-05 10:22:47 -06:00
|
|
|
use File::Path qw(mkpath rmtree);
|
2008-12-18 18:36:54 -06:00
|
|
|
use File::Glob ':glob';
|
|
|
|
use Cwd 'cwd';
|
|
|
|
|
|
|
|
my $scriptdir = cwd() . '/' . $0;
|
|
|
|
$scriptdir =~ s{/ [^/]+ $}{}x;
|
|
|
|
|
|
|
|
my $home = bsd_glob('~', GLOB_TILDE);
|
|
|
|
|
|
|
|
if(grep /^(?:-h|--help|-\?)$/, @ARGV) {
|
|
|
|
print <<EOH;
|
2008-12-18 18:54:24 -06:00
|
|
|
install.pl: installs symbolic links from dotfile repo into your home directory
|
2008-12-18 18:36:54 -06:00
|
|
|
|
|
|
|
Options:
|
2009-02-05 10:22:47 -06:00
|
|
|
-f force an overwrite existing files
|
|
|
|
-h, -? print this help
|
2008-12-18 18:36:54 -06:00
|
|
|
|
|
|
|
Destination directory is "$home".
|
|
|
|
Source files are in "$scriptdir".
|
|
|
|
EOH
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $force = 0;
|
|
|
|
$force = 1 if grep /^(?:-f|--force)$/, @ARGV;
|
|
|
|
|
|
|
|
unless(eval {symlink('', ''); 1;}) {
|
2008-12-18 18:54:24 -06:00
|
|
|
die "Your symbolic links are not very link-like.\n";
|
2008-12-18 18:36:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
my %links = (
|
|
|
|
screenrc => '.screenrc',
|
2010-04-02 02:47:08 -05:00
|
|
|
ackrc => '.ackrc',
|
2008-12-18 18:36:54 -06:00
|
|
|
toprc => '.toprc',
|
2009-08-28 18:05:55 -05:00
|
|
|
dir_colors => '.dir_colors',
|
2008-12-18 18:36:54 -06:00
|
|
|
lessfilter => '.lessfilter',
|
|
|
|
|
|
|
|
vim => '.vim',
|
2008-12-23 16:40:05 -06:00
|
|
|
vimrc => '.vimrc',
|
2010-11-10 00:10:54 -06:00
|
|
|
_vimrc => '_vimrc',
|
2008-12-23 16:40:05 -06:00
|
|
|
gvimrc => '.gvimrc',
|
|
|
|
|
2009-01-03 09:58:48 -06:00
|
|
|
commonsh => '.commonsh',
|
|
|
|
|
2009-01-01 22:53:25 -05:00
|
|
|
inputrc => '.inputrc',
|
|
|
|
|
2009-01-03 02:28:09 -05:00
|
|
|
bash => '.bash',
|
|
|
|
bashrc => '.bashrc',
|
|
|
|
bash_profile => '.bash_profile',
|
|
|
|
|
2008-12-18 18:36:54 -06:00
|
|
|
zsh => '.zsh',
|
2008-12-23 16:40:05 -06:00
|
|
|
zshrc => '.zshrc',
|
2008-12-18 18:36:54 -06:00
|
|
|
|
2009-01-13 01:31:32 -06:00
|
|
|
ksh => '.ksh',
|
|
|
|
kshrc => '.kshrc',
|
|
|
|
mkshrc => '.mkshrc',
|
|
|
|
|
2009-01-13 01:36:03 -06:00
|
|
|
shinit => '.shinit',
|
|
|
|
|
2008-12-18 18:36:54 -06:00
|
|
|
Xdefaults => '.Xdefaults',
|
|
|
|
Xresources => '.Xresources',
|
|
|
|
|
|
|
|
'uncrustify.cfg' => '.uncrustify.cfg',
|
|
|
|
'indent.pro' => '.indent.pro',
|
|
|
|
|
|
|
|
xmobarrc => '.xmobarrc',
|
|
|
|
'xmonad.hs' => '.xmonad/xmonad.hs',
|
2008-12-20 00:02:28 -06:00
|
|
|
|
2009-02-05 10:22:47 -06:00
|
|
|
gitconfig => '.gitconfig',
|
2010-06-25 11:41:00 -07:00
|
|
|
gitignore => '.gitignore',
|
2009-02-02 01:03:28 -06:00
|
|
|
|
2010-07-12 16:00:18 -07:00
|
|
|
tigrc => '.tigrc',
|
|
|
|
|
2009-04-28 15:27:28 -05:00
|
|
|
caffeinate => 'bin/caffeinate',
|
|
|
|
lock => 'bin/lock',
|
2009-09-02 21:19:01 -05:00
|
|
|
|
2010-09-02 11:33:04 -05:00
|
|
|
'git-info' => 'bin/git-info',
|
2010-02-05 15:27:20 -06:00
|
|
|
'git-untrack-ignored' => 'bin/git-untracked-ignored',
|
|
|
|
|
2010-04-24 01:26:16 -05:00
|
|
|
gdbinit => '.gdbinit',
|
2008-12-18 18:36:54 -06:00
|
|
|
);
|
|
|
|
|
2010-07-09 00:19:48 -07:00
|
|
|
my $contained = (substr $scriptdir, 0, length($home)) eq $home;
|
|
|
|
my $prefix = undef;
|
|
|
|
if ($contained) {
|
|
|
|
$prefix = substr $scriptdir, length($home);
|
2010-07-09 00:21:03 -07:00
|
|
|
($prefix) = $prefix =~ m{^\/? (.+) [^/]+ $}x;
|
2010-07-09 00:19:48 -07:00
|
|
|
}
|
|
|
|
|
2010-10-28 13:57:37 -05:00
|
|
|
chomp(my $uname = `uname -s`);
|
|
|
|
`cc answerback.c -o answerback.$uname`;
|
|
|
|
if ($? != 0) {
|
|
|
|
warn "Could not compile answerback.\n";
|
|
|
|
} else {
|
|
|
|
$links{"answerback.$uname"} = "bin/answerback.$uname";
|
|
|
|
}
|
|
|
|
|
2010-10-27 16:20:46 -05:00
|
|
|
|
2009-02-05 10:22:47 -06:00
|
|
|
my $i = 0; # Keep track of how many links we added
|
2008-12-18 18:36:54 -06:00
|
|
|
for my $file (keys %links) {
|
2009-02-05 10:22:47 -06:00
|
|
|
# See if this file resides in a directory, and create it if needed.
|
2008-12-18 18:36:54 -06:00
|
|
|
my($path) = $links{$file} =~ m{^ (.+/)? [^/]+ $}x;
|
2008-12-18 18:54:24 -06:00
|
|
|
mkpath("$home/$path") if $path;
|
2008-12-18 18:36:54 -06:00
|
|
|
|
|
|
|
my $src = "$scriptdir/$file";
|
|
|
|
my $dest = "$home/$links{$file}";
|
|
|
|
|
2009-02-05 10:22:47 -06:00
|
|
|
# If a link already exists, see if it points to this file. If so, skip it.
|
|
|
|
# This prevents extra warnings caused by previous runs of install.pl.
|
2009-09-05 16:51:59 -05:00
|
|
|
if(!$force && -e $dest && -l $dest) {
|
2009-02-05 10:22:47 -06:00
|
|
|
next if readlink($dest) eq $src;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Remove the destination if it exists and we were told to force an overwrite
|
2009-09-22 16:12:37 -05:00
|
|
|
if($force && -d $dest) {
|
2009-02-05 10:22:47 -06:00
|
|
|
rmtree($dest) || warn "Couldn't rmtree '$dest': $!\n";
|
2009-09-22 16:12:37 -05:00
|
|
|
} elsif($force) {
|
|
|
|
unlink($dest) || warn "Couldn't unlink '$dest': $!\n";
|
2008-12-18 18:36:54 -06:00
|
|
|
}
|
|
|
|
|
2010-07-09 00:19:48 -07:00
|
|
|
if ($contained) {
|
|
|
|
chdir $home;
|
|
|
|
$dest = "$links{$file}";
|
|
|
|
$src = "$prefix$file";
|
|
|
|
if ($path) {
|
|
|
|
$src = "../$src";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 10:22:47 -06:00
|
|
|
symlink($src => $dest) ? $i++ : warn "Couldn't link '$src' to '$dest': $!\n";
|
2008-12-18 18:36:54 -06:00
|
|
|
}
|
2009-02-05 10:22:47 -06:00
|
|
|
|
|
|
|
print "$i link";
|
|
|
|
print 's' if $i != 1;
|
|
|
|
print " created\n";
|