Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding interactive setup menu and updating readme #300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ To install any of these, add them as arguments to `$> setup.sh`. Examples:
./setup.sh golang docker kubernetes cloud-foundry terraform concourse
```

The tool also supports a menu for selecting which packages you'd like to include. Specifying no opt-ins will present you with the selection menu instead:

```
./setup.sh
```

## Analytics

The tool will send anonymous user data to our Google Analytics account, so we can see what command line arguments are popular. You can disable this:
Expand All @@ -91,6 +97,8 @@ If you're having problems using the setup script, please let us know by [opening

If you see errors from `brew`, try running `brew doctor` and include the diagnostic output in your issue submission.

Using the `--help` or `-h` flags will also present you with a help page for the command syntax.

## Customizing

If you'd like to customize this project for a project's use:
Expand Down
134 changes: 126 additions & 8 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,133 @@ sudo -K
sudo true;
clear

LIGHT_CYAN="\033[1;36m"
GREEN="\033[0;32m"
RED="\033[0;31m"
NO_COLOUR="\033[0m"
UNDERLINE="\033[4m"
NO_STYLE=$NO_COLOUR
bold=$(tput bold)
normal=$(tput sgr0)

MY_DIR="$(dirname "$0")"
SKIP_ANALYTICS=${SKIP_ANALYTICS:-0}
if (( SKIP_ANALYTICS == 0 )); then
clientID=$(od -vAn -N4 -tx < /dev/urandom)
source ${MY_DIR}/scripts/helpers/google-analytics.sh ${clientID} start $@
OPT_IN_FOLDER="${MY_DIR}/scripts/opt-in"

SELECTED_OPT_INS=()

present_options () {
shopt -s nullglob
local optionsArray=($OPT_IN_FOLDER/*)
shopt -u nullglob # Turn off nullglob to make sure it doesn't interfere with anything later

local optionNamesArray=()
for index in ${!optionsArray[@]}; do
optionNamesArray+=(`echo ${optionsArray[index]} | sed -e "s:\.sh$::" -e "s:${OPT_IN_FOLDER}/::"`)
done

while true; do
clear
echo "Available Opt-Ins:"
for index in ${!optionsArray[@]}; do
local offsetIndex=$(expr $index + 1)
printf "%d.\t${LIGHT_CYAN}%s${NO_COLOUR}\n" ${offsetIndex} ${optionNamesArray[index]}
done
IFS=','
local chosenOptInsString chosenOptIns
read -p "Selected (comma-separated):" chosenOptInsString
read -a chosenOptIns <<< "$chosenOptInsString"
echo "---------------------------------------------------"
echo "You have selected the following Opt-Ins to install:"
for index in ${chosenOptIns[@]}; do
local optionName=${optionNamesArray[index - 1]}
printf "${GREEN}%s${NO_COLOUR}\n" $optionName
SELECTED_OPT_INS+=($optionName)
done
local optInsAreCorrect
read -p "Are these correct (y/n)? " optInsAreCorrect
if [ "$optInsAreCorrect" == "y" ]; then
return 0;
else
SELECTED_OPT_INS=()
fi
done
}

prompt_for_options () {
local wantToInstallOptIns
read -p "Would you like to install opt-ins (y/n)? " wantToInstallOptIns
if [ "$wantToInstallOptIns" != "y" ]; then
return 0
fi
present_options
}

has_param () {
local terms="$1"
shift
for term in $terms; do
for arg; do
if [[ $arg == "$term" ]]; then
return 0
fi
done
done
return 1
}

# If there are no args
if [ -z $@ ]; then
prompt_for_options
elif has_param "-h --help" "$@"; then
printf "\n${bold}NAME${normal}\n"
printf "\t${0} - install commonly needed workstation tools\n"
printf "\n${bold}SYNOPSIS${normal}\n"
printf "\t${bold}${0}${normal} [${UNDERLINE}FLAG${NO_STYLE}]... [${UNDERLINE}OPT-IN${NO_STYLE}]...\n"
printf "\n${bold}DESCRIPTION${normal}\n"
printf "\tSetup behaves in two different ways depending on whether any OPT-INs have been passed in. Passing in OPT-INS will be referred to as ${bold}PASSIVE${normal} mode and passing ${UNDERLINE}no${NO_STYLE} OPT-INS will be referred to as ${bold}INTERACTIVE${normal} mode. Both modes also take in a small set of optional FLAGs:\n"
printf "\n\t${bold}-h${normal}, ${bold}--help${normal}\n"
printf "\t\tdisplay this help and exit\n"
printf "\n\t${bold}--skip-analytics${normal}\n"
printf "\t\tskips google analytics statistics capture and upload\n"
printf "\t\t${bold}Note${normal}: If not set, the setup will default to whether the environment variable ${bold}SKIP_ANALYTICS${normal} is set. If the environment variable is not set and you are running in ${bold}INTERACTIVE${normal} mode, you will be prompted by the interface as to your decision."
exit 0
elif [ "$#" -eq 1 ] && has_param "--skip-analtyics" "$@"; then
SKIP_ANALYTICS=1
prompt_for_options
else
export HOMEBREW_NO_ANALYTICS=1
echo "You passed in the following opt-ins:"
for var in "$@"; do
printf "${GREEN}%s${NO_COLOUR}\n" $var
done
SELECTED_OPT_INS=$@
fi

echo $SELECTED_OPT_INS

init_analytics () {
# If SKIP_ANALYTICS wasn't defined and there were no args
if [ -z $SKIP_ANALYTICS ] && [ $1 == 0 ]; then
local wantToShareAnalytics
read -p "Share usage analytics (y/n)? " wantToShareAnalytics
if [ "$wantToShareAnalytics" != "y" ]; then
SKIP_ANALYTICS=1
printf "${LIGHT_CYAN}Analytics will not be shared${NO_COLOUR}\n"
else
SKIP_ANALYTICS=0
printf "${GREEN}Analytics will be shared${NO_COLOUR}\n"
fi
fi
SKIP_ANALYTICS=${SKIP_ANALYTICS:-0}
if (( SKIP_ANALYTICS == 0 )); then
clientID=$(od -vAn -N4 -tx < /dev/urandom)
source ${MY_DIR}/scripts/helpers/google-analytics.sh ${clientID} start $SELECTED_OPT_INS
else
export HOMEBREW_NO_ANALYTICS=1
fi
}

init_analytics $#

# Note: Homebrew needs to be set up first
source ${MY_DIR}/scripts/common/homebrew.sh

Expand All @@ -40,10 +158,10 @@ source ${MY_DIR}/scripts/common/unix.sh
source ${MY_DIR}/scripts/common/configuration-osx.sh

# For each command line argument, try executing the corresponding script in opt-in/
for var in "$@"
for var in "$SELECTED_OPT_INS"
do
echo "$var"
FILE=${MY_DIR}/scripts/opt-in/${var}.sh
FILE=${OPT_IN_FOLDER}/${var}.sh
echo "$FILE"
if [ -f $FILE ]; then
source ${FILE}
Expand All @@ -54,5 +172,5 @@ done

source ${MY_DIR}/scripts/common/finished.sh
if (( SKIP_ANALYTICS == 0 )); then
source ${MY_DIR}/scripts/helpers/google-analytics.sh ${clientID} finish $@
source ${MY_DIR}/scripts/helpers/google-analytics.sh ${clientID} finish $SELECTED_OPT_INS
fi