-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
289 lines (258 loc) · 4.78 KB
/
install.sh
File metadata and controls
289 lines (258 loc) · 4.78 KB
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# install the config files for a component
#export COMPONENTS="vim tmux screen bash aws git sp3 gdb "
export COMPONENTS="vim tmux screen bash aws git gdb "
export THIS_DIR=`pwd`
export OS_TYPE=`uname -s`
export PLIST="vim tmux git gcc python"
create()
{
echo "create $1"
if [ $# -eq 0 ]; then
echo "no <args>"
exit -1
fi
if [ $1 = "all" ]; then
for i in $COMPONENTS
do
create $i
done
fi
if [ $1 = "vim" ]; then
mkdir -p ~/.vim
cp ${THIS_DIR}/vim/vimrc ~/.vimrc
fi
if [ $1 = "tmux" ]; then
cp ${THIS_DIR}/tmux/tmux.conf ~/.tmux.conf
fi
if [ $1 = "screen" ]; then
cp ${THIS_DIR}/screen/screenrc ~/.screenrc
fi
if [ $1 = "bash" ]; then
if [ ! -f ~/.bash_profile ]; then
cp ${THIS_DIR}/bash/bash_profile ~/.bash_profile
echo "~/.xbash/xbashrc please add the following to ~/.bash_profile"
echo ""
echo "if [ -f ~/.xbash/xbashrc ]; then"
echo " . ~/.xbash/xbashrc"
echo "fi"
fi
mkdir -p ~/.xbash
cp ${THIS_DIR}/bash/xbash/xbashrc ~/.xbash/xbashrc
cp ${THIS_DIR}/bash/xbash/*env ~/.xbash/
cp ${THIS_DIR}/bash/xbash/aliases ~/.xbash/
fi
if [ $1 = "aws" ]; then
mkdir -p ~/.aws
cp ${THIS_DIR}/aws/config ~/.aws/config
cp ${THIS_DIR}/aws/credentials ~/.aws/credentials
fi
if [ $1 = "git" ]; then
cp ${THIS_DIR}/gitconfig/gitconfig ~/.gitconfig
fi
if [ $1 = "sp3" ]; then
cp ${THIS_DIR}/sp3/sp3 ~/.sp3
fi
if [ $1 = "gdb" ]; then
cp ${THIS_DIR}/gdb/gdbinit ~/.gdbinit
fi
}
backup()
{
echo "backup $1"
if [ $# -eq 0 ]; then
echo "no <args>"
exit -1
fi
if [ ! -d ~/.backup ]; then
mkdir -p ~/.backup
fi
if [ $1 = "all" ]; then
for i in $COMPONENTS
do
backup $i
done
fi
if [ $1 = "vim" ]; then
cp ~/.vimrc ~/.backup/.vimrc
fi
if [ $1 = "tmux" ]; then
cp ~/.tmux.conf ~/.backup/.tmux.conf
fi
if [ $1 = "screen" ]; then
cp ~/.screenrc ~/.backup/.screenrc
fi
if [ $1 = "bash" ]; then
cp ~/.bash_profile ~/.backup
cp -r ~/.xbash ~/.backup
fi
if [ $1 = "aws" ]; then
cp -r ~/.aws ~/.backup
fi
if [ $1 = "git" ]; then
cp ~/.gitconfig ~/.backup/.gitconfig
fi
if [ $1 = "sp3" ]; then
cp ~/.sp3e ~/.backup/.sp3e
fi
if [ $1 = "gdb" ]; then
cp ~/.gdbinit ~/.backup/.gdbinit
fi
}
restore()
{
echo "restore $1"
if [ $# -eq 0 ]; then
echo "no <args>"
exit -1
fi
if [ ! -d ~/.backup ]; then
echo "~/.backup not found"
exit -1
fi
if [ $1 = "all" ]; then
for i in $COMPONENTS
do
restore $i
done
exit 0
fi
if [ $1 = "vim" ]; then
cp ~/.backup/.vimrc ~/.vimrc
fi
if [ $1 = "tmux" ]; then
cp ~/.backup/.tmux.conf ~/.tmux.conf
fi
if [ $1 = "screen" ]; then
cp ~/.backup/.screenrc ~/.screenrc
fi
if [ $1 = "bash" ]; then
cp ~/.backup/.bash_profile ~/
cp -r ~/.backup/.xbash ~/
fi
if [ $1 = "aws" ]; then
cp -r ~/.backup/.aws ~/
fi
if [ $1 = "git" ]; then
cp ~/.backup/.gitconfig ~/.gitconfig
fi
if [ $1 = "sp3" ]; then
cp ~/.backup/.sp3e ~/.sp3e
fi
if [ $1 = "gdb" ]; then
cp ~/.backup/.gdbinit ~/.gdbinit
fi
}
cleanup()
{
echo "cleanup $1"
if [ $# -eq 0 ]; then
echo "no <args>"
exit -1
fi
if [ $1 = "all" ]; then
for i in $COMPONENTS
do
cleanup $i
done
exit 0
fi
if [ $1 = "vim" ]; then
rm -f ~/.vimrc
fi
if [ $1 = "tmux" ]; then
rm -f ~/.tmux.conf
fi
if [ $1 = "screen" ]; then
rm -f ~/.screenrc
fi
if [ $1 = "bash" ]; then
rm -f ~/.bash_profile
rm -rf ~/.xbash
fi
if [ $1 = "aws" ]; then
rm -rf ~/.aws
fi
if [ $1 = "git" ]; then
rm -f ~/.gitconfig
fi
if [ $1 = "sp3" ]; then
rm -f ~/.sp3e
fi
if [ $1 = "gdb" ]; then
rm -f ~/.gdbinit
fi
}
clobber()
{
echo "clobber"
if [ -d ~/.backup ]; then
rm -rf ~/.backup
fi
}
pkginstall()
{
echo "Package Install"
if [ $OS_TYPE == "MSYS_NT-10.0-21390" ]; then
pacman --noconfirm -S $PLIST
fi
}
usage() {
cat << EOF
$UTIL COMMAND
Commands are:
create <args> - install the files from here
backup <args> - backup the existing dotfiles
cleanup <args> - cleanup the dotfiles
restore <args> - restore the dotfiles from previous backup
clobber <args> - remove the backup files
packages <args> - installed the required base packages
-h, --help - Show this help screen
EOF
echo "<args> : "
echo " all | $COMPONENTS"
}
UTIL=$(basename $0)
if [ $# -eq 0 ]; then
usage
exit 0
fi
case $1 in
"create")
shift
create "$@"
exit 0
;;
"cleanup")
shift
cleanup "$@"
exit 0
;;
"restore")
shift
restore "$@"
exit 0
;;
"clobber")
shift
clobber "$@"
exit 0
;;
"backup")
shift
backup "$@"
exit 0
;;
"packages")
shift
pkginstall "@"
exit 0
;;
-h | --help)
usage
exit 0
;;
*)
echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)"
exit 1
;;
esac