Last active
March 9, 2018 16:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Install using: | |
# bash < <(curl -s https://gist.githubusercontent.com/jaygooby/1248106/raw/6d8ef1c0c84a47a34a6890973c8d32d22466a736/os-x-ghostscript-imagemagick) | |
IM_TGZ=ImageMagick-x86_64-apple-darwin17.3.0.tar.gz | |
IM_URL=https://www.imagemagick.org/download/binaries/$IM_TGZ | |
IM_TMP_FILE=/tmp/$(basename $IM_URL) | |
IM_SUM="33849 17409" | |
GS_URL=http://pages.uoregon.edu/koch/Ghostscript-9.22.pkg | |
GS_TMP_FILE=/tmp/$(basename $GS_URL) | |
GS_SUM="11670 22743" | |
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) == "$GS_SUM $GS_TMP_FILE" ]]; 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 | |
echo "Ghost script downloaded. I'll open a window for you to install it. Come back here once you're done." | |
$(open $GS_TMP_FILE) | |
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) == "$IM_SUM /tmp/$IM_TGZ" ]]; 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 -s,ImageMagick-7.0.7/,.ImageMagick-7.0.7/, | |
echo 'export MAGICK_HOME="$HOME/.ImageMagick-7.0.7"' >> ~/.bash_profile | |
echo 'export PATH="$MAGICK_HOME/bin:$PATH"' >> ~/.bash_profile | |
echo 'export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"' >> ~/.bash_profile | |
export MAGICK_HOME="$HOME/.ImageMagick-7.0.7" | |
export PATH="$MAGICK_HOME/bin:$PATH" | |
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/" | |
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" | |
echo "Now we'll check whether we can run them..." | |
convert --version | |
if [ $? == 0 ]; then | |
echo "Imagemagick looks good" | |
else | |
echo "There's a problem with ImageMagick" | |
fi | |
gs --version | |
if [ $? == 0 ]; then | |
echo "ghostscript looks good" | |
else | |
echo "There's a problem with ghostscript" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment