Last active
August 7, 2024 22:25
-
-
Save nkg/b134a6319e3bd1653ea28dd123b36e5d 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
| #!/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