Skip to content

Instantly share code, notes, and snippets.

@maxheadroom
Created October 27, 2013 13:40
Show Gist options
  • Select an option

  • Save maxheadroom/7182242 to your computer and use it in GitHub Desktop.

Select an option

Save maxheadroom/7182242 to your computer and use it in GitHub Desktop.
A simple shell script to mount a SparkleShare DiskImage on a Mac and start the SparkleShare application
#!/bin/bash -x
# Precondition:
# SparkleShare folder is located into a Mac Sparse Bundle that
# must be mounted before SparkleShare is started
# the user who runs this script needs to get permissions to
# to delete a directory in /Volumes. Therefore sudo is used
# entry in /etc/sudoers:
# %users ALL=(All) NOPASSWD:/bin/rm -rf /Volumes/Sparkle
# where is your SparkleBundle located?
BUNDLE="${HOME}/Documents/SparkleBundle.sparsebundle/"
# check whether the SparkleBundle is actually a directory
if [ ! -d $BUNDLE ];then
echo "Cant't find SparkleShare Bundle at $BUNDLE"
exit 1
fi
# a function to start SparkleShare if it's not started yet
function start_sparkle {
ps -ef | grep -v grep | grep SparkleShare.app
if [ $? -eq 0 ]; then
echo "SparkleShare already running"
else
echo "Starting SparkleShare"
open /Applications/SparkleShare.app
fi
}
# check whether SparkleBundle is already mounted
mount | grep Sparkle
if [ $? -eq 0 ]; then
MOUNTPOINT=`mount | grep Sparkle | sed 's/.*on \(.*\) (\(.*\)/\1/'`
DEVICE=`hdiutil info | grep /Volumes/Sparkle | awk '{print $1}'`
if [ "$MOUNTPOINT" = "/Volumes/Sparkle" ]; then
echo "OK, Sparkle correct mounted"
start_sparkle
else
echo "Sparkle mounted on wrong dir. Remounting"
hdiutil detach $DEVICE
if [ $? -eq 0 ];then
sudo /bin/rm -rf /Volumes/Sparkle
hdiutil attach $BUNDLE
start_sparkle
else
echo "Unmount not successful! Giving up"
exit 1
fi
fi
else
# Sparkle not yet mounted
if [ -d /Volumes/Sparkle ]; then
sudo /bin/rm -rf /Volumes/Sparkle
hdiutil attach $BUNDLE
start_sparkle
else
hdiutil attach $BUNDLE
start_sparkle
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment