Created
August 4, 2024 00:28
-
-
Save sh1dow3r/bf3d3d9ddf07dd78e6f437a16be4abae to your computer and use it in GitHub Desktop.
Setting up a new mac installtion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Colors for log messages | |
GREEN='\033[0;32m' | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
log_success() { | |
echo -e "${GREEN}[SUCCESS]${NC} $1" | |
} | |
log_error() { | |
echo -e "${RED}[ERROR]${NC} $1" >&2 | |
} | |
check_macos() { | |
if [[ "$OSTYPE" != "darwin"* ]]; then | |
log_error "This script is designed for macOS only." | |
exit 1 | |
fi | |
} | |
backup_zshrc() { | |
if [[ -f "$HOME/.zshrc" ]]; then | |
cp "$HOME/.zshrc" "$HOME/.zshrc.backup" && log_success ".zshrc backed up to .zshrc.backup" | |
fi | |
} | |
update_system() { | |
echo "Updating system..." | |
sudo softwareupdate -i -a && log_success "System updated" || log_error "System update failed" | |
} | |
install_xcode() { | |
echo "Installing Xcode Command Line Tools..." | |
xcode-select --install || echo "Xcode Command Line Tools already installed." | |
} | |
install_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)" && log_success "Homebrew installed" || log_error "Homebrew installation failed" | |
else | |
log_success "Homebrew already installed" | |
fi | |
} | |
update_homebrew() { | |
echo "Upgrading brew and updating package lists..." | |
brew update && brew upgrade && log_success "Brew updated and upgraded" || log_error "Brew update/upgrade failed" | |
} | |
install_iterm2() { | |
echo "Installing iTerm2..." | |
brew install --cask iterm2 && log_success "iTerm2 installed" || log_error "iTerm2 installation failed" | |
} | |
install_zsh() { | |
echo "Installing zsh..." | |
brew install zsh && log_success "zsh installed" || log_error "zsh installation failed" | |
} | |
install_oh_my_zsh() { | |
echo "Installing Oh My Zsh..." | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && log_success "Oh My Zsh installed" || log_error "Oh My Zsh installation failed" | |
} | |
install_powerlevel10k() { | |
echo "Installing Powerlevel10k theme..." | |
git clone https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k && log_success "Powerlevel10k theme installed" || log_error "Powerlevel10k theme installation failed" | |
} | |
configure_zsh_theme() { | |
if ! grep -q "powerlevel10k/powerlevel10k" ~/.zshrc; then | |
echo "Configuring zsh to use Powerlevel10k theme..." | |
sed -i '' 's/^ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc && log_success "zsh configured to use Powerlevel10k theme" || log_error "zsh configuration failed" | |
else | |
log_success "Powerlevel10k theme already configured in zsh" | |
fi | |
} | |
install_fd() { | |
echo "Installing fd..." | |
brew install fd && log_success "fd installed" || log_error "fd installation failed" | |
} | |
install_additional_tools() { | |
echo "Installing additional tools (htop, wget, curl)..." | |
brew install htop wget curl && log_success "Additional tools installed" || log_error "Installation of additional tools failed" | |
} | |
configure_powerlevel10k() { | |
echo "Configuring Powerlevel10k with default settings..." | |
cat <<EOF >>~/.zshrc | |
# To customize prompt, run 'p10k configure' or edit ~/.p10k.zsh. | |
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh | |
EOF | |
log_success "Powerlevel10k configuration added to .zshrc" | |
} | |
install_zsh_plugins() { | |
echo "Installing Zsh plugins..." | |
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting | |
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions | |
log_success "Zsh plugins installed" | |
echo "Configuring Zsh plugins..." | |
sed -i '' 's/^plugins=(/plugins=(zsh-syntax-highlighting zsh-autosuggestions /' ~/.zshrc && log_success "Zsh plugins configured" || log_error "Zsh plugin configuration failed" | |
} | |
install_mas() { | |
echo "Installing mas-cli..." | |
brew install mas && log_success "mas-cli installed" || log_error "mas-cli installation failed" | |
} | |
install_mas_apps() { | |
echo "Installing Mac App Store applications..." | |
mas install 409201541 # Pages | |
mas install 409183694 # Keynote | |
mas install 409203825 # Numbers | |
log_success "Mac App Store applications installed" | |
} | |
install_gui_apps() { | |
echo "Installing GUI applications (Google Chrome, Slack, Visual Studio Code)..." | |
brew install --cask google-chrome slack visual-studio-code && log_success "GUI applications installed" || log_error "Installation of GUI applications failed" | |
} | |
configure_git() { | |
read -p "Enter your Git user name: " git_user_name | |
read -p "Enter your Git email: " git_email | |
echo "Configuring Git..." | |
git config --global user.name "$git_user_name" | |
git config --global user.email "$git_email" | |
git config --global core.editor "vim" | |
log_success "Git configured with user name '$git_user_name' and email '$git_email'" | |
} | |
set_default_shell_to_zsh() { | |
if [[ "$SHELL" != "$(which zsh)" ]]; then | |
echo "Setting zsh as the default shell..." | |
chsh -s $(which zsh) && log_success "zsh set as the default shell" || log_error "Failed to set zsh as the default shell" | |
else | |
log_success "zsh is already the default shell" | |
fi | |
} | |
add_common_env_vars() { | |
echo "Adding common environment variables to .zshrc..." | |
cat <<EOF >>~/.zshrc | |
# Common environment variables | |
export PATH="/usr/local/bin:\$PATH" | |
export EDITOR="vim" | |
EOF | |
log_success "Common environment variables added to .zshrc" | |
} | |
post_installation_summary() { | |
echo -e "${GREEN}Installation complete. Summary:${NC}" | |
echo "1. System updated" | |
echo "2. Xcode Command Line Tools installed" | |
echo "3. Homebrew installed and updated" | |
echo "4. iTerm2 installed" | |
echo "5. zsh installed and set as default shell" | |
echo "6. Oh My Zsh installed" | |
echo "7. Powerlevel10k theme installed and configured" | |
echo "8. fd, htop, wget, and curl installed" | |
echo "9. Zsh plugins installed and configured" | |
echo "10. GUI applications installed (Google Chrome, Slack, Visual Studio Code)" | |
echo "11. Mac App Store applications installed (Pages, Keynote, Numbers)" | |
echo "12. Git configured" | |
echo "13. Common environment variables added to .zshrc" | |
echo -e "${GREEN}Please restart your terminal for all changes to take effect.${NC}" | |
} | |
main() { | |
check_macos | |
backup_zshrc | |
update_system | |
install_xcode | |
install_homebrew | |
update_homebrew | |
install_iterm2 | |
install_zsh | |
install_oh_my_zsh | |
install_powerlevel10k | |
configure_zsh_theme | |
configure_powerlevel10k | |
install_fd | |
install_additional_tools | |
install_zsh_plugins | |
install_mas | |
install_mas_apps | |
install_gui_apps | |
configure_git | |
set_default_shell_to_zsh | |
add_common_env_vars | |
post_installation_summary | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment