-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e203b1
commit f0cf7d4
Showing
4 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
brew 'gh' | ||
brew 'git' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"entries": { | ||
"brew": { | ||
"asdf": { | ||
"version": "0.14.1", | ||
"bottle": { | ||
"rebuild": 0, | ||
"root_url": "https://ghcr.io/v2/homebrew/core", | ||
"files": { | ||
"all": { | ||
"cellar": ":any_skip_relocation", | ||
"url": "https://ghcr.io/v2/homebrew/core/asdf/blobs/sha256:e9b4116ff1cd0efd06d32b784cac45845bf4b277754e0e3f8ac70e8be11f0a8d", | ||
"sha256": "e9b4116ff1cd0efd06d32b784cac45845bf4b277754e0e3f8ac70e8be11f0a8d" | ||
} | ||
} | ||
} | ||
}, | ||
"yarn": { | ||
"version": "1.22.22", | ||
"bottle": { | ||
"rebuild": 1, | ||
"root_url": "https://ghcr.io/v2/homebrew/core", | ||
"files": { | ||
"all": { | ||
"cellar": ":any_skip_relocation", | ||
"url": "https://ghcr.io/v2/homebrew/core/yarn/blobs/sha256:edb63a1b15d560263270324b63bee4c2aa8145197636a755436cc14424fc1e12", | ||
"sha256": "edb63a1b15d560263270324b63bee4c2aa8145197636a755436cc14424fc1e12" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"system": { | ||
"macos": { | ||
"ventura": { | ||
"HOMEBREW_VERSION": "4.4.2", | ||
"HOMEBREW_PREFIX": "/opt/homebrew", | ||
"Homebrew/homebrew-core": "api", | ||
"CLT": "14.3.1.0.1.1683849156", | ||
"Xcode": "14.3.1", | ||
"macOS": "13.5" | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"entries": { | ||
"brew": { | ||
"gh": { | ||
"version": "2.59.0", | ||
"bottle": { | ||
"rebuild": 0, | ||
"root_url": "https://ghcr.io/v2/homebrew/core", | ||
"files": { | ||
"arm64_sequoia": { | ||
"cellar": ":any_skip_relocation", | ||
"url": "https://ghcr.io/v2/homebrew/core/gh/blobs/sha256:4db292686e8c16f6282f60ef492e3986e1407d6b6d1675d8588218ee20032e42", | ||
"sha256": "4db292686e8c16f6282f60ef492e3986e1407d6b6d1675d8588218ee20032e42" | ||
}, | ||
"arm64_sonoma": { | ||
"cellar": ":any_skip_relocation", | ||
"url": "https://ghcr.io/v2/homebrew/core/gh/blobs/sha256:4db292686e8c16f6282f60ef492e3986e1407d6b6d1675d8588218ee20032e42", | ||
"sha256": "4db292686e8c16f6282f60ef492e3986e1407d6b6d1675d8588218ee20032e42" | ||
}, | ||
"arm64_ventura": { | ||
"cellar": ":any_skip_relocation", | ||
"url": "https://ghcr.io/v2/homebrew/core/gh/blobs/sha256:4db292686e8c16f6282f60ef492e3986e1407d6b6d1675d8588218ee20032e42", | ||
"sha256": "4db292686e8c16f6282f60ef492e3986e1407d6b6d1675d8588218ee20032e42" | ||
}, | ||
"sonoma": { | ||
"cellar": ":any_skip_relocation", | ||
"url": "https://ghcr.io/v2/homebrew/core/gh/blobs/sha256:7e5921393887a7f1bc8fb36176f1e5e252040386b750f3cf207f7bab5ba21338", | ||
"sha256": "7e5921393887a7f1bc8fb36176f1e5e252040386b750f3cf207f7bab5ba21338" | ||
}, | ||
"ventura": { | ||
"cellar": ":any_skip_relocation", | ||
"url": "https://ghcr.io/v2/homebrew/core/gh/blobs/sha256:cc34fd3400d8736dda6a193b1a3b973cca18236140d6e867151a38016becca88", | ||
"sha256": "cc34fd3400d8736dda6a193b1a3b973cca18236140d6e867151a38016becca88" | ||
}, | ||
"x86_64_linux": { | ||
"cellar": ":any_skip_relocation", | ||
"url": "https://ghcr.io/v2/homebrew/core/gh/blobs/sha256:e0631067441cb34c73c660f73dfbab885167c3ac5b1f8ade765b14c5ebdbf0f9", | ||
"sha256": "e0631067441cb34c73c660f73dfbab885167c3ac5b1f8ade765b14c5ebdbf0f9" | ||
} | ||
} | ||
} | ||
}, | ||
"git": { | ||
"version": "2.47.0", | ||
"bottle": { | ||
"rebuild": 0, | ||
"root_url": "https://ghcr.io/v2/homebrew/core", | ||
"files": { | ||
"arm64_sequoia": { | ||
"cellar": "/opt/homebrew/Cellar", | ||
"url": "https://ghcr.io/v2/homebrew/core/git/blobs/sha256:7c09abec73bcb89e12d067fb023ec7f69df73a903fa1b5eef5121a404af2694c", | ||
"sha256": "7c09abec73bcb89e12d067fb023ec7f69df73a903fa1b5eef5121a404af2694c" | ||
}, | ||
"arm64_sonoma": { | ||
"cellar": "/opt/homebrew/Cellar", | ||
"url": "https://ghcr.io/v2/homebrew/core/git/blobs/sha256:d4691f0e34143bb274e4d3af579ce5f594d36e649caf3b9fc782c81b68866c59", | ||
"sha256": "d4691f0e34143bb274e4d3af579ce5f594d36e649caf3b9fc782c81b68866c59" | ||
}, | ||
"arm64_ventura": { | ||
"cellar": "/opt/homebrew/Cellar", | ||
"url": "https://ghcr.io/v2/homebrew/core/git/blobs/sha256:d2cc6cabb360f80a7da428124583637405ed6de28f94808261b1f085d6770896", | ||
"sha256": "d2cc6cabb360f80a7da428124583637405ed6de28f94808261b1f085d6770896" | ||
}, | ||
"sonoma": { | ||
"cellar": "/usr/local/Cellar", | ||
"url": "https://ghcr.io/v2/homebrew/core/git/blobs/sha256:adb1b3e9b44d11e9a80054420285aa2f4bfc2481fdb198980a036ecb216fbc71", | ||
"sha256": "adb1b3e9b44d11e9a80054420285aa2f4bfc2481fdb198980a036ecb216fbc71" | ||
}, | ||
"ventura": { | ||
"cellar": "/usr/local/Cellar", | ||
"url": "https://ghcr.io/v2/homebrew/core/git/blobs/sha256:b07289bf4b54882ec05a1207694d5cdd8dd99c03de6b78cf0e633a621a0074d8", | ||
"sha256": "b07289bf4b54882ec05a1207694d5cdd8dd99c03de6b78cf0e633a621a0074d8" | ||
}, | ||
"x86_64_linux": { | ||
"cellar": "/home/linuxbrew/.linuxbrew/Cellar", | ||
"url": "https://ghcr.io/v2/homebrew/core/git/blobs/sha256:64a6e0fddaabaff55223a88111366967ecb5e73fd15f9af9fae74070eccd52fa", | ||
"sha256": "64a6e0fddaabaff55223a88111366967ecb5e73fd15f9af9fae74070eccd52fa" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"system": { | ||
"macos": { | ||
"ventura": { | ||
"HOMEBREW_VERSION": "4.4.2", | ||
"HOMEBREW_PREFIX": "/opt/homebrew", | ||
"Homebrew/homebrew-core": "api", | ||
"CLT": "14.3.1.0.1.1683849156", | ||
"Xcode": "14.3.1", | ||
"macOS": "13.5" | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
#!/usr/bin/env bash | ||
|
||
fancy_echo() { | ||
local fmt="$1"; shift | ||
|
||
# shellcheck disable=SC2059 | ||
printf "\\n$fmt\\n" "$@" | ||
} | ||
|
||
append_to_file() { | ||
local file="$1" | ||
local text="$2" | ||
|
||
if ! grep -qs "^$text$" "$file"; then | ||
printf "\\n%s\\n" "$text" >> "$file" | ||
fi | ||
} | ||
|
||
append_to_beginning_of_file() { | ||
local file="$1" | ||
local text="$2" | ||
|
||
if ! grep -qs "^$text$" "$file"; then | ||
echo "$text" | cat - "$file" > temp && mv temp "$file" | ||
fi | ||
} | ||
|
||
create_zshrc_and_set_it_as_shell_file() { | ||
if [ ! -f "$HOME/.zshrc" ]; then | ||
touch "$HOME/.zshrc" | ||
fi | ||
|
||
shell_file="$HOME/.zshrc" | ||
} | ||
|
||
create_bash_profile_and_set_it_as_shell_file() { | ||
if [ ! -f "$HOME/.bash_profile" ]; then | ||
touch "$HOME/.bash_profile" | ||
fi | ||
|
||
shell_file="$HOME/.bash_profile" | ||
} | ||
|
||
create_fish_config_and_set_it_as_shell_file() { | ||
if [ ! -d "$HOME/.config/fish" ]; then | ||
mkdir "$HOME/.config/fish" | ||
fi | ||
|
||
if [ ! -f "$HOME/.config/fish/config.fish" ]; then | ||
touch "$HOME/.config/fish/config.fish" | ||
fi | ||
|
||
shell_file="$HOME/.config/fish/config.fish" | ||
} | ||
|
||
apple_m1() { | ||
sysctl -n machdep.cpu.brand_string | grep "Apple M1" | ||
} | ||
|
||
rosetta() { | ||
uname -m | grep "x86_64" | ||
} | ||
|
||
homebrew_installed_on_m1() { | ||
apple_m1 && ! rosetta && [ -d "/opt/homebrew" ] | ||
} | ||
|
||
homebrew_installed_on_intel() { | ||
! apple_m1 && command -v brew >/dev/null | ||
} | ||
|
||
install_or_update_homebrew() { | ||
if homebrew_installed_on_m1 || homebrew_installed_on_intel; then | ||
update_homebrew | ||
else | ||
install_homebrew | ||
fi | ||
} | ||
|
||
install_homebrew() { | ||
fancy_echo "Installing Homebrew ..." | ||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | ||
|
||
configure_shell_file_for_homebrew | ||
} | ||
|
||
update_homebrew() { | ||
fancy_echo "Homebrew already installed. Updating Homebrew ..." | ||
configure_shell_file_for_homebrew | ||
brew update | ||
} | ||
|
||
configure_shell_file_for_homebrew() { | ||
if apple_m1 && ! rosetta; then | ||
configure_shell_file_for_homebrew_on_m1 | ||
else | ||
# shellcheck disable=SC2016 | ||
append_to_file "$shell_file" 'export PATH="/usr/local/bin:$PATH"' | ||
fi | ||
} | ||
|
||
configure_shell_file_for_homebrew_on_m1() { | ||
if [[ $SHELL == *fish ]]; then | ||
# shellcheck disable=SC2016 | ||
append_to_beginning_of_file "$shell_file" 'status --is-interactive; and eval (/opt/homebrew/bin/brew shellenv)' | ||
else | ||
# shellcheck disable=SC2016 | ||
append_to_file "$HOME/.zprofile" 'eval $(/opt/homebrew/bin/brew shellenv)' | ||
fi | ||
eval "$(/opt/homebrew/bin/brew shellenv)" | ||
} | ||
|
||
# shellcheck disable=SC2154 | ||
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT | ||
|
||
set -e | ||
|
||
case "$SHELL" in | ||
*/zsh) : | ||
create_zshrc_and_set_it_as_shell_file | ||
;; | ||
*/bash) | ||
create_bash_profile_and_set_it_as_shell_file | ||
;; | ||
*/fish) | ||
create_fish_config_and_set_it_as_shell_file | ||
;; | ||
esac | ||
|
||
brew_is_installed() { | ||
brew list -1 --formula | grep -Fqx "$1" | ||
} | ||
|
||
tap_is_installed() { | ||
brew tap | grep -Fqx "$1" | ||
} | ||
|
||
fancy_echo 'Welcome to the fresh-brew script!' | ||
fancy_echo 'You should be up and running with a working dev environment in a few minutes.' | ||
fancy_echo 'The following lines are to help debug any issues:' | ||
fancy_echo "====Start of debugging====" | ||
fancy_echo "Current shell: $SHELL" | ||
fancy_echo "Current PATH: $PATH" | ||
fancy_echo "macOS version:" | ||
sw_vers | ||
|
||
fancy_echo "Mac model:" | ||
sysctl hw.model | ||
|
||
fancy_echo "Mac CPU:" | ||
sysctl -n machdep.cpu.brand_string | ||
|
||
fancy_echo "CPU architecture:" | ||
uname -m | ||
|
||
fancy_echo "====End of debugging====" | ||
|
||
install_or_update_homebrew | ||
|
||
# Remove brew-cask since it is now installed as part of brew tap caskroom/cask. | ||
# See https://github.com/caskroom/homebrew-cask/releases/tag/v0.60.0 | ||
if brew_is_installed 'brew-cask'; then | ||
brew uninstall --force 'brew-cask' | ||
fi | ||
|
||
if tap_is_installed 'caskroom/versions'; then | ||
brew untap caskroom/versions | ||
fi | ||
|
||
fancy_echo "Verifying the Homebrew installation..." | ||
if brew doctor; then | ||
fancy_echo "Your Homebrew installation is good to go." | ||
else | ||
fancy_echo "Your Homebrew installation reported some errors or warnings." | ||
echo "Review the Homebrew messages to see if any action is needed." | ||
fi | ||
|
||
fancy_echo "Installing formulas and casks from the Brewfile ..." | ||
if brew bundle --file="Brewfile"; then | ||
fancy_echo "All formulas were installed successfully." | ||
else | ||
fancy_echo "Some formulas failed to install." | ||
fi | ||
|
||
if [ -f "fresh-brew.local" ] && ! [[ $SKIP_LOCAL == true ]]; then | ||
# shellcheck source=/dev/null | ||
. "fresh-brew.local" | ||
fi | ||
|
||
fancy_echo 'All done!' | ||
fancy_echo 'Now make sure to quit and restart your terminal!' |