Skip to content

Commit

Permalink
more m1 fixes for bobs (#11)
Browse files Browse the repository at this point in the history
* moved m1 logic to install step

* Bump version to 0.1.2

Co-authored-by: SteveRuble <SteveRuble@@users.noreply.github.com>
  • Loading branch information
SteveRuble and SteveRuble authored Feb 7, 2022
1 parent f9ed134 commit 2e278eb
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 80 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ruby 2.7.2
python 3.9.7
pre-commit 2.15.0
shfmt 3.4.1
shellcheck 0.8.0
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2
71 changes: 25 additions & 46 deletions bootstrap
Original file line number Diff line number Diff line change
@@ -1,65 +1,44 @@
#!/bin/bash

#shellcheck disable=SC2034

if ! command -v brew &>/dev/null; then

if [[ $(uname -m) == 'arm64' ]]; then
echo '-----------------------------------
You have an M1 chip and you are not
running in a Rosetta-flavored shell.
There may be a day when all our tools
work correctly on M1, but until that day
you will need to install them in x86
compatibility mode. I will install brew
in x86 compatibiility mode to support that.
When you run brew commands in the future
you may run into a message telling you
that you need to install it in another mode.
You can follow those instructions, or just
make a new shell using "arch -x86_64 zsh"
and do your brew install from there.
Press any key to continue
'
read -rn 1
arch -x86_64 /bin/bash -c "$(curl -fsSL https://github.com/raw/Homebrew/install/master/install.sh)"
else
/bin/bash -c "$(curl -fsSL https://github.com/raw/Homebrew/install/master/install.sh)"
fi
if ! command -v brew >/dev/null; then
/bin/bash -c "$(curl -fsSL https://github.com/raw/Homebrew/install/master/install.sh)"
fi

eval "$(/usr/local/bin/brew shellenv)"
# Activate the correct brew for the CPU
if [[ "$(uname -m)" == 'arm64' ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi

echo "Installing ih-core formula..."
echo "Sometimes the dependency downloads fail, possibly due to the VPN, so \
I will retry installing a couple times if it fails."

if [[ $1 == "local" ]]; then
THIS_DIR=$(dirname "$(realpath "$0")")

for i in 1 2 3; do brew install --formula -s "$THIS_DIR/formula/ih-core.rb" && break; done
brew update
brew tap ConsultingMD/homebrew-ih-public https://github.com/ConsultingMD/homebrew-ih-public.git

elif [[ ${#} -eq 1 ]]; then
VERSION=$1
echo "Installing version $VERSION"
TMP_DIR=$(mktemp -d)
FORMULA_PATH="$TMP_DIR/ih-core.rb"
curl -L -o "$FORMULA_PATH" "https://github.com/ConsultingMD/homebrew-ih-public/releases/download/$VERSION/ih-core.rb"
SUCCEEDED=1
for _ in 1 2 3; do
brew install ih-core
SUCCEEDED=$?
if [ $SUCCEEDED -eq 0 ]; then
break
fi
done

for i in 1 2 3; do brew install --formula -s "$FORMULA_PATH" && break; done
rm -rf "$TMP_DIR"
else
brew update
brew tap ConsultingMD/homebrew-ih-public https://github.com/ConsultingMD/homebrew-ih-public.git
for i in 1 2 3; do brew install ih-core && break; done
if [ $SUCCEEDED -eq 1 ]; then
echo "Install of ih-setup formula failed. Please contact platform support
in the #developer-platform-support stream in Zulip or the #dept-eng_infra channel
in Slack. You can also search Confluence for 'Engineer Onboarding Guide' for
more troubleshooting tips."
exit 1
fi

if command -v ih-setup; then
ih-setup install
else
echo "ih-setup is not available in your PATH. Check the logs above to see if there was a fatal error,
and make sure that /usr/local/bin is in your PATH. Then run 'ih-setup install' again."
and make sure that /usr/local/bin is in your PATH"
exit 1
fi
2 changes: 1 addition & 1 deletion formula/ih-core.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class IhCore < Formula
VERSION="0.1.1"
VERSION="0.1.2"
desc "Brew formula for installing core tools used at Included Health engineering."
homepage "https://github.com/ConsultingMD/homebrew-ih-public"
license "CC BY-NC-ND 4.0"
Expand Down
20 changes: 9 additions & 11 deletions lib/bobs/bazel/step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
# IH_CORE_DIR will be set to the directory containing the bin and lib directories.

function ih::setup::bobs.bazel::help() {
echo 'Installs bazelisk for bazel management
echo 'Installs bazel correctly
This step will:
- Install bazelisk
- Check that bazel is working
- Install bazelisk in x86 mode
- symlink bazel to bazelisk
- Configure bazel keystore to trust DLP certificate
'
}

# Check if the step has been installed and return 0 if it has.
# Otherwise return 1.
function ih::setup::bobs.bazel::test() {
if ! type bazelisk >/dev/null; then

if ! type bazelisk >/dev/null 2>&1; then
return 1
fi

if ! type bazel >/dev/null; then
if ! type bazel >/dev/null 2>&1; then
return 1
fi

Expand All @@ -40,13 +41,10 @@ function ih::setup::bobs.bazel::deps() {
function ih::setup::bobs.bazel::install() {

set -e
ih::log::info "Installing bazelisk using brew..."
brew install bazelisk
ih::log::info "Checking bazelisk version..."
bazelisk version

ih::log::info "Checking bazel version..."
bazel version
ih::arch::ibrew install bazelisk

ln -s /usr/local/bin/bazelisk /usr/local/bin/bazel

ih::setup::bobs.bazel::private::java-certs "install"
}
Expand Down
20 changes: 20 additions & 0 deletions lib/bobs/go/default/01_bobs_go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# This file defines the go environment variables you
# should have when working on the bobs repo.
# It was created by `ih-setup install bobs go`

# ██████╗ ██████╗ ███╗ ██╗ ██████╗ ████████╗ ███████╗██████╗ ██╗████████╗
# ██╔══██╗██╔═══██╗ ████╗ ██║██╔═══██╗╚══██╔══╝ ██╔════╝██╔══██╗██║╚══██╔══╝
# ██║ ██║██║ ██║ ██╔██╗ ██║██║ ██║ ██║ █████╗ ██║ ██║██║ ██║
# ██║ ██║██║ ██║ ██║╚██╗██║██║ ██║ ██║ ██╔══╝ ██║ ██║██║ ██║
# ██████╔╝╚██████╔╝ ██║ ╚████║╚██████╔╝ ██║ ███████╗██████╔╝██║ ██║
# ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚══════╝╚═════╝ ╚═╝ ╚═╝
# Changes to this file will be overwritten if you re-install the step

export GO111MODULE=on
export GOPATH="${HOME}/go"
export GOBIN="${GOPATH}/bin"
export PATH=$PATH:"${GOBIN}"
export GOPROXY=direct
export GOPRIVATE='github.com/ConsultingMD/*'
45 changes: 45 additions & 0 deletions lib/bobs/go/step.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# IH_CORE_DIR will be set to the directory containing the bin and lib directories.
BOBSGOVERSION="1.15.15"

function ih::setup::bobs.go::help() {
echo "This correctly installs Go for use in the bobs repo
This step will:
- install an x86 version of go $BOBSGOVERSION for asdf
- configure your shell with required go environment variables
"
}

# Check if the step has been installed and return 0 if it has.
# Otherwise return 1.
function ih::setup::bobs.go::test() {

if ! ih::file::check-shell-defaults "$IH_CORE_DIR"/lib/bobs/go/default; then
return 1
fi

if ! asdf list golang | grep -q "$BOBSGOVERSION"; then
return 1
fi

return 0
}

# Echo a space-delimited list of steps which must be installed before this one can be.
function ih::setup::bobs.go::deps() {
# echo "step1 step2"
echo ""
}

function ih::setup::bobs.go::install() {

set -e

ih::arch::x86 asdf install golang "$BOBSGOVERSION"

ih::file::sync-shell-defaults "$IH_CORE_DIR"/lib/bobs/go/default

export IH_WANT_RE_SOURCE=1
}
6 changes: 3 additions & 3 deletions lib/bobs/jdk/step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function ih::setup::bobs.jdk::help() {
# Check if the step has been installed and return 0 if it has.
# Otherwise return 1.
function ih::setup::bobs.jdk::test() {
if brew list --cask adoptopenjdk8 >/dev/null 2>&1; then
if ih::arch::ibrew list --cask adoptopenjdk8 >/dev/null 2>&1; then
return 0
fi
return 1
Expand All @@ -28,8 +28,8 @@ function ih::setup::bobs.jdk::deps() {
function ih::setup::bobs.jdk::install() {

ih::log::info "Tapping adoptopenjdk/openjdk"
brew tap adoptopenjdk/openjdk
ih::arch::ibrew tap adoptopenjdk/openjdk

ih::log::info "Installing adoptopenjdk8"
brew install --cask adoptopenjdk8
ih::arch::ibrew install --cask adoptopenjdk8
}
29 changes: 29 additions & 0 deletions lib/bobs/scala/step.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# IH_CORE_DIR will be set to the directory containing the bin and lib directories.

function ih::setup::bobs.scala::help() {
echo 'This will install the correct scala
This step will:
- Install scala 2.12 in x86 mode
'
}

# Check if the step has been installed and return 0 if it has.
# Otherwise return 1.
function ih::setup::bobs.scala::test() {
if ! ih::arch::ibrew list scala@2.12 >/dev/null 2>&1; then
return 1
fi
return 0
}

# Echo a space-delimited list of steps which must be installed before this one can be.
function ih::setup::bobs.scala::deps() {
echo ""
}

function ih::setup::bobs.scala::install() {
ih::arch::ibrew install scala@2.12
}
1 change: 0 additions & 1 deletion lib/core/asdf/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
python 3.9.7
bazel 3.7.2
buf 0.51.1
golang 1.16.3
helm 3.6.1
Expand Down
2 changes: 1 addition & 1 deletion lib/core/certificates/default/11_certificates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# This script adds environment variables needed for
# our DLP certificates to be respected

export NODE_EXTRA_CA_CERTS="$HOME/.ih/certs/ga_root_ca.pem"
export NODE_EXTRA_CA_CERTS="$HOME/.ih/certs/grand_rounds_chained_ca.pem"
15 changes: 15 additions & 0 deletions lib/core/m1/default/01_m1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# Use correct brew and brew path stuff based on shell architecture compatibility
if [[ "$(uname -m)" == 'arm64' ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi

# Aliases to switch compatibility mode in shells
alias x86='arch -x86_64 $SHELL'
alias amd64='arch -arm64 $SHELL'

alias ibrew='arch -x86_64 /usr/local/bin/brew'
alias mbrew='arch -arm64 /opt/homebrew/bin/brew'
56 changes: 56 additions & 0 deletions lib/core/m1/step.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# IH_CORE_DIR will be set to the directory containing the bin and lib directories.

function ih::setup::core.m1::help() {
echo 'Installs M1 compatibility fixes if needed
This step only runs if you have an M1
CPU. It installs various things that make
it easier to fall back to x86 mode for
tools that do not work on M1. It will:
- Install the x86 version of brew
- Augment your shell setup with some aliases
- x86 will start a new shell in x86 mode
- amd64 will start a new shell in amd64 (M1) mode
- Set up your shell so that if you are
in x86 mode the x86 version of brew will be used.
'
}

# Check if the step has been installed and return 0 if it has.
# Otherwise return 1.
function ih::setup::core.m1::test() {
if sysctl -n machdep.cpu.brand_string | grep "M1"; then

# M1 CPU detected
if [ ! -x /usr/local/bin/brew ]; then
ih::log::debug "Brew is not installed in x86 mode"
return 1
fi

if ! ih::file::check-shell-defaults "${IH_CORE_LIB_DIR}/core/m1/default"; then
ih::log::debug "M1 shell script out of date"
return 1
fi
fi

return 0
}

# Echo a space-delimited list of steps which must be installed before this one can be.
function ih::setup::core.m1::deps() {
# echo "step1 step2"
echo "core.shell"
}

function ih::setup::core.m1::install() {

if [ ! -x /usr/local/bin/brew ]; then
arch -x86_64 /bin/bash -c "$(curl -fsSL https://github.com/raw/Homebrew/install/master/install.sh)"
fi

ih::file::sync-shell-defaults "${IH_CORE_LIB_DIR}/core/m1/default"

export IH_WANT_RE_SOURCE=1
}
8 changes: 2 additions & 6 deletions lib/core/shell/default/00_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
# Signals that IH shell augments have been sourced
export IH_AUGMENT_SOURCED=yes

# Use correct brew and brew path stuff based on shell architecture compatibility
if [[ "$(uname -m)" == 'arm64' ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi
# Activate brew paths
[ -f "/usr/local/bin/brew" ] && eval "$(/usr/local/bin/brew shellenv)"

#Make sure home ~/bin is in the path
[[ ! "$PATH" =~ ${HOME}/bin ]] && export PATH="${HOME}/bin:${PATH}"
Expand Down
4 changes: 0 additions & 4 deletions lib/core/shell/default/99_bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ if type brew &>/dev/null; then
fi
fi

# Aliases to switch compatibility mode in shells
alias x86='arch -x86_64 bash'
alias m1='arch -arm64 bash'

# ██████╗ ██████╗ ███╗ ██╗ ██████╗ ████████╗ ███████╗██████╗ ██╗████████╗
# ██╔══██╗██╔═══██╗ ████╗ ██║██╔═══██╗╚══██╔══╝ ██╔════╝██╔══██╗██║╚══██╔══╝
# ██║ ██║██║ ██║ ██╔██╗ ██║██║ ██║ ██║ █████╗ ██║ ██║██║ ██║
Expand Down
4 changes: 0 additions & 4 deletions lib/core/shell/default/99_zsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ alias edit-zshrc='eval "$EDITOR $HOME/.zshrc" && source $HOME/.zshrc'
alias edit-aliases='eval "$EDITOR $HOME/.ih/custom/99_zsh.sh" && source $HOME/.ih/custom/99_zsh.sh'
alias edit-env='eval "$EDITOR $HOME/.ih/custom/00_env.sh" && source $HOME/.ih/custom/00_env.sh'

# Aliases to switch compatibility mode in shells
alias x86='arch -x86_64 zsh'
alias m1='arch -arm64 zsh'

# Wire up completions for things installed by brew
if type brew &>/dev/null; then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
Expand Down
Loading

0 comments on commit 2e278eb

Please sign in to comment.