-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·159 lines (133 loc) · 2.79 KB
/
setup.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
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
#!/usr/bin/env bash
# =========
# Logging
# =========
error() {
printf '%b\n' " - [$(date +'%m/%d/%y %H:%M:%S')] <Error>: $1"
}
info() {
printf '%b\n' " - [$(date +'%m/%d/%y %H:%M:%S')] <Info>: $1"
}
# ========
# Utils
# ========
command_check() {
if ! command -v "${1}" &> /dev/null; then
error "In order to use this script, ${1} must be installed"
exit 1
fi
}
# =================
# Install Functions
# =================
install_nvim() {
info "Installing nvim"
mkdir -p "$NVIM_DIR"
case "$OS" in
Linux)
apt-get install -y neovim
;;
Mac)
brew install -q neovim
;;
esac
}
insatll_zsh() {
brew install -q zsh
chsh -s /opt/homebrew/bin/zsh
info "Installing Oh My Zsh"
if [ ! -d "$ZSH" ]; then
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
else
info "Oh My Zsh already installed"
fi
}
install_node() {
info "Installing nodejs"
case "$OS" in
Linux)
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
apt-get install -y nodejs
;;
Mac)
brew install -q nodejs
;;
esac
}
# =========
# Variables
# =========
SCRIPTS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
pushd "$SCRIPTS_DIR" || exit 1 > /dev/null
SOURCE_DIR=$PWD
NVIM_DIR="${HOME}/.config/nvim"
# ==================
# Detect Environment
# ==================
OS=""
case $(uname) in
Linux*)
OS="Linux"
;;
Darwin*)
OS="Mac"
;;
*)
error "Unknown OS_TYPE: ${OS_TYPE}"
exit 1
;;
esac
# ====================
# Detect Prerequisites
# ====================
info "Detecting if system has prereqs"
command_check curl
case "$OS" in
Linux)
[ "$(id -u)" -ne 0 ] && {
error "In order to use this script, run with root or use sudo."
exit 1
}
;;
Mac)
[ "$(id -u)" -eq 0 ] && {
error "In order to use this script, it must run without root nor sudo"
exit 1
}
command_check brew
;;
esac
# ====================
# Installation/Setup
# ====================
install_tools() {
info "Installing all the things"
case "$OS" in
Linux)
install_nvim
install_node
;;
Mac)
install_nvim
insatll_zsh
install_node
;;
esac
}
# install_tools
# =========
# Symlinks
# =========
info "Symlink dotfiles to ${HOME}"
sleep 3
# BASH
ln -sf "${SOURCE_DIR}/.profile" "${HOME}/.profile"
# ZSH
[[ ! -e "${HOME}/.zshrc" ]] && cp "${SOURCE_DIR}/.zshrc" "${HOME}/.zshrc"
ln -sf "${SOURCE_DIR}/.zshrc" "${HOME}/.zshrc"
# NVIM
ln -sf "${SOURCE_DIR}/.config/nvim/init.lua" "${NVIM_DIR}/init.lua"
ln -sfh "${SOURCE_DIR}/.config/nvim/lua" "${NVIM_DIR}/lua"
# GIT
ln -sf "${SOURCE_DIR}/.gitconfig" "${HOME}/.gitconfig"
ln -sf "${SOURCE_DIR}/.gitconfig-github" "${HOME}/.gitconfig-github"