-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_symlinks.server
117 lines (106 loc) · 2.7 KB
/
create_symlinks.server
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
#! /usr/bin/perl -w
use strict;
use File::Copy;
use File::Path qw(make_path);
use File::Basename qw(fileparse);
sub file_names
{
return qw{
.ackrc
.bash_profile
.bashrc
bash_completion
.config/fish/config.fish
.consularc
.dir_colors
.gemrc
.gitconfig
.gitignore
.git-completion.sh
.htoprc
.config/htop/htoprc
.inputrc
.irbrc
.irssi
.NERDTreeBookmarks
.rdebugrc
.rvmrc
.screenrc
.sh_aliases
.shrc
.slate
.ssh/config
.tigrc
.tmux.conf
.vimrc
.vimrc_files
.vim/vimrc.mine
.vim/colors/railscasts.vim
.zprofile
.zshrc
.zshenv
bin/diff_painter.pl
bin/tree.sh
bin/tpm
bin/tpc
bin/tpi
bin/tpcert
bin/hub
bin/git-checkout-by-match
bin/redmine-ticket-status
bin/git-rmbranch
bin/git-large
bin/git-stale-remote-branches
bin/bundle-update-lockfile
.completion
soloistrc
Cheffile
Cheffile.lock
};
}
link_files();
sub get_timestamp {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($mon < 10) { $mon = "0$mon"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
$year=$year+1900;
return $year . $mon . $mday . '_' . $hour . '_' . $min;
}
sub file_links
{
my %file_links = map {glob("~/$_") => glob("~/.config_files/dotFiles.server/$_")} file_names();
return %file_links;
}
sub backup_links
{
my %backup_links = map {glob("~/$_") => glob("~/.config_files/backups/$_")} file_names();
return %backup_links;
}
sub link_files
{
make_path(glob('~/bin'));
make_path(glob('~/.ssh/tmp'));
my %file_links = file_links();
my %backup_links = backup_links();
my $backup_date = get_timestamp();
for my $file (keys %file_links) {
my $source_file = $file_links{$file};
my $backup_file = "$backup_links{$file}.${backup_date}";
if (-e $source_file) {
if (-l $file) {
unlink $file;
} elsif (-e $file) {
my ($filename, $path) = fileparse($backup_file);
make_path(glob($path));
move($file, $backup_file);
print("Backed up ${file} to $backup_file\n");
}
my $symlink_exists = eval { symlink($source_file, $file); 1 };
die "Symlinking unsuccessful" unless $symlink_exists;
print "Linking $file Verified\n";
}
}
print "\nLinking Complete\n";
}