-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac_setup.sh
More file actions
208 lines (180 loc) · 6.92 KB
/
mac_setup.sh
File metadata and controls
208 lines (180 loc) · 6.92 KB
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
#!/bin/bash
set -e # Exit on any error
echo "=== Starting Mac Setup Script ==="
# Install Xcode Command Line Tools
if ! xcode-select -p &> /dev/null; then
echo "Installing Xcode Command Line Tools..."
xcode-select --install
else
echo "Xcode Command Line Tools already installed."
fi
# Install Homebrew if not present
if ! command -v brew &> /dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH (for Apple Silicon or Intel; adjust if needed)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
else
echo "Homebrew already installed."
fi
# Install Xcode app from the Mac App Store if not present
if ! [ -d "/Applications/Xcode.app" ]; then
echo "Xcode app not found. Attempting to install via Mac App Store..."
if ! command -v mas &> /dev/null; then
echo "Installing mas (Mac App Store CLI)..."
brew install mas
fi
# Xcode's Mac App Store ID is 497799835
mas install 497799835
echo "Xcode app installation triggered. Please open the App Store to monitor progress if needed."
else
echo "Xcode app already installed."
fi
# Update Homebrew
echo "Updating Homebrew..."
brew update
# Install git if not present
if ! command -v git &> /dev/null; then
echo "Installing git..."
brew install git
else
echo "git already installed."
fi
GIT_NAME=$(git config --global user.name || true)
GIT_EMAIL=$(git config --global user.email || true)
if [[ -z "$GIT_NAME" || -z "$GIT_EMAIL" ]]; then
echo "Git is not fully configured."
if [[ -z "$GIT_NAME" ]]; then
read -p "Enter your git user.name: " GIT_NAME_INPUT
git config --global user.name "$GIT_NAME_INPUT"
fi
if [[ -z "$GIT_EMAIL" ]]; then
read -p "Enter your git user.email: " GIT_EMAIL_INPUT
git config --global user.email "$GIT_EMAIL_INPUT"
fi
echo "Git configuration complete."
else
echo "Git is already configured (user.name: $GIT_NAME, user.email: $GIT_EMAIL)."
fi
# Install nvm (Node Version Manager)
if [ ! -d "$HOME/.nvm" ]; then
echo "Installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
else
echo "nvm already installed."
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
fi
# Install latest LTS Node.js and pnpm
if ! command -v node &> /dev/null; then
echo "Installing latest LTS Node.js via nvm..."
nvm install --lts
nvm use --lts
else
echo "Node.js already installed."
fi
if ! command -v pnpm &> /dev/null; then
echo "Installing pnpm..."
npm install -g pnpm
else
echo "pnpm already installed."
fi
# Install rustup (Rust toolchain installer)
if ! command -v rustup &> /dev/null; then
echo "Installing rustup..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
export PATH="$HOME/.cargo/bin:$PATH"
else
echo "rustup already installed."
fi
# Install dockutil for Dock management
if ! command -v dockutil &> /dev/null; then
echo "Installing dockutil..."
brew install dockutil
else
echo "dockutil already installed."
fi
# List of apps to install via Homebrew Cask
apps=(
cursor
google-chrome
slack
zoom
iterm2
discord
raycast
)
echo "Installing apps via Homebrew Cask..."
for app in "${apps[@]}"; do
if brew list --cask | grep -q "^${app}$"; then
echo "${app} already installed."
else
brew install --cask "${app}"
fi
done
brew cleanup
echo "Configuring Dock..."
# Reset Dock to defaults
defaults delete com.apple.dock
dockutil --remove all
# Add items to Dock (logical order: Launchpad, browsers/editors, communication, settings, utilities)
dockutil --add '/System/Applications/Apps.app'
dockutil --add '/Applications/Safari.app'
dockutil --add '/Applications/Google Chrome.app'
dockutil --add '/Applications/Cursor.app'
dockutil --add '/Applications/iTerm.app'
dockutil --add '/System/Applications/FaceTime.app'
dockutil --add '/Applications/Messages.app'
dockutil --add '/System/Applications/System Settings.app'
dockutil --add '~/Downloads' --view grid --display folder
# Trash is added automatically by macOS
# Add more as needed, e.g., dockutil --add '/Applications/Slack.app'
# Dock preferences
defaults write com.apple.dock tilesize -int 64 # Icon size
defaults write com.apple.dock orientation -string bottom # Position
# defaults write com.apple.dock autohide -bool true # Auto-hide
# defaults write com.apple.dock autohide-delay -float 0 # No delay
# defaults write com.apple.dock autohide-time-modifier -float 0 # No modifier
# defaults write com.apple.dock mineffect -string scale # Minimize effect
defaults write com.apple.dock show-recents -bool false # No recent apps
# defaults write com.apple.dock magnification -bool false # No magnification
killall Dock
echo "Applying other system tweaks..."
# Finder tweaks
defaults write NSGlobalDomain AppleShowAllExtensions -bool true # Show file extensions
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv" # List view
defaults write com.apple.finder ShowPathbar -bool true # Show path bar
killall Finder
# Screenshot tweaks
mkdir -p ~/Pictures/Screenshots
defaults write com.apple.screencapture location -string "~/Pictures/Screenshots"
defaults write com.apple.screencapture type -string "png"
defaults write com.apple.screencapture disable-shadow -bool true
killall SystemUIServer
# Set Xcode path and accept license before installing iOS Simulator
echo "Setting Xcode path and accepting license..."
sudo xcode-select -s /Applications/Xcode.app
sudo xcodebuild -license accept
# Install latest iOS Simulator (LTS) and create a simulator
echo "Installing latest available iOS Simulator (LTS)..."
LATEST_RUNTIME=$(xcrun simctl list runtimes | grep -E "iOS [0-9]+.[0-9]+" | grep -v unavailable | sort -V | tail -1 | awk -F '[()]' '{print $2}')
if [ -z "$LATEST_RUNTIME" ]; then
echo "Could not determine latest iOS runtime. Please check Xcode installation."
else
echo "Latest iOS runtime identifier: $LATEST_RUNTIME"
# Find latest iPhone device type
LATEST_DEVICE_TYPE=$(xcrun simctl list devicetypes | grep -E "iPhone" | sort | tail -1 | awk -F '[()]' '{print $2}')
if [ -z "$LATEST_DEVICE_TYPE" ]; then
echo "Could not determine latest iPhone device type."
else
SIM_NAME="LTS-iPhone"
echo "Creating simulator '$SIM_NAME' with device type '$LATEST_DEVICE_TYPE' and runtime '$LATEST_RUNTIME'..."
xcrun simctl create "$SIM_NAME" "$LATEST_DEVICE_TYPE" "$LATEST_RUNTIME" || echo "Simulator may already exist."
fi
fi
echo "=== Setup complete! Restart your Mac or log out/in for full effect. ==="