-
-
Save densmirnov/a813de9a64e7d4701ddc to your computer and use it in GitHub Desktop.
Sync Homebrew installations via Microsoft OneDrive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Sync Homebrew installations via Microsoft OneDrive | |
# | |
# Colored Output | |
b='\033[1;34m' # Blue | |
w='\033[1;30m' # White | |
c='\033[0m' # No Color | |
BREW="/usr/local/bin/brew" | |
ONEDRIVE="$HOME/OneDrive/.backup/Homebrew" | |
CASK="$BREW cask" | |
LIST="$BREW list" | |
# First get local settings... | |
echo -e "${w}➔ ${b}Reading local settings ...${c}" | |
rm -f /tmp/brew-sync.* | |
$BREW tap > /tmp/brew-sync.taps | |
$BREW list > /tmp/brew-sync.installed | |
$CASK list > /tmp/brew-cask.installed | |
# ...then combine it with list in OneDrive | |
echo -e "${w}➔ ${b}Reading settings from OneDrive ...${c}" | |
[ -e "$ONEDRIVE"/brew-sync.taps ] && cat "${ONEDRIVE}"/brew-sync.taps >> /tmp/brew-sync.taps | |
[ -e "$ONEDRIVE"/brew-sync.installed ] && cat "${ONEDRIVE}"/brew-sync.installed >> /tmp/brew-sync.installed | |
[ -e "${ONEDRIVE}"/brew-cask.installed ] && cat "${ONEDRIVE}"/brew-cask.installed >> /tmp/brew-cask.installed | |
# Make the lists unique and sync into OneDrive | |
echo -e "${w}➔ ${b}Syncing to OneDrive ...${c}" | |
mkdir -p "${ONEDRIVE}" | |
cat /tmp/brew-sync.taps | sort | uniq > "${ONEDRIVE}"/brew-sync.taps | |
cat /tmp/brew-sync.installed | sort | uniq > "${ONEDRIVE}"/brew-sync.installed | |
cat /tmp/brew-cask.installed | sort | uniq > "${ONEDRIVE}"/brew-cask.installed | |
# Set taps | |
echo -e "${w}➔ ${b}Setting taps ...${c}" | |
grep -v '^ *#' < "${ONEDRIVE}"/brew-sync.taps | while IFS= read -r TAP | |
do | |
$BREW tap "${TAP}" > /dev/null | |
done | |
# Install missing Homebrew packages | |
echo -e "${w}➔ ${b}Installing missing packages ...${c}" | |
grep -v '^ *#' < "${ONEDRIVE}"/brew-sync.installed | while IFS= read -r PACKAGE | |
do | |
$LIST "${PACKAGE}" > /dev/null | |
[ "$?" != "0" ] && $BREW install "${PACKAGE}" | |
done | |
# Install missing Homebrew Cask applications | |
echo -e "${w}➔ ${b}Install missing packages ...${c}" | |
grep -v '^ *#' < "${ONEDRIVE}"/brew-cask.installed | while IFS= read -r PACKAGE | |
do | |
$LIST "${PACKAGE}" > /dev/null | |
[ "$?" != "0" ] && $CASK install "${PACKAGE}" | |
done | |
# Update and clean everything | |
echo -e "${w}➔ ${b}Finishing ...${c}" | |
brew update && brew upgrade brew-cask && brew cask update && brew cleanup && brew cask cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment