commit 41f0b45d89017d34180a55546dded8373fb931b1
parent 678214b824de2bf0276432a03594d1e9de7be80f
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Tue, 29 May 2018 14:45:16 +0200
Some UI additions to updatemaster, moved to bash from zsh
Diffstat:
M | bin/updatemaster | | | 111 | ++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- |
1 file changed, 65 insertions(+), 46 deletions(-)
diff --git a/bin/updatemaster b/bin/updatemaster
@@ -1,57 +1,69 @@
-#!/usr/local/bin/zsh
+#!/usr/local/bin/bash
### 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 "terminal-notifier not found, defaulting to bell. Install terminal-notifier to get the most out of this script."
- notify() { echo '\a'; }
+ echo -e "terminal-notifier not found, defaulting to bell. Install terminal-notifier to get the most out of this script."
+ notify() { echo -e '\a'; }
fi
fi
### HOMEBREW ###
-echo "-- Homebrew update/upgrade."
+echo -e "-- 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
# Potentially upgrade programs
if [ ${#outdated} = 0 ]; then
- echo "No programs to update."
+ echo -e "No programs to update."
else
- echo "\nTo update:\n"
+ echo -e "To update:\n"
brew outdated;
notify "Brew: Finished reading updates" "Click to view outdated packages."
- echo -n "Continue? [Y/n]"
- read -sqn CONF
+ echo; read -sn 1 -p "Continue? [Y/n]" CONF
- if [ "$CONF" != "y" ]; then
- echo "\nCancelled brew upgrade."
- else
- echo "\nContinuing with brew upgrade."
- brew upgrade;
- fi
+ case $CONF in
+ [yY] )
+ echo -e "\nContinuing with brew upgrade."
+ brew upgrade;
+ ;;
+ * )
+ echo -e "\nCancelled brew upgrade."
+ ;;
+ esac
fi
# Potentially upgrade casks
if [ ${#outdated_c} = 0 ]; then
- echo "No casks to update."
+ echo -e "No casks to update."
else
- echo "\nCasks to update:\n"
+ echo -e "Casks to update:"
brew cask outdated --greedy;
notify "Cask: Finished reading updates" "Click to view outdated casks."
- echo -n "Continue? [Y/n]"
- read -sqn CONF
+ read -sn 1 -p "Continue? [Y(es)/n(o)/s(elect)]: " CONF
- if [ "$CONF" != "y" ]; then
- echo "\nCancelled cask upgrade."
- else
- echo "\nContinuing with cask upgrade."
- brew cask upgrade --greedy;
- 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
# Final steps & cleanup
@@ -62,55 +74,62 @@ if command -v brew &> /dev/null; then
brew missing;
notify "Brewed." "All packages have been upgraded.";
else
- echo "brew not found."
- echo "Cannot upgrade Homebrew packages. Please do so manually."
+ echo -e "brew not found."
+ echo -e "Cannot upgrade Homebrew packages. Please do so manually."
fi
### Mac App Store (MAS) ###
-echo "-- MAS update/upgrade."
+echo -e "\n-- MAS update/upgrade."
if command -v mas &> /dev/null; then
- echo "MAS outdated:"
+ echo -e "MAS outdated:"
mas outdated
- echo -n "Continue? [Y/n]"
- read -sqn CONF
+ read -sn 1 -p "Continue? [Y/n]" CONF
- if [ "$CONF" != "y" ]; then
- echo "\nCancelled mas upgrade."
- else
- echo "\nContinuing with mas upgrade."
- mas upgrade;
- fi
+ case $CONF in
+ [Yy] )
+ echo -e "\nContinuing with mas upgrade."
+ mas upgrade;
+ ;;
+
+ * )
+ echo -e "\nCancelled mas upgrade."
+ ;;
+ esac
notify "MAS Updated." "All apps at newest version."
else
- echo "mas not found. Install mas to update App Store apps on the command line."
- echo "Cannot update Mac App Store apps. Please do so manually."
+ echo -e "\nmas not found. Install mas to update App Store apps on the command line."
+ echo -e "\nCannot update Mac App Store apps. Please do so manually."
fi
### NPM ###
-echo "-- NPM update/upgrade."
+echo -e "\n-- NPM update/upgrade."
if command -v npm &> /dev/null; then
npm update -g
notify "NPM Update Finished" "See Terminal for info."
else
- echo "npm not found."
- echo "Cannot update NPM packages. Please do so manually."
+ echo -e "\nnpm not found."
+ echo -e "\nCannot update NPM packages. Please do so manually."
fi
### PIP3 ###
-echo "-- PIP3 update/upgrade."
+echo -e "\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."
else
- echo "Cannot upgrade pip3 packages. Please do so manully."
+ echo -e "\nCannot upgrade pip3 packages. Please do so manully."
fi
### PIP ###
-echo "-- PIP update/upgrade."
+echo -e "-- PIP update/upgrade."
if command -v pip list &> /dev/null; then
- pip freeze — local | grep -v ‘^\-e’ | cut -d = -f 1 | xargs pip install -U
+ if pip freeze; then
+ pip freeze — local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U
+ else
+ echo -e "Cannot upgrade pip packages. Please do so manully."
+ fi
notify "Pip Update Finished" "See Terminal for info."
else
- echo "Cannot upgrade pip packages. Please do so manully."
+ echo -e "Cannot upgrade pip packages. Please do so manully."
fi