Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automatically update WebKit via script and launchd Web Browsers
WebKit doesn't have any way to automatically update to the latest nightly build, so I put together a quick script to do so.

It has the option of automatically backing up the currently installed version of WebKit, or just removing the old version and updating to the newer version. There's also optional logging of the old WebKit build, the new WebKit build, and what time it was replaced. By creating a launchd agent, it can be run automatically every night. The script is:
#!/bin/sh
#Automatically update to the latest WebKit nightly build.
#By Zach Drayer, zach@drayer.name
#-----------------------------------------------------------------------------
#Set environment up
#-----------------------------------------------------------------------------
export LOGGING_LOCATION="$HOME"/Library/Logs/WebKitUpdate.log
export WEBKIT_BACKUP_LOCATION=""$HOME"/Documents/WebKit Backup/"
curl -LOs "http://nightly.webkit.org/index.html" 
export WEBKIT_NIGHTLY_BUILT_VERSION=`cat index.html | grep mac/WebKit-SVN | grep Download | cut -c 47-51`
if [ -d /Applications/WebKit.app ]; then
  export WEBKIT_INSTALLED_VERSION=`cat /Applications/WebKit.app/Contents/Resources/VERSION`
  if [ "$WEBKIT_NIGHTLY_BUILT_VERSION" == "$WEBKIT_INSTALLED_VERSION" ]; then
    exit
  fi
fi
export WEBKIT_TEMP_INSTALL_LOCATION="/tmp/WebKit-$WEBKIT_NIGHTLY_BUILT_VERSION-$RANDOM"
mkdir "$WEBKIT_TEMP_INSTALL_LOCATION"
cd "$WEBKIT_TEMP_INSTALL_LOCATION"
#-----------------------------------------------------------------------------
#Checks if WebKit is running or not
#-----------------------------------------------------------------------------
ps aux | grep Web >> web.txt
cat web.txt | grep WebKit >> web2.txt
WEBKIT_RUNNING=`cat web2.txt`
if [ "$WEBKIT_RUNNING" != "" ]; then
  kill -9 `cat web2.txt | sed s/"$USER"      //g | cut -c 1-5`
fi
#-----------------------------------------------------------------------------
#Back WebKit up
#-----------------------------------------------------------------------------
if [ -d /Applications/Webkit.app ]; then
  #Comment out this if/elseif block if you don't want to back WebKit up
  #Start commenting below --v
	if [ -d "$WEBKIT_BACKUP_LOCATION" ]; then
		mv /Applications/WebKit.app "$WEBKIT_BACKUP_LOCATION"WebKit-r"$WEBKIT_INSTALLED_VERSION".app
	else
		mkdir "$WEBKIT_BACKUP_LOCATION"
		mv /Applications/WebKit.app "$WEBKIT_BACKUP_LOCATION"WebKit-r"$WEBKIT_INSTALLED_VERSION".app
	fi
	curl -LOs "http://nightly.webkit.org/files/trunk/mac/WebKit-SVN-r"$WEBKIT_NIGHTLY_BUILT_VERSION".dmg"
else
  #Stop Commmenting here --^
#Also uncomment the next line if you dont back WebKit up
#	rm -rf /Applications/WebKit.app
	curl -LOs "http://nightly.webkit.org/files/trunk/mac/WebKit-SVN-r"$WEBKIT_NIGHTLY_BUILT_VERSION".dmg"
fi
#-----------------------------------------------------------------------------
#Install WebKit
#-----------------------------------------------------------------------------
hdiutil attach -quiet "$WEBKIT_TEMP_INSTALL_LOCATION"/WebKit-SVN-r"$WEBKIT_NIGHTLY_BUILT_VERSION".dmg
cp -R /Volumes/WebKit/WebKit.app /Applications/
hdiutil detach -quiet /Volumes/WebKit
rm -rf "$WEBKIT_TEMP_INSTALL_LOCATION"
#-----------------------------------------------------------------------------
#Logging
##Comment this block out if you dont want a log of 
#-----------------------------------------------------------------------------
echo "WebKit build " $WEBKIT_NIGHTLY_BUILT_VERSION " replaced build " $WEBKIT_INSTALLED_VERSION " on " `date` 
>> $HOME/Library/Logs/WebKitUpdate.log
A sample plist for a launchd agent looks like this: Alternately, you can download the script here, and the plist here.

