2012-06-19 01:35:38 +04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# usage: just run this script (after having run build.sh)
|
|
|
|
# and deploy the created tarball to your target machine.
|
|
|
|
#
|
|
|
|
# It creates a phantomjs-$version folder and copies the binary,
|
|
|
|
# example, license etc. together with all shared library dependencies
|
|
|
|
# to that folder. Furthermore brandelf is used to make the lib
|
|
|
|
# and binary compatible with older unix/linux machines that don't
|
|
|
|
# know the new Linux ELF ABI.
|
|
|
|
#
|
|
|
|
|
|
|
|
cd $(dirname $0)
|
|
|
|
|
|
|
|
if [[ ! -f ../bin/phantomjs ]]; then
|
|
|
|
echo "phantomjs was not built yet, please run build.sh first"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-07-09 04:42:15 +04:00
|
|
|
if [[ "$1" = "--bundle-libs" ]]; then
|
|
|
|
bundle_libs=1
|
|
|
|
else
|
|
|
|
bundle_libs=0
|
|
|
|
fi
|
|
|
|
|
2012-06-19 01:35:38 +04:00
|
|
|
version=$(../bin/phantomjs --version | sed 's/ /-/' | sed 's/[()]//g')
|
|
|
|
src=..
|
|
|
|
|
|
|
|
echo "packaging phantomjs $version"
|
|
|
|
|
|
|
|
if [[ $OSTYPE = darwin* ]]; then
|
2012-07-07 19:15:17 +04:00
|
|
|
dest="phantomjs-$version-macosx"
|
2012-06-19 01:35:38 +04:00
|
|
|
else
|
2012-07-07 19:15:17 +04:00
|
|
|
dest="phantomjs-$version-linux-$(uname -m)"
|
2012-06-19 01:35:38 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -Rf $dest{.tar.bz2,} &> /dev/null
|
|
|
|
mkdir -p $dest/bin
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
echo -n "copying files..."
|
|
|
|
cp $src/bin/phantomjs $dest/bin
|
2012-08-19 11:49:55 +04:00
|
|
|
cp -r $src/{ChangeLog,examples,LICENSE.BSD,third-party.txt,README.md} $dest/
|
2012-06-19 01:35:38 +04:00
|
|
|
echo "done"
|
|
|
|
echo
|
|
|
|
|
2012-07-09 04:42:15 +04:00
|
|
|
phantomjs=$dest/bin/phantomjs
|
|
|
|
|
2012-07-07 19:15:17 +04:00
|
|
|
if [[ "$bundle_libs" = "1" ]]; then
|
|
|
|
mkdir -p $dest/lib
|
2012-07-09 04:42:15 +04:00
|
|
|
|
2012-07-07 19:15:17 +04:00
|
|
|
if [[ ! -f brandelf ]]; then
|
|
|
|
echo
|
|
|
|
echo "brandelf executable not found in current dir"
|
|
|
|
echo -n "compiling it now..."
|
|
|
|
g++ brandelf.c -o brandelf || exit 1
|
|
|
|
echo "done"
|
2012-07-09 04:42:15 +04:00
|
|
|
fi
|
|
|
|
|
2012-07-07 19:15:17 +04:00
|
|
|
libs=$(ldd $phantomjs | egrep -o "/[^ ]+ ")
|
|
|
|
|
2012-06-19 01:35:38 +04:00
|
|
|
echo -n "copying shared libs..."
|
|
|
|
libld=
|
2012-07-09 04:42:15 +04:00
|
|
|
for l in $libs; do
|
|
|
|
ll=$(basename $l)
|
|
|
|
cp $l $dest/lib/$ll
|
|
|
|
|
|
|
|
if [[ "$bundle_libs" = "1" ]]; then
|
2012-06-19 01:35:38 +04:00
|
|
|
# ensure OS ABI compatibility
|
|
|
|
./brandelf -t SVR4 $dest/lib/$ll
|
|
|
|
if [[ "$l" == *"ld-linux"* ]]; then
|
|
|
|
libld=$ll
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "done"
|
|
|
|
echo
|
2012-07-09 04:42:15 +04:00
|
|
|
|
2012-07-07 19:15:17 +04:00
|
|
|
echo -n "writing run script..."
|
|
|
|
mv $phantomjs $phantomjs.bin
|
|
|
|
phantomjs=$phantomjs.bin
|
|
|
|
run=$dest/bin/phantomjs
|
|
|
|
echo '#!/bin/sh' >> $run
|
|
|
|
echo 'path=$(dirname $(dirname $(readlink -f $0)))' >> $run
|
|
|
|
echo 'export LD_LIBRARY_PATH=$path/lib' >> $run
|
|
|
|
echo 'exec $path/lib/'$libld' $phantomjs $@' >> $run
|
|
|
|
chmod +x $run
|
|
|
|
echo "done"
|
|
|
|
echo
|
2012-06-19 01:35:38 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo -n "stripping binary and libs..."
|
|
|
|
if [[ $OSTYPE = darwin* ]]; then
|
2012-07-09 04:42:15 +04:00
|
|
|
strip -x $phantomjs
|
2012-06-19 01:35:38 +04:00
|
|
|
else
|
2012-07-07 19:15:17 +04:00
|
|
|
strip -s $phantomjs
|
|
|
|
[[ -d $dest/lib ]] && strip -s $dest/lib/*
|
2012-06-19 01:35:38 +04:00
|
|
|
fi
|
|
|
|
echo "done"
|
|
|
|
echo
|
|
|
|
|
2012-07-07 19:15:17 +04:00
|
|
|
echo -n "compressing binary..."
|
|
|
|
if [[ ! -z upx ]]; then
|
|
|
|
upx -qqq -9 $phantomjs
|
|
|
|
echo "done"
|
|
|
|
else
|
|
|
|
echo "upx not found"
|
2012-06-19 01:35:38 +04:00
|
|
|
fi
|
2012-07-07 19:15:17 +04:00
|
|
|
echo
|
2012-06-19 01:35:38 +04:00
|
|
|
|
2012-06-29 17:54:39 +04:00
|
|
|
echo -n "creating archive..."
|
2012-07-09 04:42:15 +04:00
|
|
|
if [[ $OSTYPE = darwin* ]]; then
|
2012-06-29 17:54:39 +04:00
|
|
|
zip -r $dest.zip $dest
|
|
|
|
else
|
|
|
|
tar -cjf $dest{.tar.bz2,}
|
|
|
|
fi
|
2012-06-19 01:35:38 +04:00
|
|
|
echo "done"
|
|
|
|
echo
|