Skip to content

Instantly share code, notes, and snippets.

@Addigy-BenM
Last active August 2, 2024 16:04
Show Gist options
  • Save Addigy-BenM/f4826887fd14426065c2333e3e15c4ae to your computer and use it in GitHub Desktop.
Save Addigy-BenM/f4826887fd14426065c2333e3e15c4ae to your computer and use it in GitHub Desktop.
Script to check if the Dropbox agent download redirect URL changes from an expected value
#!/bin/bash
# This script looks at the headers for a URL to download the Dropbox desktop app to determine the redirect URL to the actual
# download from Dropbox's CDN. It then compares this to an expected URL and logs when they do not match.
#
# There seems to be an issue where the redirect will randomly change to point at an unexpected (beta) build instead of the
# expected stable build.
## Vars
# URL with redirect the check for change
checkURL='https://www.dropbox.com/download?plat=mac&full=1'
# The expected URL to the redirected to for the stable build. This will change over time, current as of 8/2/24.
knownCorrectRedirectURL="https://edge.dropboxstatic.com/dbx-releng/client/Dropbox%20204.4.5420.dmg"
# Interval between checks
sleepIntervalSeconds=20
# Paths to log to
logHome="$HOME/Desktop/Dropbox_issue" # Folder the logs will live in
logPath="$logHome/dropbox_redirect_log.txt" # log containing all output
problemLogPath="$logHome/bad_redirect_log.txt" # log containing the bad redirect events
## Functions
# Logging function to write to console and main log file
logme () {
local input="$1"
echo "$(date '+%Y-%m-%d_%H:%M:%S_%Z') :: $input" | tee -a "$logPath"
}
## Main
# Setup
mkdir -p "$logHome"
# Loop indefinitely
while true; do
# clear previous value and check for the redirect URL
thisCheck=''
thisCheck="$(curl -Is "$checkURL" | grep 'location' | awk -F ': ' '{print $NF}' | tr -d '\n\t\r ')"
# Determine if we got a good or bad redirect
if [[ -z "$thisCheck" ]]; then
logme "Couldn't determine redirect URL."
elif [[ "$thisCheck" != "$knownCorrectRedirectURL" ]]; then
logme "Redirect URL mismatch. Currently redirecting to: $thisCheck" | tee -a "$problemLogPath"
else
logme "Expected redirect URL was returned."
fi
# Wait and run again
sleep "$sleepIntervalSeconds"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment