Restoring previous Perl library in El Capitan
Because I need an historic Perl 5.10 library for a program I use (GPSPhotoLinker), after upgrading to El Capitan I wanted to recover the old libraries in /System/Library/Perl/5.10 from Time Machine.
Unlike the previous times I did this, Time Machine refused.
So I restored the folder elsewhere and was in for a surprise.
$ sudo mv 5.10 /System/Library/Perl
mv: rename 5.10 to /System/Library/Perl/5.10: Operation not permitted
Hmmm, that's not supposed to happen. A bit of googling revealed the cause.
$ ls -lO /System/Library/Perl/
total 0
drwxr-xr-x 130 root wheel restricted 4420 23 Aug 02:09 5.16/
drwxr-xr-x 130 root wheel restricted 4420 23 Aug 02:08 5.18/
drwxr-xr-x 4 root wheel restricted 136 23 Aug 05:49 Extras/
There's a new restricted flag at work that's not documented in chflags(1).
Some more googling produced the video that explains it all, including how to disable the system integrity protection from Recovery as a developer.
Rather than jumping through all the hoops of installing perl in the expected location only to lose it again after the next OS upgrade, I decided to copy perl into the application bundle instead.
Playing with otool(1) and install_name_tool(1) let me change the binary's search path, but as soon as the perl code attempted to load a library it failed. In the end my solution was to create a small wrapper script to set PERL5LIB and DYLD_LIBRARY_PATH to the perl embedded into the application bundle.
$ cd /Applications/GPSPhotoLinker.app/Contents/MacOS
$ mv GPSPhotoLinker GPSPhotoLinker.bin
$ cat >GPSPhotoLinker <<EOF
#!/bin/sh
PERL5LIB=${PERL5LIB}:${0%/*}/../Perl/5.10 \
DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:${0%/*}/../Perl/5.10/darwin-thread-multi-2level/CORE \
"${0}.bin"
EOF
$ chmod a+x GPSPhotoLinker
Comments
Post a Comment