diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index a95c609..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "zshdb", - "request": "launch", - "name": "Zsh-Debug (simplest configuration)", - "program": "${file}" - } - ] -} \ No newline at end of file diff --git a/macupdater-logo-2500x2500.afdesign b/macupdater-logo-2500x2500.afdesign deleted file mode 100644 index 6d652b7..0000000 Binary files a/macupdater-logo-2500x2500.afdesign and /dev/null differ diff --git a/macupdater-logo-2500x2500.png b/macupdater-logo-2500x2500.png deleted file mode 100644 index 21dcaa2..0000000 Binary files a/macupdater-logo-2500x2500.png and /dev/null differ diff --git a/macupdater.app/Contents/Info.plist b/macupdater.app/Contents/Info.plist new file mode 100644 index 0000000..5ed58e3 Binary files /dev/null and b/macupdater.app/Contents/Info.plist differ diff --git a/macupdater.app/Contents/MacOS/macupdater b/macupdater.app/Contents/MacOS/macupdater new file mode 100755 index 0000000..249a99b Binary files /dev/null and b/macupdater.app/Contents/MacOS/macupdater differ diff --git a/macupdater.app/Contents/Resources/AppIcon.icns b/macupdater.app/Contents/Resources/AppIcon.icns new file mode 100644 index 0000000..0fcf8ed Binary files /dev/null and b/macupdater.app/Contents/Resources/AppIcon.icns differ diff --git a/macupdater.app/Contents/Resources/AppSettings.plist b/macupdater.app/Contents/Resources/AppSettings.plist new file mode 100644 index 0000000..b3d35f3 Binary files /dev/null and b/macupdater.app/Contents/Resources/AppSettings.plist differ diff --git a/macupdater.app/Contents/Resources/MainMenu.nib/designable.nib b/macupdater.app/Contents/Resources/MainMenu.nib/designable.nib new file mode 100644 index 0000000..59df482 --- /dev/null +++ b/macupdater.app/Contents/Resources/MainMenu.nib/designable.nib @@ -0,0 +1,705 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macupdater.app/Contents/Resources/MainMenu.nib/keyedobjects.nib b/macupdater.app/Contents/Resources/MainMenu.nib/keyedobjects.nib new file mode 100644 index 0000000..f215593 Binary files /dev/null and b/macupdater.app/Contents/Resources/MainMenu.nib/keyedobjects.nib differ diff --git a/macupdater.app/Contents/Resources/script b/macupdater.app/Contents/Resources/script new file mode 100755 index 0000000..36f3def --- /dev/null +++ b/macupdater.app/Contents/Resources/script @@ -0,0 +1,110 @@ +#!/Users/gugulethu/brew/bin/zsh + +# This script updates brew, brew cask apps, ruby gems, node packages and macOS (including system software) Apps. +# Version 10.1.1 (08 September 2020) + +# Ask for the password up-front +sudo -v + +# Keep-alive: update existing sudo time stamp if set, otherwise do nothing. +while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & + +# Open an alert that requires the user the click RUN to start the process. +ANSWER=$(./alerter -message "Run an update?" -actions Run -title macupdater -timeout 10 -sound default) + +# Check the response from the alert and close if it is anything but RUN. +if [ $ANSWER = "@TIMEOUT" ]; then + echo "NOTIFICATION: Update process exited." + exit +elif [ $ANSWER = "@CLOSED" ]; then + exit +else + echo "NOTIFICATION: Updater starting..." # Send a notification (with logo) +fi + +# Set the path to the log file +export LOG=~/Desktop/macupdater-log.txt + +# Export paths for appification. +export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/$" + +# Function: Reviews the last command for errors. Then prints update complete to log or shows error dialog. Takes section variable. +catcher () { +if [ "$?" = "0" ]; then + printf "$1 updates complete." >> $LOG # If no error, print update complete to file. + printf "" >> $LOG # Add a line to file. +else # If error, show a dialog stating the section where the error occured. + echo "NOTIFICATION: '$1' updates failed." + ERROR=1 # Sets variable for error in script to 1. +fi +} + +# Function: Creates a horizontal line in the text file. +line () { +echo "" >> $LOG # Starts the horizontal line on its own fresh line. +printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - >> $LOG # Prints line +} + +# Function: If there has been an error in the script open the log file. +verify () { +if [ $ERROR = 1 ]; then + open $LOG + echo "NOTIFICATION: Updates completed with some errors." +else + echo "NOTIFICATION: Updates completed." +fi +} + +# Writes the header for the log file: Program, Version number, Date and Line. +{ echo "macupdater 10.1.1"; echo "Log: " `date`; line; } > $LOG + +# Brew update commands. +{ trash -rf $(brew --cache); echo "Brew"; echo ""; brew update; brew upgrade; brew cleanup; } >> $LOG +catcher Brew +line + +# Brew-cask update commands. +{ echo "Brew Cask"; echo ""; brew cu -ayf --cleanup; } >> $LOG +catcher Brew-cask +line + +# # Push and pull all git remotes. +# { cd Projects/Programming/push/;find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} push \; cd Projects/Programming/pull/; find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \; } >> $LOG +# catcher Git-remote +# line + +# Node update commands. +{ echo "Node"; echo ""; npm install npm@latest -g; npm update; npm prune; } >> $LOG +catcher Node +line + +# Ruby update commands. +{ echo "Ruby"; echo ""; gem update --system; gem cleanup; } >> $LOG +catcher Ruby +line + +# Perl update commands. +# { echo "Perl"; echo ""; perlbrew self-upgrade; perlbrew upgrade-perl; perlbrew clean; } >> $LOG +# catcher Perl +# line + +# Python update commands. +{ echo "Python"; echo ""; pip install -U pip; } >> $LOG +catcher Python +line + +# App Store update commands. +{ echo "Apps"; echo ""; mas upgrade; } >> $LOG +catcher Apps +line + +# System software update commads. +{ echo "macOS"; echo ""; softwareupdate -ia; } >> $LOG +catcher macOS +line + +# Prints and shows dialog box confirming all updates are done. +printf "All updates complete. END" >> $LOG +verify $ERROR + +echo "QUITAPP" \ No newline at end of file diff --git a/macupdater.sh b/macupdater.sh index f188bc0..36f3def 100755 --- a/macupdater.sh +++ b/macupdater.sh @@ -1,7 +1,13 @@ #!/Users/gugulethu/brew/bin/zsh # This script updates brew, brew cask apps, ruby gems, node packages and macOS (including system software) Apps. -# Version 10.0 (18 January 2020) +# Version 10.1.1 (08 September 2020) + +# Ask for the password up-front +sudo -v + +# Keep-alive: update existing sudo time stamp if set, otherwise do nothing. +while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & # Open an alert that requires the user the click RUN to start the process. ANSWER=$(./alerter -message "Run an update?" -actions Run -title macupdater -timeout 10 -sound default) @@ -17,7 +23,7 @@ else fi # Set the path to the log file -export LOG=~/Projects/Programming/push/macupdater/macupdater-log.txt +export LOG=~/Desktop/macupdater-log.txt # Export paths for appification. export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/$" @@ -50,7 +56,7 @@ fi } # Writes the header for the log file: Program, Version number, Date and Line. -{ echo "macupdater 10.0"; echo "Log: " `date`; line; } > $LOG +{ echo "macupdater 10.1.1"; echo "Log: " `date`; line; } > $LOG # Brew update commands. { trash -rf $(brew --cache); echo "Brew"; echo ""; brew update; brew upgrade; brew cleanup; } >> $LOG @@ -62,10 +68,10 @@ line catcher Brew-cask line -# Push and pull all git remotes. -{ cd Projects/Programming/push/ find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} push \; cd Projects/Programming/pull/; find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \; } >> $LOG -catcher Git-remote -line +# # Push and pull all git remotes. +# { cd Projects/Programming/push/;find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} push \; cd Projects/Programming/pull/; find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \; } >> $LOG +# catcher Git-remote +# line # Node update commands. { echo "Node"; echo ""; npm install npm@latest -g; npm update; npm prune; } >> $LOG diff --git a/readme.md b/readme.md index 0cf73b3..c788217 100644 --- a/readme.md +++ b/readme.md @@ -1,20 +1,87 @@ -# MacUpdater +![macupdater logo](https://gugulet.hu/site/wp-content/uploads/macupdater-logo-1200x600-1.png) -This script updates brew, brew cask apps, apm packages, ruby gems, rvm, npm packages and macOS (including system software) Apps. +[![License: MIT](https://img.shields.io/badge/License-MIT-red.svg)](https://opensource.org/licenses/MIT) -## Dependencies +Package managment on macOS is a challenge. This is my amateurish attempt to combine all my package updates into one app. This app updates brew, brew cask apps, apm packages, ruby gems, rvm, npm packages and macOS (including system software) Apps. Note: the app only runs in admin account as it needs admin privileges. -brew -*https://brew.sh/* +## Before you start -apm -*Atom package manager* +This app relies on [alerter](https://github.com/vjeantet/alerter) for its notifications, so install that before you get started. -npm -*brew install node* +## Editing the script -mas -*brew install mas* +Editing the script requires some scripting know how, but it is documented. Here's a quick guide on how to customise it for your needs. -## Notes -Editing the script requires some scripting know how, but it is well documented. +### Preamble + +In the preamble we get sudo rights and ask for the password to ensure everything that follows runs smoothly. + +```shell +# Ask for the password up-front +sudo -v + +# Keep-alive: update existing sudo time stamp if set, otherwise do nothing. +while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & +``` + +And then we start the script by prompting the user. + +```shell +# Open an alert that requires the user the click RUN to start the process. +ANSWER=$(./alerter -message "Run an update?" -actions Run -title macupdater -timeout 10 -sound default) + +# Check the response from the alert and close if it is anything but RUN. +if [ $ANSWER = "@TIMEOUT" ]; then + echo "NOTIFICATION: Update process exited." + exit +elif [ $ANSWER = "@CLOSED" ]; then + exit +else + echo "NOTIFICATION: Updater starting..." # Send a notification (with logo) +fi +``` + +### Set variables + +We set the path for the log file, which documents errors and progress. The path makes the script work when we use Platypus to convert it into an app. + +```shell +# Set the path to the log file +export LOG=~/Desktop/macupdater-log.txt + +# Export paths for appification. +export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/$" +``` + +### Functions + +The app has three functions: one to check the last update commands for errors, one to create a horizontal line in the log file and the last to open the log file at the end if there has been an error. I won;t go itno the functions here. You can read their comments in the file. + +### Update commands + +Lastly we have the update modules themselves for each package manager. Below is the update command for Homebrew. First it clears the Brew cache, then updates the log file, then runs updates, then upgrades, then cleanup. All of this is logged to the file (>> \$LOG). Then we call the catcher function to see if there have been any errors. And finally add a line to the log to seperate this from the next update section. You can add your won package managers in this fashion or remove some of the ones I have. + +```shell +# Brew update commands. +{ trash -rf $(brew --cache); echo "Brew"; echo ""; brew update; brew upgrade; brew cleanup; } >> $LOG +catcher Brew +line +``` + +### Creating the app + +I use [Platypus][https://github.com/sveinbjornt/platypus] to convert the script into an application for macOS. You are welcome to run this purely as a shell script. This is very much a work in progress, so feel free to tinker. + +### Problems + +The biggest problem I have right now is that this app needs to be run as an admin user. I prefer to use a non-admin account day-to-day so I'm going to have to tackle the run as another user problem soon. Running as a non-admin causes the brew and brew-cask updates to fail. + +## License + +All the works are available under the MIT license. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.