Skip to content

Instantly share code, notes, and snippets.

@nkg
Last active August 7, 2024 22:25
Show Gist options
  • Select an option

  • Save nkg/b134a6319e3bd1653ea28dd123b36e5d to your computer and use it in GitHub Desktop.

Select an option

Save nkg/b134a6319e3bd1653ea28dd123b36e5d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Ask for the administrator password upfront
# As my dotfiles are private, I need to configure github auth first
# USAGE: /bin/bash -c "export BW_SERVER=vault.bitwarden.com && $(curl -fsSL https://gist.githubusercontent.com/nkg/b134a6319e3bd1653ea28dd123b36e5d/raw/pre_bootstrap.sh)”
set -ufo pipefail
sudo -v
: ${BW_SERVER:-}
: ${BW_USER_EMAIL:="[email protected]"}
: ${GITHUB_USERNAME:="nkg"}
: ${HOMEBREW_PREFIX:="/usr/local"}
: ${HOMEBREW_REPOSITORY:="${HOMEBREW_PREFIX}/Homebrew"}
OS="$(uname)"
ARCH="$(/usr/bin/uname -m)"
tmpdir="$(mktemp -d)"
trap 'rm -rf -- "${tmpdir}"' EXIT
trap 'exit' INT TERM
abort() {
printf "%s\n" "$@" >&2
exit 1
}
if ! [[ "${OS}" == "Darwin" ]]
then
abort "Script is only supported on macOS."
fi
xcode-select -p &> /dev/null
if [[ $? -ne 0 ]]
then
echo "πŸ‘Š Installing CommandLineTools"
# This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress;
PROD=$(softwareupdate -l | grep "\*.*Command Line" | tail -n 1 | sed 's/^[^C]* //')
softwareupdate -i "$PROD" --verbose --agree-to-license;
rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
else
echo "βœ… Command Line Tools already installed. Skipping ..."
fi
if [[ "${ARCH}" == "arm64" ]]
then
# On ARM macOS, this script installs to /opt/homebrew only
HOMEBREW_PREFIX="/opt/homebrew"
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}"
fi
export PATH="${HOMEBREW_PREFIX}/bin:${PATH}"
if ! which brew &>/dev/null
then
echo "🍺 Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
brew analytics off
export HOMEBREW_CASK_OPTS="--appdir=~/Applications"
else
echo "βœ… Homebrew already installed. Skipping ..."
fi
if ! which chezmoi &>/dev/null
then
echo "πŸ‘Š Installing chezmoi"
brew install chezmoi
else
echo "βœ… chezmoi already installed. Skipping ..."
fi
if ! which git-credential-manager &>/dev/null
then
echo "πŸ‘Š Installing git-credential-manager"
brew tap microsoft/git
brew install --cask git-credential-manager-core
else
echo "βœ… git-credential-manager already installed. Skipping ..."
fi
if ! which rbw &>/dev/null
then
echo "πŸ‘Š Installing rbw (bitwarden cli client)"
# Don't like this as it installs node, which i want to manage with asdf
brew install rbw
if [[ -z ${BW_SERVER+x} ]]
then
read -p "Enter the Bitwarden server url. (exanple https://bitwarden.com): " BW_SERVER
fi
read -s -p "Enter user bitwarden password: " BW_USER_PASSWORD
rbw config set base_url "https://${BW_SERVER}"
rbw config set email "${BW_USER_EMAIL}"
rbw login
else
echo "βœ… bw already installed. Skipping ..."
fi
git clone "https://github.com/${GITHUB_USERNAME}/dotfiles.git" "${tmpdir}/dotfiles"
if [[ ! -d "$HOME/.local/share/chezmoi/" ]]
then
echo "πŸ‘Š Initazlising $GITHUB_USERNAME chezmoi repo"
chezmoi init --apply "https://github.com/${GITHUB_USERNAME}/dotfiles.git"
else
echo "βœ… chezmoi repo for ${GITHUB_USERNAME} exists. Skipping ..."
fi
echo "🎯 Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment