-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·251 lines (219 loc) · 8.56 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
# ===> Colors ======================================================================================
GREEN="\033[32m"
NC="\033[0m"
# ==================================================================================================
OS_NAME=""
LINUX="Linux"
MACOS="macOS"
case $(uname) in
Darwin)
OS_NAME=$MACOS
;;
Linux)
OS_NAME=$LINUX
;;
esac
# ===> Prompt User for the repo to clone ===========================================================
printf "Please enter the terminal-setup github repo to clone (default: saltchang/terminal-setup): \n> "
read -r REPO </dev/tty
if [ -z "$REPO" ]; then
REPO="saltchang/terminal-setup"
fi
# ==================================================================================================
# ===> Prompt User for installing Pnpm =============================================================
printf "\nDo you want to install pnpm(https://pnpm.io)? (y/n, default: y): \n> "
read -r INSTALL_PNPM </dev/tty
if [ -z "$INSTALL_PNPM" ]; then
INSTALL_PNPM="y"
fi
# ==================================================================================================
# ===> Prompt User for using iTerm2 as terminal app ================================================
case $OS_NAME in
"$MACOS")
printf "\nDo you want to use iTerm2(https://iterm2.com) as terminal app? (y/n, default: y): \n> "
read -r USE_ITERM2 </dev/tty
if [ -z "$USE_ITERM2" ]; then
USE_ITERM2="y"
fi
;;
esac
# ==================================================================================================
# ===> Prompt User for using alacritty as terminal app =============================================
if [ "$USE_ITERM2" != "y" ]; then
printf "\nDo you want to use Alacritty(https://alacritty.org) as terminal app? (y/n, default: n): \n> "
read -r USE_ALACRITTY </dev/tty
if [ -z "$USE_ALACRITTY" ]; then
USE_ALACRITTY="n"
fi
fi
# ==================================================================================================
echo
echo "Check and install necessary stuffs..."
echo
# ===> Basic Setup By System =======================================================================
case $OS_NAME in
"$MACOS")
if ! [ -x "$(command -v brew)" ]; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
echo -e "${GREEN}homebrew is already installed${NC}"
# install coreutils if it's not installed
if ! [ -x "$(command -v greadlink)" ]; then
echo "Installing coreutils..."
brew install coreutils
fi
echo -e "${GREEN}coreutils is already installed${NC}"
# install jump if it's not installed
if ! [ -x "$(command -v jump)" ]; then
echo "Installing jump..."
brew install jump
fi
echo -e "${GREEN}jump is already installed${NC}"
# install python3 if it's not installed via homebrew
BREW_PYTHON_PATH=$(brew --prefix python3 2>/dev/null)
if ! [ -x "$(command -v python3)" ] || [ -z "$BREW_PYTHON_PATH" ]; then
echo "Installing python3..."
brew install python3
fi
echo -e "${GREEN}python3 is already installed via homebrew${NC}"
# install pipx if it's not installed
if ! [ -x "$(command -v pipx)" ]; then
echo "Installing pipx..."
brew install pipx
fi
echo -e "${GREEN}pipx is already installed${NC}"
;;
"$LINUX")
# install jump if it's not installed
if ! [ -x "$(command -v jump)" ]; then
sudo snap install jump
fi
echo -e "${GREEN}jump is already installed${NC}"
;;
*) ;;
esac
# ==================================================================================================
# ===> Install Fonts ===============================================================================
# download and install font if it's not installed: Meslo & Fira Code
case $OS_NAME in
"$MACOS")
if ! [ -f "/Library/Fonts/MesloLGLNerdFont-Regular.ttf" ]; then
echo "Installing Meslo..."
curl -s -L -o /tmp/Meslo.zip https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/Meslo.zip
unzip /tmp/Meslo.zip -d /tmp/Meslo
cp /tmp/Meslo/*.ttf /Library/Fonts
fi
echo -e "${GREEN}font \"Meslo\" is already installed${NC}"
if ! [ -f "/Library/Fonts/FiraCode-Regular.ttf" ]; then
curl -s -L -o /tmp/FiraCode_v6.2.zip https://github.com/tonsky/FiraCode/releases/download/6.2/Fira_Code_v6.2.zip
unzip /tmp/FiraCode_v6.2.zip -d /tmp/FiraCode
cp /tmp/FiraCode/ttf/*.ttf /Library/Fonts
fi
echo -e "${GREEN}font \"Fira Code\" is already installed${NC}"
;;
"$LINUX")
if ! [ -f "/usr/local/share/fonts/MesloLGLNerdFont-Regular.ttf" ]; then
curl -s -L -o /tmp/Meslo.tar.xz https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/Meslo.tar.xz
mkdir -p /tmp/Meslo
tar xvf /tmp/Meslo.tar.xz -C /tmp/Meslo
sudo cp /tmp/Meslo/*.ttf /usr/local/share/fonts
fi
echo -e "${GREEN}font \"Meslo\" is already installed${NC}"
if ! [ -f "/usr/local/share/fonts/FiraCode-Regular.ttf" ]; then
sudo apt install fonts-firacode
sudo fc-cache -f -v
fi
echo -e "${GREEN}font \"Fira Code\" is already installed${NC}"
;;
*) ;;
esac
# ==================================================================================================
# ===> Install packages ============================================================================
# Install pnpm if it's not installed
if [ "$INSTALL_PNPM" = "y" ]; then
if ! [ -x "$(command -v pnpm)" ]; then
echo "Installing pnpm..."
curl -fsSL https://get.pnpm.io/install.sh | sh -
fi
echo -e "${GREEN}pnpm is already installed${NC}"
fi
# ==================================================================================================
# ===> Install iTerm2 ==============================================================================
if [ "$USE_ITERM2" = "y" ]; then
case $OS_NAME in
"$MACOS")
ITERM2_APP_PATH=$(mdfind "kMDItemCFBundleIdentifier == com.googlecode.iterm2")
if [ -z "$ITERM2_APP_PATH" ]; then
echo "Installing iTerm2..."
brew install --cask iterm2
fi
echo -e "${GREEN}iTerm2 is already installed${NC}"
;;
*) ;;
esac
fi
# ==================================================================================================
# ===> Install alacritty ===========================================================================
if [ "$USE_ALACRITTY" = "y" ]; then
case $OS_NAME in
"$MACOS")
if ! [ -x "$(command -v alacritty)" ]; then
echo "Installing alacritty..."
brew install alacritty
fi
echo -e "${GREEN}alacritty is already installed${NC}"
;;
"$LINUX")
if ! [ -x "$(command -v alacritty)" ]; then
sudo snap install alacritty --classic
fi
echo -e "${GREEN}alacritty is already installed${NC}"
;;
*) ;;
esac
fi
# ==================================================================================================
# ===> Setup zsh ===================================================================================
# install zsh if it's not installed
if ! [ -x "$(command -v zsh)" ]; then
case $OS_NAME in
"$LINUX")
sudo apt update && sudo apt -y install zsh
;;
*) ;;
esac
fi
echo -e "${GREEN}zsh is already installed${NC}"
# set zsh as default shell if not
if [ "$SHELL" != "$(which zsh)" ]; then
echo "Setting zsh as default shell..."
sudo chsh -s "$(which zsh)"
fi
echo -e "${GREEN}zsh is already set as default shell${NC}"
# ==================================================================================================
# ===> Clone and setup =============================================================================
mkdir -p "$HOME/projects/personal"
cd "$HOME/projects/personal" || exit 1
if [ -d "$HOME/projects/personal/terminal-setup" ]; then
echo -e "${GREEN}terminal-setup is already cloned${NC}"
else
echo "Cloning terminal-setup..."
# check if git ssh key is setup
if [ -f "$HOME/.ssh/id_rsa" ] || [ -f "$HOME/.ssh/id_ed25519" ]; then
git clone "git@github.com:$REPO.git" || (echo -e "\nFailed to clone the repo via ssh, try https..\n" && git clone "https://github.com/$REPO.git")
else
git clone "https://github.com/$REPO.git"
fi
fi
cd terminal-setup || exit 1
echo
if [ "$USE_ALACRITTY" = "y" ]; then
./setup.sh --setup-alacritty
elif [ "$USE_ITERM2" = "y" ]; then
./setup.sh --setup-iterm2
else
./setup.sh
fi