-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runMe.sh
executable file
·138 lines (121 loc) · 7.11 KB
/
runMe.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#
# Project:: macOS DevOps Configurator
#
# Copyright 2020, Route 1337, LLC, All Rights Reserved.
#
# Maintainers:
# - Matthew Ahrenstein: matthew@route1337.com
#
# Using MIT Licensed Code From:
# - "rtrouton": https://github.com/rtrouton
#
# See LICENSE
#
# Check if Apple Silicon
if [ "$(uname -m)" == "arm64" ]; then
IS_ARM=1
BREW_BIN_PATH="/opt/homebrew/bin"
ConsoleUser="$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )"
else
IS_ARM=0
BREW_BIN_PATH="/usr/local/bin"
ConsoleUser="$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')"
fi
echo "This script will configure macOS 15+ for DevOps."
echo "You will be prompted for your password during several steps!"
read -p "Press [ENTER] to install and configure this Mac for development use!"
### INSTALL XCODE ###
### Script from rtrouton ###
# Source: https://github.com/ryangball/rtrouton_scripts/blob/main/rtrouton_scripts/install_xcode_command_line_tools/install_xcode_command_line_tools.sh
# Installing the latest Xcode command line tools on 10.9.x or higher
ignoreBeta="true" # Setting to true will ignore beta. However, setting to false does not guarantee a beta is available.
# Save current IFS state
OLDIFS=$IFS
IFS='.' read osvers_major osvers_minor osvers_dot_version <<< "$(/usr/bin/sw_vers -productVersion)"
# restore IFS to previous state
IFS=$OLDIFS
cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
if [[ ( ${osvers_major} -eq 10 && ${osvers_minor} -ge 9 ) || ( ${osvers_major} -ge 11 && ${osvers_minor} -ge 0 ) ]]; then
# Create the placeholder file which is checked by the softwareupdate tool
# before allowing the installation of the Xcode command line tools.
touch "$cmd_line_tools_temp_file"
# Identify the correct update in the Software Update feed with "Command Line Tools" in the name for the OS version in question.
if [[ ( ${osvers_major} -eq 10 && ${osvers_minor} -ge 15 ) || ( ${osvers_major} -ge 11 && ${osvers_minor} -ge 0 ) ]]; then
cmd_line_tools=$(softwareupdate -l | awk '/\*\ Label: Command Line Tools/ { $1=$1;print }' | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 9-)
elif [[ ( ${osvers_major} -eq 10 && ${osvers_minor} -gt 9 ) ]] && [[ ( ${osvers_major} -eq 10 && ${osvers_minor} -lt 15 ) ]]; then
cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | grep "$osvers_minor" | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-)
elif [[ ( ${osvers_major} -eq 10 && ${osvers_minor} -eq 9 ) ]]; then
cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | grep "Mavericks" | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-)
fi
# Check to see if the softwareupdate tool has returned more than one Xcode
# command line tool installation option. If it has, use the one with the
# largest detected version number
if (( $(grep -c . <<<"$cmd_line_tools") > 1 )); then
version_check=$(echo "$cmd_line_tools" | awk -F'-' '{print $2}' | sort -V | tail -n1)
newest_version=$(echo "$cmd_line_tools" | grep -F "Xcode-$version_check")
cmd_line_tools=$newest_version
fi
#Install the command line tools
softwareupdate -i "$cmd_line_tools" --verbose
# Remove the temp file
if [[ -f "$cmd_line_tools_temp_file" ]]; then
rm "$cmd_line_tools_temp_file"
fi
fi
### Script from rtrouton ###
### END INSTALL XCODE ###
### INSTALL HOMEBREW ###
echo "Checking if Homebrew is installed..."
if test ! "$(sudo -u ${ConsoleUser} which brew)"; then
if [[ "$IS_ARM" == 0 ]];then
echo "Installing x86_64 Homebrew..."
/bin/mkdir -p /usr/local/bin
/bin/chmod u+rwx /usr/local/bin
/bin/chmod g+rwx /usr/local/bin
/bin/mkdir -p /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
/bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
/bin/chmod g+rwx /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
/bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
/usr/sbin/chown ${ConsoleUser} /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
/usr/bin/chgrp admin /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
/bin/mkdir -p /Users/${ConsoleUser}/Library/Caches/Homebrew
/bin/chmod g+rwx /Users/${ConsoleUser}/Library/Caches/Homebrew
/usr/sbin/chown ${ConsoleUser} /Users/${ConsoleUser}/Library/Caches/Homebrew
/bin/mkdir -p /Library/Caches/Homebrew
/bin/chmod g+rwx /Library/Caches/Homebrew
/usr/sbin/chown ${ConsoleUser} /Library/Caches/Homebrew
else:
echo "Installing arm64 Homebrew..."
/bin/mkdir -p /opt/homebrew
/bin/chmod u+rwx /opt/homebrew
/usr/sbin/chown ${ConsoleUser} /opt/homebrew
fi
sudo -H -u ${ConsoleUser} /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo "Disabling Homebrew analytics..."
sudo -H -iu ${ConsoleUser} ${BREW_BIN_PATH}/brew analytics off
else
echo "Homebrew already installed."
fi
### END INSTALL HOMEBREW ###
### INSTALL AND RUN ANSIBLE ###
echo "Checking if Ansible is installed..."
if test ! "$(sudo -u ${ConsoleUser} which ansible)"; then
echo "Installing Ansible..."
sudo -H -u ${ConsoleUser} ${BREW_BIN_PATH}/brew install ansible
else
echo "Ansible already installed"
fi
echo "Deleting old versions of roles..."
rm -rf ansible/roles/ahrenstein* ansible/roles/route1337*
echo "Pulling new versions of dependency roles..."
sudo -H -u ${ConsoleUser} ${BREW_BIN_PATH}/ansible-galaxy install -r ansible/roles/requirements.yml -p ./ansible/roles
echo "Done."
echo "Running the Ansible playbook mac-devops.yml"
sudo -H -u ${ConsoleUser} ${BREW_BIN_PATH}/ansible-playbook -i ansible/local.inventory ansible/mac-devops.yml
###END INSTALL AND RUN ANSIBLE ###
### FINAL TWEAKS ###
echo "Searching for and installing any available macOS updates..."
softwareupdate -ia
### END FINAL TWEAKS ###
echo "This Mac is now ready for DevOps!"