Sync Homebrew installations via Microsoft OneDrive

#!/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" # Get local settings... echo -e "${w}➔ ${b}Reading local settings ...${c}" rm -f /tmp/brew-sync.* $BREW tap > /tmp/brew-taps.installed $BREW list > /tmp/brew-sync.installed $CASK list > /tmp/brew-cask.installed # ...and combine it with list in OneDrive echo -e "${w}➔ ${b}Reading settings from OneDrive ...${c}" [ -e "${ONEDRIVE}"/brew-taps.installed ] && cat "${ONEDRIVE}"/brew-taps.installed >> /tmp/brew-taps.installed [ -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-taps.installed | sort | uniq > "${ONEDRIVE}"/brew-taps.installed 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-taps.installed | 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}" &> /dev/null 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}" &> /dev/null done # Update and clean everything echo -e "${w}➔ ${b}Finishing ...${c}" brew update &> /dev/null && brew cask update &> /dev/null brew cleanup &> /dev/null && brew cask cleanup &> /dev/null echo -e "

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.