-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
90 lines (74 loc) · 1.62 KB
/
install.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
#!/bin/bash
# @param {string} $1 - prompt message
# @param {string} $2 - callback function
function confirm() {
echo $1
read -p "y/n: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
$2
fi
}
# @param {string} $1 - file name
# @param {string} $2 - file url
function downloadWithCurl() {
curl -sL -o $1 $2
}
# @param {string} $1 - file name
# @param {string} $2 - file url
function downloadWithWget() {
wget -q -O $1 $2
}
# @param {string} $1 - command name
function commandExists() {
test ! -z "$(command -v $1)"
}
# @param {string} $1 - file name
# @param {string} $2 - file url
function pickDownloadStrategy() {
if commandExists wget
then
downloadWithWget $1 $2
elif commandExists curl
then
downloadWithCurl $1 $2
fi
}
# @param {string} $1 - file name
function download() {
pickDownloadStrategy ~/$1 https://raw.githubusercontent.com/RecuencoJones/.files/master/$1
if [ "$?" -eq "0" ]
then
echo "Done installing $1"
else
echo 'Unexpected error :('
fi
}
function installProfile() {
download '.aliases'
download '.bash_profile'
}
function installGitConfig() {
download '.gitconfig'
}
function installVimConfig() {
download '.vimrc'
}
function all() {
echo "Running RecuencoJones .files config script!"
echo
confirm "Do you want to install .gitconfig?" installGitConfig
confirm "Do you want to install .vimrc?" installVimConfig
confirm "Do you want to install profile and aliases? (OS X only)" installProfile
echo
echo "You are all done! :)"
}
function main() {
case $1 in
vim) installVimConfig;;
git) installGitConfig;;
*) all;;
esac
}
main "$@"