Skip to content

Instantly share code, notes, and snippets.

@dzabel
Last active January 15, 2020 23:15
Show Gist options
  • Save dzabel/1006884f2b8441f4f6850c567b03dc16 to your computer and use it in GitHub Desktop.
Save dzabel/1006884f2b8441f4f6850c567b03dc16 to your computer and use it in GitHub Desktop.
update installed brew packages and push brew_packes to git, to get it work, your need to install "brew tap buo/cask-upgrade"
#!/bin/bash
dateValue=''
newDate=$(date +"%m_%d_%Y")
if [ -f /tmp/brew_update_date.txt ]; then
dateValue=$(</tmp/brew_update_date.txt)
fi
if [ ! -f /tmp/brew_upgrade.lock ]; then
touch /tmp/brew_upgrade.lock
export HOMEBREW_GITHUB_API_TOKEN=<put your token here>
#check for connection
if [ "$dateValue" != "$newDate" ]; then
echo -e "\033[35m### Prepare 'brew' and 'brew cask' for updates ###\033[0m"
sudo /bin/rm -rf "$(brew --cache)"
/usr/local/bin/brew cleanup
echo ""
echo -e "\033[35m### Upgrade 'brew' packages ###\033[0m"
/usr/local/bin/brew update
/usr/local/bin/brew upgrade
echo -e "\033[35m### Upgrade 'brew cask' packages ###\033[0m"
echo ""
/usr/local/bin/brew cu -ay
date +"%m_%d_%Y" > /tmp/brew_update_date.txt
else
echo -e "\033[35m### 'brew' and 'brew cask' already updated today ###\033[0m"
echo ""
fi
echo "# brew packet list" > ~/dev/osx-dotfiles/brew_packages
for i in $(brew list); do
echo "brew install $i" >> ~/dev/osx-dotfiles/brew_packages
done
echo "# brew cask list" >> ~/dev/osx-dotfiles/brew_packages
for i in $(brew cask list); do
echo "brew cask install $i" >> ~/dev/osx-dotfiles/brew_packages
done
cd ~/dev/osx-dotfiles/
find . -name '.[a-z]*' -not -path "./.git" -not -path "./.git/*" -not -path "./.idea" -not -path "./.idea/*" -exec git add '{}' ';'
git add .
git commit -m "add new/changed files"
git push >/dev/null 2>&1
cd ~
rm -f /tmp/brew_upgrade.lock
else
echo "another brew upgrade is running"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment