-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·257 lines (222 loc) · 4.74 KB
/
deploy.sh
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
DIRNAME="$(dirname $0)"
>/dev/null pushd $DIRNAME || { >&2 echo === WTF ===; exit 1; }
CWD="$(pwd)"
>/dev/null popd
HOME=${HOME:-~}
function backup_original {
if [ ! -f "$1.original" ]; then
echo "creating '$1.original'"
if [ -f "$1" ]; then
cp "$1" "$1.original"
else
touch "$1.original"
fi
return 0
else
echo "'$1.original' already exists, not deploying"
return 1
fi
}
function link {
# $1 -- src file
# $2 -- dst directory (optional)
# $3 -- dst filename (optional)
filename="$1"
path="${CWD}/$1"
if [ -n "$2" ]; then
linkname="$2/$1"
if [ ! -d "$2" ]; then
echo "'$2' doesn't exist, creating it"
mkdir -p "$2"
if [ ! -d "$2" ]; then
echo "Warning: failed to create '$2'!"
fi
fi
if [ -n "$3" ]; then
linkname="$2/$3"
fi
else
linkname="$HOME/.$1"
fi
if [ ! -e "$path" ]; then
echo "'$path' doesn't exist, not deploying"
return 1
fi
if [ -e "$linkname" ]; then
echo "'$linkname' already exists, not deploying"
return 2
fi
echo "creating a link '$linkname' -> '$path'"
ln -s "$path" "$linkname"
}
function deploy_bashrc {
[ -s ~/.bashrc ] || {
backup_original ~/.bashrc || return 1;
cat ~/.bashrc.original > ~/.bashrc;
}
grep DOTFILES ~/.bashrc || {
cat >> ~/.bashrc << EOF
export DOTFILES="\$HOME/dotfiles"
source "\$DOTFILES/utils.sh"
source "\$DOTFILES/bashrc"
EOF
}
}
function deploy_gitconfig {
[ -s ~/.gitconfig ] || {
backup_original ~/.gitconfig || return 1
cat ~/.gitconfig.original > ~/.gitconfig
}
cat ./gitconfig >> ~/.gitconfig
}
function deploy_dircolors {
link "dircolors" ~/.dir_colors
}
function deploy_gdbinit {
link "gdbinit"
}
function deploy_gitignore {
link "gitignore"
}
function deploy_gtkrc {
link "gtkrc-2.0"
}
function deploy_tmux_conf {
link "tmux.conf"
}
function deploy_inputrc {
link "inputrc"
}
function deploy_rtorrent {
link "rtorrent.rc"
}
function deploy_openbox {
link "lubuntu-rc.xml" ~/.config/openbox
}
function deploy_i3 {
link "i3.config" ~/.config/i3 "config"
link "i3status.conf"
link "i3blocks.conf"
}
function deploy_xmodmap {
link "Xmodmap"
}
function deploy_lubuntu_autostart {
local autostart=~/.config/lxsession/Lubuntu/autostart
if [ ! -f $autostart ]; then
mkdir -p $(dirname $autostart)
fi
echo ~/dotfiles/scripts/lubuntu-autostart.sh >> $autostart
}
function deploy_zathurarc {
link zathurarc ~/.config/zathura/
}
function deploy_cmus {
link cmus.rc ~/.config/cmus/ rc
link cmus.theme ~/.config/cmus/ mine.theme
}
function deploy_lesskey {
lesskey lesskey
}
function deploy_htoprc {
link htoprc ~/.config/htop/
}
function deploy_ranger {
link ranger/scope.sh ~/.config/
link ranger/rc.conf ~/.config/
}
function deploy_radare2 {
link radare2/radare2rc ~/.config/
}
function deploy_keynavrc {
link keynavrc
}
function deploy_zsh {
[ -f ~/.zshenv ] && rm ~/.zshenv
link zshenv
grep DOTFILES ~/.zshrc || {
cat >> ~/.zshrc << EOF
source "\$DOTFILES/zshrc"
EOF
}
}
function deploy_kak {
link kak ~/.config
}
function deploy_nvim {
link nvim ~/.config
}
function deploy_cargo {
# who wrote this??!?
link cargo/config.toml ~/.cargo config.toml
# ^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^
# src file dst dir dst filename
}
function print_help {
cat << EOF
Usage:
$0 <options> [module]
Perform actions required for the deployment of the given module
options:
-h | --help: print this shit
-l | --list: list all modules available for deploying
-a | --all: deploy all modules available for deploying
EOF
}
modules=(
bashrc
gitconfig
dircolors
gdbinit
gitignore
gtkrc
tmux_conf
inputrc
rtorrent
openbox
lubuntu_autostart
zathurarc
i3
xmodmap
cmus
lesskey
htoprc
ranger
radare2
keynavrc
zsh
kak
nvim
cargo
)
function deploy_all {
for f in ${modules[@]}; do
echo "Deploying ${f}"
"deploy_$f"
done
}
function deploy_one {
for f in ${modules[@]}; do
if [ "$1" = "$f" ]; then
echo "Deploying ${f}"
"deploy_$f"
exit
fi
done
echo "Unknown module '$1', please seek help"
}
case "$1" in
"-l" | "--list" )
echo ${modules[@]}
;;
"" | "-h" | "--help" )
print_help
;;
"-a" | "--all" )
deploy_all
;;
* )
deploy_one "$1"
;;
esac