-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.pl
executable file
·137 lines (106 loc) · 3.44 KB
/
install.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#! /usr/bin/env perl
# install.pl
# script to create symlinks from the checkout of MikesDots to the home directory
# Mostly taken, like the majority of MikesDots from davesdots
use strict;
use warnings;
use File::Path qw(mkpath rmtree);
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;
install.pl: installs symbolic links from dotfile repo into your home directory
Options:
-f force an overwrite existing files
-h, -? print this help
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;}) {
die "Your symbolic links are not very link-like.\n";
}
my %links = (
# Mine
xmodmap => '.xmodmap'
, xsession => '.xsession'
, xinitrc => '.xinitrc'
, xmonad => '.xmonad'
, apvlvrc => '.apvlvrc'
, emacs => 'emacs'
, dotemacs => '.emacs'
, nethackrc => '.nethackrc'
, aspellenprepl => ".aspell.en.prepl"
, aspellenpws => ".aspell.en.pws"
, xvidcaprc => ".xvidcaprc"
, wpa => 'bin/wpa'
, go => 'bin/go'
, wep_ssid => 'bin/wep-ssid'
, trackpad_toggle => 'bin/trackpad-toggle'
, tap_toggle => 'bin/tap-toggle'
, rec => 'bin/rec'
, ptd => 'bin/ptd'
, backup => 'bin/backup'
, mk_backups => 'bin/mk-backups'
, myimport => 'bin/myimport'
, gf2pdf_children => 'bin/sgf2pdf-children'
, go_news => 'bin/igo-news'
# Dave's
, screenrc => '.screenrc'
, toprc => '.toprc'
, dircolors => '.dircolors'
, gdircolors => '.gdircolors'
, lessfilter => '.lessfilter'
, vim => '.vim'
, vimrc => '.vimrc'
, gvimrc => '.gvimrc',
, commonsh => '.commonsh'
, inputrc => '.inputrc'
, bash => '.bash'
, bashrc => '.bashrc'
, bash_profile => '.bash_profile'
, zsh => '.zsh'
, zshrc => '.zshrc'
, ksh => '.ksh'
, kshrc => '.kshrc'
# mkshrc => '.mkshrc',
, sh => '.sh'
, shinit => '.shinit'
, Xdefaults => '.Xdefaults'
, Xresources => '.Xresources'
, 'uncrustify.cfg' => '.uncrustify.cfg'
, 'indent.pro' => '.indent.pro'
, xmobarrc => '.xmobarrc'
, gitconfig => '.gitconfig'
, caffeinate => 'bin/caffeinate'
, lock => 'bin/lock'
);
my $i = 0; # Keep track of how many links we added
for my $file (keys %links) {
# See if this file resides in a directory, and create it if needed.
my($path) = $links{$file} =~ m{^ (.+/)? [^/]+ $}x;
mkpath("$home/$path") if $path;
my $src = "$scriptdir/$file";
my $dest = "$home/$links{$file}";
# 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.
if(-e $dest && -l $dest) {
next if readlink($dest) eq $src;
}
# 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";