-
Notifications
You must be signed in to change notification settings - Fork 3
/
macos.sh
83 lines (81 loc) · 2.64 KB
/
macos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
#
# Initialize text format variables
TEXT_RED="\033[0;31m"
TEXT_BLUE="\033[0;34m"
TEXT_BLUE_BOLD="\033[1;34m"
TEXT_RESET="\033[0m"
#
echo "$TEXT_BLUE_BOLD START development environment setup $TEXT_RESET"
echo
#
echo "$TEXT_BLUE Check for Homebrew...$TEXT_RESET"
# Initialize homebrew variables based on chip architecture
UNAME_MACHINE="$(/usr/bin/uname -m)"
HOMEBREW_PREFIX=""
HOMEBREW_INIT=""
if [ "${UNAME_MACHINE}" == "arm64" ]; then
# On ARM macOS, homebrew installs to /opt/homebrew
HOMEBREW_PREFIX='/opt/homebrew/'
HOMEBREW_INIT='eval $(/opt/homebrew/bin/brew shellenv)'
elif [ "${UNAME_MACHINE}" == "x86_64" ]; then
# On Intel macOS, homebrew installs to /usr/local
HOMEBREW_PREFIX='/usr/local/'
HOMEBREW_INIT='eval $(/usr/local/bin/brew shellenv)'
else
echo "$TEXT_RED Chip architecture not recognized. $TEXT_RESET"
exit
fi
# Check whether Homebrew is installed
if [ -f "$HOMEBREW_PREFIX/bin/brew" ]; then
echo "$TEXT_BLUE Homebrew is installed $TEXT_RESET"
else
# If not, install
echo "$TEXT_BLUE Install Homebrew...$TEXT_RESET"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Confirm the installation worked
if [ -f "$HOMEBREW_PREFIX/bin/brew" ]; then
echo "$TEXT_BLUE Homebrew is installed $TEXT_RESET"
else
echo "$TEXT_RED Homebrew installation was unsuccessful. $TEXT_RESET"
exit
fi
fi
#
# Set Homebrew enviroment variables
# Check if .zprofile exists and includes the Homebrew initialization script
if [[ -f $HOME/.zprofile && $(grep -c "$HOMEBREW_INIT" $HOME/.zprofile) != 0 ]]; then
eval $HOMEBREW_INIT
echo "$TEXT_BLUE Homebrew is initialized $TEXT_RESET"
else
# if not, add initialization script to .zprofile and run it in the current shell
echo "$TEXT_BLUE Initialize Homebrew... $TEXT_RESET"
echo $HOMEBREW_INIT >>$HOME/.zprofile
eval $HOMEBREW_INIT
echo "$TEXT_BLUE\n Homebrew initialization complete $TEXT_RESET"
fi
#
echo "$TEXT_BLUE Update Homebrew... $TEXT_RESET"
brew update
#
echo "$TEXT_BLUE Check for Ansible... $TEXT_RESET"
# Check if ansible is installed
if [ -f "$HOMEBREW_PREFIX/bin/ansible" ]; then
echo "$TEXT_BLUE Ansible is installed $TEXT_RESET"
else
# If not, install
echo "$TEXT_BLUE Install Ansible... $TEXT_RESET"
brew install ansible
ansible-galaxy collection install community.postgresql community.general
# Confirm the installation worked
if [ -f "$HOMEBREW_PREFIX/bin/ansible" ]; then
echo "$TEXT_BLUE Ansible is installed $TEXT_RESET"
else
echo "$TEXT_RED Ansible is not installed. $TEXT_RESET"
exit
fi
fi
#
echo "$TEXT_BLUE\n Update Ansible to latest version... $TEXT_RESET"
brew upgrade ansible
#