-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
179 lines (152 loc) · 5.25 KB
/
setup.sh
File metadata and controls
179 lines (152 loc) · 5.25 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
#!/bin/zsh
set -e
# Zsh-specific options for script compatibility
setopt SH_WORD_SPLIT # Make word splitting behave like bash
setopt POSIX_ALIASES # Make aliases behave like bash
# Function to set up SSH keys
setup_ssh() {
echo "--- Setting up SSH ---"
if [ ! -d "$HOME/.ssh" ]; then
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
fi
read -p "Enter a comment for your SSH key (e.g., your email): " ssh_comment
read -p "Enter a name for your SSH key (default: id_ed25519): " ssh_key_name
ssh_key_name=${ssh_key_name:-id_ed25519}
local ssh_key_path="$HOME/.ssh/$ssh_key_name"
if [ -f "$ssh_key_path" ]; then
echo "SSH key $ssh_key_path already exists."
else
echo "Creating an SSH key for you..."
ssh-keygen -t ed25519 -C "$ssh_comment" -f "$ssh_key_path"
echo "Your SSH key ($ssh_key_name) was created in ~/.ssh"
fi
local ssh_config_path="$HOME/.ssh/config"
if [ ! -f "$ssh_config_path" ]; then
touch "$ssh_config_path"
fi
# Add common Git hosts
local hosts=("github.com" "bitbucket.org")
for host in "${hosts[@]}"; do
if ! grep -q "Host $host" "$ssh_config_path"; then
echo "Adding $host to SSH config..."
{
echo "Host $host"
echo " Hostname $host"
echo " IdentityFile $ssh_key_path"
echo " UseKeychain yes"
echo " AddKeysToAgent yes"
echo ""
} >> "$ssh_config_path"
else
echo "$host already configured in SSH config."
fi
done
echo "Please add this public key to your preferred version control platform:"
cat "$ssh_key_path.pub"
echo "https://github.com/settings/keys"
echo "https://bitbucket.org/account/settings/ssh-keys/"
echo "https://gitlab.com/-/profile/keys"
echo "--------------------"
}
# Function to install Homebrew and its dependencies
install_homebrew() {
echo "--- Installing Homebrew ---"
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
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> "$HOME/.zprofile"
eval "$(/opt/homebrew/bin/brew shellenv)"
else
echo "Homebrew is already installed."
fi
# Update Homebrew
echo "Updating Homebrew..."
brew update
echo "--------------------"
}
# Function to install packages from Brewfile
install_packages() {
echo "--- Installing Packages from Brewfile ---"
if [ -f "Brewfile" ]; then
brew bundle --file="./Brewfile"
else
echo "Brewfile not found. Skipping package installation."
fi
echo "--------------------"
}
# Function to configure Git global settings
configure_git() {
echo "--- Configuring Git ---"
read -p "Enter your name for Git: " name
git config --global user.name "$name"
read -p "Enter your email for Git: " email
git config --global user.email "$email"
echo "--------------------"
}
# Function to set macOS defaults
configure_macos() {
echo "--- Configuring macOS Settings ---"
# Dock - Clear all icons and configure settings
echo "Clearing all dock icons..."
defaults write com.apple.dock persistent-apps -array
defaults write com.apple.dock persistent-others -array
defaults write com.apple.dock "autohide" -bool "true"
defaults write com.apple.dock "show-recents" -bool "false"
defaults write com.apple.dock minimize-to-application -bool "true"
killall Dock || true
# Finder
defaults write NSGlobalDomain "AppleShowAllExtensions" -bool "true"
defaults write com.apple.finder "ShowPathbar" -bool "true"
killall Finder || true
# Xcode
defaults write com.apple.dt.Xcode "ShowBuildOperationDuration" -bool "true"
killall Xcode || true
echo "--------------------"
}
# Function to set up Zsh configuration
setup_zsh() {
echo "--- Setting up Zsh ---"
local zshrc_source="config/.zshrc"
local zshrc_dest="$HOME/.zshrc"
if [ -f "$zshrc_dest" ]; then
echo "Backing up existing .zshrc to .zshrc.bak"
mv "$zshrc_dest" "$zshrc_dest.bak"
fi
if [ -f "$zshrc_source" ]; then
cp "$zshrc_source" "$zshrc_dest"
echo ".zshrc copied to home directory."
source "$zshrc_dest"
else
echo "Source .zshrc not found in 'config' directory."
fi
echo "--------------------"
}
# Function to install Xcode Command Line Tools
install_xcode_tools() {
echo "--- Installing Xcode Command Line Tools ---"
if ! xcode-select -p &> /dev/null; then
echo "Installing Xcode Command Line Tools..."
# This will open a prompt, user interaction is required
xcode-select --install
else
echo "Xcode Command Line Tools are already installed."
fi
echo "--------------------"
}
# Main function to run all setup steps
main() {
echo "Starting Mac Setup..."
setup_ssh
install_xcode_tools
install_homebrew
install_packages
configure_git
configure_macos
setup_zsh
echo "Cleaning up brew..."
brew cleanup
echo "Done! ✅"
}
main