public
Created

Download and install imagemagick plus configure automator app for converting PDFs to PNGs

  • Download Gist
os-x-ghostscript-imagemagick
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#!/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"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.