Last active
March 26, 2025 18:38
-
-
Save attilah/a8a40e1b0fab67388d24952231cbd142 to your computer and use it in GitHub Desktop.
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 | |
# ----------------------------------------------------------------------------- | |
# XCode | |
# ----------------------------------------------------------------------------- | |
os=$(sw_vers -productVersion | awk -F. '{print $1 "." $2}') | |
if softwareupdate --history | grep --silent "Command Line Tools.*${os}"; then | |
echo 'Command-line tools already installed. Skipping' | |
else | |
echo 'Installing Command-line tools...' | |
in_progress=/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | |
touch ${in_progress} | |
product=$(softwareupdate --list | awk "/\* Command Line.*${os}/ { sub(/^ \* /, \"\"); print }") | |
if ! softwareupdate --verbose --install "${product}"; then | |
echo 'Installation failed.' 1>&2 | |
rm ${in_progress} | |
exit 1 | |
fi | |
rm ${in_progress} | |
echo 'Installation succeeded.' | |
fi | |
# ----------------------------------------------------------------------------- | |
# Install Rosetta 2 | |
# ----------------------------------------------------------------------------- | |
os=$(sw_vers -productVersion | awk -F. '{print $1 "." $2}') | |
if /usr/bin/pgrep -q oahd; then | |
echo 'Rosetta 2 is already installed. Skipping' | |
else | |
echo 'Installing Rosetta 2...' | |
in_progress=/tmp/.com.apple.dt.Rosetta2.installondemand.in-progress | |
touch ${in_progress} | |
if ! softwareupdate --install-rosetta --agree-to-license; then | |
echo 'Installation failed.' 1>&2 | |
rm ${in_progress} | |
exit 1 | |
fi | |
rm ${in_progress} | |
echo 'Installation succeeded.' | |
fi | |
# ----------------------------------------------------------------------------- | |
# Homebrew | |
# ----------------------------------------------------------------------------- | |
if ! [ -x "$(command -v brew)" ]; then | |
echo "Installing Homebrew…" | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
if [[ "$(uname -p)" == "arm" ]]; then | |
# Apple Silicon M1/M2 Macs | |
export PATH=/opt/homebrew/bin:$PATH | |
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >>$HOME/.zprofile | |
eval "$(/opt/homebrew/bin/brew shellenv)" | |
else | |
# Intel Macs | |
export PATH=/usr/local/bin:$PATH | |
fi | |
echo "Homebrew installed!" | |
else | |
echo "Homebrew already installed. Updating Homebrew formulae…" | |
brew update --quiet >/dev/null 2>&1 | |
fi | |
source $HOME/.zprofile | |
# Define the SSH config file path | |
SSH_CONFIG_FILE="$HOME/.ssh/config" | |
# Define the content to be written to the config file | |
CONFIG_CONTENT="Include ~/.orbstack/ssh/config | |
Host * | |
IdentityAgent \"~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock\" | |
SetEnv TERM=xterm-256color" | |
# Function to create the .ssh directory if it doesn't exist | |
create_ssh_directory() { | |
if [ ! -d "$HOME/.ssh" ]; then | |
echo "Creating .ssh directory..." | |
mkdir -p "$HOME/.ssh" | |
chmod 700 "$HOME/.ssh" | |
echo ".ssh directory created successfully." | |
fi | |
} | |
# Check if the SSH config file already exists | |
if [ -f "$SSH_CONFIG_FILE" ]; then | |
echo "SSH config file already exists at: $SSH_CONFIG_FILE" | |
echo "Skipping creation to avoid overwriting existing configuration." | |
else | |
echo "SSH config file does not exist. Preparing to create it..." | |
# Create .ssh directory if it doesn't exist | |
create_ssh_directory | |
# Write the configuration to the file | |
echo "Creating SSH config file..." | |
echo "$CONFIG_CONTENT" > "$SSH_CONFIG_FILE" | |
# Set appropriate permissions | |
chmod 600 "$SSH_CONFIG_FILE" | |
echo "SSH config file created successfully at: $SSH_CONFIG_FILE" | |
fi | |
# Install bash, chezmoi and 1password | |
brew install \ | |
bash \ | |
chezmoi | |
brew install --cask \ | |
1password \ | |
1password-cli |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment