Codesign a Script bundle with embedded ImageMagick


#1

Hi,

I want to include ImageMagick in my Script, so that the script works out of the box on a fresh Mac. The problem is, that including the binary distribution doesn’t get through Gatekeeper. I already tried to sign the binaries and dylibs from ImageMagick manually (Terminal: codesign -s). It does not help. Strange is, that the auto-sign from Script Debugger will remove signatures from the files Magick++-config, MagickCore-config and MagickWand-config

The Console App gives me an Xprotect Error:
{RESOURCESFOLDER}/ImageMagick-7.0.7/bin/magick failed on loadCmd /ImageMagick-7.0.7/lib/libMagickCore-7.Q16HDRI.5.dylib

It seems there’s an absolute path in ImageMagick.

I already tried to build a standalone ImageMagick. There I get a similar message in console where there seems to be a hardcoded path to my temporary build directory.

Thanks in advance for any advices. I’m no coder, I don’t really know what I’m doing. :wink: I just want to share my script (not public).


(Shane Stanley) #2

Where in the bundle are you storing ImageMagic?


#3

IIt’s a subfolder in the resources folder .


(Shane Stanley) #4

I assume it’s unsigned when you put it there. You might try putting it in the MacOS directory. The docs say:

Typically, this directory contains only one binary file with your application’s main entry point and statically linked code. However, you may put other standalone executables (such as command-line tools) in this directory as well.


#5

Thanks for your help. Your tip and a custom build of ImageMagick seems to work.

I use this script to create compile a standalone ImageMagick:

#!/usr/bin/env bash
### based on: http://blog.schdbr.de/imagemagic-osx-static-relocatable-build/

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

COL='\033[1;31m\n'
RST='\033[0m\n'
IMBUILD=/tmp/imbuild
IMDOWNLOAD=/tmp/imdownload
rm -rf $IMBUILD
mkdir $IMBUILD
cd $IMBUILD
export PATH="$IMBUILD/bin:$PATH"
export MAKEFLAGS="-j"

# get IM (Version 7 at the moment)
mkdir $IMDOWNLOAD
if [ ! -f $IMDOWNLOAD/ImageMagick.tar.gz ]; then
	curl http://www.imagemagick.org/download/ImageMagick.tar.gz -o $IMDOWNLOAD/ImageMagick.tar.gz
fi
mkdir $IMBUILD/ImageMagick && tar zxf $IMDOWNLOAD/ImageM*.gz -C ImageMagick --strip 1 && cd ImageMagick

### GET AND COMPILE DELEGATES

echo -e "${COL}### PKG-CONFIG${RST}"
if [ ! -f $IMDOWNLOAD/pkg-config.tar.gz ]; then
	curl https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz -o $IMDOWNLOAD/pkg-config.tar.gz
fi
mkdir pkg-config && tar zxf $IMDOWNLOAD/pkg-config*.gz -C pkg-config --strip 1 && cd pkg-config
export LDFLAGS="-framework CoreFoundation"
export PKG_CONFIG_PATH=$IMBUILD/lib/pkgconfig
./configure --disable-shared --disable-dependency-tracking --with-internal-glib --prefix=$IMBUILD
make && make check
make install
cd ..

echo -e "${COL}### LCMS${RST}"
if [ ! -f $IMDOWNLOAD/lcms.tar.gz ]; then
	curl http://www.imagemagick.org/download/delegates/lcms2-2.8.tar.gz -o $IMDOWNLOAD/lcms.tar.gz
fi
mkdir lcms && tar zxf $IMDOWNLOAD/lcms*.gz -C lcms --strip 1 && cd lcms
./configure --disable-shared --disable-dependency-tracking --prefix=$IMBUILD
make && make check
make install
cd ..

echo -e "${COL}### ZLIB${RST}"
if [ ! -f $IMDOWNLOAD/zlib.tar.gz ]; then
	curl http://www.imagemagick.org/download/delegates/zlib-1.2.11.tar.gz -o $IMDOWNLOAD/zlib.tar.gz
fi
mkdir zlib && tar zxf $IMDOWNLOAD/zlib*.gz -C zlib --strip 1 && cd zlib
#./configure --disable-shared --disable-dependency-tracking --prefix=$IMBUILD
./configure --static --prefix=$IMBUILD
make && make check
make install
cd ..

echo -e "${COL}### JPEG${RST}"
if [ ! -f $IMDOWNLOAD/jpeg.tar.gz ]; then
	curl http://www.imagemagick.org/download/delegates/jpegsrc.v9b.tar.gz -o $IMDOWNLOAD/jpeg.tar.gz
fi
mkdir jpeg && tar zxf $IMDOWNLOAD/jpeg*.gz -C jpeg --strip 1 && cd jpeg
./configure --disable-shared --disable-dependency-tracking --prefix=$IMBUILD
make && make check
make install
cd ..

echo -e "${COL}### PNG${RST}"
if [ ! -f $IMDOWNLOAD/libpng.tar.gz ]; then
	curl http://www.imagemagick.org/download/delegates/libpng-1.6.31.tar.gz -o $IMDOWNLOAD/libpng.tar.gz
fi
mkdir png && tar zxf $IMDOWNLOAD/libpng*.gz -C png --strip 1 && cd png
./configure --disable-shared --disable-dependency-tracking --prefix=$IMBUILD
make && make check
make install
cd ..

echo -e "${COL}### FREETYPE${RST}"
if [ ! -f $IMDOWNLOAD/freetype.tar.gz ]; then
	curl http://www.imagemagick.org/download/delegates/freetype-2.8.1.tar.gz -o $IMDOWNLOAD/freetype.tar.gz
fi
mkdir freetype && tar zxf $IMDOWNLOAD/freetype*.gz -C freetype --strip 1 && cd freetype
./configure --disable-shared --disable-dependency-tracking --prefix=$IMBUILD
make && make check
make install
cd ..

echo -e "${COL}### TIFF${RST}"
if [ ! -f $IMDOWNLOAD/tiff.tar.gz ]; then
	curl https://www.imagemagick.org/download/delegates/tiff-4.0.8.tar.gz -o $IMDOWNLOAD/tiff.tar.gz
fi
mkdir tiff && tar zxf $IMDOWNLOAD/tiff*.gz -C tiff --strip 1 && cd tiff
./configure --disable-shared --disable-dependency-tracking --disable-lzma --prefix=$IMBUILD
make && make check
make install
cd ..

### COMPILE IMAGEMAGICK

echo -e "${COL}### IMAGEMAGICK${RST}"
pwd
./configure --prefix=$IMBUILD --disable-shared --disable-dependency-tracking --enable-delegate-build --disable-installed --without-frozenpaths --with-zlib --with-lcms --with-freetype --with-jpeg --with-png --with-tiff -enable-zero-configuration --without-x --without-fontconfig --without-magick-plus-plus --without-perl --enable-reproducible-build --without-lzma 

make && make check
make install

codesign -s LT5T7AJDUK $IMBUILD/bin/magick

afplay /System/Library/Sounds/Glass.aiff

open $IMBUILD/bin