Skip to content

Commit

Permalink
switch secondary global default to false
Browse files Browse the repository at this point in the history
  • Loading branch information
bretonics committed Apr 8, 2020
1 parent 4766b41 commit bf3f653
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 121 deletions.
31 changes: 31 additions & 0 deletions bin/functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

#===============================================================================================
# HELPER FUNCTIONS
#===============================================================================================

# Global Variables
source ./bin/globals

# Get Apple ID Username (email)
getAccountId() {
defaults read MobileMeAccounts Accounts | sed -n -e 's/.*AccountID = \"\(.*\)\"\;/\1/p'
}

# Display Nicely Formatted Message
message() {
if [ "$1" = "info" ]; then
local msg="${RED}\n\n${EMOJI_INFO} ${2}${NC}\n\n\n"
elif [ "$1" = "warning" ]; then
local msg="${RED}\n\n${EMOJI_WARNING} ${2}${NC}\n\n\n"
elif [ "$1" = "fail" ]; then
local msg="${RED}\n\n${EMOJI_FAIL} ${2}${NC}\n\n\n"
elif [ "$1" = "error" ]; then
local msg="${RED}\n\n${EMOJI_ERROR} ${2}${NC}\n\n\n"
else
local msg="${GREEN}\n\n${EMOJI_CHECKMARK} ${1}${NC}\n\n\n"
fi

shift
printf "${msg}"
}
98 changes: 98 additions & 0 deletions bin/getopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

#===============================================================================================
# COMMAND LINE OPTIONS
#===============================================================================================

# Global Variables
source ./bin/globals

#-----------------------------------------------------------------------------------------------
# HELPER FUNCTIONS

# Handle CLI Arguments
handle_arguments() {
# Set Additional Defaults
if [ $# -ne 0 ]; then
BREW_FILE=${1}
echo "Using Brewfile '${BREW_FILE}'"
fi
}

# Bash Builtin Getopts
handle_getopts() {
OPTIONS=":EFhi:s"

# No Arguments Runs FULL Install
if [ $# -eq 0 ]; then
RUN_SECONDARY=true
fi

# Handle Options
while getopts ${OPTIONS} option; do
case "${option}" in
E)
SETUP_MODE="ESSENTIALS"
;;
F)
# Global Default: SETUP_MODE="FULL"
RUN_SECONDARY=true
;;
i)
SETUP_MODE=$(echo ${OPTARG} | tr [:lower:] [:upper:])
case "${SETUP_MODE}" in
FULL)
# Global Default: SETUP_MODE="FULL"
RUN_SECONDARY=true
;;
ESSENTIALS)
;;
*)
echo "Incorrect option provided for -i: ${OPTARG}"
usage
;;
esac
;;
s)
RUN_SECONDARY=true
;;
\?)
echo "Invalid Option: -${OPTARG}"
usage
;;
:)
echo "Invalid Option: -${OPTARG} requires an argument"
usage
;;
h | *)
usage
;;
esac
done

shift $((OPTIND -1)) # remove options already handled by getopts from $@

handle_arguments "$@"
}

# Prettify Options Output Message
print_option() {
printf "\t%s\t%s\n" "${1}" "${2}" | expand -t 4,28
}

# Usage Message
usage() {
echo -e "\nUsage: $(basename "$0") [Options] Brewfile\n"
echo -e "\nRunning install without any options below will run a FULL setup by default.\n"
echo -e "\nOptions:\n"
print_option "-F" "Full install setup (Defaults: -s=true)"
print_option "-E" "Essentials only installations"
print_option "-i [full|essentials]" "More explicit install type declaration"
print_option "-s" "Run secondary installation (Default: false)"
print_option "-h" "Prints this usage message"
echo -e "\nArguments:\n"
print_option "Brewfile" "Path to Brew bundle file (Default: '${BREW_FILE}')"
echo -e "\n"
1>&2
exit 1
}
29 changes: 29 additions & 0 deletions bin/globals
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

#===============================================================================================
# GLOBAL ENVIRONMENT VARIABLES
#===============================================================================================

# General
SETUP_MODE="FULL" # DEFAULT: Full setup - installs everything in Brewfile and secondary
RUN_SECONDARY=false

