-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmac_install.sh
executable file
·199 lines (167 loc) · 6.22 KB
/
mac_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
#!/bin/bash
#
# Separator
sep="\n************************************\n"
# Check if Xcode Command Line Tools are installed, install if we don't have them
if ! xcode-select --version &>/dev/null; then
echo -e "${sep}Installing Xcode Command Line Tools..."
xcode-select --install
else
echo "Xcode Command Line Tools are already installed"
fi
# Check if Homebrew is installed, install if we don't have it
if ! command -v brew &>/dev/null; then
echo -e "${sep}Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# in the current running environment, disable the brew auto update
export HOMEBREW_NO_AUTO_UPDATE=1
# Define an array of taps
taps=("homebrew/cask-fonts" "epk/epk")
# Tap into the repositories in the taps array if not already done
for tap in "${taps[@]}"; do
if ! brew tap | grep -q "$tap"; then
echo -e "${sep}Tapping into $tap..."
brew tap $tap
else
echo "$tap is already tapped"
fi
done
# Install tools with 'brew install'
tools=("wget" "ripgrep" "python" "fzf" "neovim" "lazygit" "alacritty")
for tool in "${tools[@]}"; do
if ! brew list $tool &>/dev/null; then
echo -e "${sep}Installing $tool..."
brew install $tool
else
echo "$tool is already installed"
fi
done
# Install tools with 'brew install --cask'
cask_tools=("iterm2" "font-meslo-lg-nerd-font" "font-sf-mono-nerd-font")
for tool in "${cask_tools[@]}"; do
if ! brew list --cask $tool &>/dev/null; then
echo -e "${sep}Installing $tool..."
brew install --cask $tool
else
echo "$tool is already installed"
fi
done
# Install KDiff3 application
KDIFF3_DMG_PATH=~/Downloads/kdiff3-1.11.1-macos-arm64.dmg
KDIFF3_VOLUME_NAME="KDiff3"
KDIFF3_VOLUME_PATH="/Volumes/$KDIFF3_VOLUME_NAME"
KDIFF3_APP_NAME="kdiff3.app"
KDIFF3_APP_PATH="/Applications/$KDIFF3_APP_NAME/Contents/MacOS/kdiff3"
KDIFF3_DOWNLOAD_URL="https://download.kde.org/stable/kdiff3/kdiff3-1.11.1-macos-arm64.dmg"
# Check if kdiff3 is already installed
if [ ! -f "$KDIFF3_APP_PATH" ]; then
# kdiff3 is not installed, download it if necessary
if [ ! -f "$KDIFF3_DMG_PATH" ]; then
curl -L "$KDIFF3_DOWNLOAD_URL" -o "$KDIFF3_DMG_PATH"
else
echo "$KDIFF3_DMG_PATH exists"
fi
# Mount the .dmg file
echo "attaching kdiff3 image..."
hdiutil attach "$KDIFF3_DMG_PATH" -nobrowse -noautoopen -mountpoint "$KDIFF3_VOLUME_PATH"
# Copy the application to the Applications directory
echo "installing kdiff3 application..."
cp -R "$KDIFF3_VOLUME_PATH/$KDIFF3_APP_NAME" /Applications
# Detach the .dmg file
echo "detaching kdiff3 image..."
hdiutil detach "$KDIFF3_VOLUME_PATH"
echo "kdiff3 is installed successfully"
else
echo "kdiff3 is already installed"
fi
# Set git configs
echo "Setup git configuration"
git config --global diff.tool kdiff3
git config --global diff.guitool kdiff3
git config --global difftool.prompt false
git config --global difftool.kdiff3.path "$KDIFF3_APP_PATH"
git config --global difftool.kdiff3.trustExitCode false
git config --global merge.tool kdiff3
git config --global mergetool.prompt false
git config --global mergetool.kdiff3.path "$KDIFF3_APP_PATH"
git config --global mergetool.kdiff3.trustExitCode false
git config --global diff.tool nvim
git config --global difftool.nvim.cmd 'nvim -d $LOCAL $REMOTE'
git config --global core.pager "less -F -X"
# Install NVM (using brew install nvm can't work well)
# Check for .nvm directory and nvm.sh script file
if [ -d "$HOME/.nvm" ] && [ -s "$HOME/.nvm/nvm.sh" ]; then
echo "NVM is already installed"
else
echo -e "${sep}Installing NVM..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
fi
# Source nvm script
[ -s "$HOME/.nvm/nvm.sh" ] && \. "$HOME/.nvm/nvm.sh"
# Define Node.js version as your requirement
node_version="18.17.1"
# Install Node version if it's not installed, and use it
if nvm ls $node_version >/dev/null 2>&1; then
echo "Node.js version $node_version is already installed"
else
echo -e "${sep}Installing Node.js version $node_version..."
nvm install $node_version
fi
nvm use $node_version
# Define the lines to be added
lines=(
'export HOMEBREW_NO_AUTO_UPDATE=1 # disable the brew auto update'
'export NVM_DIR="$HOME/.nvm"'
'[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'
'[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion'
'eval "$(fzf --zsh)"'
)
# Check if the lines already exist in the file, if not, add them
file="$HOME/.zshrc" # Define the file to be checked
echo -e "${sep}Adding configurations to .zshrc for brew, NVM, fzf, etc."
for line in "${lines[@]}"; do
if ! grep -Fxq "$line" "$file"; then
echo "$line" >> "$file"
fi
done
echo -e "Done${sep}"
# Define the directories and files
SETUP_DIR="$HOME/.setup_env"
DEV_ENV_DIR="$SETUP_DIR/dev-env"
ALACRITTY_DIR="$HOME/.config/alacritty"
ALACRITTY_CONFIG="$ALACRITTY_DIR/alacritty.toml"
NVIM_DIR="$HOME/.config/nvim"
NVIM_CONFIG="$NVIM_DIR/init.lua"
# Check if the Neovim configurations exist, if not, install them
if [ ! -f "$NVIM_CONFIG" ]; then
echo -e "${sep}Installing Neovim configurations..."
# Remove setup folder if it exists
[ -d "$SETUP_DIR" ] && rm -rf "$SETUP_DIR"
# Clone the dev-env repository
mkdir "$SETUP_DIR"
git clone https://github.com/alexya/josean-dev-env.git "$DEV_ENV_DIR"
# Remove existing nvim folders
rm -rf "$NVIM_DIR" "$HOME/.local/share/nvim" "$HOME/.local/state/nvim"
# Copy nvim configuration
cp -r -f "$DEV_ENV_DIR/.config/nvim" "$HOME/.config"
echo -e "Neovim configurations are installed"
else
echo "The Neovim configurations are already installed"
fi
# Check if the Alacritty configurations exist, if not, copy them
if [ -f "$ALACRITTY_CONFIG" ]; then
echo "The configurations of the alacritty are already installed"
else
echo "Installing Alacritty configurations..."
if [ ! -d "$SETUP_DIR" ]; then
mkdir "$SETUP_DIR"
git clone https://github.com/alexya/josean-dev-env.git "$DEV_ENV_DIR"
fi
cp -r -f "$DEV_ENV_DIR/.config/alacritty" "$HOME/.config"
echo -e "Alacritty configurations are installed"
fi
# Remove setup folder if it exists
[ -d "$SETUP_DIR" ] && rm -rf "$SETUP_DIR"
echo -e "${sep}"
echo -e "\033[0;32mAll tasks completed!\033[0m"