Skip to content

Instantly share code, notes, and snippets.

@dmdeller
Created January 15, 2019 23:16
Show Gist options
  • Save dmdeller/63c34eacd9dd2bacee58937d6739f7b6 to your computer and use it in GitHub Desktop.
Save dmdeller/63c34eacd9dd2bacee58937d6739f7b6 to your computer and use it in GitHub Desktop.
Redline Addons Updater
#/bin/sh
echo " ________ _____ "
echo "/_______ \___ ____/ / (_)___ ___ "
echo " / /_/ / _ \/ __ / / / __ \/ _ \ "
echo " / _, _/ __/ /_/ / / / / / / __/_________________________"
echo " /_/ |_|\___/\__,_/_/_/_/ /_/\_____________________________/"
echo ""
echo "Addons Updater v1.3.2 by D.M.Deller"
echo ""
ver=132
# Ugly hack to make this run from the directory in which it was
# double-clicked - only when we're run as a .command file
#cd "`dirname "$0"`"
#pwd
# Platypus: change to .app dir, then parent (Redline folder!)
cd "$1"
cd ..
#pwd
# Make sure we have a Plug-Ins folder to write to...
if [ -d Plug-Ins ]
then
sleep 2
echo "Starting up..."
else
echo "You need to place this in your Redline folder."
echo ""
echo -n "(Press Quit)"
exit
fi
# Remove bad versions from 1.0 and 1.1
# Intel:
#-rwxr-xr-x 1 dmd dmd 141788 Mar 22 2006 unzip
#-rwxr-xr-x 1 dmd dmd 189260 Mar 23 2006 wget
# PPC:
#-rwxr-xr-x 1 dmd dmd 126064 Mar 22 2006 unzip
#-rwxr-xr-x 1 dmd dmd 192404 Mar 23 2006 wget
#---code here---
if [ -e "Update Addons.command" ]
then
echo "Removing old version of Addons Updater..."
rm "Update Addons.command"
fi
if [ -e Plug-Ins/wget ]
then
echo "Removing old version of wget from Plug-Ins..."
rm Plug-Ins/wget
fi
if [ -e Plug-Ins/unzip ]
then
echo "Removing old version of unzip from Plug-Ins..."
rm Plug-Ins/unzip
fi
# Make sure we also have the right tools...
if [ -e /usr/bin/unzip ]
then
echo "Found unzip..." > /dev/null
else
echo "Your unzip binary seems to be missing. Updater cannot continue."
echo "Are you running Mac OS X 10.4 or later?"
echo "If so, please report this as a bug to the author."
echo ""
echo -n "(Press Quit)"
exit
fi
# Check for new version
echo "Checking updater version..."
newver=`"$1/Contents/Resources/wget" -o /dev/null -O - http://horizon-nigh.org/redline/ver.php`
if [ $newver ]
then
echo "Version check ok" > /dev/null
else
echo "Version check failed! :("
fi
# Create temporary data location
if [ -e /tmp/redline-addons-updater ]
then
echo "" > /dev/null # i know, i know... hey! step away from thedailywtf...
else
mkdir /tmp/redline-addons-updater
fi
# regular expression for use with sed, cuts out everything in 'ls -ln'
# except last modified and filename
sst='s/^.+[[:space:]]+[0-9]+[[:space:]]+[0-9]+[[:space:]]+[0-9]+[[:space:]]+[0-9]+[[:space:]]+|total.+//g'
# Write current directory listing to temp file 1
ls -ln Plug-Ins | sed -E $sst > /tmp/redline-addons-updater/ls1
echo "---"
# Get from the web:
# recursively,
# only to one level,
# only if a newer version exists,
# no creating directories locally,
# in the folder "Plug-Ins",
# trying 3 times (if necessary),
# using FTP passive mode (for people behind firewalls),
# leaving a .listing file (just in case),
# everything at this FTP URL.
"$1/Contents/Resources/wget" -r -l 1 -N -nd -P Plug-Ins -t 3 --passive-ftp -nr --progress=dot:mega ftp://ftp.ambrosiasw.com/pub/redline/cars/ ftp://ftp.ambrosiasw.com/pub/redline/tracks/
# Write current directory listing to temp file 1 and a half ;P
ls -ln Plug-Ins | sed -E $sst > /tmp/redline-addons-updater/ls1.5
echo "---"
# Look at every zip file that was just downloaded,
# and unzip them,
# overwriting existing files,
# without creating any directories,
# without printing anything to terminal,
# to the folder "Plug-Ins".
#for file in `diff /tmp/redline-addons-updater/ls1 /tmp/redline-addons-updater/ls1.5 | grep \> | cut -c17-999 | egrep .zip$`
#do
# echo "Unzipping $file ..."
# /usr/bin/unzip -o -j -qq "Plug-Ins/$file" -d Plug-Ins
#done
# the above method breaks for filenames with spaces in them...
# Compare changes before and after downloading,
# Get only the filenames from that,
# Get only lines ending in .zip from that,
# And tell perl:
# for each line, call 'unzip',
# overwriting existing files,
# without creating any directories,
# without printing anything to terminal,
# to the folder "Plug-Ins".
diff /tmp/redline-addons-updater/ls1 /tmp/redline-addons-updater/ls1.5 | grep \> | cut -c16-999 | egrep .zip$ | perl -ln -e 'print "Unzipping ".$_."...\n"; system("unzip","-o","-j","-qq","Plug-Ins/".$_,"-d","Plug-Ins")'
# at this point you're wondering, well why didn't you just do the
# whole damn thing in perl or something else? well... I only just
# discovered Platypus :)
# Write current directory listing to temp file 2
ls -ln Plug-Ins | sed -E $sst > /tmp/redline-addons-updater/ls2
# Compare the two temp files, and count the differences
nummod=`diff /tmp/redline-addons-updater/ls1 /tmp/redline-addons-updater/ls2 | grep \> | wc -l | tr -s " "`
echo "---"
echo "Updated $nummod files."
# If there were changes made, display them
if [ $nummod -gt 0 ]
then
diff /tmp/redline-addons-updater/ls1 /tmp/redline-addons-updater/ls2 | grep \>
fi
# If there were changes made to bin/hqx/dmg files, display a warning
if [ `diff /tmp/redline-addons-updater/ls1 /tmp/redline-addons-updater/ls2 | grep \> | egrep \(.bin\|.hqx\|.dmg\|.sit\|.sitx\) | wc -l | tr -s " "` -gt 0 ]
then
echo ""
echo "WARNING: The updater cannot decompress bin/hqx/dmg/sit/sitx files."
echo "You should visit your Plug-Ins folder and do those manually."
fi
# Remove temporary files
rm -r /tmp/redline-addons-updater
# New version notification
if [ $newver ]
then
if [ $newver -gt $ver ]
then
echo "---"
echo "Hey, there's a new version of Addons Updater available!"
echo "Opening your web browser..."
sleep 2
open "http://horizon-nigh.org/redline"
fi
fi
echo "---"
echo "All done!"
echo ""
echo -n "(Press Quit)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment