Skip to content

Instantly share code, notes, and snippets.

@dzogrim
Created January 26, 2019 18:22
Show Gist options
  • Select an option

  • Save dzogrim/29620c3d8bc7fca708545ba421ce80d1 to your computer and use it in GitHub Desktop.

Select an option

Save dzogrim/29620c3d8bc7fca708545ba421ce80d1 to your computer and use it in GitHub Desktop.
Easily spot difference between 2 Mac computers installed macOS applications
#!/bin/bash
set -e
shopt -s extglob
## The tool was designed to easily spot difference between 2 Mac computers installed macOS applications.
## Copyleft (C) 2016-2019 dzogrim
## dzogrim < dzogrim [@] dzogrim [.] pw >
#VERSION="1.2 (2019-01-26)"
DropboxPath="Dropbox/Private/_SyncThat/confInfos"
tempfile="/tmp/apps"
findOpt1="-maxdepth 1 -mindepth 1"
findOpt2="-maxdepth 2 -mindepth 2"
# Find installed Applications
{
find /Applications $findOpt1 -iname "*.app"
find "${HOME}/Applications" $findOpt1 -iname "*.app"
find /Applications $findOpt1 -type d -not -iname "*.app" | grep -v Unified | grep -v Utilities
find "${HOME}/Applications" $findOpt1 -type d -not -iname "*.app" | grep -v Unified | grep -v Utilities
# Find specific installed utilities
find /Applications/Unified\ Tools $findOpt2 -iname "*.app"
find /Applications/Utilities $findOpt1 -iname "*.app"
} >"${tempfile}"
# Anonymize user's home directory
envHomeDir="$( sed -e s'|/Users/||' <<<${HOME})"
sed -i -e "s/${envHomeDir}/homedir/g" "${tempfile}"
# Handle different dropbox sync folders
# Office environnement (directly in the homedir)
[[ -d "$HOME/$DropboxPath" ]] && \
DropboxDir="$HOME/$DropboxPath" && envSuff="office"
# Home environnement (inside Documents subdir)
[[ -d "$HOME/Documents/$DropboxPath" ]] && \
DropboxDir="$HOME/Documents/$DropboxPath" && envSuff="home"
# Mac App Store installed apps
/opt/local/bin/mas list|cut -d" " -f2-|awk 'NF{--NF};1' > "$DropboxDir/mas-apps-$envSuff.txt"
# Mac Ports installed ports
/opt/local/bin/port -qv installed | sort > "${DropboxDir}/portsCompleteList-${envSuff}.txt"
/opt/local/bin/port -q echo requested | awk '{print $1}' | sort | uniq | tr '\n' ' ' > "${DropboxDir}/portsToInstall-${envSuff}.txt"
/opt/local/bin/port -q echo installed | awk '{print $1}' | sort | uniq | tr '\n' ' ' > "${DropboxDir}/portsInstalled-${envSuff}.txt"
# Make sure file replacement is needed
checksumSrce="$( /opt/local/libexec/gnubin/md5sum "${tempfile}" | awk '{print $1}' )"
checksumDest="$( /opt/local/libexec/gnubin/md5sum "${DropboxDir}/apps-${envSuff}.txt" | awk '{print $1}' )"
if [[ ! $checksumSrce =~ $checksumDest ]]
then
mv "${tempfile}" "$DropboxDir/apps-$envSuff.txt"
else
rm "${tempfile}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment