Skip to content

Instantly share code, notes, and snippets.

@Gerst20051
Last active July 24, 2022 12:22
Show Gist options
  • Save Gerst20051/1028d2ed1ca8de80afe5144e5188c745 to your computer and use it in GitHub Desktop.
Save Gerst20051/1028d2ed1ca8de80afe5144e5188c745 to your computer and use it in GitHub Desktop.
MacMini Preprovision Script
#!/usr/bin/env sh
# ASCII: http://patorjk.com/software/taag/#p=display&f=Graffiti&t=MacMini%20Preprovision
# SOURCE: https://gist.github.com/Gerst20051/1028d2ed1ca8de80afe5144e5188c745
playbook_repo_name='MacMini-Ansible-Playbook'
playbook_repo_url="[email protected]:Gerst20051/$playbook_repo_name.git"
playbook_repo_directory="$HOME/$playbook_repo_name"
secrets_repo_name='Ansible-Playbook-Secrets'
secrets_repo_url="[email protected]:Gerst20051/$playbook_repo_name.git"
secrets_repo_directory="$HOME/.secrets"
brew_path='/usr/local/bin'
function double_echo {
echo && echo
}
function newline {
echo
}
bold=$(tput bold)
normal=$(tput sgr0)
function init {
echo
print_purpose_header && double_echo
confirm_continue && double_echo
xcode_tools_install && double_echo
confirm_xcode_tools_install && double_echo
install_brew && double_echo
brew_upgrade && double_echo
install_ansible && double_echo
install_gpg && double_echo
install_git && double_echo
install_jq && double_echo
docker_setup_script && double_echo
github_ssh_key_setup_script && double_echo
clone_provision_repo && double_echo
update_provision_repo && double_echo
clone_secrets_repo && double_echo
update_secrets_repo && double_echo
print_finished_header && double_echo
}
function print_purpose_header {
echo ' _____ _____ .__ .__ __________ .__ .__ '
echo ' / \ _____ ____ / \ |__| ____ |__| \______ \_______ ____ _____________ _______ _|__| _____|__| ____ ____ '
echo ' / \ / \\__ \ _/ ___\ / \ / \| |/ \| | | ___/\_ __ \_/ __ \\____ \_ __ \/ _ \ \/ / |/ ___/ |/ _ \ / \ '
echo '/ Y \/ __ \\ \___/ Y \ | | \ | | | | | \/\ ___/| |_> > | \( <_> ) /| |\___ \| ( <_> ) | \'
echo '\____|__ (____ /\___ >____|__ /__|___| /__| |____| |__| \___ > __/|__| \____/ \_/ |__/____ >__|\____/|___| /'
echo ' \/ \/ \/ \/ \/ \/|__| \/ \/ '
}
function confirm_continue {
echo '_________ _____.__ _________ __ .__ '
echo '\_ ___ \ ____ _____/ ____\__|______ _____ \_ ___ \ ____ _____/ |_|__| ____ __ __ ____ '
echo '/ \ \/ / _ \ / \ __\| \_ __ \/ \ / \ \/ / _ \ / \ __\ |/ \| | \_/ __ \ '
echo '\ \___( <_> ) | \ | | || | \/ Y Y \ \ \___( <_> ) | \ | | | | \ | /\ ___/ '
echo ' \______ /\____/|___| /__| |__||__| |__|_| / \______ /\____/|___| /__| |__|___| /____/ \___ >'
echo ' \/ \/ \/ \/ \/ \/ \/ '
double_echo
local CONTINUE_CONFIRM=''
until [ "$CONTINUE_CONFIRM" = 'run' ]; do
read -p 'type "run" to continue: ' CONTINUE_CONFIRM
done
}
function xcode_tools_install {
echo '____ ___ .___ ___________ .__ .___ __ .__ .__ '
echo '\ \/ /____ ____ __| _/____ \__ ___/___ ____ | | ______ | | ____ _______/ |______ | | | | '
echo ' \ // ___\/ _ \ / __ |/ __ \ | | / _ \ / _ \| | / ___/ | |/ \ / ___/\ __\__ \ | | | | '
echo ' / \ \__( <_> ) /_/ \ ___/ | |( <_> | <_> ) |__\___ \ | | | \\___ \ | | / __ \| |_| |__'
echo '/___/\ \___ >____/\____ |\___ > |____| \____/ \____/|____/____ > |___|___| /____ > |__| (____ /____/____/'
echo ' \_/ \/ \/ \/ \/ \/ \/ \/ '
double_echo
# NOTE: the command line developer tools will need to be reinstalled after updating macos to a new version
# NOTE: installing the command line developer tools will solve the following error
# xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
echo "this step is very ${bold}time consuming${normal} it might take 30 minutes to complete"
double_echo
echo 'click the blue "Install" button when prompted to install the command line developer tools'
# The "xcode-select" command requires the command line developer tools.
# Would you like to install the tools now?
# Choose Install to download and install the command line developer tools now.
double_echo
echo 'click the "Agree" button when prompted with the "Command Line Tools License Agreement"'
double_echo
echo 'you will see a dialog progress bar for "Downloading software" and "Installing software"'
double_echo
echo 'you will see a dialog that says "The software was installed." when it is finished'
double_echo
echo "[\$]> xcode-select --install"
double_echo
xcode-select --install
# success output "xcode-select: note: install requested for command line developer tools"
# failure output "xcode-select: error: command line tools are already installed, use "Software Update" to install updates"
newline
}
function confirm_xcode_tools_install {
echo '_________ _____.__ ____ ___ .___ .___ __ .__ .__ '
echo '\_ ___ \ ____ _____/ ____\__|______ _____ \ \/ /____ ____ __| _/____ | | ____ _______/ |______ | | | | '
echo '/ \ \/ / _ \ / \ __\| \_ __ \/ \ \ // ___\/ _ \ / __ |/ __ \ | |/ \ / ___/\ __\__ \ | | | | '
echo '\ \___( <_> ) | \ | | || | \/ Y Y \ / \ \__( <_> ) /_/ \ ___/ | | | \\___ \ | | / __ \| |_| |__'
echo ' \______ /\____/|___| /__| |__||__| |__|_| / /___/\ \___ >____/\____ |\___ > |___|___| /____ > |__| (____ /____/____/'
echo ' \/ \/ \/ \_/ \/ \/ \/ \/ \/ \/ '
double_echo
echo 'confirm that the xcode command line developer tools have finished installing'
double_echo
local XCODE_TOOLS_INSTALL_CONFIRM=''
until [ "$XCODE_TOOLS_INSTALL_CONFIRM" = 'xcode' ]; do
read -p 'type "xcode" to acknowledge: ' XCODE_TOOLS_INSTALL_CONFIRM
done
}
function install_brew {
echo '.___ __ .__ .__ .__ __________ '
echo '| | ____ _______/ |______ | | | | |__| ____ ____ \______ \_______ ______ _ __'
echo '| |/ \ / ___/\ __\__ \ | | | | | |/ \ / ___\ | | _/\_ __ \_/ __ \ \/ \/ /'
echo '| | | \\___ \ | | / __ \| |_| |_| | | \/ /_/ > | | \ | | \/\ ___/\ / '
echo '|___|___| /____ > |__| (____ /____/____/__|___| /\___ / |______ / |__| \___ >\/\_/ '
echo ' \/ \/ \/ \//_____/ \/ \/ '
double_echo
# NOTE: you will need to enter your machine password when installing brew
# NOTE: i needed to run `[$]> sudo chown -R $(whoami):admin /usr/local`
if which $brew_path/brew >/dev/null; then
echo "[\$]> $brew_path/brew update"
double_echo
$brew_path/brew update
else
echo '[$]> /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
double_echo
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# ==> Checking for `sudo` access (which may request your password)...
# Password:
# ==> You are using macOS 10.11.
# ==> We (and Apple) do not provide support for this old version.
# This installation may not succeed.
# After installation, you will encounter build failures with some formulae.
# Please create pull requests instead of asking for help on Homebrew's GitHub,
# Twitter or any other official channels. You are responsible for resolving any
# issues you experience while you are running this old version.
# ==> This script will install:
# /usr/local/bin/brew
# /usr/local/share/doc/homebrew
# /usr/local/share/man/man1/brew.1
# /usr/local/share/zsh/site-functions/_brew
# /usr/local/etc/bash_completion.d/brew
# /usr/local/Homebrew
# ==> The following new directories will be created:
# /usr/local/sbin
# /usr/local/var
# /usr/local/var/homebrew
# /usr/local/var/homebrew/linked
# /usr/local/Caskroom
# Press RETURN/ENTER to continue or any other key to abort:
# ==> /usr/bin/sudo /bin/mkdir -p /usr/local/sbin /usr/local/var /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Caskroom
# ==> /usr/bin/sudo /bin/chmod ug=rwx /usr/local/sbin /usr/local/var /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Caskroom
# ==> /usr/bin/sudo /usr/sbin/chown andrew /usr/local/sbin /usr/local/var /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Caskroom
# ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/sbin /usr/local/var /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Caskroom
# ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew
# ==> /usr/bin/sudo /usr/sbin/chown -R andrew:admin /usr/local/Homebrew
# ==> /usr/bin/sudo /bin/mkdir -p /Users/andrew/Library/Caches/Homebrew
# ==> /usr/bin/sudo /bin/chmod g+rwx /Users/andrew/Library/Caches/Homebrew
# ==> /usr/bin/sudo /usr/sbin/chown -R andrew /Users/andrew/Library/Caches/Homebrew
# ==> Downloading and installing Homebrew...
fi
}
function brew_upgrade {
echo '__________ ____ ___ .___ '
echo '\______ \_______ ______ _ __ | | \______ ________________ __| _/____ '
echo ' | | _/\_ __ \_/ __ \ \/ \/ / | | /\____ \ / ___\_ __ \__ \ / __ |/ __ \ '
echo ' | | \ | | \/\ ___/\ / | | / | |_> > /_/ > | \// __ \_/ /_/ \ ___/ '
echo ' |______ / |__| \___ >\/\_/ |______/ | __/\___ /|__| (____ /\____ |\___ >'
echo ' \/ \/ |__| /_____/ \/ \/ \/ '
double_echo
echo "[\$]> $brew_path/brew upgrade"
double_echo
$brew_path/brew upgrade
}
function install_ansible {
echo '.___ __ .__ .__ .__ _____ ._____. .__ '
echo '| | ____ _______/ |______ | | | | |__| ____ ____ / _ \ ____ _____|__\_ |__ | | ____ '
echo '| |/ \ / ___/\ __\__ \ | | | | | |/ \ / ___\ / /_\ \ / \ / ___/ || __ \| | _/ __ \ '
echo '| | | \\___ \ | | / __ \| |_| |_| | | \/ /_/ > / | \ | \\___ \| || \_\ \ |_\ ___/ '
echo '|___|___| /____ > |__| (____ /____/____/__|___| /\___ / \____|__ /___| /____ >__||___ /____/\___ >'
echo ' \/ \/ \/ \//_____/ \/ \/ \/ \/ \/ '
double_echo
if which $brew_path/ansible >/dev/null; then
echo "[\$]> $brew_path/brew upgrade ansible"
double_echo
$brew_path/brew upgrade ansible
else
echo "[\$]> $brew_path/brew install ansible"
double_echo
$brew_path/brew install ansible
fi
double_echo
echo "[\$]> $brew_path/brew unlink ansible"
double_echo
$brew_path/brew unlink ansible
double_echo
echo "[\$]> $brew_path/brew link --overwrite ansible"
double_echo
$brew_path/brew link --overwrite ansible
}
function install_gpg {
echo '.___ __ .__ .__ .__ __________________ ________ '
echo '| | ____ _______/ |______ | | | | |__| ____ ____ / _____/\______ \/ _____/ '
echo '| |/ \ / ___/\ __\__ \ | | | | | |/ \ / ___\ / \ ___ | ___/ \ ___ '
echo '| | | \\___ \ | | / __ \| |_| |_| | | \/ /_/ > \ \_\ \| | \ \_\ \'
echo '|___|___| /____ > |__| (____ /____/____/__|___| /\___ / \______ /|____| \______ /'
echo ' \/ \/ \/ \//_____/ \/ \/ '
double_echo
if which $brew_path/gpg >/dev/null; then
echo "[\$]> $brew_path/brew upgrade gnupg"
double_echo
$brew_path/brew upgrade gnupg
else
echo "[\$]> $brew_path/brew install gnupg"
double_echo
$brew_path/brew install gnupg
fi
}
function install_git {
echo '.___ __ .__ .__ .__ ________.__ __ '
echo '| | ____ _______/ |______ | | | | |__| ____ ____ / _____/|__|/ |_ '
echo '| |/ \ / ___/\ __\__ \ | | | | | |/ \ / ___\ / \ ___| \ __\'
echo '| | | \\___ \ | | / __ \| |_| |_| | | \/ /_/ > \ \_\ \ || | '
echo '|___|___| /____ > |__| (____ /____/____/__|___| /\___ / \______ /__||__| '
echo ' \/ \/ \/ \//_____/ \/ '
double_echo
if $brew_path/brew ls --versions git >/dev/null; then
echo "[\$]> $brew_path/brew upgrade git"
double_echo
$brew_path/brew upgrade git
else
echo "[\$]> $brew_path/brew install git"
double_echo
$brew_path/brew install git
fi
}
function install_jq {
echo '.___ __ .__ .__ .__ ____.________ '
echo '| | ____ _______/ |______ | | | | |__| ____ ____ | |\_____ \ '
echo '| |/ \ / ___/\ __\__ \ | | | | | |/ \ / ___\ | | / / \ \ '
echo '| | | \\___ \ | | / __ \| |_| |_| | | \/ /_/ > /\__| |/ \_/. \'
echo '|___|___| /____ > |__| (____ /____/____/__|___| /\___ / \________|\_____\ \_/'
echo ' \/ \/ \/ \//_____/ \__>'
double_echo
if which $brew_path/jq >/dev/null; then
echo "[\$]> $brew_path/brew upgrade jq"
double_echo
$brew_path/brew upgrade jq
else
echo "[\$]> $brew_path/brew install jq"
double_echo
$brew_path/brew install jq
fi
}
function docker_setup_script {
echo '________ __ _________ __ _________ .__ __ '
echo '\______ \ ____ ____ | | __ ___________ / _____/ _____/ |_ __ ________ / _____/ ___________|__|______/ |_ '
echo ' | | \ / _ \_/ ___\| |/ // __ \_ __ \ \_____ \_/ __ \ __\ | \____ \ \_____ \_/ ___\_ __ \ \____ \ __\'
echo ' | ` ( <_> ) \___| <\ ___/| | \/ / \ ___/| | | | / |_> > / \ \___| | \/ | |_> > | '
echo '/_______ /\____/ \___ >__|_ \\___ >__| /_______ /\___ >__| |____/| __/ /_______ /\___ >__| |__| __/|__| '
echo ' \/ \/ \/ \/ \/ \/ |__| \/ \/ |__| '
double_echo
echo '(/bin/bash -c "$(curl -s https://api.github.com/gists/bf1341448bd43f430761c1f8150fb1b7 | jq -r '\''.files["docker-setup.sh"].content'\'')")'
double_echo
(/bin/bash -c "$(curl -s https://api.github.com/gists/bf1341448bd43f430761c1f8150fb1b7 | jq -r '.files["docker-setup.sh"].content')")
}
function github_ssh_key_setup_script {
echo ' ________.__ __ .__ ___. _________ _________ ___ ___ ____ __. _________ .__ __ '
echo ' / _____/|__|/ |_| |__ __ _\_ |__ / _____// _____// | \ | |/ _|____ ___.__. / _____/ ___________|__|______/ |_ '
echo '/ \ ___| \ __\ | \| | \ __ \ \_____ \ \_____ \/ ~ \ | <_/ __ < | | \_____ \_/ ___\_ __ \ \____ \ __\'
echo '\ \_\ \ || | | Y \ | / \_\ \ / \/ \ Y / | | \ ___/\___ | / \ \___| | \/ | |_> > | '
echo ' \______ /__||__| |___| /____/|___ / /_______ /_______ /\___|_ / |____|__ \___ > ____| /_______ /\___ >__| |__| __/|__| '
echo ' \/ \/ \/ \/ \/ \/ \/ \/\/ \/ \/ |__| '
double_echo
echo '(/bin/bash -c "$(curl -s https://api.github.com/gists/3add6fe949b7eef6b4957e5b7d3707c6 | jq -r '\''.files["github-ssh-key-setup.sh"].content'\'')")'
double_echo
(/bin/bash -c "$(curl -s https://api.github.com/gists/3add6fe949b7eef6b4957e5b7d3707c6 | jq -r '.files["github-ssh-key-setup.sh"].content')")
}
function clone_provision_repo {
echo '_________ .__ .__ __________ .__ .__ __________ '
echo '\_ ___ \| | ____ ____ |__| ____ ____ \______ \_______ _______ _|__| _____|__| ____ ____ \______ \ ____ ______ ____ '
echo '/ \ \/| | / _ \ / \| |/ \ / ___\ | ___/\_ __ \/ _ \ \/ / |/ ___/ |/ _ \ / \ | _// __ \\____ \ / _ \ '
echo '\ \___| |_( <_> ) | \ | | \/ /_/ > | | | | \( <_> ) /| |\___ \| ( <_> ) | \ | | \ ___/| |_> > <_> )'
echo ' \______ /____/\____/|___| /__|___| /\___ / |____| |__| \____/ \_/ |__/____ >__|\____/|___| / |____|_ /\___ > __/ \____/ '
echo ' \/ \/ \//_____/ \/ \/ \/ \/|__| '
double_echo
if [ ! -d $playbook_repo_directory ]; then
echo "[\$]> git clone $playbook_repo_url $playbook_repo_directory"
double_echo
git clone $playbook_repo_url $playbook_repo_directory
else
echo "$playbook_repo_name has already been cloned"
fi
}
function update_provision_repo {
echo ' ____ ___ .___ __ .__ __________ .__ .__ __________ '
echo '| | \______ __| _/____ _/ |_|__| ____ ____ \______ \_______ _______ _|__| _____|__| ____ ____ \______ \ ____ ______ ____ '
echo '| | /\____ \ / __ |\__ \\ __\ |/ \ / ___\ | ___/\_ __ \/ _ \ \/ / |/ ___/ |/ _ \ / \ | _// __ \\____ \ / _ \ '
echo '| | / | |_> > /_/ | / __ \| | | | | \/ /_/ > | | | | \( <_> ) /| |\___ \| ( <_> ) | \ | | \ ___/| |_> > <_> )'
echo '|______/ | __/\____ |(____ /__| |__|___| /\___ / |____| |__| \____/ \_/ |__/____ >__|\____/|___| / |____|_ /\___ > __/ \____/ '
echo ' |__| \/ \/ \//_____/ \/ \/ \/ \/|__| '
double_echo
if [ ! -d $playbook_repo_directory ]; then
echo "$playbook_repo_name has not been cloned"
exit 1
else
echo "[\$]> git -C $playbook_repo_directory pull"
double_echo
git -C $playbook_repo_directory pull
fi
}
function clone_secrets_repo {
echo '_________ .__ .__ _________ __ __________ '
echo '\_ ___ \| | ____ ____ |__| ____ ____ / _____/ ____ ___________ _____/ |_ ______ \______ \ ____ ______ ____ '
echo '/ \ \/| | / _ \ / \| |/ \ / ___\ \_____ \_/ __ \_/ ___\_ __ \_/ __ \ __\/ ___/ | _// __ \\____ \ / _ \ '
echo '\ \___| |_( <_> ) | \ | | \/ /_/ > / \ ___/\ \___| | \/\ ___/| | \___ \ | | \ ___/| |_> > <_> )'
echo ' \______ /____/\____/|___| /__|___| /\___ / /_______ /\___ >\___ >__| \___ >__| /____ > |____|_ /\___ > __/ \____/ '
echo ' \/ \/ \//_____/ \/ \/ \/ \/ \/ \/ \/|__| '
double_echo
if [ ! -d $secrets_repo_directory ]; then
echo "[\$]> git clone $secrets_repo_url $secrets_repo_directory"
double_echo
git clone $secrets_repo_url $secrets_repo_directory
else
echo "$secrets_repo_name has already been cloned"
fi
}
function update_secrets_repo {
echo ' ____ ___ .___ __ .__ _________ __ __________ '
echo '| | \______ __| _/____ _/ |_|__| ____ ____ / _____/ ____ ___________ _____/ |_ ______ \______ \ ____ ______ ____ '
echo '| | /\____ \ / __ |\__ \\ __\ |/ \ / ___\ \_____ \_/ __ \_/ ___\_ __ \_/ __ \ __\/ ___/ | _// __ \\____ \ / _ \ '
echo '| | / | |_> > /_/ | / __ \| | | | | \/ /_/ > / \ ___/\ \___| | \/\ ___/| | \___ \ | | \ ___/| |_> > <_> )'
echo '|______/ | __/\____ |(____ /__| |__|___| /\___ / /_______ /\___ >\___ >__| \___ >__| /____ > |____|_ /\___ > __/ \____/ '
echo ' |__| \/ \/ \//_____/ \/ \/ \/ \/ \/ \/ \/|__| '
double_echo
if [ ! -d $secrets_repo_directory ]; then
echo "$secrets_repo_name has not been cloned"
exit 1
else
echo "[\$]> git -C $secrets_repo_directory pull"
double_echo
git -C $secrets_repo_directory pull
fi
}
function print_finished_header {
echo '___________.__ .__ .__ .___'
echo '\_ _____/|__| ____ |__| _____| |__ ____ __| _/'
echo ' | __) | |/ \| |/ ___/ | \_/ __ \ / __ | '
echo ' | \ | | | \ |\___ \| Y \ ___// /_/ | '
echo ' \___ / |__|___| /__/____ >___| /\___ >____ | '
echo ' \/ \/ \/ \/ \/ \/ '
}
init
@Gerst20051
Copy link
Author

Command To Run The Preprovision Script

[$]> /bin/bash -c "$(curl -s https://api.github.com/gists/1028d2ed1ca8de80afe5144e5188c745 | jq -r '.files["macmini-preprovision-script.sh"].content')"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment