-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
209 lines (171 loc) · 5.79 KB
/
install
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
#!/usr/bin/env bash
LOG="${HOME}/Library/Logs/dotfiles.log"
GITHUB_USER="nikkegg"
GITHUB_REPO="dotfiles"
USER_GIT_AUTHOR_NAME="nikkegg"
USER_GIT_AUTHOR_EMAIL="[email protected]"
DIR="${HOME}/${GITHUB_REPO}"
_process() {
echo "$(date) PROCESSING: $@" >> $LOG
printf "$(tput setaf 6) %s...$(tput sgr0)\n" "$@"
}
_success() {
local message=$1
printf "%s✓ Success:%s\n" "$(tput setaf 2)" "$(tput sgr0) $message"
}
download_dotfiles() {
_process "→ Creating directory at ${DIR} and setting permissions"
mkdir -p "${DIR}"
_process "→ Downloading repository to /tmp directory"
curl -#fLo /tmp/${GITHUB_REPO}.tar.gz "https://github.com/${GITHUB_USER}/${GITHUB_REPO}/tarball/main"
_process "→ Extracting files to ${DIR}"
tar -zxf /tmp/${GITHUB_REPO}.tar.gz --strip-components 1 -C "${DIR}"
_process "→ Removing tarball from /tmp directory"
rm -rf /tmp/${GITHUB_REPO}.tar.gz
[[ $? ]] && _success "${DIR} created, repository downloaded and extracted"
# Change to the dotfiles directory
cd "${DIR}"
}
link_dotfiles() {
# symlink files to the HOME directory.
if [[ -f "${DIR}/opt/files" ]]; then
_process "→ Symlinking dotfiles in /configs"
# Set variable for list of files
files="${DIR}/opt/files"
# Store IFS separator within a temp variable
OIFS=$IFS
# Set the separator to a carriage return & a new line break
# read in passed-in file and store as an array
IFS=$'\r\n'
links=($(cat "${files}"))
# Loop through array of files
for index in ${!links[*]}; do
for link in ${links[$index]}; do
_process "→ Linking ${links[$index]}"
# set IFS back to space to split string on
IFS=$' '
# create an array of line items
file=(${links[$index]})
# Create symbolic link
ln -fs "${DIR}/${file[0]}" "${HOME}/${file[1]}"
done
# set separater back to carriage return & new line break
IFS=$'\r\n'
done
# Reset IFS back
IFS=$OIFS
[[ $? ]] && _success "All files have been copied"
fi
}
install_homebrew() {
if ! command -v brew &> /dev/null; then
_process "→ Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
_process "→ Running brew doctor"
brew doctor
[[ $? ]] \
&& _success "Installed Homebrew"
fi
}
install_vim_plug() {
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
}
install_oh_my_zsh() {
_process "→ Installing Oh-My-Zsh"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --keep-zshrc
[[ $? ]] \
&& _success "Installed Oh-My-Zsh"
}
install_oh_my_zsh_plugins() {
git clone https://github.com/jeffreytse/zsh-vi-mode.git ${ZSH}/custom/plugins/zsh-vi-mode
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH}/custom/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
source "~/.zshrc"
}
install_node() {
if ! type -P 'npm' &> /dev/null; then
_process "→ Installing node"
curl https://www.npmjs.org/install.sh | sh
[[ $? ]] \
&& _success "Installed npm"
fi
}
install_formulae() {
if ! type -P 'brew' &> /dev/null; then
_error "Homebrew not found"
else
_process "→ Installing Homebrew packages"
# Set variable for list of homebrew formulaes
brews="${DIR}/opt/homebrew"
# Update and upgrade all packages
_process "→ Updating and upgrading Homebrew packages"
brew update
brew upgrade
#instal rosetta as some casks need it (e.g aws vpn)
sudo softwareupdate --install-rosetta
# Tap some necessary formulae
brew tap homebrew/cask-versions
brew tap homebrew/cask-drivers
brew tap vitorgalvao/tiny-scripts
brew tap homebrew/cask-fonts
brew install --cask font-hack-nerd-font
brew install --cask font-fira-code-nerd-font
brew install --cask iterm2
brew install --cask aws-vpn-client
brew install --cask flycut
# Store IFS within a temp variable
OIFS=$IFS
# Set the separator to a carriage return & a new line break
# read in passed-in file and store as an array
IFS=$'\r\n' formulae=($(cat "${brews}"))
# Loop through split list of formulae
_process "→ Checking status of desired Homebrew formulae"
for index in ${!formulae[*]}; do
# Test whether a Homebrew formula is already installed
if ! brew list ${formulae[$index]} &> /dev/null; then
brew install ${formulae[$index]}
fi
done
# Reset IFS back
IFS=$OIFS
brew cleanup
[[ $? ]] && _success "All Homebrew packages installed and updated"
fi
}
setup_git_authorship() {
GIT_AUTHOR_NAME=eval "git config user.name"
GIT_AUTHOR_EMAIL=eval "git config user.email"
if [[ ! -z "$GIT_AUTHOR_NAME" ]]; then
_process "→ Setting up Git author"
read USER_GIT_AUTHOR_NAME
if [[ ! -z "$USER_GIT_AUTHOR_NAME" ]]; then
GIT_AUTHOR_NAME="${USER_GIT_AUTHOR_NAME}"
$(git config --global user.name "$GIT_AUTHOR_NAME")
else
_warning "No Git user name has been set. Please update manually"
fi
read USER_GIT_AUTHOR_EMAIL
if [[ ! -z "$USER_GIT_AUTHOR_EMAIL" ]]; then
GIT_AUTHOR_EMAIL="${USER_GIT_AUTHOR_EMAIL}"
$(git config --global user.email "$GIT_AUTHOR_EMAIL")
else
_warning "No Git user email has been set. Please update manually"
fi
else
_process "→ Git author already set, moving on..."
fi
}
install() {
download_dotfiles
link_dotfiles
install_homebrew
install_node
install_formulae
setup_git_authorship
install_vim_plug
install_oh_my_zsh
install_oh_my_zsh_plugins
}
install