[robg adds: This script worked as described, though I didn't test the launchd agent. Depending on your connection speed, it may take a few minutes to run, so give it time.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[14,841 views]  

Automatically update WebKit via script and launchd | 9 comments | Create New Account
Click here to return to the 'Automatically update WebKit via script and launchd' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically update WebKit via script and launchd
Authored by: narf_tm on Apr 15, '08 07:41:07AM
There is also NightShift

[ Reply to This | # ]
Automatically update WebKit via script and launchd
Authored by: BrentT on Apr 15, '08 10:16:40AM

I haven't been able to get NightShift to work. It is unable to find the nightly build.



[ Reply to This | # ]
Automatically update WebKit via script and launchd
Authored by: ishanb on Apr 16, '08 01:58:15PM
Nightshift works fine, but you have to update the old url that's in the app to ""http://nightly.webkit.org/builds/latest/mac"; (without the quotation marks).

[ Reply to This | # ]
Automatically update WebKit via script and launchd
Authored by: derekschrock on Apr 15, '08 09:25:00PM
I use my own script do this:

http://www.lifeofadishwasher.com/thirdphase/

Also works with anything else that has a static URL.

[ Reply to This | # ]
Automatically update WebKit via script and launchd
Authored by: davidbk1 on Apr 15, '08 08:22:44AM

You could trim the terminate WebKit part and remove the need for a text file by using killall instead.



[ Reply to This | # ]
Change the first line of the plist
Authored by: noah on Apr 16, '08 09:44:47AM
You'll need to make the first line for the launchd plist something like:
<?xml version="1.0" encoding="UTF-8"?>
To make it truly valid so tools like plutil don't complain. Also, note that the inline launchd plist is different than the downloadable one, as they call different arguments, so be sure to inspect them first for what's appropriate.

[ Reply to This | # ]
Automatically update WebKit via script and launchd
Authored by: koen on Apr 18, '08 03:58:32PM

Where do I store these files?



[ Reply to This | # ]
Automatically update WebKit via script and launchd
Authored by: alextm on Jul 15, '08 10:47:59PM
This script was broken when i went to try to run it today. (I dont update very often, I do it manually when i remember) so i decided to try to fix it.

Sometime inbetween today and last time i ran the script the site changed and broke the script. to fix it just change

WEBKIT_NIGHTLY_BUILT_VERSION=`cat \
index.html | grep mac/WebKit-SVN | grep Download | cut -c 47-51`
to
WEBKIT_NIGHTLY_BUILT_VERSION=`cat \
index.html | grep mac/WebKit-SVN | grep Download | cut -c 79-83`


[ Reply to This | # ]
Automatically update WebKit via script and launchd
Authored by: daaku on Aug 04, '08 05:56:34PM
A simpler script:
#!/bin/sh

tmpdir=/tmp/webkit-nightly
URL=$(curl http://nightly.webkit.org/ | grep dmg | head -1 | perl -pe 's/.*(http.*dmg).*/$1/')
FILE=$(basename $URL)
mkdir -p $tmpdir &&
cd $tmpdir &&
curl $URL --remote-name &&
hdiutil attach -quiet $tmpdir/$FILE &&
mv /Applications/WebKit.app ~/.Trash/WebKit-`date +%Y-%m-%d_%H-%M-%s`.app/ &&
cp -R /Volumes/WebKit/WebKit.app /Applications/ &&
hdiutil detach -quiet /Volumes/WebKit &&
echo Installed $FILE


[ Reply to This | # ]