File: package.sh

package info (click to toggle)
phantomjs 2.1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 9,268 kB
  • ctags: 7,827
  • sloc: cpp: 6,363; ansic: 4,601; java: 2,041; python: 1,244; sh: 395; ruby: 48; cs: 27; xml: 14; makefile: 12
file content (120 lines) | stat: -rwxr-xr-x 2,732 bytes parent folder | download | duplicates (2)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env 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

if [[ "$1" = "--bundle-libs" ]]; then
    bundle_libs=1
else
    bundle_libs=0
fi

version=$(../bin/phantomjs --version | sed 's/ /-/' | sed 's/[()]//g')
src=..

echo "packaging phantomjs $version"

if [[ $OSTYPE = darwin* ]]; then
    dest="phantomjs-$version-macosx"
else
    dest="phantomjs-$version-linux-$(uname -m)"
fi

rm -Rf $dest{.tar.bz2,} &> /dev/null
mkdir -p $dest/bin

echo

echo -n "copying files..."
cp $src/bin/phantomjs $dest/bin
cp -r $src/{ChangeLog,examples,LICENSE.BSD,third-party.txt,README.md} $dest/
echo "done"
echo

phantomjs=$dest/bin/phantomjs

if [[ "$bundle_libs" = "1" ]]; then
    mkdir -p $dest/lib

    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"
    fi

    libs=$(ldd $phantomjs | egrep -o "/[^ ]+ ")

    echo -n "copying shared libs..."
    libld=
    for l in $libs; do
        ll=$(basename $l)
        cp $l $dest/lib/$ll

        if [[ "$bundle_libs" = "1" ]]; then
            # ensure OS ABI compatibility
            ./brandelf -t SVR4 $dest/lib/$ll
            if [[ "$l" == *"ld-linux"* ]]; then
                libld=$ll
            fi
        fi
    done
    echo "done"
    echo

    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
fi

echo -n "stripping binary and libs..."
if [[ $OSTYPE = darwin* ]]; then
    strip -x $phantomjs
else
    strip -s $phantomjs
    [[ -d $dest/lib ]] && strip -s $dest/lib/*
fi
echo "done"
echo

echo -n "compressing binary..."
if type upx >/dev/null 2>&1; then
    upx -qqq -9 $phantomjs
    echo "done"
else
    echo "upx not found"
fi
echo

echo -n "creating archive..."
if [[ $OSTYPE = darwin* ]]; then
    zip -r $dest.zip $dest
else
    tar -cjf $dest{.tar.bz2,}
fi
echo "done"
echo