From 040b1cd184fd23fe03c52d4f642a93161975c5a0 Mon Sep 17 00:00:00 2001 From: Jason Pitman Date: Tue, 2 Jul 2019 17:26:22 -0500 Subject: [PATCH] working --- .../basic_IM_utilities_setup/lib/echos.sh | 81 +++++++++++++++++++ .../basic_IM_utilities_setup/lib/functions.sh | 70 ++++++++++++++++ .../macos/basic_IM_utilities_setup/setup.sh | 23 ++++++ 3 files changed, 174 insertions(+) create mode 100755 system/macos/basic_IM_utilities_setup/lib/echos.sh create mode 100755 system/macos/basic_IM_utilities_setup/lib/functions.sh create mode 100755 system/macos/basic_IM_utilities_setup/setup.sh diff --git a/system/macos/basic_IM_utilities_setup/lib/echos.sh b/system/macos/basic_IM_utilities_setup/lib/echos.sh new file mode 100755 index 0000000..403207c --- /dev/null +++ b/system/macos/basic_IM_utilities_setup/lib/echos.sh @@ -0,0 +1,81 @@ +#!//bin/bash + +### +# some colorized echo helpers +# @author Adam Eivy +# https://raw.githubusercontent.com/atomantic/dotfiles/master/lib_sh/echos.sh +### + +# Colors +ESC_SEQ="\x1b[" +COL_RESET=$ESC_SEQ"39;49;00m" +COL_RED=$ESC_SEQ"31;01m" +COL_GREEN=$ESC_SEQ"32;01m" +COL_YELLOW=$ESC_SEQ"33;01m" +COL_BLUE=$ESC_SEQ"34;01m" +COL_MAGENTA=$ESC_SEQ"35;01m" +COL_CYAN=$ESC_SEQ"36;01m" +SEP_COLOR=$ESC_SEQ"36;01m" + +COL_DIM=$ESC_SEQ"2;49;90m" +SEP_COLOR_DIM=$ESC_SEQ"38;5;8m" +DIMDOTS=$ESC_SEQ"2;49;90m..."$COL_RESET + +COL_PURPLE_BG=$ESC_SEQ"38;2;0;0;0m"$ESC_SEQ"48;2;110;0;255m" + +columns="$(tput cols)" +ov_sep="-------------------------------------------------" +open_vers_1="MacOS install script - v0.0.1" +open_vers_2="via https://github.com/ff4500/utilities" +open_title="We're going to run some tests to see what you already have setup on your system." + +function ok() { + echo -e "${COL_GREEN}[ok]${COL_RESET}" $1 +} + +function bot() { + echo -e "\n${COL_GREEN}\[._.]/${COL_RESET} -" $1 +} + +function running() { + echo -e "${COL_YELLOW} ⇒ ${COL_RESET}" $1 ": " +} + +function action() { + echo -e "\n${COL_YELLOW}[action]:${COL_RESET}\n ⇒ $1..." +} + +function warn() { + echo -e "${COL_YELLOW}[warning]${COL_RESET}" $1 +} + +function error() { + echo -e "${COL_RED}[error]${COL_RESET}" $1 +} + +function seperator() { + local sized=$(stty size | awk '{print $2}') + local len=${sized} + local ch="-" + local TERM_WIDTH="$(printf '%*s' "${len}" | tr ' ' "${ch}")" + + echo -e "${SEP_COLOR}${TERM_WIDTH}${COL_RESET}" +} + +function display_center() { + while IFS= read -r line; do + printf "%*s\n" $(( (${#line} + columns) / 2)) "$line" + done < "$1" +} + +function opening_title() { + echo -e "${SEP_COLOR_DIM}" + printf "%*s\n" $(((${#ov_sep}+$columns)/2)) "$ov_sep" + printf "%*s\n" $(((${#open_vers_1}+$columns)/2)) "$open_vers_1" + printf "%*s\n" $(((${#open_vers_2}+$columns)/2)) "$open_vers_2" + printf "%*s\n" $(((${#ov_sep}+$columns)/2)) "$ov_sep" + echo -e "${COL_RESET}"; + seperator + printf "%*s\n" $(((${#open_title}+$columns)/2)) "$open_title" + seperator +} diff --git a/system/macos/basic_IM_utilities_setup/lib/functions.sh b/system/macos/basic_IM_utilities_setup/lib/functions.sh new file mode 100755 index 0000000..9d319cf --- /dev/null +++ b/system/macos/basic_IM_utilities_setup/lib/functions.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +function install_homebrew() { + brew_check=$(command -v brew) > /dev/null 2>&1 + + if [[ $? != 0 ]]; then + echo -e "You don't have Homebrew installed. Installing..." + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + if [[ $? != 0 ]]; then + error "unable to install homebrew, script $0 abort!" + exit 2 + fi + else + echo -e "Brew is already installed" + read -r -p "Would you like to run brew update && upgrade? [y|N] " response + if [[ $response =~ (y|yes|Y) ]]; then + action "Updating homebrew..." + brew update + ok "Homebrew updated" + action "Upgrading brew packages..." + brew upgrade + ok "Brews upgraded" + else + ok "Skipped brew package upgrades." + fi + fi +} + +function install_brewcask() { + output=$(command -v brew cask --version) > /dev/null 2>&1 + if [[ $? != 0 ]]; then + echo -e "brew-cask is not installed" + else + echo -e "brew-cask is installed" + fi +} + + + + + +# source ./echos.sh + +function require_cask() { + running "brew cask $1" + brew cask list $1 > /dev/null 2>&1 | true + if [[ ${PIPESTATUS[0]} != 0 ]]; then + action "brew cask install $1 $2" + brew cask install $1 + if [[ $? != 0 ]]; then + error "failed to install $1! aborting..." + # exit -1 + fi + fi + ok +} + +function require_brew() { + running "brew $1 $2" + brew list $1 > /dev/null 2>&1 | true + if [[ ${PIPESTATUS[0]} != 0 ]]; then + action "brew install $1 $2" + brew install $1 $2 + if [[ $? != 0 ]]; then + error "failed to install $1! aborting..." + # exit -1 + fi + fi + ok +} diff --git a/system/macos/basic_IM_utilities_setup/setup.sh b/system/macos/basic_IM_utilities_setup/setup.sh new file mode 100755 index 0000000..2c6ff68 --- /dev/null +++ b/system/macos/basic_IM_utilities_setup/setup.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Install Homebrew +# ---------------------------------------------------------------- +# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +# +# Install iterm2 and Atom +# ---------------------------------------------------------------- +# brew cask install iterm2 atom +# +# Install ImageMagick +# ---------------------------------------------------------------- +# brew install imagemagick + +source ./lib/echos.sh +source ./lib/functions.sh + +opening_title + +# Install Homebrew +# ---------------------------------------------------------------- +running "Checking homebrew..." +install_homebrew