# Setup Files
BREW_CASKS="./src/casks.txt"
BREW_FILE="./src/Brewfile"
BREW_FORMULAE="./src/formulae.txt"
BREW_TAPS="./src/taps.txt"
MAC_APPS="./src/apps.txt"

# Color Outputs
GREEN="\033[0;32m"
RED="\033[0;31m"
NC="\033[0m"

# Emojis Hex
EMOJI_CHECKMARK="\xe2\x9c\x85"
EMOJI_ERROR="\xe2\x9b\x94\xef\xb8\x8f"
EMOJI_FAIL="\xe2\x9d\x8c"
EMOJI_INFO="\xe2\x84\xb9\xef\xb8\x8f"
EMOJI_WARNING="\xe2\x9b\x94\xef\xb8\x8f"

150 changes: 29 additions & 121 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -6,124 +6,23 @@

#-----------------------------------------------------------------------------------------------
# LOGS

# The first line redirects and appends (-a) everything from the standard ouput stream to the logfile and prints it to the screen.
# The second line redirects the standard error to log file.
# - The first line redirects and appends (-a) everything from the standard ouput stream to the logfile and prints it to the screen.
# - The second line redirects the standard error to log file.
exec 1> >(tee -a setup.log)
exec 2> error.log

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# GLOBALS

EMOJI_CHECKMARK="\xe2\x9c\x85"
EMOJI_ERROR="\xe2\x9b\x94\xef\xb8\x8f"
EMOJI_FAIL="\xe2\x9d\x8c"
EMOJI_INFO="\xe2\x84\xb9\xef\xb8\x8f"
EMOJI_WARNING="\xe2\x9b\x94\xef\xb8\x8f"
BREW_CASKS="./src/casks.txt"
BREW_FILE="./src/Brewfile"
BREW_FORMULAE="./src/formulae.txt"
BREW_TAPS="./src/taps.txt"
MAC_APPS="./src/apps.txt"
SETUP_TYPE="full" # DEFAULT full setup: installS everything in Brewfile and secondary

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# CLI ARGUMENT OPTIONS

print_option() {
printf "\t%s\t%s\n" "${1}" "${2}" | expand -t 4,25
}

# Usage Message
usage() {
echo -e "\nUsage: $0 [OPTIONS] [Brewfile]\n"
echo -e "\nOptions:\n"
print_option "-F" "Full install"
print_option "-E" "Essentials install"
print_option "-i [full|essentials]" "More explicit intall type declaration"
print_option "-s" "Run secondary installation. Default: true"
print_option "-h" "Prints this usage message"
echo -e "\nArguments:\n"
print_option "Brewfile" "Path to Brew bundle file. Default: '${BREW_FILE}'"
echo -e "\n"
exit 1
}

