Skip to content

Instantly share code, notes, and snippets.

@jaygooby
Last active March 9, 2018 16:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaygooby/1248106 to your computer and use it in GitHub Desktop.
Save jaygooby/1248106 to your computer and use it in GitHub Desktop.
Download and install imagemagick plus configure automator app for converting PDFs to PNGs
#!/usr/bin/env bash
# Install using:
# bash < <(curl -s https://raw.github.com/gist/1248106)
IM_URL=http://www.imagemagick.org/download/binaries/ImageMagick-x86_64-apple-darwin11.1.0.tar.gz
IM_TMP_FILE=/tmp/$(basename $IM_URL)
GS_URL=http://pages.uoregon.edu/koch/Ghostscript-8.71.pkg.zip
GS_TMP_FILE=/tmp/$(basename $GS_URL)
GS_TMP_PKG=/tmp/$(basename -s .zip $GS_TMP_FILE)
function continue_or_exit {
read go < /dev/tty
if [[ ! $go =~ [gG][oO] ]]; then
if [[ $go =~ [Ee][Xx][Ii][Tt] ]]; then
exit 0
else
echo -e "Type \033[1m\033[35mgo\033[0m to continue or \033[1m\033[35mexit\033[0m to quit"
continue_or_exit
fi
fi
}
# got curl?
DOWNLOAD=`which curl`
if [ $? == 0 ]
then
echo "got curl"
OPTIONS=" -o "
else
echo "trying wget"
# got wget?
DOWNLOAD=`which wget`
if [ $? == 0 ]
then
echo "got wget"
OPTIONS=" -O "
else
echo "Giving up. You need to install curl or wget"
exit 1
fi
fi
# be idempotent
if [[ ! $(sum $GS_TMP_FILE) == '34584 88352 /tmp/Ghostscript-8.71.pkg.zip' ]]; then
echo "Downloading ${GS_URL}"
$($DOWNLOAD $OPTIONS $GS_TMP_FILE $GS_URL)
fi
# if we get a 1 from $? then the download failed or timed out
if [ $? == 0 ]
then
unzip $GS_TMP_FILE -d /tmp/
echo "Ghost script downloaded. I'll open a window for you to install it. Come back here once you're done."
$(open $GS_TMP_PKG)
echo -e "Once you've completed the ghostscript install type \033[1m\033[35mgo\033[0m and then press return to continue"
echo -n "::: "
continue_or_exit
else
echo "${GS_URL} download failed or timed out. Please try again"
exit 1;
fi
if [[ ! $(sum $IM_TMP_FILE) == '17246 30119 /tmp/ImageMagick-x86_64-apple-darwin11.1.0.tar.gz' ]]; then
echo "Downloading ${IM_URL}"
$($DOWNLOAD $OPTIONS $IM_TMP_FILE $IM_URL)
fi
# if we get a 1 from $? then the download failed or timed out
if [ $? == 0 ]
then
cd $HOME
tar -zxvf $IM_TMP_FILE
echo 'export MAGICK_HOME="$HOME/ImageMagick-6.7.2"' >> ~/.bash_profile
echo 'export PATH="$MAGICK_HOME/bin:$PATH"' >> ~/.bash_profile
echo 'export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"' >> ~/.bash_profile
else
echo "${IM_URL} download failed or timed out. Please try again"
exit 1
fi
echo "OK, you're all set with Ghostscript and Imagemagick"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment