-
Notifications
You must be signed in to change notification settings - Fork 8
/
install.bash
executable file
·187 lines (166 loc) · 4.37 KB
/
install.bash
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
#! /bin/bash
# Author: Brian Cain
# Installs your dotfiles
# Function to determine package manager
function determine_package_manager() {
which yum > /dev/null && {
echo "yum"
export OSPACKMAN="yum"
return;
}
which apt-get > /dev/null && {
echo "apt-get"
export OSPACKMAN="aptget"
return;
}
which brew > /dev/null && {
echo "homebrew"
export OSPACKMAN="homebrew"
return;
}
}
# function setup_bash() {
# # TODO: Bash customization
# }
function setup_zsh() {
echo 'Adding oh-my-zsh to dotfiles...'
OMZDIR=~/.dotfiles/oh-my-zsh
if [ -d "$OMZDIR" ] ; then
echo 'Updating oh-my-zsh to latest version'
cd ~/.dotfiles/oh-my-zsh
git pull origin master
cd -
else
echo 'Adding oh-my-zsh to dotfiles...'
git clone https://www.github.com/robbyrussell/oh-my-zsh.git
fi
}
function determine_shell() {
echo 'Please pick your favorite shell:'
echo '(1) Bash'
echo '(2) Zsh'
read -p 'Enter a number: ' SHELL_CHOICE
if [[ $SHELL_CHOICE == '1' ]] ; then
export LOGIN_SHELL="bash"
elif [[ $SHELL_CHOICE == '2' ]] ; then
export LOGIN_SHELL="zsh"
else
echo 'Could not determine choice.'
exit 1
fi
}
function setup_vim() {
echo "Setting up vim...ignore any vim errors post install"
vim +BundleInstall +qall
}
function setup_git() {
echo 'Setting up git config...'
read -p 'Enter Github username: ' GIT_USER
git config --global user.name "$GIT_USER"
read -p 'Enter email: ' GIT_EMAIL
git config --global user.email $GIT_EMAIL
git config --global core.editor vim
git config --global color.ui true
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
}
# Adds a symbolic link to files in ~/.dotfiles
# to your home directory.
function symlink_files() {
ignoredfiles=(LICENSE README.md install.bash update-zsh.sh)
for f in $(ls -d *); do
if [[ ${ignoredfiles[@]} =~ $f ]]; then
echo "Skipping $f ..."
elif [[ $f =~ 'bashrc' ]]; then
if [[ $LOGIN_SHELL == 'bash' ]] ; then
link_file $f
fi
elif [[ $f =~ 'bash_logout' ]]; then
if [[ $LOGIN_SHELL == 'bash' ]] ; then
link_file $f
fi
elif [[ $f =~ 'zshrc' || $f =~ 'oh-my-zsh' ]]; then
if [[ $LOGIN_SHELL == 'zsh' ]] ; then
link_file $f
fi
elif [[ $f =~ 'oh-my-zsh' ]]; then
if [[ $LOGIN_SHELL == 'zsh' ]] ; then
link_file $f
fi
else
link_file $f
fi
done
}
# symlink a file
# arguments: filename
function link_file(){
echo "linking ~/.$1"
if ! $(ln -s "$PWD/$1" "$HOME/.$1"); then
echo "Replace file '~/.$1'?"
read -p "[Y/n]?: " Q_REPLACE_FILE
if [[ $Q_REPLACE_FILE != 'n' ]]; then
replace_file $1
fi
fi
}
# replace file
# arguments: filename
function replace_file() {
echo "replacing ~/.$1"
ln -sf "$PWD/$1" "$HOME/.$1"
}
set -e
(
determine_package_manager
# general package array
declare -a packages=('vim' 'git' 'tree' 'htop' 'wget' 'curl')
determine_shell
if [[ $LOGIN_SHELL == 'bash' ]] ; then
packages=(${packages[@]} 'bash')
elif [[ $LOGIN_SHELL == 'zsh' ]] ; then
packages=(${packages[@]} 'zsh')
fi
if [[ $OSPACKMAN == "homebrew" ]]; then
echo "You are running homebrew."
echo "Using Homebrew to install packages..."
brew update
declare -a macpackages=('findutils' 'macvim' 'the_silver_searcher')
brew install "${packages[@]}" "${macpackages[@]}"
brew cleanup
elif [[ "$OSPACKMAN" == "yum" ]]; then
echo "You are running yum."
echo "Using yum to install packages...."
sudo yum update
sudo yum install "${packages[@]}"
elif [[ "$OSPACKMAN" == "aptget" ]]; then
echo "You are running apt-get"
echo "Using apt-get to install packages...."
sudo apt-get update
sudo apt-get install "${packages[@]}"
else
echo "Could not determine OS. Exiting..."
exit 1
fi
if [[ $LOGIN_SHELL == 'bash' ]] ; then
# setup_bash
echo 'No extra bash configs yet...'
elif [[ $LOGIN_SHELL == 'zsh' ]] ; then
setup_zsh
fi
setup_git
symlink_files
setup_vim
if [[ $LOGIN_SHELL == 'bash' ]] ; then
echo "Operating System setup complete."
echo "Reloading session"
source ~/.bashrc
elif [[ $LOGIN_SHELL == 'zsh' ]] ; then
echo "Changing shells to ZSH"
chsh -s /bin/zsh
echo "Operating System setup complete."
echo "Reloading session"
exec zsh
fi
)