dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit ba87115a9d4dbf455271851f97565f907a05324e
parent 5fedd6ad420a6254810e567f2261d62360008ef3
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sun, 26 Aug 2018 15:23:15 +0200

Added non-greedy command line option to updatemaster

Diffstat:
Mdotfiles/bin/updatemaster | 405+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 210 insertions(+), 195 deletions(-)

diff --git a/dotfiles/bin/updatemaster b/dotfiles/bin/updatemaster @@ -10,279 +10,294 @@ all=0 none=0 select_casks=0 sudo_auth=0 +greedy=1 echo_succ() { - echo -e "\e[1;32m$1\e[0m" + echo -e "\e[1;32m$1\e[0m" } echo_err() { - echo -e "\e[1;31m$1\e[0m" + echo -e "\e[1;31m$1\e[0m" } echo_warn() { - echo -e "\e[1;34m$1\e[0m" + echo -e "\e[1;34m$1\e[0m" } echo_progress() { - echo -e "\e[1;36m$1\e[0m" + echo -e "\e[1;36m$1\e[0m" } echo_progress "### STARTING UPDATE SCRIPT ###\n" # Get passed options/arguments -while getopts "fcashFAC" opt; do - case "$opt" in - c) - all_casks=1 - ;; - f) - all_formulas=1 - ;; - a) - all=1 - ;; - s) - select_casks=1 - ;; - F) - no_formulas=1 - ;; - C) - no_casks=1 - ;; - A) - none=1 - ;; - h) - echo "Update your Homebrew, Mac App Store, NPM, and PIP packages in one place." - echo "Usage: updatemaster [-aAcCfFsh]" - echo "Options:" - echo "-c: Upgrade all casks, without prompting." - echo "-C: Don't update any casks." - echo "-f: Upgrade all formulas, without prompting." - echo "-F: Don't upgrade any formulas." - echo "-a: Upgrade all casks and formulas." - echo "-A: Don't upgrade any Brew programs (maintenance only)." - echo "-s: Select which casks to upgrade." - echo "-h: Show this help text." - echo - echo "Options can be combined. For example:" - echo " updatemaster -fs" - echo "Would update all formulas, and ask you to select which casks to upgrade." - exit 0 - ;; - *) - ;; - esac +while getopts "fcashFACn" opt; do + case "$opt" in + c) + all_casks=1 + ;; + f) + all_formulas=1 + ;; + a) + all=1 + ;; + s) + select_casks=1 + ;; + F) + no_formulas=1 + ;; + C) + no_casks=1 + ;; + A) + none=1 + ;; + h) + echo "Update your Homebrew, Mac App Store, NPM, and PIP packages in one place." + echo "Usage: updatemaster [-aAcCfFsh]" + echo "Options:" + echo "-c: Upgrade all casks, without prompting." + echo "-C: Don't update any casks." + echo "-f: Upgrade all formulas, without prompting." + echo "-F: Don't upgrade any formulas." + echo "-a: Upgrade all casks and formulas." + echo "-A: Don't upgrade any Brew programs (maintenance only)." + echo "-s: Select which casks to upgrade." + echo "-h: Show this help text." + echo + echo "Options can be combined. For example:" + echo " updatemaster -fs" + echo "Would update all formulas, and ask you to select which casks to upgrade." + exit 0 + ;; + n) + greedy=0;; + *) + ;; + esac done - + ### SET UP NOTIFY ### if ! command -v notify &> /dev/null; then - if command -v terminal-notifier &> /dev/null; then - notify() { terminal-notifier -title "$1" -message "$2" -activate com.googlecode.iterm2; } - else - echo_warn "terminal-notifier not found, defaulting to bell. Install terminal-notifier to get the most out of this script." - notify() { echo -e '\a'; } - fi + if command -v terminal-notifier &> /dev/null; then + notify() { terminal-notifier -title "$1" -message "$2" -activate com.googlecode.iterm2; } + else + echo_warn "terminal-notifier not found, defaulting to bell. Install terminal-notifier to get the most out of this script." + notify() { echo -e '\a'; } + fi fi ### Pre-authorise sudo ### echo -e "Root permissions will be needed for global pip update.\n" if sudo -v; then - sudo_auth=1 + sudo_auth=1 else - sudo_auth=0 + sudo_auth=0 fi echo ### HOMEBREW ### echo_progress "-- Homebrew update/upgrade." if command -v brew &> /dev/null; then - brew update; - brew update > /dev/null; - outdated="$(brew outdated)" - outdated_c="$(brew cask outdated --greedy)" - echo + brew update; + brew update > /dev/null; + outdated="$(brew outdated)" + if [ $greedy = 1 ]; then + outdated_c="$(brew cask outdated --greedy)" + else + outdated_c="$(brew cask outdated)" + fi + echo - # Potentially upgrade programs - if [ $no_formulas = 1 ] || [ $none = 1 ]; then - echo_succ "\nNo programs will be updated." - elif [ ${#outdated} = 0 ]; then - echo -e "No programs to update." - else - echo -e "To update:\n" - brew outdated; - notify "Brew: Finished reading updates" "Click to view outdated packages." - if [ $all_formulas = 1 ] || [ $all = 1 ]; then - brew upgrade - else - echo; read -sn 1 -p "Continue? [Y/n]" CONF + # Potentially upgrade programs + if [ $no_formulas = 1 ] || [ $none = 1 ]; then + echo_succ "\nNo programs will be updated." + elif [ ${#outdated} = 0 ]; then + echo -e "No programs to update." + else + echo -e "To update:\n" + brew outdated; + notify "Brew: Finished reading updates" "Click to view outdated packages." + if [ $all_formulas = 1 ] || [ $all = 1 ]; then + brew upgrade + else + echo; read -sn 1 -p "Continue? [Y/n]" CONF - case $CONF in - [yY] ) - echo -e "\nContinuing with brew upgrade." - brew upgrade; - ;; - * ) - echo -e "\nCancelled brew upgrade." - ;; - esac - fi - fi + case $CONF in + [yY] ) + echo -e "\nContinuing with brew upgrade." + brew upgrade; + ;; + * ) + echo -e "\nCancelled brew upgrade." + ;; + esac + fi + fi - # Potentially upgrade casks - if [ ${#outdated_c} = 0 ]; then - echo_succ "No casks to update." - elif [ $no_casks = 1 ] || [ $none = 1 ]; then - echo_succ "\nNo casks will be updated." - else - echo -e "Casks to update:" - brew cask outdated --greedy; - notify "Cask: Finished reading updates" "Click to view outdated casks." - if [ $all_casks = 1 ] || [ $all = 1 ]; then + # Potentially upgrade casks + if [ ${#outdated_c} = 0 ]; then + echo_succ "No casks to update." + elif [ $no_casks = 1 ] || [ $none = 1 ]; then + echo_succ "\nNo casks will be updated." + else + echo -e "Casks to update:" + if [ $greedy = 1 ]; then + brew cask outdated --greedy; + else + brew cask outdated + fi + notify "Cask: Finished reading updates" "Click to view outdated casks." + if [ $all_casks = 1 ] || [ $all = 1 ]; then + if [ $greedy = 1 ]; then brew cask upgrade --greedy - elif [ $select_casks = 1 ]; then - read -p "Casks to upgrade (empty string cancels upgrade): " -a CASKS; - for i in ${CASKS[@]}; do - if ! brew cask upgrade $i; then echo -e "Could not upgrade cask $i."; fi - done - else - read -sn 1 -p "Upgrade all? [Y(es)/n(o)/s(elect)] " CONF + else + brew cask upgrade + fi + elif [ $select_casks = 1 ]; then + read -p "Casks to upgrade (empty string cancels upgrade): " -a CASKS; + for i in ${CASKS[@]}; do + if ! brew cask upgrade $i; then echo -e "Could not upgrade cask $i."; fi + done + else + read -sn 1 -p "Upgrade all? [Y(es)/n(o)/s(elect)] " CONF - case $CONF in - [Ss] | [Ss]elect ) - echo - read -p "Which casks would you like to upgrade? " -a CASKS; - for i in ${CASKS[@]}; do - if ! brew cask upgrade $i; then echo -e "Could not upgrade cask $i."; fi - done - ;; - [Yy] | [Yy]es ) - echo -e "\nContinuing with cask upgrade." - brew cask upgrade --greedy; - ;; - * ) - echo -e "\nCancelled cask upgrade." - ;; - esac - fi - fi + case $CONF in + [Ss] | [Ss]elect ) + echo + read -p "Which casks would you like to upgrade? " -a CASKS; + for i in ${CASKS[@]}; do + if ! brew cask upgrade $i; then echo -e "Could not upgrade cask $i."; fi + done + ;; + [Yy] | [Yy]es ) + echo -e "\nContinuing with cask upgrade." + brew cask upgrade --greedy; + ;; + * ) + echo -e "\nCancelled cask upgrade." + ;; + esac + fi + fi - # Final steps & cleanup - brew cleanup -s; - brew prune; - brew doctor; - brew missing; - echo "Backuping up Brew installation..." - brew bundle dump --force --file=~/.cfg/Brewfile; - echo_succ "Backup complete." - notify "Brewed." "All packages have been upgraded."; + # Final steps & cleanup + brew cleanup -s; + brew prune; + brew doctor; + brew missing; + echo "Backuping up Brew installation..." + brew bundle dump --force --file=~/.cfg/Brewfile; + echo_succ "Backup complete." + notify "Brewed." "All packages have been upgraded."; else - echo_err "brew not found." - echo_err "Cannot upgrade Homebrew packages. Please do so manually." + echo_err "brew not found." + echo_err "Cannot upgrade Homebrew packages. Please do so manually." fi ### Mac App Store (MAS) ### echo_progress "\n-- MAS update/upgrade." if command -v mas &> /dev/null; then - echo -e "MAS outdated:" - outdated=$(mas outdated) + echo -e "MAS outdated:" + outdated=$(mas outdated) - if [ ${#outdated} = 0 ]; then - echo_succ "\nEverything is up to date." - else - mas outdated - read -sn 1 -p "Continue? [Y/n]" CONF + if [ ${#outdated} = 0 ]; then + echo_succ "\nEverything is up to date." + else + mas outdated + read -sn 1 -p "Continue? [Y/n]" CONF - case $CONF in - [Yy] ) - echo_succ -e "\nContinuing with mas upgrade." - mas upgrade; - ;; + case $CONF in + [Yy] ) + echo_succ -e "\nContinuing with mas upgrade." + mas upgrade; + ;; - * ) - echo -e "\nCancelled mas upgrade." - ;; - esac - notify "MAS Updated." "All apps at newest version." - fi + * ) + echo -e "\nCancelled mas upgrade." + ;; + esac + notify "MAS Updated." "All apps at newest version." + fi else - echo_err -e "\nmas not found. Install mas to update App Store apps on the command line." - echo_err -e "\nCannot update Mac App Store apps. Please do so manually." + echo_err -e "\nmas not found. Install mas to update App Store apps on the command line." + echo_err -e "\nCannot update Mac App Store apps. Please do so manually." fi ### GLOBAL NPM ### echo_progress "\n-- NPM global update/upgrade." if command -v npm &> /dev/null; then - outdated=$(npm outdated) - if [ ${#outdated} = 0 ]; then - echo_succ "\nEverything is up to date." - else - npm update -g - notify "NPM Update Finished" "See Terminal for info." - fi - npm cache verify - echo_succ "NPM update complete." + outdated=$(npm outdated) + if [ ${#outdated} = 0 ]; then + echo_succ "\nEverything is up to date." + else + npm update -g + notify "NPM Update Finished" "See Terminal for info." + fi + npm cache verify + echo_succ "NPM update complete." else - echo_err "\nnpm not found." - echo_err "\nCannot update NPM packages. Please do so manually." + echo_err "\nnpm not found." + echo_err "\nCannot update NPM packages. Please do so manually." fi ### PIP3 ### echo_progress "\n-- PIP3 update/upgrade." if command -v pip3 list &> /dev/null; then - pip3 list --outdated | cut -d ' ' -f1 | xargs -n1 pip3 install -U - notify "Pip3 Update Finished" "See Terminal for info." + pip3 list --outdated | cut -d ' ' -f1 | xargs -n1 pip3 install -U + notify "Pip3 Update Finished" "See Terminal for info." else - echo_err "\nCannot upgrade pip3 packages. Please do so manually." + echo_err "\nCannot upgrade pip3 packages. Please do so manually." fi ### PIP ### echo_progress "-- PIP update/upgrade." if command -v pip list &> /dev/null; then - if pip freeze; then - pip freeze — local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U - else - echo_err "Cannot upgrade pip packages. Please do so manually." - fi - notify "Pip Update Finished" "See Terminal for info." + if pip freeze; then + pip freeze — local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U + else + echo_err "Cannot upgrade pip packages. Please do so manually." + fi + notify "Pip Update Finished" "See Terminal for info." else - echo_err "Cannot upgrade pip packages. Please do so manually." + echo_err "Cannot upgrade pip packages. Please do so manually." fi ### SUDO PIP ### echo_progress "\n-- Global pip." if [ $sudo_auth -eq 1 ]; then - if command -v sudo -H pip list &> /dev/null; then - sudo -H pip freeze | grep -v '^\-e' | cut -d = -f 1 | xargs sudo -H pip install -U - echo_succ "Global pip upgrade complete." - else - echo -e "Cannot upgrade global pip packages. Please do so manually." - fi + if command -v sudo -H pip list &> /dev/null; then + sudo -H pip freeze | grep -v '^\-e' | cut -d = -f 1 | xargs sudo -H pip install -U + echo_succ "Global pip upgrade complete." + else + echo -e "Cannot upgrade global pip packages. Please do so manually." + fi else - echo -e "Sudo not authorised." + echo -e "Sudo not authorised." fi ### TLDR DATABASE ### if command -v tldr &> /dev/null; then - echo_progress "\n-- TLDR database update" - tldr --update - tldr_exit=$? - if [ $tldr_exit -eq 0 ]; then - echo_succ "Exit code: $tldr_exit" - else - echo_err "Exit code: $tldr_exit" - fi + echo_progress "\n-- TLDR database update" + tldr --update + tldr_exit=$? + if [ $tldr_exit -eq 0 ]; then + echo_succ "Exit code: $tldr_exit" + else + echo_err "Exit code: $tldr_exit" + fi fi ### ATOM PACKAGES ### if command -v apm &> /dev/null; then echo_progress "\n-- Atom package upgrades" - if apm outdated &> /dev/null; then - apm upgrade --no-confirm; - echo_succ "All packages upgraded." - else - echo_err "Cannot upgrade Atom packages. Please do so manually." - fi + if apm outdated &> /dev/null; then + apm upgrade --no-confirm; + echo_succ "All packages upgraded." + else + echo_err "Cannot upgrade Atom packages. Please do so manually." + fi else - echo_err "Atom not installed (or APM not functioning properly)." + echo_err "Atom not installed (or APM not functioning properly)." fi notify "APM Upgrade Complete" "See Terminal for info." echo_progress "\n-- All systems checked. \e[1;32m\u2714\e[0m"