-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·130 lines (105 loc) · 3.2 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
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
#! /usr/bin/env bash
set -e
dotfiles_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
###############################################################################
# UTILITIES
###############################################################################
function symlink_files {
for file in $1*; do
dotfile=$HOME/.$(basename $file)
if [[ -e "$dotfile" && ! -L "$dotfile" ]]; then
cp $dotfile $dotfile.bckp
fi
echo -e "\033[0;33mSymlinking\033[0m $file \033[0;35m-->\033[0m ~/.$(basename $file)"
ln -nfs $file $dotfile
done
}
function log_info {
echo -e "\033[0;34m$1\033[0m"
}
function banner {
echo
echo -e "\033[0;34m=====================================================\033[0m"
echo -e "\033[0;33m$@\033[0m"
echo -e "\033[0;34m=====================================================\033[0m"
}
function log_done {
echo -e "\033[0;35mDONE\033[0m"
}
function already_installed {
echo -e "\033[0;33m$1 is already installed.\033[0m Skipping..."
}
###############################################################################
# TASKS
###############################################################################
function install_homebrew {
banner "Installing Homebrew"
local brew=$(which brew)
if [ $? == 0 ]; then
already_installed "brew"
else
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
banner "Updating Homebrew"
brew update
log_done
}
function install_packages {
banner "Installing packages"
if [[ $OSTYPE == darwin* ]]; then
while read install_string; do
local package=$(echo $install_string | awk '{ print $1 };')
if brew ls --versions $package > /dev/null; then
already_installed $package
else
brew install $install_string
fi
done <$dotfiles_dir/packages/osx.txt
fi
log_done
}
function install_vim_config {
banner "Installing Vim Configuration"
ln -nfs $dotfiles_dir/vim $HOME/.vim
ln -nfs $dotfiles_dir/vim/vimrc $HOME/.vimrc
# Update vim-plug
vim -c 'PlugInstall'
log_done
}
function set_zsh_to_default_shell {
banner "Setting zsh to the default shell"
if [[ $SHELL == *"zsh" ]]; then
echo "Zsh is already configured"
else
echo "Setting zsh as the default shell"
if [ -e /usr/local/bin/zsh ]; then
if [ "$(cat /private/etc/shells | grep '/usr/local/bin/zsh')" != "" ]; then
echo "Adding zsh to standard shell list"
echo "/usr/local/bin/zsh" | sudo tee -a /private/etc/shells
fi
chsh -s /usr/local/bin/zsh
else
chsh -s /bin/zsh
fi
fi
log_done
}
function install_zsh_config {
banner "Installing zsh configuration"
if [ ! -d $HOME/.zprezto ]; then
git clone --recursive https://github.com/sorin-ionescu/prezto.git "$HOME/.zprezto"
fi
symlink_files "$dotfiles_dir/zsh/z"
log_done
}
###############################################################################
# Task Runner
###############################################################################
install_packages
install_vim_config
set_zsh_to_default_shell
install_zsh_config
banner "Adding miscellaneous configurations"
symlink_files $dotfiles_dir/git/
symlink_files $dotfiles_dir/tmux/
log_done