-
Notifications
You must be signed in to change notification settings - Fork 1
/
nail
executable file
·153 lines (133 loc) · 3.81 KB
/
nail
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
#!/bin/bash
# symlink dotfiles and scripts
[[ "$DOTFILES" ]] || DOTFILES="$(dirname "$(readlink -f "$0")")"
create_link(){
if [ -h "$2" ] && [ ! -e "$2" ]; then
case "$3" in
sudo)
echo -e "\033[31msudo link:\033[0m $(basename "$2")"
sudo rm "$2"
;;
*)
echo -e "\033[31mlink:\033[0m $(basename "$2")"
rm "$2"
;;
esac
fi
if [ ! -h "$2" ]; then
case "$3" in
sudo)
echo -en "\033[32msudo link:\033[0m "
sudo ln -fvsn "$1" "$2" | sed "s|$HOME|~|g;s|'||g"
;;
*)
echo -en "\033[32mlink:\033[0m "
ln -fvsn "$1" "$2" | sed "s|$HOME|~|g;s|'||g"
;;
esac
fi
}
run_make(){
make --directory="$1" | grep -q "is up to date" && return
out_install="$(make install --directory="$1" | grep -v "directory")"
echo -e "\033[32mmake install:\033[0m $out_install"
}
run_install(){
script="$1/install.sh"
[[ -f "$script" ]] || return
if bash "$script" check; then
case "$2" in
sudo)
echo -e "\033[32msudo install:\033[0m $1" |
sed "s|$HOME|~|g"
sudo bash "$script"
;;
*)
echo -e "\033[32minstall:\033[0m $1" |
sed "s|$HOME|~|g"
bash "$script"
;;
esac
fi
}
run_generate(){
if [ "$1" -nt "$2" ]; then
case "$3" in
sudo)
echo -en "\033[32msudo generate:\033[0m "
sudo python "$DOTFILES"/generate_config "$1" "$2" |
sed "s|$HOME|~|g;s|'||g"
;;
*)
echo -en "\033[32mgenerate:\033[0m "
python "$DOTFILES"/generate_config "$1" "$2" |
sed "s|$HOME|~|g;s|'||g"
;;
esac
fi
}
store_tools(){
orig="$1"
dest="$2"
mkdir -vp "$dest"
# Remove Broken Links
for tool in "$dest"/*; do
if [ -h "$tool" ] && [ ! -e "$tool" ]; then
echo -e "\033[31m$(basename "$tool")\033[0m"
rm "$tool"
fi
done
# Create Links
for tool in "$orig"/*.tool; do
tool_name=$(basename "$tool" .tool)
if [ ! -h "$dest"/"$tool_name" ]; then
echo -e "\033[32m$tool_name\033[0m"
ln -s "$tool" "$dest/$tool_name"
fi
done
chmod +x "$DOTFILES"/toolbox/*
}
config="$DOTFILES/.instalation_config"
touch "$config"
IFS=$'\n' read -d '' -r -a FILTERS < "$config"
FILTERS+=("$@")
printf "%s\n" "${FILTERS[@]}" | sort -u >| "$config"
[[ ${#FILTERS[@]} -eq 0 ]] &&
echo "error: no filters were provided" &&
echo "run hammer for initial setup" &&
exit
store_tools "$DOTFILES"/toolbox ~/.local/bin
# deploy dotfiles
while IFS= read -r line; do
IFS=',' read -ra linevec <<< "$line"
attrs=("${linevec[@]:2}")
[[ "${#FILTERS[@]}" -gt 0 ]] &&
[[ ! "$(comm -12 \
<(printf '%s\n' "${FILTERS[@]}" | sort) \
<(printf '%s\n' "${attrs[@]}" | sort))" \
]] &&
continue
orig="$DOTFILES/powertools/${linevec[0]}"
dest="${linevec[1]//\~/$HOME}"
mkdir -p "$(dirname "$dest")"
unset mode
for attr in "${attrs[@]}"; do
case "$attr" in
link)
create_link "$orig" "$dest" "$mode"
;;
make)
run_make "$orig"
;;
install)
run_install "$orig" "$mode"
;;
generate)
run_generate "$orig" "$dest" "$mode"
;;
sudo)
mode=sudo
;;
esac
done
done < "$DOTFILES/powertools/.locations"