-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·153 lines (128 loc) · 3.96 KB
/
setup
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env perl
use strict;
use warnings;
use Cwd qw();
use File::Spec;
use Term::ANSIColor;
my $op=$ARGV[0];
if(not defined $op) {
die "No op provided. Exiting.\n";
}
# my $binfolder="$ENV{HOME}/bin";
# if ( !-d $binfolder ) {
# mkdir $binfolder or die "Failed to create folder: $binfolder";
# }
my $path = Cwd::cwd();
my %links = (
"doom" => "$ENV{HOME}/.config/doom",
"tool-versions" => "$ENV{HOME}/.tool-versions",
"zshrc" => "$ENV{HOME}/.zshrc",
"ideavimrc" => "$ENV{HOME}/.ideavimrc",
"vimrc" => "$ENV{HOME}/.vimrc",
"tmux.conf" => "$ENV{HOME}/.tmux.conf",
"gitconfig" => "$ENV{HOME}/.gitconfig",
"gitexcludes" => "$ENV{HOME}/.gitexcludes",
"rspec" => "$ENV{HOME}/.rspec",
"gemrc" => "$ENV{HOME}/.gemrc",
"i3_config" => "$ENV{HOME}/.config/i3/config",
"terminator_config" => "$ENV{HOME}/.config/terminator/config",
"lynxrc" => "$ENV{HOME}/.lynxrc",
"gdbinit" => "$ENV{HOME}/.gdbinit",
"ctags/nim.ctags" => "$ENV{HOME}/.ctags.d/nim.ctags",
"shell" => "$ENV{HOME}/.shell",
"bashrc" => "$ENV{HOME}/.bashrc",
"neovim/init.lua" => "$ENV{HOME}/.config/nvim/init.lua",
"bin/todofile" => "$ENV{HOME}/bin/todofile",
"bin/docxgrep" => "$ENV{HOME}/bin/docxgrep",
"bin/onlymd5" => "$ENV{HOME}/bin/onlymd5",
"bin/md5allfiles" => "$ENV{HOME}/bin/md5allfiles",
"bin/starttmux" => "$ENV{HOME}/bin/starttmux",
"bin/dfcollect" => "$ENV{HOME}/bin/dfcollect",
"ripgreprc" => "$ENV{HOME}/.ripgreprc",
"rofi" => "$ENV{HOME}/.config/rofi/config.rasi",
"kitty" => "$ENV{HOME}/.config/kitty/kitty.conf",
);
my @sources = keys %links;
if($op eq "install") {
print("Installing...\n");
for my $src (@sources) {
my $source_path = "$path/$src";
my $dest_path = $links{$src};
# Check whether folder exists
my ($volume, $directory, $file) = File::Spec->splitpath($dest_path);
mkdir($directory, 0700);
print(" creating symlink for $source_path -> $dest_path...\n");
if(-e $source_path) {
if(symlink($source_path, $dest_path)) {
print color('green');
print(" created.");
print color('reset');
} else {
print color('red');
print(" not created.");
print color('reset');
}
} else {
print color('red');
print(" not created: source path does not exist.");
print color('reset');
}
print("\n");
}
} elsif($op eq "uninstall") {
print "Uninstalling...\n";
for my $src (@sources) {
my $source_path = "$path/$src";
my $dest_path = $links{$src};
if (-l $dest_path) {
print(" checking symlink for $dest_path (expecting $source_path)...\n");
my $actual_link_goal = readlink($dest_path);
if (not $actual_link_goal eq $source_path) {
print(" ($dest_path symlink points to something else - ignoring.)\n");
} else {
print("-> Deleting symlink $dest_path...\n");
unlink $dest_path
or print(" Failed to remove file $dest_path: $!\n");
}
} else {
print(" ($dest_path does not seem to be a link - ignoring.)\n");
}
}
} elsif($op eq "status") {
print("Status check...\n");
my $status_ok = 1;
my $sources_size = @sources;
my $source_ok_count = 0;
print("\n");
for my $src (@sources) {
my $source_path = "$path/$src";
my $dest_path = $links{$src};
if (-l $dest_path) {
my $actual_link_goal = readlink($dest_path);
if (not $actual_link_goal eq $source_path) {
$status_ok = 0;
} else {
$source_ok_count++;
}
if ($status_ok == 0) {
print color('red');
} else {
print color('green');
}
print("$dest_path -> $actual_link_goal\n");
} else {
print color('red');
print("$dest_path -> (not a symlink)\n");
}
print color('reset');
}
print("\n");
if($status_ok == 1 && $source_ok_count == $sources_size) {
print("Looks good!");
} else {
print("Something is off...");
}
print("\n\n");
} else {
die "Please provide a valid command.\n";
}