# Handle Options
while getopts ":EFhi:s" OPTION; do
case "${OPTION}" in
E)
SETUP_TYPE="essentials"
;;
F)
# Default SETUP_TYPE globally set to "full"
RUN_SECONDARY=true
;;
i)
SETUP_TYPE=${OPTARG}
case "${SETUP_TYPE}" in
full|essentials)
;;
*)
echo "Incorrect option provided for -i: ${OPTARG}"
usage
;;
esac
;;
s)
RUN_SECONDARY=true
;;
\?)
echo "Invalid Option: -${OPTARG}"
usage
;;
:)
echo "Invalid Option: -${OPTARG} requires an argument"
usage
;;
h | *)
usage
;;
esac
#-----------------------------------------------------------------------------------------------
# SOURCES
# - General Helper Functions
# - Global Environment Variables
# - CLI Argument Options
for file in ./bin/*; do
source $file
done

shift $((OPTIND -1)) # remove options already handled by getopts from $@

if [ $# -ne 0 ]; then
BREW_FILE=${1}
echo "Using Brewfile '${BREW_FILE}"
fi

# Output Color Configs
GREEN="\033[0;32m"
RED="\033[0;31m"
NC="\033[0m"

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Functions

# Get Apple ID Username (email)
getAccountId() {
defaults read MobileMeAccounts Accounts | sed -n -e 's/.*AccountID = \"\(.*\)\"\;/\1/p'
}

# Display Nicely Formatted Message
message() {
if [ "$1" = "info" ]; then
local msg="${RED}\n\n${EMOJI_INFO} ${2}${NC}\n\n\n"
elif [ "$1" = "warning" ]; then
local msg="${RED}\n\n${EMOJI_WARNING} ${2}${NC}\n\n\n"
elif [ "$1" = "fail" ]; then
local msg="${RED}\n\n${EMOJI_FAIL} ${2}${NC}\n\n\n"
elif [ "$1" = "error" ]; then
local msg="${RED}\n\n${EMOJI_ERROR} ${2}${NC}\n\n\n"
else
local msg="${GREEN}\n\n${EMOJI_CHECKMARK} ${1}${NC}\n\n\n"
fi

shift
printf "${msg}"
}
#-----------------------------------------------------------------------------------------------
# HANDLE CLI OPTIONS
handle_getopts "$@"

#===============================================================================================
# START RUNNING SETUP
Expand All @@ -133,7 +32,7 @@ echo "This script will automate a lot of processes."
echo "Though not recommended to interrupt, exit this script at any time with Ctrl-C."
echo -e "\nPress Ctrl-C to STOP now if you don't wish to proceed. You have 5 seconds..."
sleep 5
echo "Starting automated install: $(echo ${SETUP_TYPE} | tr [:lower:] [:upper:])"
echo "Starting automated install: ${SETUP_MODE}"
sleep 2

echo ""
Expand All @@ -145,7 +44,10 @@ echo "| On: `date`"
echo "| PWD: `pwd`"
echo "| PID: $$"
echo "|"
echo "| Running '${SETUP_TYPE}' install..."
echo "| Running '${SETUP_MODE}' install..."
echo "| - Brewfile: ${BREW_FILE}"
echo "| - Secondary: $(if [ ${RUN_SECONDARY} = "true" ]; then echo "Yes"; else echo "No"; fi)"
echo "|"
echo "================================================================================"
echo ""
echo ""
Expand All @@ -170,15 +72,20 @@ message "Done installing Homebrew."
sleep 2

#-----------------------------------------------------------------------------------------------
# FULL INSTALL - INSTALL ALL FORMULAE, TAPS, AND MAC APPS
if [ "$SETUP_TYPE" = "full" ]; then
# FULL INSTALL
# - Install all Formulae, Taps, and Mac Apps specified by $BREW_FILE
if [ "$SETUP_MODE" = "FULL" ]; then
echo "INSTALLING EVERYTHING IN '${BREW_FILE}'"
printf "================================================================================\n\n"
brew bundle --file ${BREW_FILE}

#-----------------------------------------------------------------------------------------------
# ESSENTIALS INSTALL
elif [ "$SETUP_TYPE" = "essentials" ]; then
# - Homebrew Taps specified by $BREW_TAPS
# - Homebrew Forlumae specified by $BREW_FORMULAE
# - Homebrew Casks specified by $BREW_CASKS
# - applications from Mac App Store specified by $MAC_APPS
elif [ "$SETUP_MODE" = "ESSENTIALS" ]; then
echo "INSTALLING HOMEBREW TAPS, FORMULAE, AND CASKS"
printf "================================================================================\n\n"

Expand Down Expand Up @@ -225,9 +132,9 @@ elif [ "$SETUP_TYPE" = "essentials" ]; then
sleep 2

#-----------------------------------------------------------------------------------------------
# ERROR: INSTALL TYPE NOT SUPPORTED
# ERROR: INSTALL MODE NOT SUPPORTED
else
msg error "Something is terribly wrong. ${SETUP_TYPE} should have never passed."
msg error "Something is terribly wrong. ${SETUP_MODE} should have never passed."
exit 1
fi

Expand Down Expand Up @@ -272,7 +179,8 @@ echo ""
if [ "$RUN_SECONDARY" = true ]; then
echo "Runnig Secondary Install"
echo -e "--------------------------------------------------------------------------------\n"
bash ./secondary
# Execute secondary script in the current shell without forking a sub shell
. ./secondary
else
echo "Now go login to accounts (Dropbox, emails, etc...) and then run secondary installs, \`bash secondary\`."
echo ""
Expand Down
4 changes: 4 additions & 0 deletions src/taps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
brewsci/bio
homebrew/bundle
brewsci/science
caskroom/versions

0 comments on commit bf3f653

Please sign in to comment.